diff --git a/package/Editor/Images/ImagesUI.cs b/package/Editor/Images/ImagesUI.cs
index 28ca46d..97de71a 100644
--- a/package/Editor/Images/ImagesUI.cs
+++ b/package/Editor/Images/ImagesUI.cs
@@ -183,7 +183,7 @@ private void InitializeButtons()
},
{ "Upscale Image", () => {
CommonUtils.FetchTextureFromURL(Images.GetImageDataById(selectedTextureId).Url, response => {
- UpscaleEditor.ShowWindow(response, Images.GetImageDataById(selectedTextureId));
+ UpscaleEditor.UpscaleEditor.ShowWindow(response, Images.GetImageDataById(selectedTextureId));
});
}
},
diff --git a/package/Editor/UpscaleEditor/UpscaleEditor.cs b/package/Editor/UpscaleEditor/UpscaleEditor.cs
index b5cc216..ce09b1a 100644
--- a/package/Editor/UpscaleEditor/UpscaleEditor.cs
+++ b/package/Editor/UpscaleEditor/UpscaleEditor.cs
@@ -1,18 +1,32 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using Unity.EditorCoroutines.Editor;
using UnityEditor;
using UnityEngine;
-namespace Scenario.Editor
+namespace Scenario.Editor.UpscaleEditor
{
public class UpscaleEditor : EditorWindow
{
- private static readonly float MinimumWidth = 1650f;
+ #region Public Fields
+ #endregion
+
+ #region Private Fields
+
private static readonly UpscaleEditorUI UpscaleEditorUI = new();
+ #endregion
+
+ #region MonoBehaviourCallback
+
[MenuItem("Scenario/Editors/Upscale Editor", false, 5)]
public static void ShowWindow()
{
var window = EditorWindow.GetWindow(typeof(UpscaleEditor), false, "Upscale Editor") as UpscaleEditor;
- window.minSize = new Vector2(MinimumWidth, window.minSize.y);
+ window.autoRepaintOnSceneChange = true;
+ window.minSize = new Vector2(720, 540);
}
public static void ShowWindow(Texture2D selectedTexture, ImageDataStorage.ImageData imageData)
@@ -25,11 +39,163 @@ public static void ShowWindow(Texture2D selectedTexture, ImageDataStorage.ImageD
private void OnGUI()
{
UpscaleEditorUI.OnGUI(this.position);
+ UpscaleEditorUI.UpscaleEditor = this;
}
private void OnDestroy()
{
UpscaleEditorUI.currentImage = null;
}
+
+ #endregion
+
+ #region Public Methods
+
+ ///
+ /// Trigger the coroutine to get the upscale result.
+ ///
+ ///
+ ///
+ public void LaunchProgressUpscale(string _jobId, Action _answer)
+ {
+ if (!string.IsNullOrEmpty(_jobId))
+ {
+ EditorCoroutineUtility.StartCoroutineOwnerless(GetProgressUpscale(_jobId, _answer));
+ }
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ ///
+ /// Editor Coroutine to processing upscale.
+ /// Get the progress of the job id and wait the success status.
+ ///
+ /// JobId to listen
+ /// Return the result of the content at the end of the process
+ ///
+ IEnumerator GetProgressUpscale(string _jobId, Action _response)
+ {
+ bool inProgress = true;
+
+ while (inProgress)
+ {
+ if (inProgress)
+ {
+ ApiClient.RestGet($"jobs/{_jobId}", response =>
+ {
+ var progressResponse = JsonConvert.DeserializeObject(response.Content);
+
+ if (progressResponse != null)
+ {
+ if (!string.IsNullOrEmpty(progressResponse.job.status))
+ {
+ if (!progressResponse.job.status.Equals("success"))
+ {
+ switch (progressResponse.job.status)
+ {
+ case "warming-up":
+ Debug.Log("Upscale in preparation... wait...");
+ break;
+
+ case "queued":
+ Debug.Log("Upscale in queue... wait ...");
+ break;
+
+ case "in-progress":
+ Debug.Log("Upscale in progress... wait...");
+ break;
+
+ default:
+ Debug.Log("Upscale... wait...");
+ break;
+ }
+ inProgress = true;
+ }
+ else
+ {
+ Debug.Log("Upscale progress done: " + response.Content);
+ inProgress = false;
+ _response?.Invoke(response.Content);
+ return;
+ }
+ }
+ }
+ });
+ yield return new WaitForSecondsRealtime(4);
+ }
+ else
+ {
+ yield break;
+ }
+ }
+
+ yield return null;
+ }
+
+ #endregion
+
}
+
+ #region API_DTO
+
+ ///
+ /// Asset result object
+ ///
+ public class Asset
+ {
+ public string id { get; set; }
+ public string url { get; set; }
+ public string mimeType { get; set; }
+ public Metadata metadata { get; set; }
+ public string ownerId { get; set; }
+ public string authorId { get; set; }
+ public DateTime createdAt { get; set; }
+ public DateTime updatedAt { get; set; }
+ public string privacy { get; set; }
+ public List