提交修改
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class FantasySettings
|
||||
{
|
||||
[MenuItem("Fantasy/Fantasy Settings")]
|
||||
public static void OpenFantasySettings()
|
||||
{
|
||||
SettingsService.OpenProjectSettings("Project/Fantasy Settings");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 977a7c172c30403da60286ba39b7bc72
|
||||
timeCreated: 1686913667
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class FantasySettingsProvider : SettingsProvider
|
||||
{
|
||||
private SerializedObject _serializedObject;
|
||||
private SerializedProperty _autoCopyAssembly;
|
||||
private SerializedProperty _hotUpdatePath;
|
||||
private SerializedProperty _hotUpdateAssemblyDefinitions;
|
||||
private SerializedProperty _linkAssemblyDefinitions;
|
||||
private SerializedProperty _includeAssembly;
|
||||
public FantasySettingsProvider() : base("Project/Fantasy Settings", SettingsScope.Project) { }
|
||||
|
||||
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||
{
|
||||
Init();
|
||||
base.OnActivate(searchContext, rootElement);
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
base.OnDeactivate();
|
||||
FantasySettingsScriptableObject.Save();
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
_serializedObject?.Dispose();
|
||||
_serializedObject = new SerializedObject(FantasySettingsScriptableObject.Instance);
|
||||
_autoCopyAssembly = _serializedObject.FindProperty("autoCopyAssembly");
|
||||
_hotUpdatePath = _serializedObject.FindProperty("hotUpdatePath");
|
||||
_hotUpdateAssemblyDefinitions = _serializedObject.FindProperty("hotUpdateAssemblyDefinitions");
|
||||
_linkAssemblyDefinitions = _serializedObject.FindProperty("linkAssemblyDefinitions");
|
||||
_includeAssembly = _serializedObject.FindProperty("includeAssembly");
|
||||
}
|
||||
|
||||
public override void OnGUI(string searchContext)
|
||||
{
|
||||
if (_serializedObject == null || !_serializedObject.targetObject)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
using (CreateSettingsWindowGUIScope())
|
||||
{
|
||||
_serializedObject!.Update();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(_autoCopyAssembly);
|
||||
EditorGUILayout.PropertyField(_hotUpdatePath);
|
||||
EditorGUILayout.PropertyField(_hotUpdateAssemblyDefinitions);
|
||||
EditorGUILayout.PropertyField(_includeAssembly);
|
||||
EditorGUILayout.PropertyField(_linkAssemblyDefinitions);
|
||||
// EditorGUILayout.HelpBox("默认包括Fantasy.Unity,所以不需要再次指定。", MessageType.Info);
|
||||
|
||||
if (GUILayout.Button("GenerateLinkXml"))
|
||||
{
|
||||
LinkXmlGenerator.GenerateLinkXml();
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
FantasySettingsScriptableObject.Save();
|
||||
EditorApplication.RepaintHierarchyWindow();
|
||||
}
|
||||
|
||||
base.OnGUI(searchContext);
|
||||
}
|
||||
}
|
||||
|
||||
private IDisposable CreateSettingsWindowGUIScope()
|
||||
{
|
||||
var unityEditorAssembly = System.Reflection.Assembly.GetAssembly(typeof(EditorWindow));
|
||||
var type = unityEditorAssembly.GetType("UnityEditor.SettingsWindow+GUIScope");
|
||||
return Activator.CreateInstance(type) as IDisposable;
|
||||
}
|
||||
|
||||
static FantasySettingsProvider _provider;
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateMyCustomSettingsProvider()
|
||||
{
|
||||
if (FantasySettingsScriptableObject.Instance && _provider == null)
|
||||
{
|
||||
_provider = new FantasySettingsProvider();
|
||||
using (var so = new SerializedObject(FantasySettingsScriptableObject.Instance))
|
||||
{
|
||||
_provider.keywords = GetSearchKeywordsFromSerializedObject(so);
|
||||
}
|
||||
}
|
||||
return _provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 047b2f13e73f413fa000bf7be979fb4a
|
||||
timeCreated: 1688380387
|
||||
@@ -1,25 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
[ScriptableObjectPath("ProjectSettings/FantasySettings.asset")]
|
||||
public class FantasySettingsScriptableObject : ScriptableObjectSingleton<FantasySettingsScriptableObject>, ISerializationCallbackReceiver
|
||||
{
|
||||
[FormerlySerializedAs("AutoCopyAssembly")] [Header("自动拷贝程序集到HotUpdatePath目录中")]
|
||||
public bool autoCopyAssembly = false;
|
||||
[FormerlySerializedAs("HotUpdatePath")] [Header("HotUpdate目录(Unity编译后会把所有HotUpdate程序集Copy一份到这个目录下)")]
|
||||
public string hotUpdatePath;
|
||||
[FormerlySerializedAs("HotUpdateAssemblyDefinitions")] [Header("HotUpdate程序集")]
|
||||
public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions;
|
||||
[FormerlySerializedAs("LinkAssemblyDefinitions")] [Header("指定要生成Link.xml的程序集")]
|
||||
public AssemblyDefinitionAsset[] linkAssemblyDefinitions;
|
||||
[FormerlySerializedAs("IncludeAssembly")] [Header("生成Link.xml时候默认包含的程序集")]
|
||||
public string[] includeAssembly = new[] { "Assembly-CSharp", "Fantasy.Unity" };
|
||||
public void OnBeforeSerialize() { }
|
||||
public void OnAfterDeserialize() { }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27a37e930ca3454fb57bc895f50d2106
|
||||
timeCreated: 1688277120
|
||||
@@ -1,100 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
// ReSharper disable AssignNullToNotNullAttribute
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class ScriptableObjectSingleton<T> : ScriptableObject where T : ScriptableObject
|
||||
{
|
||||
private static T _instance;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = Load();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private static T Load()
|
||||
{
|
||||
var scriptableObjectPath = GetScriptableObjectPath();
|
||||
|
||||
if (string.IsNullOrEmpty(scriptableObjectPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var loadSerializedFileAndForget = InternalEditorUtility.LoadSerializedFileAndForget(scriptableObjectPath);
|
||||
|
||||
if (loadSerializedFileAndForget.Length <= 0)
|
||||
{
|
||||
return CreateInstance<T>();
|
||||
}
|
||||
|
||||
return loadSerializedFileAndForget[0] as T;
|
||||
}
|
||||
|
||||
public static void Save(bool saveAsText = true)
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
Debug.LogError("Cannot save ScriptableObjectSingleton: no instance!");
|
||||
return;
|
||||
}
|
||||
|
||||
var scriptableObjectPath = GetScriptableObjectPath();
|
||||
|
||||
if (string.IsNullOrEmpty(scriptableObjectPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var directoryName = Path.GetDirectoryName(scriptableObjectPath);
|
||||
|
||||
if (!Directory.Exists(directoryName))
|
||||
{
|
||||
Directory.CreateDirectory(directoryName);
|
||||
}
|
||||
|
||||
UnityEngine.Object[] obj = { _instance };
|
||||
InternalEditorUtility.SaveToSerializedFileAndForget(obj, scriptableObjectPath, saveAsText);
|
||||
}
|
||||
|
||||
private static string GetScriptableObjectPath()
|
||||
{
|
||||
var scriptableObjectPathAttribute = typeof(T).GetCustomAttribute(typeof(ScriptableObjectPathAttribute)) as ScriptableObjectPathAttribute;
|
||||
return scriptableObjectPathAttribute?.ScriptableObjectPath;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
public class ScriptableObjectPathAttribute : Attribute
|
||||
{
|
||||
internal readonly string ScriptableObjectPath;
|
||||
|
||||
public ScriptableObjectPathAttribute(string scriptableObjectPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scriptableObjectPath))
|
||||
{
|
||||
throw new ArgumentException("Invalid relative path (it is empty)");
|
||||
}
|
||||
|
||||
if (scriptableObjectPath[0] == '/')
|
||||
{
|
||||
scriptableObjectPath = scriptableObjectPath.Substring(1);
|
||||
}
|
||||
|
||||
ScriptableObjectPath = scriptableObjectPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c77f5208dc14542ae7497d59321ef76
|
||||
timeCreated: 1688278016
|
||||
Reference in New Issue
Block a user