mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
fix functionality of using MetaID
This commit is contained in:
parent
f05767a795
commit
75be984bdc
@ -26,6 +26,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public static void Activate()
|
||||
{
|
||||
if (Instance.GetType() == typeof(UnityDebugService)) { return; }
|
||||
Set<UnityDebugService>();
|
||||
}
|
||||
|
||||
|
@ -418,7 +418,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
var current = Event.current;
|
||||
var hover = IconHoverScan(position, current);
|
||||
using (new ColorScope(new Color(1f, 1f, 1f, hover ? 1f : 0.8f)))
|
||||
if (GUI.enabled)
|
||||
{
|
||||
using (SetColor(1f, 1f, 1f, hover ? 1f : 0.8f))
|
||||
{
|
||||
DrawIcon(position, Icons.Instance.FileIcon, hover ? 1f : 2f, "One click - Ping File. Double click - Edit Script");
|
||||
}
|
||||
@ -434,6 +436,14 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (SetColor(0.85f, 0.85f, 0.85f, 0.7f))
|
||||
{
|
||||
DrawIcon(position, Icons.Instance.FileIcon, 2f, "One click - Ping File. Double click - Edit Script");
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool CloseButton(Rect position, string description = null)
|
||||
{
|
||||
using (new ColorScope(new Color(1f, 1f, 1f, 0.8f)))
|
||||
|
@ -1,10 +1,8 @@
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
@ -101,6 +99,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
#if UNITY_EDITOR
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using UnityEditor;
|
||||
using Assembly = System.Reflection.Assembly;
|
||||
|
||||
@ -109,12 +108,17 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
static UnityEditorUtility()
|
||||
{
|
||||
const int PREWARMUP_LIST_SIZE = 64;
|
||||
EcsWorld.ResetStaticState();
|
||||
UnityDebugService.Activate();
|
||||
|
||||
_integrationAssembly = typeof(UnityEditorUtility).Assembly;
|
||||
|
||||
List<Type> serializableTypes = new List<Type>();
|
||||
List<EntityEditorBlockDrawer> entityEditorBlockDrawers = new List<EntityEditorBlockDrawer>();
|
||||
List<Type> serializableTypes = new List<Type>(PREWARMUP_LIST_SIZE);
|
||||
List<TypeMeta> typeWithMetaIDMetas = new List<TypeMeta>(PREWARMUP_LIST_SIZE);
|
||||
List<TypeMeta> serializableTypeWithMetaIDMetas = new List<TypeMeta>(PREWARMUP_LIST_SIZE);
|
||||
List<EntityEditorBlockDrawer> entityEditorBlockDrawers = new List<EntityEditorBlockDrawer>(PREWARMUP_LIST_SIZE);
|
||||
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
//var targetTypes = assembly.GetTypes().Where(type =>
|
||||
@ -124,29 +128,75 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
if ((type.IsGenericType || type.IsAbstract || type.IsInterface) == false &&
|
||||
typeof(EntityEditorBlockDrawer).IsAssignableFrom(type))
|
||||
bool hasMetaID = false;
|
||||
if (TypeMeta.TryGetCustomMeta(type, out TypeMeta meta) && meta.IsHasMetaID())
|
||||
{
|
||||
typeWithMetaIDMetas.Add(meta);
|
||||
hasMetaID = true;
|
||||
}
|
||||
|
||||
if (type.IsConcreteType())
|
||||
{
|
||||
if (typeof(EntityEditorBlockDrawer).IsAssignableFrom(type))
|
||||
{
|
||||
var drawer = (EntityEditorBlockDrawer)Activator.CreateInstance(type);
|
||||
entityEditorBlockDrawers.Add(drawer);
|
||||
}
|
||||
|
||||
if (type.IsUnityObject() == false && type.GetConstructor(Type.EmptyTypes) != null)
|
||||
{
|
||||
serializableTypes.Add(type);
|
||||
if (hasMetaID)
|
||||
{
|
||||
serializableTypeWithMetaIDMetas.Add(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var targetTypes = assembly.GetTypes().Where(type =>
|
||||
(type.IsGenericType || type.IsAbstract || type.IsInterface) == false &&
|
||||
type.IsSubclassOf(typeof(UnityObject)) == false &&
|
||||
type.GetConstructor(Type.EmptyTypes) != null);
|
||||
|
||||
serializableTypes.AddRange(targetTypes);
|
||||
}
|
||||
_serializableTypes = serializableTypes.ToArray();
|
||||
_typeWithMetaIDMetas = typeWithMetaIDMetas.ToArray();
|
||||
_serializableTypeWithMetaIDMetas = serializableTypeWithMetaIDMetas.ToArray();
|
||||
_entityEditorBlockDrawers = entityEditorBlockDrawers.ToArray();
|
||||
_serializableTypeWithMetaIDMetas = serializableTypes
|
||||
.Where(TypeMeta.IsHasMetaID)
|
||||
.Select(type => type.ToMeta())
|
||||
.ToArray();
|
||||
|
||||
foreach (var item in _serializableTypeWithMetaIDMetas)
|
||||
_metaIDCollisions = MetaID.FindMetaIDCollisions(_typeWithMetaIDMetas);
|
||||
IsHasAnyMetaIDCollision = _metaIDCollisions.IsHasAnyCollision;
|
||||
if (_metaIDCollisions.IsHasAnyCollision)
|
||||
{
|
||||
StringBuilder log = new StringBuilder();
|
||||
log.Append("MetaID identifier collisions detected. Some functions that use MetaID were disabled until the collisions were fixed. List of collisions:\r\n");
|
||||
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var collision in _metaIDCollisions)
|
||||
{
|
||||
i++;
|
||||
log.Append('├');
|
||||
log.Append($"ID: {collision.MetaID}\r\n");
|
||||
int j = 0;
|
||||
foreach (var meta in collision)
|
||||
{
|
||||
j++;
|
||||
log.Append('│');
|
||||
|
||||
|
||||
if (j == collision.Count)
|
||||
{
|
||||
log.Append('└');
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Append('├');
|
||||
}
|
||||
|
||||
log.Append($"Type: {meta.TypeName}\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug.LogError(log.ToString());
|
||||
}
|
||||
foreach (var item in _typeWithMetaIDMetas)
|
||||
{
|
||||
_metaIDTypePairs[item.MetaID] = item.Type;
|
||||
}
|
||||
@ -160,8 +210,12 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
internal static readonly Assembly _integrationAssembly;
|
||||
internal static readonly Type[] _serializableTypes;
|
||||
internal static readonly EntityEditorBlockDrawer[] _entityEditorBlockDrawers;
|
||||
internal static readonly TypeMeta[] _typeWithMetaIDMetas;
|
||||
internal static readonly TypeMeta[] _serializableTypeWithMetaIDMetas;
|
||||
internal static readonly EntityEditorBlockDrawer[] _entityEditorBlockDrawers;
|
||||
|
||||
internal static readonly MetaID.CollisionList _metaIDCollisions;
|
||||
public static readonly bool IsHasAnyMetaIDCollision;
|
||||
private static readonly Dictionary<string, Type> _metaIDTypePairs = new Dictionary<string, Type>();
|
||||
|
||||
public static bool TryGetTypeForMetaID(string metaID, out Type type)
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Internal
|
||||
{
|
||||
@ -18,6 +19,20 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
{
|
||||
return self.GetCustomAttribute<T>() != null;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsConcreteType(this Type self)
|
||||
{
|
||||
if (self.IsGenericType || self.IsAbstract || self.IsInterface)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return self.IsValueType || self.IsClass;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsUnityObject(this Type self)
|
||||
{
|
||||
return self.IsSubclassOf(typeof(UnityObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -33,18 +33,37 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
#endregion
|
||||
private static Dictionary<string, string> _metaIDScriptPathPairs = new Dictionary<string, string>();
|
||||
public static IReadOnlyDictionary<string, string> MetaIDScriptPathPairs
|
||||
{
|
||||
get
|
||||
{
|
||||
instance.InitUpdate();
|
||||
return _metaIDScriptPathPairs;
|
||||
}
|
||||
}
|
||||
|
||||
private static SparseArray<MonoScript> _scriptsAssets = new SparseArray<MonoScript>(256);
|
||||
|
||||
public static void Reinit()
|
||||
{
|
||||
instance._isInit = false;
|
||||
_metaIDScriptPathPairs.Clear();
|
||||
instance.InitUpdate();
|
||||
}
|
||||
|
||||
#region Init/Update
|
||||
private static object _lock = new object();
|
||||
private void InitUpdate()
|
||||
{
|
||||
Init();
|
||||
|
||||
if (MonoScriptsAssetProcessor.Version <= _version) { return; }
|
||||
lock (_lock)
|
||||
{
|
||||
if (MonoScriptsAssetProcessor.Version <= _version) { return; }
|
||||
|
||||
if (MonoScriptsAssetProcessor.RemovedScriptPaths.Count > 0)
|
||||
{
|
||||
List<string> removedKeys = new List<string>();
|
||||
uint pathsLength = (uint)MonoScriptsAssetProcessor.RemovedScriptPaths.Count;
|
||||
string[] paths = new string[pathsLength];
|
||||
int i = 0;
|
||||
@ -58,12 +77,19 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
if (paths[j] == metaIDScriptPathPair.Value)
|
||||
{
|
||||
_metaIDScriptPathPairs[metaIDScriptPathPair.Key] = null;
|
||||
}
|
||||
removedKeys.Add(metaIDScriptPathPair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var key in removedKeys)
|
||||
{
|
||||
_metaIDScriptPathPairs.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (MonoScriptsAssetProcessor.NewScriptPaths.Count > 0)
|
||||
{
|
||||
List<string> metaIDs = new List<string>();
|
||||
foreach (var assetPath in MonoScriptsAssetProcessor.NewScriptPaths)
|
||||
{
|
||||
@ -73,15 +99,23 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
_metaIDScriptPathPairs[metaID] = assetPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_version = MonoScriptsAssetProcessor.Version;
|
||||
|
||||
Save(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if (_isInit && _metaIDScriptPathPairs.Count > 0) { return; }
|
||||
|
||||
if (_metaIDScriptPathPairs == null)
|
||||
{
|
||||
_metaIDScriptPathPairs = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
_metaIDScriptPathPairs.Clear();
|
||||
var scriptGuids = AssetDatabase.FindAssets($"* t:MonoScript");
|
||||
|
||||
@ -113,27 +147,25 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
Save(true);
|
||||
}
|
||||
public void Reinit()
|
||||
{
|
||||
_isInit = false;
|
||||
InitUpdate();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Get
|
||||
public static bool TryGetScriptAsset(TypeMeta meta, out MonoScript script)
|
||||
{
|
||||
int uniqueID = meta.GetHashCode();
|
||||
int metaUniqueID = meta.GetHashCode();
|
||||
|
||||
if (_scriptsAssets.TryGetValue(uniqueID, out script) == false)
|
||||
if (_scriptsAssets.TryGetValue(metaUniqueID, out script) == false)
|
||||
{
|
||||
script = null;
|
||||
|
||||
//Ищем по мета айди совпадения
|
||||
string metaID = meta.MetaID;
|
||||
if (string.IsNullOrEmpty(metaID) == false)
|
||||
if (UnityEditorUtility.IsHasAnyMetaIDCollision == false)
|
||||
{
|
||||
if (meta.IsHasMetaID())
|
||||
{
|
||||
instance.InitUpdate();
|
||||
|
||||
string metaID = meta.MetaID;
|
||||
if (_metaIDScriptPathPairs.TryGetValue(metaID, out string assetPath))
|
||||
{
|
||||
if (assetPath == null)
|
||||
@ -150,6 +182,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (script == null)
|
||||
{
|
||||
@ -199,7 +233,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
|
||||
}
|
||||
_scriptsAssets.Add(uniqueID, script);
|
||||
|
||||
|
||||
_scriptsAssets.Add(metaUniqueID, script);
|
||||
}
|
||||
return script != null;
|
||||
}
|
||||
|
8
src/Tools/DeepDebugger.meta
Normal file
8
src/Tools/DeepDebugger.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da6b7ba7fc0a44a4f8228f10ef5abcd1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
src/Tools/DeepDebugger/Editors.meta
Normal file
8
src/Tools/DeepDebugger/Editors.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 620c5dc67428c21428ff4bd9c92ed631
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
47
src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs
Normal file
47
src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs
Normal file
@ -0,0 +1,47 @@
|
||||
#if UNITY_EDITOR
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
internal class DeepDebuggerWindow : EditorWindow
|
||||
{
|
||||
public const string TITLE = "DeepDebuggerWindow";
|
||||
|
||||
#if DRAGONECS_DEEP_DEBUG
|
||||
[MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/" + TITLE)]
|
||||
static void Open()
|
||||
{
|
||||
var wnd = GetWindow<DeepDebuggerWindow>();
|
||||
wnd.titleContent = new GUIContent(TITLE);
|
||||
wnd.minSize = new Vector2(100f, 120f);
|
||||
wnd.Show();
|
||||
}
|
||||
#endif
|
||||
|
||||
private Vector2 pos;
|
||||
private void OnGUI()
|
||||
{
|
||||
var dicst = ScriptsCache.MetaIDScriptPathPairs;
|
||||
|
||||
pos = GUILayout.BeginScrollView(pos);
|
||||
|
||||
if (GUILayout.Button("Reset"))
|
||||
{
|
||||
ScriptsCache.Reinit();
|
||||
}
|
||||
|
||||
foreach (var (metaID, scriptPath) in dicst)
|
||||
{
|
||||
GUILayout.Label("", GUILayout.ExpandWidth(true));
|
||||
Rect rect = GUILayoutUtility.GetLastRect();
|
||||
var (leftRect, rightRect) = rect.HorizontalSliceLerp(0.5f);
|
||||
GUI.Label(leftRect, metaID);
|
||||
GUI.Label(rightRect, scriptPath);
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs.meta
Normal file
11
src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66e2240e9dd52204daec6a089888e7be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -42,7 +42,7 @@ namespace DCFApixels.DragonECS.Unity.Docs
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
if (TypeMeta.IsHasMeta(type))
|
||||
if (TypeMeta.IsHasCustomMeta(type))
|
||||
{
|
||||
result.Add(type);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user