更新00
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using HybridCLR.Editor;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 监听编辑器状态,当编辑器重新 focus 时,重新加载实例,避免某些情景下 svn 、git 等外部修改了数据却无法同步的异常。
|
||||
/// </summary>
|
||||
[InitializeOnLoad]
|
||||
public static class EditorStatusWatcher
|
||||
{
|
||||
public static Action OnEditorFocused;
|
||||
static bool isFocused;
|
||||
static EditorStatusWatcher() => EditorApplication.update += Update;
|
||||
static void Update()
|
||||
{
|
||||
if (isFocused != InternalEditorUtility.isApplicationActive)
|
||||
{
|
||||
isFocused = InternalEditorUtility.isApplicationActive;
|
||||
if (isFocused)
|
||||
{
|
||||
HybridCLRSettings.LoadOrCreate();
|
||||
OnEditorFocused?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 093a9e6c1e7399244bbcd8983fdbfdee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Presets;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public class HybridCLRSettingsProvider : SettingsProvider
|
||||
{
|
||||
private SerializedObject _serializedObject;
|
||||
private SerializedProperty _enable;
|
||||
private SerializedProperty _useGlobalIl2cpp;
|
||||
private SerializedProperty _hybridclrRepoURL;
|
||||
private SerializedProperty _il2cppPlusRepoURL;
|
||||
private SerializedProperty _hotUpdateAssemblyDefinitions;
|
||||
private SerializedProperty _hotUpdateAssemblies;
|
||||
private SerializedProperty _preserveHotUpdateAssemblies;
|
||||
private SerializedProperty _hotUpdateDllCompileOutputRootDir;
|
||||
private SerializedProperty _externalHotUpdateAssembliyDirs;
|
||||
private SerializedProperty _strippedAOTDllOutputRootDir;
|
||||
private SerializedProperty _patchAOTAssemblies;
|
||||
private SerializedProperty _outputLinkFile;
|
||||
private SerializedProperty _outputAOTGenericReferenceFile;
|
||||
private SerializedProperty _maxGenericReferenceIteration;
|
||||
private SerializedProperty _maxMethodBridgeGenericIteration;
|
||||
private GUIStyle buttonStyle;
|
||||
public HybridCLRSettingsProvider() : base("Project/HybridCLR Settings", SettingsScope.Project) { }
|
||||
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||
{
|
||||
EditorStatusWatcher.OnEditorFocused += OnEditorFocused;
|
||||
InitGUI();
|
||||
}
|
||||
private void InitGUI()
|
||||
{
|
||||
var setting = HybridCLRSettings.LoadOrCreate();
|
||||
_serializedObject?.Dispose();
|
||||
_serializedObject = new SerializedObject(setting);
|
||||
_enable = _serializedObject.FindProperty("enable");
|
||||
_useGlobalIl2cpp = _serializedObject.FindProperty("useGlobalIl2cpp");
|
||||
_hybridclrRepoURL = _serializedObject.FindProperty("hybridclrRepoURL");
|
||||
_il2cppPlusRepoURL = _serializedObject.FindProperty("il2cppPlusRepoURL");
|
||||
_hotUpdateAssemblyDefinitions = _serializedObject.FindProperty("hotUpdateAssemblyDefinitions");
|
||||
_hotUpdateAssemblies = _serializedObject.FindProperty("hotUpdateAssemblies");
|
||||
_preserveHotUpdateAssemblies = _serializedObject.FindProperty("preserveHotUpdateAssemblies");
|
||||
_hotUpdateDllCompileOutputRootDir = _serializedObject.FindProperty("hotUpdateDllCompileOutputRootDir");
|
||||
_externalHotUpdateAssembliyDirs = _serializedObject.FindProperty("externalHotUpdateAssembliyDirs");
|
||||
_strippedAOTDllOutputRootDir = _serializedObject.FindProperty("strippedAOTDllOutputRootDir");
|
||||
_patchAOTAssemblies = _serializedObject.FindProperty("patchAOTAssemblies");
|
||||
_outputLinkFile = _serializedObject.FindProperty("outputLinkFile");
|
||||
_outputAOTGenericReferenceFile = _serializedObject.FindProperty("outputAOTGenericReferenceFile");
|
||||
_maxGenericReferenceIteration = _serializedObject.FindProperty("maxGenericReferenceIteration");
|
||||
_maxMethodBridgeGenericIteration = _serializedObject.FindProperty("maxMethodBridgeGenericIteration");
|
||||
}
|
||||
private void OnEditorFocused()
|
||||
{
|
||||
InitGUI();
|
||||
Repaint();
|
||||
}
|
||||
public override void OnTitleBarGUI()
|
||||
{
|
||||
base.OnTitleBarGUI();
|
||||
var rect = GUILayoutUtility.GetLastRect();
|
||||
buttonStyle = buttonStyle ?? GUI.skin.GetStyle("IconButton");
|
||||
|
||||
#region 绘制官方网站跳转按钮
|
||||
var w = rect.x + rect.width;
|
||||
rect.x = w - 57;
|
||||
rect.y += 6;
|
||||
rect.width = rect.height = 18;
|
||||
var content = EditorGUIUtility.IconContent("_Help");
|
||||
content.tooltip = "点击访问 HybridCLR 官方文档";
|
||||
if (GUI.Button(rect, content, buttonStyle))
|
||||
{
|
||||
Application.OpenURL("https://focus-creative-games.github.io/hybridclr/");
|
||||
}
|
||||
#endregion
|
||||
#region 绘制 Preset
|
||||
rect.x += 19;
|
||||
content = EditorGUIUtility.IconContent("Preset.Context");
|
||||
content.tooltip = "点击存储或加载 Preset .";
|
||||
if (GUI.Button(rect, content, buttonStyle))
|
||||
{
|
||||
var target = HybridCLRSettings.Instance;
|
||||
var receiver = ScriptableObject.CreateInstance<SettingsPresetReceiver>();
|
||||
receiver.Init(target, this);
|
||||
PresetSelector.ShowSelector(target, null, true, receiver);
|
||||
}
|
||||
#endregion
|
||||
#region 绘制 Reset
|
||||
rect.x += 19;
|
||||
content = EditorGUIUtility.IconContent(
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
"pane options"
|
||||
#else
|
||||
"_Popup"
|
||||
#endif
|
||||
);
|
||||
content.tooltip = "Reset";
|
||||
if (GUI.Button(rect, content, buttonStyle))
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent("Reset"), false, () =>
|
||||
{
|
||||
Undo.RecordObject(HybridCLRSettings.Instance, "Capture Value for Reset");
|
||||
var dv = ScriptableObject.CreateInstance<HybridCLRSettings>();
|
||||
var json = EditorJsonUtility.ToJson(dv);
|
||||
UnityEngine.Object.DestroyImmediate(dv);
|
||||
EditorJsonUtility.FromJsonOverwrite(json, HybridCLRSettings.Instance);
|
||||
HybridCLRSettings.Save();
|
||||
});
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
public override void OnGUI(string searchContext)
|
||||
{
|
||||
using (CreateSettingsWindowGUIScope())
|
||||
{
|
||||
//解决编辑器打包时出现的 _serializedObject.targetObject 意外销毁的情况
|
||||
if (_serializedObject == null||!_serializedObject.targetObject)
|
||||
{
|
||||
InitGUI();
|
||||
}
|
||||
_serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(_enable);
|
||||
EditorGUILayout.PropertyField(_hybridclrRepoURL);
|
||||
EditorGUILayout.PropertyField(_il2cppPlusRepoURL);
|
||||
EditorGUILayout.PropertyField(_useGlobalIl2cpp);
|
||||
EditorGUILayout.PropertyField(_hotUpdateAssemblyDefinitions);
|
||||
EditorGUILayout.PropertyField(_hotUpdateAssemblies);
|
||||
EditorGUILayout.PropertyField(_preserveHotUpdateAssemblies);
|
||||
EditorGUILayout.PropertyField(_hotUpdateDllCompileOutputRootDir);
|
||||
EditorGUILayout.PropertyField(_externalHotUpdateAssembliyDirs);
|
||||
EditorGUILayout.PropertyField(_strippedAOTDllOutputRootDir);
|
||||
EditorGUILayout.PropertyField(_patchAOTAssemblies);
|
||||
EditorGUILayout.PropertyField(_outputLinkFile);
|
||||
EditorGUILayout.PropertyField(_outputAOTGenericReferenceFile);
|
||||
EditorGUILayout.PropertyField(_maxGenericReferenceIteration);
|
||||
EditorGUILayout.PropertyField(_maxMethodBridgeGenericIteration);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
HybridCLRSettings.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
private IDisposable CreateSettingsWindowGUIScope()
|
||||
{
|
||||
var unityEditorAssembly = Assembly.GetAssembly(typeof(EditorWindow));
|
||||
var type = unityEditorAssembly.GetType("UnityEditor.SettingsWindow+GUIScope");
|
||||
return Activator.CreateInstance(type) as IDisposable;
|
||||
}
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
base.OnDeactivate();
|
||||
EditorStatusWatcher.OnEditorFocused -= OnEditorFocused;
|
||||
HybridCLRSettings.Save();
|
||||
}
|
||||
|
||||
static HybridCLRSettingsProvider provider;
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateMyCustomSettingsProvider()
|
||||
{
|
||||
if (HybridCLRSettings.Instance && provider == null)
|
||||
{
|
||||
provider = new HybridCLRSettingsProvider();
|
||||
using (var so = new SerializedObject(HybridCLRSettings.Instance))
|
||||
{
|
||||
provider.keywords = GetSearchKeywordsFromSerializedObject(so);
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2bd1694fedc8b54c88bb9f6c67907d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
[FilePath("ProjectSettings/HybridCLRSettings.asset")]
|
||||
public class HybridCLRSettings : ScriptableSingleton<HybridCLRSettings>
|
||||
{
|
||||
[Header("开启HybridCLR插件")]
|
||||
public bool enable = true;
|
||||
|
||||
[Header("使用全局安装的il2cpp")]
|
||||
public bool useGlobalIl2cpp;
|
||||
|
||||
[Header("hybridclr 仓库 URL")]
|
||||
public string hybridclrRepoURL = "https://gitee.com/focus-creative-games/hybridclr";
|
||||
|
||||
[Header("il2cpp_plus 仓库 URL")]
|
||||
public string il2cppPlusRepoURL = "https://gitee.com/focus-creative-games/il2cpp_plus";
|
||||
|
||||
[Header("热更新Assembly Definitions")]
|
||||
public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions;
|
||||
|
||||
[Header("热更新dlls")]
|
||||
public string[] hotUpdateAssemblies;
|
||||
|
||||
[Header("预留的热更新dlls")]
|
||||
public string[] preserveHotUpdateAssemblies;
|
||||
|
||||
[Header("热更新dll编译输出根目录")]
|
||||
public string hotUpdateDllCompileOutputRootDir = "HybridCLRData/HotUpdateDlls";
|
||||
|
||||
[Header("外部热更新dll搜索路径")]
|
||||
public string[] externalHotUpdateAssembliyDirs;
|
||||
|
||||
[Header("裁减后AOT dll输出根目录")]
|
||||
public string strippedAOTDllOutputRootDir = "HybridCLRData/AssembliesPostIl2CppStrip";
|
||||
|
||||
[Header("补充元数据AOT dlls")]
|
||||
public string[] patchAOTAssemblies;
|
||||
|
||||
[Header("生成的link.xml路径")]
|
||||
public string outputLinkFile = "HybridCLRGenerate/link.xml";
|
||||
|
||||
[Header("自动扫描生成的AOTGenericReferences.cs路径")]
|
||||
public string outputAOTGenericReferenceFile = "HybridCLRGenerate/AOTGenericReferences.cs";
|
||||
|
||||
[Header("AOT泛型实例化搜索迭代次数")]
|
||||
public int maxGenericReferenceIteration = 10;
|
||||
|
||||
[Header("MethodBridge泛型搜索迭代次数")]
|
||||
public int maxMethodBridgeGenericIteration = 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e189374413a3f00468e49d51d8b27a09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
using HybridCLR.Editor.Installer;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public static class MenuProvider
|
||||
{
|
||||
|
||||
[MenuItem("HybridCLR/About", priority = 0)]
|
||||
public static void OpenAbout() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/intro");
|
||||
|
||||
[MenuItem("HybridCLR/Installer...", priority = 60)]
|
||||
private static void Open()
|
||||
{
|
||||
InstallerWindow window = EditorWindow.GetWindow<InstallerWindow>("HybridCLR Installer", true);
|
||||
window.minSize = new Vector2(800f, 500f);
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Settings...", priority = 61)]
|
||||
public static void OpenSettings() => SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Quick Start")]
|
||||
public static void OpenQuickStart() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/beginner/quickstart");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Performance")]
|
||||
public static void OpenPerformance() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/basic/performance");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/FAQ")]
|
||||
public static void OpenFAQ() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/faq");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Common Errors")]
|
||||
public static void OpenCommonErrors() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/commonerrors");
|
||||
|
||||
[MenuItem("HybridCLR/Documents/Bug Report")]
|
||||
public static void OpenBugReport() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/issue");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a475a5f281298b84da32373694704c68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public class ScriptableSingleton<T> : ScriptableObject where T : ScriptableObject
|
||||
{
|
||||
private static T s_Instance;
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!s_Instance)
|
||||
{
|
||||
LoadOrCreate();
|
||||
}
|
||||
return s_Instance;
|
||||
}
|
||||
}
|
||||
public static T LoadOrCreate()
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
var arr = InternalEditorUtility.LoadSerializedFileAndForget(filePath);
|
||||
s_Instance = arr.Length > 0 ? arr[0] as T : s_Instance??CreateInstance<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"save location of {nameof(ScriptableSingleton<T>)} is invalid");
|
||||
}
|
||||
return s_Instance;
|
||||
}
|
||||
|
||||
public static void Save(bool saveAsText = true)
|
||||
{
|
||||
if (!s_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))
|
||||
{
|
||||
Directory.CreateDirectory(directoryName);
|
||||
}
|
||||
UnityEngine.Object[] obj = new T[1] { s_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 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,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 851c44a8da67a9742a7ea68815383f27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Presets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.Settings
|
||||
{
|
||||
public class SettingsPresetReceiver : PresetSelectorReceiver
|
||||
{
|
||||
private Object m_Target;
|
||||
private Preset m_InitialValue;
|
||||
private SettingsProvider m_Provider;
|
||||
|
||||
internal void Init(Object target, SettingsProvider provider)
|
||||
{
|
||||
m_Target = target;
|
||||
m_InitialValue = new Preset(target);
|
||||
m_Provider = provider;
|
||||
}
|
||||
public override void OnSelectionChanged(Preset selection)
|
||||
{
|
||||
if (selection != null)
|
||||
{
|
||||
Undo.RecordObject(m_Target, "Apply Preset " + selection.name);
|
||||
selection.ApplyTo(m_Target);
|
||||
}
|
||||
else
|
||||
{
|
||||
Undo.RecordObject(m_Target, "Cancel Preset");
|
||||
m_InitialValue.ApplyTo(m_Target);
|
||||
}
|
||||
m_Provider.Repaint();
|
||||
}
|
||||
public override void OnSelectionClosed(Preset selection)
|
||||
{
|
||||
OnSelectionChanged(selection);
|
||||
Object.DestroyImmediate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8373e0cb30c4894db7cd4d0b77a7a48
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user