mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
增加ENABLE_HYBRIDCLR的宏支持
增加ENABLE_HYBRIDCLR的宏支持
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
[HybridCLR.Editor.Settings.FilePath("ProjectSettings/AtlasConfiguration.asset")]
|
||||
public class AtlasConfiguration : HybridCLR.Editor.Settings.ScriptableSingleton<AtlasConfiguration>
|
||||
[FilePath("ProjectSettings/AtlasConfiguration.asset")]
|
||||
public class AtlasConfiguration : EditorScriptableSingleton<AtlasConfiguration>
|
||||
{
|
||||
[Header("目录设置")]
|
||||
[Tooltip("生成的图集输出目录")]
|
||||
|
@@ -17,7 +17,9 @@ public static class BuildDLLCommand
|
||||
public static void Disable()
|
||||
{
|
||||
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
|
||||
#if ENABLE_HYBRIDCLR
|
||||
HybridCLR.Editor.SettingsUtil.Enable = false;
|
||||
#endif
|
||||
// SyncAssemblyContent.RefreshAssembly();
|
||||
}
|
||||
|
||||
@@ -29,7 +31,9 @@ public static class BuildDLLCommand
|
||||
{
|
||||
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
|
||||
ScriptingDefineSymbols.AddScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
|
||||
#if ENABLE_HYBRIDCLR
|
||||
HybridCLR.Editor.SettingsUtil.Enable = true;
|
||||
#endif
|
||||
// SyncAssemblyContent.RefreshAssembly();
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
public class EditorScriptableSingleton<T> : ScriptableObject where T : ScriptableObject
|
||||
{
|
||||
private static T _instance;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_instance)
|
||||
{
|
||||
LoadOrCreate();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static T LoadOrCreate()
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
var arr = InternalEditorUtility.LoadSerializedFileAndForget(filePath);
|
||||
_instance = arr.Length > 0 ? arr[0] as T : _instance ?? CreateInstance<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"save location of {nameof(EditorScriptableSingleton<T>)} is invalid");
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public static void Save(bool saveAsText = true)
|
||||
{
|
||||
if (!_instance)
|
||||
{
|
||||
Debug.LogError("Cannot save ScriptableSingleton: no instance!");
|
||||
return;
|
||||
}
|
||||
|
||||
string filePath = GetFilePath();
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
string directoryName = Path.GetDirectoryName(filePath);
|
||||
if (!Directory.Exists(directoryName))
|
||||
{
|
||||
if (directoryName != null)
|
||||
{
|
||||
Directory.CreateDirectory(directoryName);
|
||||
}
|
||||
}
|
||||
|
||||
UnityEngine.Object[] obj = { _instance };
|
||||
InternalEditorUtility.SaveToSerializedFileAndForget(obj, filePath, saveAsText);
|
||||
}
|
||||
}
|
||||
|
||||
protected static string GetFilePath()
|
||||
{
|
||||
return typeof(T).GetCustomAttributes(inherit: true)
|
||||
.Where(v => v is FilePathAttribute)
|
||||
.Cast<FilePathAttribute>()
|
||||
.FirstOrDefault()
|
||||
?.Filepath;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class FilePathAttribute : Attribute
|
||||
{
|
||||
internal readonly string Filepath;
|
||||
|
||||
/// <summary>
|
||||
/// 单例存放路径。
|
||||
/// </summary>
|
||||
/// <param name="path">相对 Project 路径。</param>
|
||||
public FilePathAttribute(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentException("Invalid relative path (it is empty)");
|
||||
}
|
||||
|
||||
if (path[0] == '/')
|
||||
{
|
||||
path = path.Substring(1);
|
||||
}
|
||||
|
||||
Filepath = path;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bec53acfb41d41a29b3664015d318e39
|
||||
timeCreated: 1742523496
|
@@ -1,8 +1,9 @@
|
||||
#if ENABLE_HYBRIDCLR
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HybridCLR.Editor.Settings;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using HybridCLR.Editor.Settings;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
@@ -68,4 +69,5 @@ namespace TEngine.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user