From 5fd1d014ecb1f3b189114f6eb77a06c24ca84d51 Mon Sep 17 00:00:00 2001 From: Yunasawa Date: Sat, 11 May 2024 01:32:15 +0700 Subject: [PATCH] Test --- .../Scripts/EditorDefineSymbols.cs | 17 +++- Editor Extensions/Scripts/EditorManifest.cs | 89 ++++++++----------- YNLEditorSetup.cs | 4 +- package.json | 2 +- 4 files changed, 55 insertions(+), 57 deletions(-) diff --git a/Editor Extensions/Scripts/EditorDefineSymbols.cs b/Editor Extensions/Scripts/EditorDefineSymbols.cs index 5d3b5aa..ce3b7e6 100644 --- a/Editor Extensions/Scripts/EditorDefineSymbols.cs +++ b/Editor Extensions/Scripts/EditorDefineSymbols.cs @@ -1,9 +1,11 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR using UnityEditor.Build; using UnityEditor; using System.Collections.Generic; using System.Linq; using System; +using UnityEngine; +using UnityEditor.VersionControl; namespace YNL.Editors.Extensions { @@ -28,6 +30,7 @@ public static void AddSymbol(string symbol) _defineSymbols.Add(symbol); PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, String.Join(";", _defineSymbols)); + NotifySymbols(symbol, true); } /// Add multiple symbols @@ -40,6 +43,7 @@ public static void AddSymbols(params string[] symbols) _defineSymbols.Add(symbol); } PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, String.Join(";", _defineSymbols)); + NotifySymbols(String.Join("; ", symbols), true); } /// Remove a single symbol @@ -50,6 +54,7 @@ public static void RemoveSymbol(string symbol) _defineSymbols.Remove(symbol); PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, String.Join(";", _defineSymbols)); + NotifySymbols(symbol, false); } /// Remove multiple symbols @@ -62,6 +67,16 @@ public static void RemoveSymbols(params string[] symbols) _defineSymbols.Add(symbol); } PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, String.Join(";", _defineSymbols)); + NotifySymbols(String.Join("; ", symbols), false); + } + + /// + /// Print a notification into Console panel. + /// + public static void NotifySymbols(string message, bool isAdded) + { + if (isAdded) Debug.Log($"▶ Notification: A new define symbol {message} is added."); + else Debug.Log($"▶ Notification: A new define symbol {message} is removed."); } } } diff --git a/Editor Extensions/Scripts/EditorManifest.cs b/Editor Extensions/Scripts/EditorManifest.cs index 6f8ad3c..28027ac 100644 --- a/Editor Extensions/Scripts/EditorManifest.cs +++ b/Editor Extensions/Scripts/EditorManifest.cs @@ -1,4 +1,4 @@ -#if false +#if UNITY_EDITOR using System.Collections.Generic; using System.IO; using System; @@ -11,74 +11,55 @@ namespace YNL.Editors.Extensions { public static class EditorManifest { - private static string _toJsonPath; - - private static ManifestRoot _root = new(); + private static string _manifestPath; + private static ManifestRoot _manifestRoot = new(); - public static void Test() + private static void UpdateManifest() { - _toJsonPath = Application.dataPath.Replace("Assets", "Packages/manifest.json"); + _manifestPath = Application.dataPath.Replace("Assets", "Packages/manifest.json"); + _manifestRoot = JsonData.LoadNewtonJson(_manifestPath); + } - _root = JsonData.LoadNewtonJson(_toJsonPath); + public static void AddDependency(string name, string version) + { + UpdateManifest(); - if (!_root.dependencies.ContainsKey("com.yunasawa.ynl.editor")) + if (!_manifestRoot.dependencies.ContainsKey(name)) { - _root.dependencies.Add("com.yunasawa.ynl.editor", "1.3.3"); - - Registry registry = _root.scopedRegistries.Find(i => i.name == "YunasawaStudio"); - if (registry == null) - { - _root.scopedRegistries.Add(new Registry - ( - "YunasawaStudio", - "https://package.openupm.com", - "com.yunasawa.ynl.editor", - "com.yunasawa.ynl.utilities" - )); - } - else - { - if (!registry.scopes.Contains("com.yunasawa.ynl.utilities")) - { - registry.scopes.Add("com.yunasawa.ynl.editor"); - } - } + _manifestRoot.dependencies.Add(name, version); } - if (!_root.dependencies.ContainsKey("com.yunasawa.ynl.utilities")) + else { - _root.dependencies.Add("com.yunasawa.ynl.utilities", "1.2.1"); - - Registry registry = _root.scopedRegistries.Find(i => i.name == "YunasawaStudio"); - if (registry == null) - { - _root.scopedRegistries.Add(new Registry - ( - "YunasawaStudio", - "https://package.openupm.com", - "com.yunasawa.ynl.editor", - "com.yunasawa.ynl.utilities" - )); - } - else - { - if (!registry.scopes.Contains("com.yunasawa.ynl.utilities")) - { - registry.scopes.Add("com.yunasawa.ynl.utilities"); - } - } + _manifestRoot.dependencies[name] = version; } - JsonData.SaveNewtonJson(_root, _toJsonPath); + JsonData.SaveNewtonJson(_manifestRoot, _manifestPath); } - public static void AddDependency(string name, string version) + public static void AddRegistry(string name, string url, params string[] scopes) { + UpdateManifest(); - } + Registry registry = _manifestRoot.scopedRegistries.Find(i => i.name == name); - public static void AddRegistry() - { + if (registry == null) + { + _manifestRoot.scopedRegistries.Add(new Registry(name, url, scopes)); + } + else + { + foreach (var scope in scopes) AddScope(scope); + } + JsonData.SaveNewtonJson(_manifestRoot, _manifestPath); + + void AddScope(string scope) + { + if (!registry.scopes.Contains(scope)) + { + registry.scopes.Add(scope); + } + } } } diff --git a/YNLEditorSetup.cs b/YNLEditorSetup.cs index 99fda93..6d9ad0c 100644 --- a/YNLEditorSetup.cs +++ b/YNLEditorSetup.cs @@ -24,7 +24,9 @@ private static void OnPostprocessAllAssets(string[] importedAssets, string[] del public static void InitializeOnLoad() { Debug.Log("Initialize On Load"); - EditorDefineSymbols.AddSymbols("YNL_EDITOR"); + EditorManifest.AddRegistry("YunasawaStudio", "https://package.openupm.com", "com.yunasawa.ynl.utilities"); + EditorManifest.AddDependency("com.yunasawa.ynl.utilities", "1.2.3"); + EditorDefineSymbols.AddSymbols("YNL_UTILITIES"); } } } diff --git a/package.json b/package.json index 171aa08..31a0022 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yunasawa.ynl.editor", "displayName": "YNL - Editor", - "version": "1.3.14", + "version": "1.3.15", "unity": "2022.3", "description": "YNL - Editor provides you tools to help you on your developing progress.", "keywords": [