From 86313108d87c0319f5f105fb16efdbc7424468f8 Mon Sep 17 00:00:00 2001 From: qvaleroo Date: Fri, 26 Jan 2024 17:16:48 +0100 Subject: [PATCH] Release to download the repo from GitHub URL (#110) * feat(package)!: the repo is now a unity package (#106) * move every files in correct folder * added & rename asmdef * fix readme * Update package.json * fix: assembly definition * feat!: change the folders architecture * Create .gitignore * feat: update the readme to explain how to install * fix: remove deeplink WIP * fix(versionumber): the updateversionfrompackagejson function should not use a static path (#103) * change to a dynamic path it now use a dynamic path based on the assembly definition * fix: because the folder structure have changed * chore: upgrade version --------- Co-authored-by: Morgan - 6 Freedom <49686866+Morgan-6Freedom@users.noreply.github.com> --- .release-please-manifest.json | 2 +- README.md | 11 +- Scenario/package.json | 10 - package.json | 2 +- package/.gitignore | 97 ++++++ CHANGELOG.md => package/CHANGELOG.md | 0 ...rio Knowledge Center - Unity Workflows.url | 6 + .../CompositionEditor/CompositionEditor.cs | 0 .../Editor/DataBuilder/DataBuilder.cs | 0 .../Editor/DataBuilder/DepthMap.shader | 0 .../Editor}/EditorGUI/CustomStyle.cs | 0 .../Editor/ImageEditor/ImageEditor.cs | 0 .../Editor/ImageEditor/ImageEditorUI.cs | 0 .../Editor/Images/ImageDataClasses.cs | 0 {Scenario => package}/Editor/Images/Images.cs | 0 .../Editor/Images/ImagesUI.cs | 0 .../InpaintingEditor/InpaintingEditor.cs | 0 .../InpaintingEditor/InpaintingEditorUI.cs | 0 .../Editor/LayerEditor/ContextMenuActions.cs | 0 .../Editor/LayerEditor/LayerEditor.cs | 0 .../LayerEditor/LayerEditorRightPanel.cs | 0 {Scenario => package}/Editor/Models/Models.cs | 22 +- .../Editor/Models/ModelsUI.cs | 0 {Scenario => package}/Editor/PackageExport.cs | 0 .../Editor/PixelEditor/PixelEditor.cs | 0 .../Editor/PixelEditor/PixelEditorUI.cs | 0 .../Editor}/Plugins/APIPricing.cs | 0 .../Editor}/Plugins/ApiClient.cs | 0 .../Editor}/Plugins/CommonUtils.cs | 0 .../Editor}/Plugins/PluginSettings.cs | 41 ++- .../Plugins/RestSharp/RestSharp.Unity.asmdef | 0 .../Editor}/Plugins/RestSharp/RestSharp.dll | Bin .../Plugins/RestSharp/RestSharpException.cs | 0 .../Plugins/RestSharp/RestSharpExtensions.cs | 0 .../Editor/PromptImages/PromptImages.cs | 304 +++++++++--------- .../Editor/PromptImages/PromptImagesUI.cs | 0 .../PromptWindow/PromptBuilderWindow.cs | 0 .../Editor/PromptWindow/PromptWindow.cs | 0 .../Editor/PromptWindow/PromptWindowUI.cs | 0 .../PromptWindow/Views/ControlNetView.cs | 0 .../PromptWindow/Views/ImageSettingsView.cs | 0 .../PromptWindow/Views/NegativePromptView.cs | 0 .../Editor/PromptWindow/Views/PromptView.cs | 0 .../Editor/UpscaleEditor/UpscaleEditor.cs | 0 .../Editor/UpscaleEditor/UpscaleEditorUI.cs | 0 .../Editor/_CustomStyle/CustomStyle.cs | 0 .../Editor/_Services/BackgroundRemoval.cs | 0 .../Editor/_Services/DataCache.cs | 0 .../Editor/_Services/PromptFetcher.cs | 284 ++++++++-------- .../com.scenarioinc.scenario.editor.asmdef | 5 +- LICENSE => package/LICENSE | 0 .../Samples}/UnityEditorLayout/Scenario2D.wlt | 0 package/com.scenarioinc.scenario.asmdef | 14 + package/package.json | 21 ++ 54 files changed, 490 insertions(+), 329 deletions(-) delete mode 100644 Scenario/package.json create mode 100644 package/.gitignore rename CHANGELOG.md => package/CHANGELOG.md (100%) create mode 100644 package/Documentation/Scenario Knowledge Center - Unity Workflows.url rename {Scenario => package}/Editor/CompositionEditor/CompositionEditor.cs (100%) rename {Scenario => package}/Editor/DataBuilder/DataBuilder.cs (100%) rename {Scenario => package}/Editor/DataBuilder/DepthMap.shader (100%) rename {Scenario => package/Editor}/EditorGUI/CustomStyle.cs (100%) rename {Scenario => package}/Editor/ImageEditor/ImageEditor.cs (100%) rename {Scenario => package}/Editor/ImageEditor/ImageEditorUI.cs (100%) rename {Scenario => package}/Editor/Images/ImageDataClasses.cs (100%) rename {Scenario => package}/Editor/Images/Images.cs (100%) rename {Scenario => package}/Editor/Images/ImagesUI.cs (100%) rename {Scenario => package}/Editor/InpaintingEditor/InpaintingEditor.cs (100%) rename {Scenario => package}/Editor/InpaintingEditor/InpaintingEditorUI.cs (100%) rename {Scenario => package}/Editor/LayerEditor/ContextMenuActions.cs (100%) rename {Scenario => package}/Editor/LayerEditor/LayerEditor.cs (100%) rename {Scenario => package}/Editor/LayerEditor/LayerEditorRightPanel.cs (100%) rename {Scenario => package}/Editor/Models/Models.cs (99%) rename {Scenario => package}/Editor/Models/ModelsUI.cs (100%) rename {Scenario => package}/Editor/PackageExport.cs (100%) rename {Scenario => package}/Editor/PixelEditor/PixelEditor.cs (100%) rename {Scenario => package}/Editor/PixelEditor/PixelEditorUI.cs (100%) rename {Scenario => package/Editor}/Plugins/APIPricing.cs (100%) rename {Scenario => package/Editor}/Plugins/ApiClient.cs (100%) rename {Scenario => package/Editor}/Plugins/CommonUtils.cs (100%) rename {Scenario => package/Editor}/Plugins/PluginSettings.cs (73%) rename {Scenario => package/Editor}/Plugins/RestSharp/RestSharp.Unity.asmdef (100%) rename {Scenario => package/Editor}/Plugins/RestSharp/RestSharp.dll (100%) rename {Scenario => package/Editor}/Plugins/RestSharp/RestSharpException.cs (100%) rename {Scenario => package/Editor}/Plugins/RestSharp/RestSharpExtensions.cs (100%) rename {Scenario => package}/Editor/PromptImages/PromptImages.cs (96%) rename {Scenario => package}/Editor/PromptImages/PromptImagesUI.cs (100%) rename {Scenario => package}/Editor/PromptWindow/PromptBuilderWindow.cs (100%) rename {Scenario => package}/Editor/PromptWindow/PromptWindow.cs (100%) rename {Scenario => package}/Editor/PromptWindow/PromptWindowUI.cs (100%) rename {Scenario => package}/Editor/PromptWindow/Views/ControlNetView.cs (100%) rename {Scenario => package}/Editor/PromptWindow/Views/ImageSettingsView.cs (100%) rename {Scenario => package}/Editor/PromptWindow/Views/NegativePromptView.cs (100%) rename {Scenario => package}/Editor/PromptWindow/Views/PromptView.cs (100%) rename {Scenario => package}/Editor/UpscaleEditor/UpscaleEditor.cs (100%) rename {Scenario => package}/Editor/UpscaleEditor/UpscaleEditorUI.cs (100%) rename {Scenario => package}/Editor/_CustomStyle/CustomStyle.cs (100%) rename {Scenario => package}/Editor/_Services/BackgroundRemoval.cs (100%) rename {Scenario => package}/Editor/_Services/DataCache.cs (100%) rename {Scenario => package}/Editor/_Services/PromptFetcher.cs (97%) rename Scenario/com.scenario.editor.asmdef => package/Editor/com.scenarioinc.scenario.editor.asmdef (80%) rename LICENSE => package/LICENSE (100%) rename {Scenario => package/Samples}/UnityEditorLayout/Scenario2D.wlt (100%) create mode 100644 package/com.scenarioinc.scenario.asmdef create mode 100644 package/package.json diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4874a27..8607a62 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,5 +1,5 @@ { - ".": "0.3.0", + ".": "0.4.0", "extra-files": [ { "type": "json", diff --git a/README.md b/README.md index d95db05..74f6ad8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Untitled design](resources/social-header.png) +![Header](resources/social-header.png) # Scenario Unity Plugin @@ -16,6 +16,15 @@ With an open dialogue and shared passion for innovation, we look forward to the Learn more about Scenario on our [website](https://scenario.com/). +## Quick Install + +To import the package in Unity, +1. Open the package manager +2. Click [+] +3. Click "Add package from Git URL" +4. Copy past this link `https://github.com/scenario-labs/Scenario-Unity.git?path=/package` +5. Click "Add" + ## License Review the [license](LICENSE) for this project. diff --git a/Scenario/package.json b/Scenario/package.json deleted file mode 100644 index 0b0f30b..0000000 --- a/Scenario/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "com.scenario.editor", - "displayName": "Scenario Unity Plugin", - "version": "0.3.0", - "unity": "2022.3", - "dependencies": { - "com.unity.editorcoroutines": "1.0.0", - "com.unity.nuget.newtonsoft-json": "2.0.0" - } -} diff --git a/package.json b/package.json index 41c2246..0239eac 100644 --- a/package.json +++ b/package.json @@ -7,5 +7,5 @@ "dependencies": { "release-please": "^15.13.0" }, - "version": "0.3.0" + "version": "0.4.0" } diff --git a/package/.gitignore b/package/.gitignore new file mode 100644 index 0000000..1582fb8 --- /dev/null +++ b/package/.gitignore @@ -0,0 +1,97 @@ +# This .gitignore file should be placed at the root of your Unity project directory +# +# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore +# +/[Ll]ibrary/ +/[Tt]emp/ +/[Oo]bj/ +/[Bb]uild/ +/[Bb]uilds/ +/[Ll]ogs/ +/[Uu]ser[Ss]ettings/ +/.idea/ +/Documentation/obj/.cache/ +xdoc/ +/_site/ + +# Unity Recorder +/[Rr]ecordings/ + +# MemoryCaptures can get excessive in size. +# They also could contain extremely sensitive data +/[Mm]emoryCaptures/ + +# Asset meta data should only be ignored when the corresponding asset is also ignored +!/[Aa]ssets/**/*.meta + +# Uncomment this line if you wish to ignore the asset store tools plugin +# /[Aa]ssets/AssetStoreTools* + +# Autogenerated Jetbrains Rider plugin +/[Aa]ssets/Plugins/Editor/JetBrains* + +# Visual Studio cache directory +.vs/ +# Visual Studio Code cache directory +.vscode/ + +# Visual Studio cache directory +.vsconfig + +# Gradle cache directory +.gradle/ + +# MacOS files +.DS_Store + +# Autogenerated VS/MD/Consulo solution and project files +ExportedObj/ +.consulo/ +*.csproj +*.unityproj +*.sln +*.suo +*.tmp +*.user +*.userprefs +*.pidb +*.booproj +*.svd +*.pdb +*.mdb +*.opendb +*.VC.db + +# Unity3D generated meta files +*.pidb.meta +*.pdb.meta +*.mdb.meta + +# Unity3D generated file on crash reports +sysinfo.txt + +# Builds +*.apk +*.aab +*.unitypackage +*.unitypackage.meta + +# Crashlytics generated file +crashlytics-build.properties + +# Packed Addressables +/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* + +# Temporary auto-generated Android Assets +/[Aa]ssets/[Ss]treamingAssets/aa.meta +/[Aa]ssets/[Ss]treamingAssets/aa/* + +# ignore hidden ARCore files +/[Aa]ssets/[Ss]treamingAssets/HiddenARCore* + +#UWP certificate +*.pfx +*.pfx.meta + +#ARFoundationRemote +/ARFoundationRemoteCompanionApp \ No newline at end of file diff --git a/CHANGELOG.md b/package/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to package/CHANGELOG.md diff --git a/package/Documentation/Scenario Knowledge Center - Unity Workflows.url b/package/Documentation/Scenario Knowledge Center - Unity Workflows.url new file mode 100644 index 0000000..abb60f2 --- /dev/null +++ b/package/Documentation/Scenario Knowledge Center - Unity Workflows.url @@ -0,0 +1,6 @@ +[InternetShortcut] +URL=https://help.scenario.com/workflow-tutorials#unity-plugin +IDList= +HotKey=0 +IconFile=C:\Users\fangh\AppData\Local\Mozilla\Firefox\Profiles\3v5d162j.default-release\shortcutCache\szF4o2i34bUZPRW73S4a3w==.ico +IconIndex=0 diff --git a/Scenario/Editor/CompositionEditor/CompositionEditor.cs b/package/Editor/CompositionEditor/CompositionEditor.cs similarity index 100% rename from Scenario/Editor/CompositionEditor/CompositionEditor.cs rename to package/Editor/CompositionEditor/CompositionEditor.cs diff --git a/Scenario/Editor/DataBuilder/DataBuilder.cs b/package/Editor/DataBuilder/DataBuilder.cs similarity index 100% rename from Scenario/Editor/DataBuilder/DataBuilder.cs rename to package/Editor/DataBuilder/DataBuilder.cs diff --git a/Scenario/Editor/DataBuilder/DepthMap.shader b/package/Editor/DataBuilder/DepthMap.shader similarity index 100% rename from Scenario/Editor/DataBuilder/DepthMap.shader rename to package/Editor/DataBuilder/DepthMap.shader diff --git a/Scenario/EditorGUI/CustomStyle.cs b/package/Editor/EditorGUI/CustomStyle.cs similarity index 100% rename from Scenario/EditorGUI/CustomStyle.cs rename to package/Editor/EditorGUI/CustomStyle.cs diff --git a/Scenario/Editor/ImageEditor/ImageEditor.cs b/package/Editor/ImageEditor/ImageEditor.cs similarity index 100% rename from Scenario/Editor/ImageEditor/ImageEditor.cs rename to package/Editor/ImageEditor/ImageEditor.cs diff --git a/Scenario/Editor/ImageEditor/ImageEditorUI.cs b/package/Editor/ImageEditor/ImageEditorUI.cs similarity index 100% rename from Scenario/Editor/ImageEditor/ImageEditorUI.cs rename to package/Editor/ImageEditor/ImageEditorUI.cs diff --git a/Scenario/Editor/Images/ImageDataClasses.cs b/package/Editor/Images/ImageDataClasses.cs similarity index 100% rename from Scenario/Editor/Images/ImageDataClasses.cs rename to package/Editor/Images/ImageDataClasses.cs diff --git a/Scenario/Editor/Images/Images.cs b/package/Editor/Images/Images.cs similarity index 100% rename from Scenario/Editor/Images/Images.cs rename to package/Editor/Images/Images.cs diff --git a/Scenario/Editor/Images/ImagesUI.cs b/package/Editor/Images/ImagesUI.cs similarity index 100% rename from Scenario/Editor/Images/ImagesUI.cs rename to package/Editor/Images/ImagesUI.cs diff --git a/Scenario/Editor/InpaintingEditor/InpaintingEditor.cs b/package/Editor/InpaintingEditor/InpaintingEditor.cs similarity index 100% rename from Scenario/Editor/InpaintingEditor/InpaintingEditor.cs rename to package/Editor/InpaintingEditor/InpaintingEditor.cs diff --git a/Scenario/Editor/InpaintingEditor/InpaintingEditorUI.cs b/package/Editor/InpaintingEditor/InpaintingEditorUI.cs similarity index 100% rename from Scenario/Editor/InpaintingEditor/InpaintingEditorUI.cs rename to package/Editor/InpaintingEditor/InpaintingEditorUI.cs diff --git a/Scenario/Editor/LayerEditor/ContextMenuActions.cs b/package/Editor/LayerEditor/ContextMenuActions.cs similarity index 100% rename from Scenario/Editor/LayerEditor/ContextMenuActions.cs rename to package/Editor/LayerEditor/ContextMenuActions.cs diff --git a/Scenario/Editor/LayerEditor/LayerEditor.cs b/package/Editor/LayerEditor/LayerEditor.cs similarity index 100% rename from Scenario/Editor/LayerEditor/LayerEditor.cs rename to package/Editor/LayerEditor/LayerEditor.cs diff --git a/Scenario/Editor/LayerEditor/LayerEditorRightPanel.cs b/package/Editor/LayerEditor/LayerEditorRightPanel.cs similarity index 100% rename from Scenario/Editor/LayerEditor/LayerEditorRightPanel.cs rename to package/Editor/LayerEditor/LayerEditorRightPanel.cs diff --git a/Scenario/Editor/Models/Models.cs b/package/Editor/Models/Models.cs similarity index 99% rename from Scenario/Editor/Models/Models.cs rename to package/Editor/Models/Models.cs index c739d1b..5894047 100644 --- a/Scenario/Editor/Models/Models.cs +++ b/package/Editor/Models/Models.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Newtonsoft.Json; using UnityEditor; @@ -198,16 +198,16 @@ private static async Task FetchAllPublicModels() if (response is null) { return; } var modelsResponse = JsonConvert.DeserializeObject(response); - if (modelsResponse is null) { return; } - - foreach (var model in modelsResponse.models) - { - if (modelsPublic.Contains(model)) - { - continue; - } - - modelsPublic.Add(model); + if (modelsResponse is null) { return; } + + foreach (var model in modelsResponse.models) + { + if (modelsPublic.Contains(model)) + { + continue; + } + + modelsPublic.Add(model); } //* modelsPublic.AddRange(modelsResponse.models); diff --git a/Scenario/Editor/Models/ModelsUI.cs b/package/Editor/Models/ModelsUI.cs similarity index 100% rename from Scenario/Editor/Models/ModelsUI.cs rename to package/Editor/Models/ModelsUI.cs diff --git a/Scenario/Editor/PackageExport.cs b/package/Editor/PackageExport.cs similarity index 100% rename from Scenario/Editor/PackageExport.cs rename to package/Editor/PackageExport.cs diff --git a/Scenario/Editor/PixelEditor/PixelEditor.cs b/package/Editor/PixelEditor/PixelEditor.cs similarity index 100% rename from Scenario/Editor/PixelEditor/PixelEditor.cs rename to package/Editor/PixelEditor/PixelEditor.cs diff --git a/Scenario/Editor/PixelEditor/PixelEditorUI.cs b/package/Editor/PixelEditor/PixelEditorUI.cs similarity index 100% rename from Scenario/Editor/PixelEditor/PixelEditorUI.cs rename to package/Editor/PixelEditor/PixelEditorUI.cs diff --git a/Scenario/Plugins/APIPricing.cs b/package/Editor/Plugins/APIPricing.cs similarity index 100% rename from Scenario/Plugins/APIPricing.cs rename to package/Editor/Plugins/APIPricing.cs diff --git a/Scenario/Plugins/ApiClient.cs b/package/Editor/Plugins/ApiClient.cs similarity index 100% rename from Scenario/Plugins/ApiClient.cs rename to package/Editor/Plugins/ApiClient.cs diff --git a/Scenario/Plugins/CommonUtils.cs b/package/Editor/Plugins/CommonUtils.cs similarity index 100% rename from Scenario/Plugins/CommonUtils.cs rename to package/Editor/Plugins/CommonUtils.cs diff --git a/Scenario/Plugins/PluginSettings.cs b/package/Editor/Plugins/PluginSettings.cs similarity index 73% rename from Scenario/Plugins/PluginSettings.cs rename to package/Editor/Plugins/PluginSettings.cs index d03f7d2..9de37dd 100644 --- a/Scenario/Plugins/PluginSettings.cs +++ b/package/Editor/Plugins/PluginSettings.cs @@ -2,11 +2,13 @@ using UnityEditor; using UnityEngine; using System.IO; +using System.Linq; namespace Scenario { public class PluginSettings : EditorWindow { + private static string assemblyDefinitionFileName = "com.scenarioinc.scenario.editor"; private string apiKey; private string secretKey; private string saveFolder; @@ -18,7 +20,7 @@ public class PluginSettings : EditorWindow private readonly string[] imageFormats = { "JPEG", "PNG" }; private readonly string[] imageFormatExtensions = { "jpeg", "png" }; - private static string vnumber = ""; + private static string vnumber => GetVersionFromPackageJson(); private static string version => $"Scenario Beta Version {vnumber}"; [System.Serializable] @@ -27,14 +29,35 @@ private class PackageInfo public string version; } - [MenuItem("Scenario/Update Version")] - public static void UpdateVersionFromPackageJson() + /// + /// Get the correct version number from the package JSON + /// + /// The version of the plugin, as a string + private static string GetVersionFromPackageJson() { - string packageJsonPath = "Assets/Scenario/package.json"; - string packageJsonContent = File.ReadAllText(packageJsonPath); - vnumber = JsonUtility.FromJson(packageJsonContent).version; + //Find the assembly Definition which should be at package/Editor/ folder because it's a unique file. + string[] guids = AssetDatabase.FindAssets($"{assemblyDefinitionFileName} t:assemblydefinitionasset"); + + if (guids.Length > 1) + { + Debug.LogError($"it seems that you have multiple file '{assemblyDefinitionFileName}.asmdef'. Please delete one"); + return "0"; + } - EditorWindow.GetWindow().Repaint(); + if (guids.Length == 0) + { + Debug.LogError($"It seems that you don't have the file '{assemblyDefinitionFileName}.asmdef'. Please redownload the plugin from the asset store."); + return "0"; + } + + //find the folder of that file + string folderPath = AssetDatabase.GUIDToAssetPath(guids[0]); + folderPath = folderPath.Remove(folderPath.IndexOf($"Editor/{assemblyDefinitionFileName}.asmdef")); + + //find the package.json inside this folder + string packageJsonPath = $"{folderPath}/package.json"; + string packageJsonContent = File.ReadAllText(packageJsonPath); + return JsonUtility.FromJson(packageJsonContent).version; } public static string EncodedAuth @@ -62,7 +85,7 @@ public static void ShowWindow() private void OnEnable() { - UpdateVersionFromPackageJson(); + GetVersionFromPackageJson(); LoadSettings(); } @@ -70,7 +93,7 @@ private void OnGUI() { Color backgroundColor = new Color32(18, 18, 18, 255); EditorGUI.DrawRect(new Rect(0, 0, Screen.width, Screen.height), backgroundColor); - + GUILayout.Space(10); apiKey = EditorGUILayout.TextField("API Key", apiKey); diff --git a/Scenario/Plugins/RestSharp/RestSharp.Unity.asmdef b/package/Editor/Plugins/RestSharp/RestSharp.Unity.asmdef similarity index 100% rename from Scenario/Plugins/RestSharp/RestSharp.Unity.asmdef rename to package/Editor/Plugins/RestSharp/RestSharp.Unity.asmdef diff --git a/Scenario/Plugins/RestSharp/RestSharp.dll b/package/Editor/Plugins/RestSharp/RestSharp.dll similarity index 100% rename from Scenario/Plugins/RestSharp/RestSharp.dll rename to package/Editor/Plugins/RestSharp/RestSharp.dll diff --git a/Scenario/Plugins/RestSharp/RestSharpException.cs b/package/Editor/Plugins/RestSharp/RestSharpException.cs similarity index 100% rename from Scenario/Plugins/RestSharp/RestSharpException.cs rename to package/Editor/Plugins/RestSharp/RestSharpException.cs diff --git a/Scenario/Plugins/RestSharp/RestSharpExtensions.cs b/package/Editor/Plugins/RestSharp/RestSharpExtensions.cs similarity index 100% rename from Scenario/Plugins/RestSharp/RestSharpExtensions.cs rename to package/Editor/Plugins/RestSharp/RestSharpExtensions.cs diff --git a/Scenario/Editor/PromptImages/PromptImages.cs b/package/Editor/PromptImages/PromptImages.cs similarity index 96% rename from Scenario/Editor/PromptImages/PromptImages.cs rename to package/Editor/PromptImages/PromptImages.cs index 031f333..c7746b4 100644 --- a/Scenario/Editor/PromptImages/PromptImages.cs +++ b/package/Editor/PromptImages/PromptImages.cs @@ -1,153 +1,153 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using Newtonsoft.Json; -using RestSharp; -using Unity.EditorCoroutines.Editor; -using UnityEditor; -using UnityEngine; -using UnityEngine.Networking; - -namespace Scenario -{ - public class PromptImages : EditorWindow - { - public static PromptImagesUI promptImagesUI = new(); - public static string downloadPath; - - [MenuItem("Window/Scenario/Prompt Images")] - public static void ShowWindow() - { - UpdateImages(); - - var promptImages = (PromptImages) EditorWindow.GetWindow(typeof(PromptImages)); - - promptImagesUI.Init(promptImages); - - downloadPath = EditorPrefs.GetString("SaveFolder", "Assets"); - } - - public void DeleteImageAtIndex(int selectedTextureIndex) - { - var imgData = DataCache.instance.GetImageDataAtIndex(selectedTextureIndex); - - string imageId = imgData.Id; - string modelId = DataCache.instance.SelectedModelId; - string inferenceId = imgData.InferenceId; - EditorCoroutineUtility.StartCoroutineOwnerless(DeleteImageRequest(inferenceId, modelId, imageId)); - - Repaint(); - } - - private static async void LoadTexture(string url, Action result) - { - using UnityWebRequest www = UnityWebRequestTexture.GetTexture(url); - - www.SendWebRequest(); - - while (!www.isDone) - { - await Task.Delay(10); - } - - if (www.result != UnityWebRequest.Result.Success) - { - Debug.LogError(www.error + $"\n{url}"); - result(null); - } - - result(DownloadHandlerTexture.GetContent(www)); - } - - private void OnGUI() - { - promptImagesUI.OnGUI(this.position); - } - - private static void UpdateImages() - { - for (int i = DataCache.instance.GetImageDataCount() - 1; i >= 0; i--) - { - var imageData = DataCache.instance.GetImageDataAtIndex(i); - - if (imageData.Url != null && imageData.Url.Length > 10 && imageData.texture == null) - { - LoadTexture(imageData.Url, result => - { - imageData.texture = result; - - if (promptImagesUI != null) - { - if (promptImagesUI.promptImages != null) - { - promptImagesUI.promptImages.Repaint(); - } - } - }); - } - } - - if (promptImagesUI != null) - { - if (promptImagesUI.promptImages != null) - { - promptImagesUI.promptImages.Repaint(); - } - } - } - - IEnumerator DeleteImageRequest(string inferenceId, string modelId, string imageId) - { - Debug.Log("Requesting image deletion please wait.."); - - string url = $"{PluginSettings.ApiUrl}/models/{modelId}/inferences/{inferenceId}/images/{imageId}"; - Debug.Log(url); - - RestClient client = new RestClient(url); - RestRequest request = new RestRequest(Method.DELETE); - request.AddHeader("accept", "application/json"); - request.AddHeader("Authorization", $"Basic {PluginSettings.EncodedAuth}"); - - yield return client.ExecuteAsync(request, response => - { - if (response.ErrorException != null) - { - Debug.Log($"Error: {response.ErrorException.Message}"); - } - else - { - Debug.Log($"Response: {response.Content}"); - } - }); - } - - private void OnDestroy() - { - //ClearData(); - promptImagesUI.selectedTexture = null; - promptImagesUI.selectedImageId = null; - } - - private void OnLostFocus() - { - promptImagesUI.selectedTexture = null; - promptImagesUI.selectedImageId = null; - } - - /*private void ClearData() - { - DataCache.instance.ClearAllImageData(); - }*/ - - internal void RemoveBackground(int selectedTextureIndex) - { - BackgroundRemoval.RemoveBackground(DataCache.instance.GetImageDataAtIndex(selectedTextureIndex).texture, bytes => - { - string fileName = CommonUtils.GetRandomImageFileName(); - CommonUtils.SaveImageBytesToFile(fileName, bytes); - }); - } - } +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Newtonsoft.Json; +using RestSharp; +using Unity.EditorCoroutines.Editor; +using UnityEditor; +using UnityEngine; +using UnityEngine.Networking; + +namespace Scenario +{ + public class PromptImages : EditorWindow + { + public static PromptImagesUI promptImagesUI = new(); + public static string downloadPath; + + [MenuItem("Window/Scenario/Prompt Images")] + public static void ShowWindow() + { + UpdateImages(); + + var promptImages = (PromptImages) EditorWindow.GetWindow(typeof(PromptImages)); + + promptImagesUI.Init(promptImages); + + downloadPath = EditorPrefs.GetString("SaveFolder", "Assets"); + } + + public void DeleteImageAtIndex(int selectedTextureIndex) + { + var imgData = DataCache.instance.GetImageDataAtIndex(selectedTextureIndex); + + string imageId = imgData.Id; + string modelId = DataCache.instance.SelectedModelId; + string inferenceId = imgData.InferenceId; + EditorCoroutineUtility.StartCoroutineOwnerless(DeleteImageRequest(inferenceId, modelId, imageId)); + + Repaint(); + } + + private static async void LoadTexture(string url, Action result) + { + using UnityWebRequest www = UnityWebRequestTexture.GetTexture(url); + + www.SendWebRequest(); + + while (!www.isDone) + { + await Task.Delay(10); + } + + if (www.result != UnityWebRequest.Result.Success) + { + Debug.LogError(www.error + $"\n{url}"); + result(null); + } + + result(DownloadHandlerTexture.GetContent(www)); + } + + private void OnGUI() + { + promptImagesUI.OnGUI(this.position); + } + + private static void UpdateImages() + { + for (int i = DataCache.instance.GetImageDataCount() - 1; i >= 0; i--) + { + var imageData = DataCache.instance.GetImageDataAtIndex(i); + + if (imageData.Url != null && imageData.Url.Length > 10 && imageData.texture == null) + { + LoadTexture(imageData.Url, result => + { + imageData.texture = result; + + if (promptImagesUI != null) + { + if (promptImagesUI.promptImages != null) + { + promptImagesUI.promptImages.Repaint(); + } + } + }); + } + } + + if (promptImagesUI != null) + { + if (promptImagesUI.promptImages != null) + { + promptImagesUI.promptImages.Repaint(); + } + } + } + + IEnumerator DeleteImageRequest(string inferenceId, string modelId, string imageId) + { + Debug.Log("Requesting image deletion please wait.."); + + string url = $"{PluginSettings.ApiUrl}/models/{modelId}/inferences/{inferenceId}/images/{imageId}"; + Debug.Log(url); + + RestClient client = new RestClient(url); + RestRequest request = new RestRequest(Method.DELETE); + request.AddHeader("accept", "application/json"); + request.AddHeader("Authorization", $"Basic {PluginSettings.EncodedAuth}"); + + yield return client.ExecuteAsync(request, response => + { + if (response.ErrorException != null) + { + Debug.Log($"Error: {response.ErrorException.Message}"); + } + else + { + Debug.Log($"Response: {response.Content}"); + } + }); + } + + private void OnDestroy() + { + //ClearData(); + promptImagesUI.selectedTexture = null; + promptImagesUI.selectedImageId = null; + } + + private void OnLostFocus() + { + promptImagesUI.selectedTexture = null; + promptImagesUI.selectedImageId = null; + } + + /*private void ClearData() + { + DataCache.instance.ClearAllImageData(); + }*/ + + internal void RemoveBackground(int selectedTextureIndex) + { + BackgroundRemoval.RemoveBackground(DataCache.instance.GetImageDataAtIndex(selectedTextureIndex).texture, bytes => + { + string fileName = CommonUtils.GetRandomImageFileName(); + CommonUtils.SaveImageBytesToFile(fileName, bytes); + }); + } + } } \ No newline at end of file diff --git a/Scenario/Editor/PromptImages/PromptImagesUI.cs b/package/Editor/PromptImages/PromptImagesUI.cs similarity index 100% rename from Scenario/Editor/PromptImages/PromptImagesUI.cs rename to package/Editor/PromptImages/PromptImagesUI.cs diff --git a/Scenario/Editor/PromptWindow/PromptBuilderWindow.cs b/package/Editor/PromptWindow/PromptBuilderWindow.cs similarity index 100% rename from Scenario/Editor/PromptWindow/PromptBuilderWindow.cs rename to package/Editor/PromptWindow/PromptBuilderWindow.cs diff --git a/Scenario/Editor/PromptWindow/PromptWindow.cs b/package/Editor/PromptWindow/PromptWindow.cs similarity index 100% rename from Scenario/Editor/PromptWindow/PromptWindow.cs rename to package/Editor/PromptWindow/PromptWindow.cs diff --git a/Scenario/Editor/PromptWindow/PromptWindowUI.cs b/package/Editor/PromptWindow/PromptWindowUI.cs similarity index 100% rename from Scenario/Editor/PromptWindow/PromptWindowUI.cs rename to package/Editor/PromptWindow/PromptWindowUI.cs diff --git a/Scenario/Editor/PromptWindow/Views/ControlNetView.cs b/package/Editor/PromptWindow/Views/ControlNetView.cs similarity index 100% rename from Scenario/Editor/PromptWindow/Views/ControlNetView.cs rename to package/Editor/PromptWindow/Views/ControlNetView.cs diff --git a/Scenario/Editor/PromptWindow/Views/ImageSettingsView.cs b/package/Editor/PromptWindow/Views/ImageSettingsView.cs similarity index 100% rename from Scenario/Editor/PromptWindow/Views/ImageSettingsView.cs rename to package/Editor/PromptWindow/Views/ImageSettingsView.cs diff --git a/Scenario/Editor/PromptWindow/Views/NegativePromptView.cs b/package/Editor/PromptWindow/Views/NegativePromptView.cs similarity index 100% rename from Scenario/Editor/PromptWindow/Views/NegativePromptView.cs rename to package/Editor/PromptWindow/Views/NegativePromptView.cs diff --git a/Scenario/Editor/PromptWindow/Views/PromptView.cs b/package/Editor/PromptWindow/Views/PromptView.cs similarity index 100% rename from Scenario/Editor/PromptWindow/Views/PromptView.cs rename to package/Editor/PromptWindow/Views/PromptView.cs diff --git a/Scenario/Editor/UpscaleEditor/UpscaleEditor.cs b/package/Editor/UpscaleEditor/UpscaleEditor.cs similarity index 100% rename from Scenario/Editor/UpscaleEditor/UpscaleEditor.cs rename to package/Editor/UpscaleEditor/UpscaleEditor.cs diff --git a/Scenario/Editor/UpscaleEditor/UpscaleEditorUI.cs b/package/Editor/UpscaleEditor/UpscaleEditorUI.cs similarity index 100% rename from Scenario/Editor/UpscaleEditor/UpscaleEditorUI.cs rename to package/Editor/UpscaleEditor/UpscaleEditorUI.cs diff --git a/Scenario/Editor/_CustomStyle/CustomStyle.cs b/package/Editor/_CustomStyle/CustomStyle.cs similarity index 100% rename from Scenario/Editor/_CustomStyle/CustomStyle.cs rename to package/Editor/_CustomStyle/CustomStyle.cs diff --git a/Scenario/Editor/_Services/BackgroundRemoval.cs b/package/Editor/_Services/BackgroundRemoval.cs similarity index 100% rename from Scenario/Editor/_Services/BackgroundRemoval.cs rename to package/Editor/_Services/BackgroundRemoval.cs diff --git a/Scenario/Editor/_Services/DataCache.cs b/package/Editor/_Services/DataCache.cs similarity index 100% rename from Scenario/Editor/_Services/DataCache.cs rename to package/Editor/_Services/DataCache.cs diff --git a/Scenario/Editor/_Services/PromptFetcher.cs b/package/Editor/_Services/PromptFetcher.cs similarity index 97% rename from Scenario/Editor/_Services/PromptFetcher.cs rename to package/Editor/_Services/PromptFetcher.cs index 5dc1d17..70c0010 100644 --- a/Scenario/Editor/_Services/PromptFetcher.cs +++ b/package/Editor/_Services/PromptFetcher.cs @@ -1,143 +1,143 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Unity.EditorCoroutines.Editor; -using UnityEngine; - -namespace Scenario -{ - public class PromptFetcher - { - public static List cancelledInferences = new(); - - public static void PostInferenceRequest(string inputData, int imagesliderIntValue, - string promptinputText, float samplesliderValue, float widthSliderValue, float heightSliderValue, - float guidancesliderValue, string seedinputText) - { - Debug.Log("Requesting image generation please wait.."); - - string modelName = UnityEditor.EditorPrefs.GetString("postedModelName"); - string modelId = DataCache.instance.SelectedModelId; - - ApiClient.RestPost($"models/{modelId}/inferences", inputData,response => - { - PromptWindow.InferenceRoot inferenceRoot = JsonConvert.DeserializeObject(response.Content); - - string inferenceId = inferenceRoot.inference.id; - int numImages = imagesliderIntValue; - - DataCache.instance.ReserveSpaceForImageDatas(numImages, inferenceId, - promptinputText, - samplesliderValue, - widthSliderValue, - heightSliderValue, - guidancesliderValue, - "Default", - seedinputText); - - PromptImages.ShowWindow(); - - GetInferenceStatus(inferenceId, modelId); - }); - } - - private static async void GetInferenceStatus(string inferenceId, string modelId) - { - Debug.Log("Requesting status please wait.."); - - await Task.Delay(4000); - - if (cancelledInferences.Contains(inferenceId)) - { - DataCache.instance.RemoveInferenceData(inferenceId); - cancelledInferences.Remove(inferenceId); - return; - } - - if (DataCache.instance.GetReservedSpaceCount() <= 0) - { - return; - } - - ApiClient.RestGet($"models/{modelId}/inferences/{inferenceId}",response => - { - InferenceStatusRoot inferenceStatusRoot = JsonConvert.DeserializeObject(response.Content); - - if (inferenceStatusRoot.inference.status != "succeeded" && - inferenceStatusRoot.inference.status != "failed" ) - { - Debug.Log("Commission in process, please wait.."); - GetInferenceStatus(inferenceId, modelId); - } - else - { - if (inferenceStatusRoot.inference.status == "failed") - { - Debug.LogError("Api Response: Status == failed, Try Again.."); - return; - } - - foreach (var item in inferenceStatusRoot.inference.images) - { - /*Debug.Log("Image URL: " + item);*/ - var img = JsonConvert.DeserializeObject(item.ToString()); - DataCache.instance.FillReservedSpaceForImageData( - inferenceId, - img.Id, - img.Url, - inferenceStatusRoot.inference.createdAt); - } - - PromptImages.ShowWindow(); - } - }); - } - - public class ImageDataAPI - { - public string Id { get; set; } - public string Url { get; set; } - } - - [Serializable] - public class InferenceStatusRoot - { - public Inference inference { get; set; } - } - - [Serializable] - public class Inference - { - public string id { get; set; } - public string userId { get; set; } - public string ownerId { get; set; } - public string authorId { get; set; } - public string modelId { get; set; } - public DateTime createdAt { get; set; } - public Parameters parameters { get; set; } - public string status { get; set; } - public List images { get; set; } - public int imagesNumber { get; set; } - public string displayPrompt { get; set; } - } - - [Serializable] - public class Parameters - { - public string negativePrompt { get; set; } - public int numSamples { get; set; } - public double guidance { get; set; } - public int numInferenceSteps { get; set; } - public bool enableSafetyCheck { get; set; } - public ulong seed { get; set; } - public int width { get; set; } - public int height { get; set; } - public string type { get; set; } - public string image { get; set; } - public string prompt { get; set; } - public string mask { get; set; } - } - } +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Unity.EditorCoroutines.Editor; +using UnityEngine; + +namespace Scenario +{ + public class PromptFetcher + { + public static List cancelledInferences = new(); + + public static void PostInferenceRequest(string inputData, int imagesliderIntValue, + string promptinputText, float samplesliderValue, float widthSliderValue, float heightSliderValue, + float guidancesliderValue, string seedinputText) + { + Debug.Log("Requesting image generation please wait.."); + + string modelName = UnityEditor.EditorPrefs.GetString("postedModelName"); + string modelId = DataCache.instance.SelectedModelId; + + ApiClient.RestPost($"models/{modelId}/inferences", inputData,response => + { + PromptWindow.InferenceRoot inferenceRoot = JsonConvert.DeserializeObject(response.Content); + + string inferenceId = inferenceRoot.inference.id; + int numImages = imagesliderIntValue; + + DataCache.instance.ReserveSpaceForImageDatas(numImages, inferenceId, + promptinputText, + samplesliderValue, + widthSliderValue, + heightSliderValue, + guidancesliderValue, + "Default", + seedinputText); + + PromptImages.ShowWindow(); + + GetInferenceStatus(inferenceId, modelId); + }); + } + + private static async void GetInferenceStatus(string inferenceId, string modelId) + { + Debug.Log("Requesting status please wait.."); + + await Task.Delay(4000); + + if (cancelledInferences.Contains(inferenceId)) + { + DataCache.instance.RemoveInferenceData(inferenceId); + cancelledInferences.Remove(inferenceId); + return; + } + + if (DataCache.instance.GetReservedSpaceCount() <= 0) + { + return; + } + + ApiClient.RestGet($"models/{modelId}/inferences/{inferenceId}",response => + { + InferenceStatusRoot inferenceStatusRoot = JsonConvert.DeserializeObject(response.Content); + + if (inferenceStatusRoot.inference.status != "succeeded" && + inferenceStatusRoot.inference.status != "failed" ) + { + Debug.Log("Commission in process, please wait.."); + GetInferenceStatus(inferenceId, modelId); + } + else + { + if (inferenceStatusRoot.inference.status == "failed") + { + Debug.LogError("Api Response: Status == failed, Try Again.."); + return; + } + + foreach (var item in inferenceStatusRoot.inference.images) + { + /*Debug.Log("Image URL: " + item);*/ + var img = JsonConvert.DeserializeObject(item.ToString()); + DataCache.instance.FillReservedSpaceForImageData( + inferenceId, + img.Id, + img.Url, + inferenceStatusRoot.inference.createdAt); + } + + PromptImages.ShowWindow(); + } + }); + } + + public class ImageDataAPI + { + public string Id { get; set; } + public string Url { get; set; } + } + + [Serializable] + public class InferenceStatusRoot + { + public Inference inference { get; set; } + } + + [Serializable] + public class Inference + { + public string id { get; set; } + public string userId { get; set; } + public string ownerId { get; set; } + public string authorId { get; set; } + public string modelId { get; set; } + public DateTime createdAt { get; set; } + public Parameters parameters { get; set; } + public string status { get; set; } + public List images { get; set; } + public int imagesNumber { get; set; } + public string displayPrompt { get; set; } + } + + [Serializable] + public class Parameters + { + public string negativePrompt { get; set; } + public int numSamples { get; set; } + public double guidance { get; set; } + public int numInferenceSteps { get; set; } + public bool enableSafetyCheck { get; set; } + public ulong seed { get; set; } + public int width { get; set; } + public int height { get; set; } + public string type { get; set; } + public string image { get; set; } + public string prompt { get; set; } + public string mask { get; set; } + } + } } \ No newline at end of file diff --git a/Scenario/com.scenario.editor.asmdef b/package/Editor/com.scenarioinc.scenario.editor.asmdef similarity index 80% rename from Scenario/com.scenario.editor.asmdef rename to package/Editor/com.scenarioinc.scenario.editor.asmdef index cb7ceb0..93c8d82 100644 --- a/Scenario/com.scenario.editor.asmdef +++ b/package/Editor/com.scenarioinc.scenario.editor.asmdef @@ -1,9 +1,10 @@ { "name": "com.scenario.editor", - "rootNamespace": "Scenario", + "rootNamespace": "Scenario.Editor", "references": [ "Unity.EditorCoroutines.Editor", - "RestSharp.Unity" + "RestSharp.Unity", + "Needle.Deeplink" ], "includePlatforms": [ "Editor" diff --git a/LICENSE b/package/LICENSE similarity index 100% rename from LICENSE rename to package/LICENSE diff --git a/Scenario/UnityEditorLayout/Scenario2D.wlt b/package/Samples/UnityEditorLayout/Scenario2D.wlt similarity index 100% rename from Scenario/UnityEditorLayout/Scenario2D.wlt rename to package/Samples/UnityEditorLayout/Scenario2D.wlt diff --git a/package/com.scenarioinc.scenario.asmdef b/package/com.scenarioinc.scenario.asmdef new file mode 100644 index 0000000..36b1bc0 --- /dev/null +++ b/package/com.scenarioinc.scenario.asmdef @@ -0,0 +1,14 @@ +{ + "name": "com.scenario.scenario", + "rootNamespace": "Scenario", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/package/package.json b/package/package.json new file mode 100644 index 0000000..1677f7b --- /dev/null +++ b/package/package.json @@ -0,0 +1,21 @@ +{ + "name": "com.scenarioinc.scenario", + "displayName": "Scenario", + "description": "Craft unique and style-consistent game assets with custom-trained AI models.", + "documentationUrl": "https://help.scenario.com/", + "changelogUrl": "https://github.com/scenario-labs/Scenario-Unity/", + "licensesUrl": "https://github.com/scenario-labs/Scenario-Unity/", + "version": "0.4.0", + "unity": "2022.3", + "dependencies": { + "com.unity.editorcoroutines": "1.0.0", + "com.unity.nuget.newtonsoft-json": "2.0.0" + }, + "samples": [ + { + "displayName": "Unity Editor Layout", + "description": "Example layout for 2D workflow", + "path": "Samples/UnityEditorLayout" + } + ] +} \ No newline at end of file