Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunasawa committed May 10, 2024
1 parent c9c5b79 commit 5fd1d01
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 57 deletions.
17 changes: 16 additions & 1 deletion Editor Extensions/Scripts/EditorDefineSymbols.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -28,6 +30,7 @@ public static void AddSymbol(string symbol)

_defineSymbols.Add(symbol);
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, String.Join(";", _defineSymbols));
NotifySymbols(symbol, true);
}

/// <summary> Add multiple symbols </summary>
Expand All @@ -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);
}

/// <summary> Remove a single symbol </summary>
Expand All @@ -50,6 +54,7 @@ public static void RemoveSymbol(string symbol)

_defineSymbols.Remove(symbol);
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, String.Join(";", _defineSymbols));
NotifySymbols(symbol, false);
}

/// <summary> Remove multiple symbols </summary>
Expand All @@ -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);
}

/// <summary>
/// Print a notification into Console panel.
/// </summary>
public static void NotifySymbols(string message, bool isAdded)
{
if (isAdded) Debug.Log($"<color=#FFCD45><b>▶ Notification:</b></color> A new define symbol <color=#ffdb7a><b>{message}</b></color> is added.");
else Debug.Log($"<color=#FFCD45><b>▶ Notification:</b></color> A new define symbol <color=#ffdb7a><b>{message}</b></color> is removed.");
}
}
}
Expand Down
89 changes: 35 additions & 54 deletions Editor Extensions/Scripts/EditorManifest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if false
#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using System;
Expand All @@ -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<ManifestRoot>(_manifestPath);
}

_root = JsonData.LoadNewtonJson<ManifestRoot>(_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);
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion YNLEditorSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 5fd1d01

Please sign in to comment.