mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
stash
This commit is contained in:
parent
a5277126e7
commit
ecf1f4b4c4
@ -8,11 +8,12 @@ namespace DCFApixels.DragonECS.Unity.Docs.Editors
|
||||
{
|
||||
internal class DragonDocsWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/Documentation")]
|
||||
public const string TITLE = "Documentation";
|
||||
[MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/" + TITLE)]
|
||||
static void Open()
|
||||
{
|
||||
var wnd = GetWindow<DragonDocsWindow>();
|
||||
wnd.titleContent = new GUIContent($"{EcsConsts.FRAMEWORK_NAME} Documentation");
|
||||
wnd.titleContent = new GUIContent(TITLE);
|
||||
wnd.minSize = new Vector2(100f, 120f);
|
||||
wnd.Show();
|
||||
}
|
||||
|
64
src/Internal/ArrayUtility.cs
Normal file
64
src/Internal/ArrayUtility.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Internal
|
||||
{
|
||||
internal interface ILinkedNext
|
||||
{
|
||||
int Next { get; }
|
||||
}
|
||||
internal readonly struct LinkedListIterator<T> : IEnumerable<T>
|
||||
where T : ILinkedNext
|
||||
{
|
||||
public readonly T[] Array;
|
||||
public readonly int Count;
|
||||
public readonly int StartIndex;
|
||||
public LinkedListIterator(T[] array, int count, int startIndex)
|
||||
{
|
||||
Array = array;
|
||||
Count = count;
|
||||
StartIndex = startIndex;
|
||||
}
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator(Array, Count, StartIndex);
|
||||
}
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() { return GetEnumerator(); }
|
||||
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||
public struct Enumerator : IEnumerator<T>
|
||||
{
|
||||
private readonly T[] _array;
|
||||
private readonly int _count;
|
||||
private int _index;
|
||||
private int _counter;
|
||||
public Enumerator(T[] array, int count, int index)
|
||||
{
|
||||
_array = array;
|
||||
_count = count;
|
||||
_index = index;
|
||||
_counter = 0;
|
||||
}
|
||||
public ref T Current
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return ref _array[_index]; }
|
||||
}
|
||||
T IEnumerator<T>.Current { get { return _array[_index]; } }
|
||||
object IEnumerator.Current { get { return Current; } }
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (++_counter > _count) { return false; }
|
||||
if (_counter > 1)
|
||||
{
|
||||
_index = _array[_index].Next;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IDisposable.Dispose() { }
|
||||
void IEnumerator.Reset() { throw new NotSupportedException(); }
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
@ -104,6 +103,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
#if UNITY_EDITOR
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
using UnityEditor;
|
||||
|
||||
[InitializeOnLoad]
|
||||
internal static partial class UnityEditorUtility
|
||||
{
|
||||
@ -111,8 +112,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
colorBoxeStyles = new SparseArray<GUIStyle>();
|
||||
|
||||
#region InitSerializableTypes
|
||||
List<Type> types = new List<Type>();
|
||||
List<Type> serializableTypes = new List<Type>();
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
var targetTypes = assembly.GetTypes().Where(type =>
|
||||
@ -120,18 +120,20 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
type.IsSubclassOf(typeof(UnityObject)) == false &&
|
||||
type.GetCustomAttribute<SerializableAttribute>() != null);
|
||||
|
||||
types.AddRange(targetTypes);
|
||||
serializableTypes.AddRange(targetTypes);
|
||||
}
|
||||
_serializableTypes = types.ToArray();
|
||||
_serializableTypes = serializableTypes.ToArray();
|
||||
_serializableTypeWithMetaIDMetas = serializableTypes.Where(type => TypeMeta.IsHasMetaID(type)).Select(type => type.GetMeta()).ToArray();
|
||||
//Array.Sort(_serializableTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal));
|
||||
|
||||
//_noHiddenSerializableTypes = _serializableTypes.Where(o => {
|
||||
// var atr = o.GetCustomAttribute<MetaTagsAttribute>();
|
||||
// return atr != null && atr.Tags.Contains(MetaTags.HIDDEN);
|
||||
//}).ToArray();
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal static readonly Type[] _serializableTypes;
|
||||
internal static readonly TypeMeta[] _serializableTypeWithMetaIDMetas;
|
||||
//private static Type[] _noHiddenSerializableTypes;
|
||||
|
||||
private static SparseArray<GUIStyle> colorBoxeStyles = new SparseArray<GUIStyle>();
|
||||
|
@ -1,16 +1,19 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Internal
|
||||
{
|
||||
internal static class ReflectionExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool TryGetAttribute<T>(this MemberInfo self, out T attrbiute) where T : Attribute
|
||||
{
|
||||
attrbiute = self.GetCustomAttribute<T>();
|
||||
return attrbiute != null;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool HasAttribute<T>(this MemberInfo self) where T : Attribute
|
||||
{
|
||||
return self.GetCustomAttribute<T>() != null;
|
||||
|
8
src/RefRepairer.meta
Normal file
8
src/RefRepairer.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d2e79fd0957b6d43a3334b142c0cc72
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
src/RefRepairer/Editor.meta
Normal file
8
src/RefRepairer/Editor.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4c9608eab407004dba648302e06974b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
src/RefRepairer/Editor/RefRepairerWindow.cs
Normal file
54
src/RefRepairer/Editor/RefRepairerWindow.cs
Normal file
@ -0,0 +1,54 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
internal class RefRepairerWindow : EditorWindow
|
||||
{
|
||||
public const string TITLE = "Reference Repairer";
|
||||
[MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/" + TITLE)]
|
||||
static void Open()
|
||||
{
|
||||
var wnd = GetWindow<RefRepairerWindow>();
|
||||
wnd.titleContent = new GUIContent(TITLE);
|
||||
wnd.minSize = new Vector2(100f, 120f);
|
||||
wnd.Show();
|
||||
}
|
||||
|
||||
private List<ContainerMissingTypes> _missingTypes;
|
||||
//private readonly CollectorMissingTypes _collectorMissingTypes = new CollectorMissingTypes();
|
||||
|
||||
private bool TryInit()
|
||||
{
|
||||
var allCurrentDirtyScenes = EditorSceneManager
|
||||
.GetSceneManagerSetup()
|
||||
.Where(sceneSetup => sceneSetup.isLoaded)
|
||||
.Select(sceneSetup => EditorSceneManager.GetSceneByPath(sceneSetup.path))
|
||||
.Where(scene => scene.isDirty)
|
||||
.ToArray();
|
||||
|
||||
if (allCurrentDirtyScenes.Length != 0)
|
||||
{
|
||||
bool result = EditorUtility.DisplayDialog(
|
||||
"Current active scene(s) is dirty",
|
||||
"Please save all active scenes as they may be overwritten",
|
||||
"Save active scene and Continue",
|
||||
"Cancel update"
|
||||
);
|
||||
if (result == false)
|
||||
return false;
|
||||
|
||||
foreach (var dirtyScene in allCurrentDirtyScenes)
|
||||
EditorSceneManager.SaveScene(dirtyScene);
|
||||
}
|
||||
|
||||
//_missingTypes = _collectorMissingTypes.Collect();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
src/RefRepairer/Editor/RefRepairerWindow.cs.meta
Normal file
11
src/RefRepairer/Editor/RefRepairerWindow.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a7d6a916b19cda418d5b119c0b02804
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
173
src/RefRepairer/MetaIDRegistry.cs
Normal file
173
src/RefRepairer/MetaIDRegistry.cs
Normal file
@ -0,0 +1,173 @@
|
||||
#if UNITY_EDITOR
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
[FilePath(EcsUnityConsts.LOCAL_CACHE_FOLDER + "/" + nameof(MetaIDRegistry) + ".prefs", FilePathAttribute.Location.ProjectFolder)]
|
||||
internal class MetaIDRegistry : ScriptableSingleton<MetaIDRegistry>, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField]
|
||||
private TypeDataList[] _typeDataLists;
|
||||
[SerializeField]
|
||||
private int _typeDataListsCount = 0;
|
||||
[SerializeField]
|
||||
private TypeDataNode[] _typeDataNodes;
|
||||
[SerializeField]
|
||||
private int _typeDataNodesCount = 0;
|
||||
#region [SerializeField]
|
||||
private struct Pair
|
||||
{
|
||||
public string metaID;
|
||||
public int listIndex;
|
||||
public Pair(string metaID, int listIndex)
|
||||
{
|
||||
this.metaID = metaID;
|
||||
this.listIndex = listIndex;
|
||||
}
|
||||
}
|
||||
private Pair[] _metaIDListIndexPairsSerializable;
|
||||
#endregion
|
||||
private Dictionary<string, int> _metaIDListIndexPairs = new Dictionary<string, int>();
|
||||
|
||||
|
||||
|
||||
#region Update
|
||||
private void Update()
|
||||
{
|
||||
var typeMetas = UnityEditorUtility._serializableTypeWithMetaIDMetas;
|
||||
bool isChanged = false;
|
||||
|
||||
for (int i = 0; i < _typeDataListsCount; i++)
|
||||
{
|
||||
_typeDataLists[i].containsFlag = false;
|
||||
}
|
||||
|
||||
foreach (var meta in typeMetas)
|
||||
{
|
||||
var type = meta.Type;
|
||||
|
||||
var name = type.Name;
|
||||
var nameSpace = type.Namespace;
|
||||
var assembly = type.Assembly.FullName;
|
||||
|
||||
if (_metaIDListIndexPairs.TryGetValue(meta.MetaID, out int listIndex) == false)
|
||||
{
|
||||
if (_typeDataLists.Length <= _typeDataListsCount)
|
||||
{
|
||||
Array.Resize(ref _typeDataLists, _typeDataLists.Length << 1);
|
||||
}
|
||||
listIndex = _typeDataListsCount++;
|
||||
_metaIDListIndexPairs.Add(meta.MetaID, listIndex);
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
ref var listRef = ref _typeDataLists[listIndex];
|
||||
listRef.containsFlag = true;
|
||||
if (listRef.count > 0 && _typeDataNodes[listRef.startNode].EqualsWith(name, nameSpace, assembly))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_typeDataNodes.Length <= _typeDataNodesCount)
|
||||
{
|
||||
Array.Resize(ref _typeDataNodes, _typeDataNodes.Length << 1);
|
||||
}
|
||||
int nodeIndex = _typeDataNodesCount++;
|
||||
ref var nodeRef = ref _typeDataNodes[nodeIndex];
|
||||
isChanged = true;
|
||||
|
||||
nodeRef = new TypeDataNode(name, nameSpace, assembly);
|
||||
nodeRef.next = listRef.startNode;
|
||||
listRef.startNode = listIndex;
|
||||
listRef.count++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _typeDataListsCount; i++)
|
||||
{
|
||||
ref var list = ref _typeDataLists[i];
|
||||
if (list.containsFlag == false)
|
||||
{
|
||||
_metaIDListIndexPairs.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ISerializationCallbackReceiver
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||
{
|
||||
_metaIDListIndexPairs.Clear();
|
||||
if (_typeDataNodes == null)
|
||||
{
|
||||
_typeDataLists = new TypeDataList[256];
|
||||
_typeDataListsCount = 0;
|
||||
_typeDataNodes = new TypeDataNode[256];
|
||||
_typeDataNodesCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var pair in _metaIDListIndexPairsSerializable)
|
||||
{
|
||||
_metaIDListIndexPairs[pair.metaID] = pair.listIndex;
|
||||
}
|
||||
}
|
||||
Update();
|
||||
}
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
int i = 0;
|
||||
_metaIDListIndexPairsSerializable = new Pair[_metaIDListIndexPairs.Count];
|
||||
foreach (var pair in _metaIDListIndexPairs)
|
||||
{
|
||||
_metaIDListIndexPairsSerializable[i++] = new Pair(pair.Key, pair.Value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Utils
|
||||
[Serializable]
|
||||
public struct TypeDataList
|
||||
{
|
||||
public string metaID_key;
|
||||
public bool containsFlag;
|
||||
public int startNode;
|
||||
public int count;
|
||||
}
|
||||
[Serializable]
|
||||
public struct TypeDataNode : ILinkedNext
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly string Namespace;
|
||||
public readonly string Assembly;
|
||||
public int next;
|
||||
|
||||
public bool EqualsWith(string name, string nameSpace, string assembly)
|
||||
{
|
||||
return name == Name && nameSpace == Namespace && assembly == Assembly;
|
||||
}
|
||||
public TypeDataNode(string name, string nameSpace, string assembly) : this()
|
||||
{
|
||||
Name = name;
|
||||
Namespace = nameSpace;
|
||||
Assembly = assembly;
|
||||
}
|
||||
int ILinkedNext.Next
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return next; }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
257
src/RefRepairer/RefRepaireUtility.cs
Normal file
257
src/RefRepairer/RefRepaireUtility.cs
Normal file
@ -0,0 +1,257 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
public static class UnityObjectExtensions
|
||||
{
|
||||
public static int GetLocalIdentifierInFile(this UnityObject unityObject)
|
||||
{
|
||||
PropertyInfo inspectorModeInfo = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
SerializedObject serializedObject = new SerializedObject(unityObject);
|
||||
inspectorModeInfo.SetValue(serializedObject, InspectorMode.Debug, null);
|
||||
SerializedProperty localIdProp = serializedObject.FindProperty("m_LocalIdentfierInFile");
|
||||
return localIdProp.intValue;
|
||||
}
|
||||
}
|
||||
|
||||
internal class RefRepaireUtility
|
||||
{
|
||||
private readonly Dictionary<TypeData, ContainerMissingTypes> _missingTypes = new Dictionary<TypeData, ContainerMissingTypes>();
|
||||
|
||||
|
||||
#region Collect
|
||||
public List<ContainerMissingTypes> Collect()
|
||||
{
|
||||
_missingTypes.Clear();
|
||||
|
||||
CollectByPrefabs();
|
||||
CollectByScriptableObjects();
|
||||
CollectByScenes();
|
||||
|
||||
List<ContainerMissingTypes> result = new List<ContainerMissingTypes>(_missingTypes.Select((typeAndContainer) => typeAndContainer.Value));
|
||||
_missingTypes.Clear();
|
||||
return result;
|
||||
}
|
||||
private void CollectByPrefabs()
|
||||
{
|
||||
Scene previewScene = EditorSceneManager.NewPreviewScene();
|
||||
|
||||
foreach (var pathToPrefab in AssetDatabase.GetAllAssetPaths().Where(path => path.StartsWith("Assets/") && path.EndsWith(".prefab")))
|
||||
{
|
||||
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(pathToPrefab);
|
||||
PrefabUtility.LoadPrefabContentsIntoPreviewScene(pathToPrefab, previewScene);
|
||||
var copyPrefab = previewScene.GetRootGameObjects()[0];
|
||||
|
||||
var componentsPrefab = prefab.GetComponentsInChildren<MonoBehaviour>();
|
||||
var componentsCopyPrefab = copyPrefab.GetComponentsInChildren<MonoBehaviour>();
|
||||
|
||||
for (int i = 0; i < componentsCopyPrefab.Length; ++i)
|
||||
{
|
||||
var monoBehaviour = componentsCopyPrefab[i];
|
||||
if (SerializationUtility.HasManagedReferencesWithMissingTypes(monoBehaviour) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var missingType in SerializationUtility.GetManagedReferencesWithMissingTypes(monoBehaviour))
|
||||
{
|
||||
var prefabObject = new UnityObjectData(componentsPrefab[i].gameObject, pathToPrefab);
|
||||
|
||||
AddMissingType(missingType, prefabObject);
|
||||
}
|
||||
}
|
||||
|
||||
UnityObject.DestroyImmediate(copyPrefab);
|
||||
}
|
||||
|
||||
EditorSceneManager.ClosePreviewScene(previewScene);
|
||||
}
|
||||
private void CollectByScriptableObjects()
|
||||
{
|
||||
foreach (var pathToPrefab in AssetDatabase.GetAllAssetPaths().Where(path => path.StartsWith("Assets/") && path.EndsWith(".asset")))
|
||||
{
|
||||
var scriptableObject = AssetDatabase.LoadAssetAtPath<ScriptableObject>(pathToPrefab);
|
||||
|
||||
if (SerializationUtility.HasManagedReferencesWithMissingTypes(scriptableObject) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var missingType in SerializationUtility.GetManagedReferencesWithMissingTypes(scriptableObject))
|
||||
{
|
||||
var prefabObject = new UnityObjectData(scriptableObject, pathToPrefab);
|
||||
AddMissingType(missingType, prefabObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CollectByScenes()
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var scene in GetAllScenesInAssets())
|
||||
{
|
||||
var gameObjects = scene.GetRootGameObjects();
|
||||
|
||||
foreach (var objectOnScene in gameObjects)
|
||||
{
|
||||
foreach (var monoBehaviour in objectOnScene.GetComponentsInChildren<MonoBehaviour>())
|
||||
{
|
||||
if (SerializationUtility.HasManagedReferencesWithMissingTypes(monoBehaviour) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var missingType in SerializationUtility.GetManagedReferencesWithMissingTypes(monoBehaviour))
|
||||
{
|
||||
var sceneObject = new SceneObjectData(scene);
|
||||
AddMissingType(missingType, sceneObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
|
||||
Debug.LogException(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// SerializationUtility.
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Utils
|
||||
private static IEnumerable<Scene> GetAllScenesInAssets()
|
||||
{
|
||||
var oldScenesSetup = EditorSceneManager.GetSceneManagerSetup();
|
||||
|
||||
(bool isHasSelected, string scenePath, int identifierInFile) oldSelectedObject = default;
|
||||
GameObject activeGameObject = Selection.activeGameObject;
|
||||
if (activeGameObject != null)
|
||||
{
|
||||
oldSelectedObject.isHasSelected = true;
|
||||
oldSelectedObject.scenePath = activeGameObject.scene.path;
|
||||
oldSelectedObject.identifierInFile = activeGameObject.GetLocalIdentifierInFile();
|
||||
}
|
||||
|
||||
foreach (var pathToScene in AssetDatabase.GetAllAssetPaths().Where(path => path.StartsWith("Assets/") && path.EndsWith(".unity")))
|
||||
{
|
||||
Scene scene = EditorSceneManager.OpenScene(pathToScene, OpenSceneMode.Single);
|
||||
yield return scene;
|
||||
}
|
||||
|
||||
EditorSceneManager.RestoreSceneManagerSetup(oldScenesSetup);
|
||||
|
||||
if (oldSelectedObject.isHasSelected)
|
||||
{
|
||||
Selection.activeGameObject = SceneManager.GetSceneByPath(oldSelectedObject.scenePath)
|
||||
.GetRootGameObjects()
|
||||
.FirstOrDefault(gameObject => gameObject.GetLocalIdentifierInFile() == oldSelectedObject.identifierInFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
Selection.activeGameObject = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddMissingType(ManagedReferenceMissingType missingType, BaseUnityObjectData unityObject)
|
||||
{
|
||||
var typeData = new TypeData(missingType);
|
||||
var missingTypeData = new MissingTypeData(missingType, unityObject);
|
||||
if (_missingTypes.TryGetValue(typeData, out var containerMissingTypes) == false)
|
||||
{
|
||||
containerMissingTypes = new ContainerMissingTypes(typeData);
|
||||
_missingTypes.Add(typeData, containerMissingTypes);
|
||||
}
|
||||
|
||||
containerMissingTypes.Add(missingTypeData);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class ContainerMissingTypes
|
||||
{
|
||||
public readonly TypeData TypeData;
|
||||
|
||||
private readonly List<MissingTypeData> _managedReferencesMissingTypeDatas = new List<MissingTypeData>();
|
||||
|
||||
public IReadOnlyCollection<MissingTypeData> ManagedReferencesMissingTypeDatas => _managedReferencesMissingTypeDatas;
|
||||
|
||||
public ContainerMissingTypes(TypeData typeData)
|
||||
{
|
||||
TypeData = typeData;
|
||||
}
|
||||
|
||||
public void Add(MissingTypeData missingTypeData) => _managedReferencesMissingTypeDatas.Add(missingTypeData);
|
||||
|
||||
public void Remove(MissingTypeData missingTypeData) => _managedReferencesMissingTypeDatas.Remove(missingTypeData);
|
||||
|
||||
public void RemoveAt(int index) => _managedReferencesMissingTypeDatas.RemoveAt(index);
|
||||
}
|
||||
public struct MissingTypeData
|
||||
{
|
||||
public readonly ManagedReferenceMissingType Data;
|
||||
public readonly BaseUnityObjectData UnityObject;
|
||||
|
||||
public MissingTypeData(ManagedReferenceMissingType missingType, BaseUnityObjectData unityObject)
|
||||
{
|
||||
Data = missingType;
|
||||
UnityObject = unityObject;
|
||||
}
|
||||
}
|
||||
public struct TypeData
|
||||
{
|
||||
public readonly string AssemblyName;
|
||||
public readonly string NamespaceName;
|
||||
public readonly string ClassName;
|
||||
|
||||
public TypeData(ManagedReferenceMissingType missingType)
|
||||
{
|
||||
AssemblyName = missingType.assemblyName;
|
||||
NamespaceName = missingType.namespaceName;
|
||||
ClassName = missingType.className;
|
||||
}
|
||||
}
|
||||
public abstract class BaseUnityObjectData
|
||||
{
|
||||
public string LocalAssetPath => AssetDatabase.GUIDToAssetPath(AssetGuid);
|
||||
public abstract GUID AssetGuid { get; }
|
||||
}
|
||||
public class SceneObjectData : BaseUnityObjectData
|
||||
{
|
||||
public readonly string SceneName;
|
||||
|
||||
public override GUID AssetGuid { get; }
|
||||
|
||||
public SceneObjectData(Scene scene)
|
||||
{
|
||||
SceneName = scene.name;
|
||||
AssetGuid = AssetDatabase.GUIDFromAssetPath(scene.path);
|
||||
}
|
||||
}
|
||||
public class UnityObjectData : BaseUnityObjectData
|
||||
{
|
||||
public readonly UnityObject UnityObject;
|
||||
public override GUID AssetGuid { get; }
|
||||
|
||||
public UnityObjectData(UnityObject unityObject, string pathToPrefab)
|
||||
{
|
||||
UnityObject = unityObject;
|
||||
AssetGuid = AssetDatabase.GUIDFromAssetPath(pathToPrefab);
|
||||
}
|
||||
}
|
||||
}
|
11
src/RefRepairer/RefRepaireUtility.cs.meta
Normal file
11
src/RefRepairer/RefRepaireUtility.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 784d02aa2b8675846ae22da855eca93f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
75
src/RefRepairer/RepairerFile.cs
Normal file
75
src/RefRepairer/RepairerFile.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
public static class FileRepaireUtility
|
||||
{
|
||||
private const string REFLINE_PATTERN = "- rid:";
|
||||
public static void Replace(string filePath)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
public class RepairerFile
|
||||
{
|
||||
private readonly Type _type;
|
||||
private readonly string[] _fileLines;
|
||||
|
||||
private string _currentLine;
|
||||
private string _nextLine;
|
||||
|
||||
private int _currentIndex;
|
||||
|
||||
private readonly string _path;
|
||||
private readonly string _localAssetPath;
|
||||
|
||||
public RepairerFile(Type type, string localAssetPath)
|
||||
{
|
||||
_type = type;
|
||||
_localAssetPath = localAssetPath;
|
||||
|
||||
_path = $"{Application.dataPath.Replace("/Assets", "")}/{localAssetPath}";
|
||||
_fileLines = File.ReadAllLines(_path);
|
||||
}
|
||||
|
||||
public delegate bool GetterMissingTypeData(out MissingTypeData missingType);
|
||||
|
||||
public void Repair(Func<bool> callbackForNextLine)
|
||||
{
|
||||
for (int i = 0; i < _fileLines.Length - 1; ++i)
|
||||
{
|
||||
_currentIndex = i;
|
||||
|
||||
_currentLine = _fileLines[i];
|
||||
_nextLine = _fileLines[i + 1];
|
||||
|
||||
if (callbackForNextLine.Invoke())
|
||||
break;
|
||||
}
|
||||
|
||||
File.WriteAllLines(_path, _fileLines);
|
||||
|
||||
AssetDatabase.ImportAsset(_localAssetPath, ImportAssetOptions.ForceUpdate);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public bool CheckNeedLineAndReplacedIt(ManagedReferenceMissingType missingType)
|
||||
{
|
||||
string rid = $"rid: {missingType.referenceId}";
|
||||
string oldTypeData = $"type: {{class: {missingType.className}, ns: {missingType.namespaceName}, asm: {missingType.assemblyName}}}";
|
||||
|
||||
if (_currentLine.Contains(rid) && _nextLine.Contains(oldTypeData))
|
||||
{
|
||||
string newTypeData = $"type: {{class: {_type.Name}, ns: {_type.Namespace}, asm: {_type.Assembly.GetName().Name}}}";
|
||||
_fileLines[_currentIndex + 1] = _nextLine.Replace(oldTypeData, newTypeData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
src/RefRepairer/RepairerFile.cs.meta
Normal file
11
src/RefRepairer/RepairerFile.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd87f9f7b02388741a94e1e36f1a46ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -18,7 +18,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
private ReorderableList _reorderableComponentsList;
|
||||
|
||||
#region Init
|
||||
protected override bool IsInit => _componentDropDown != null;
|
||||
protected override bool IsInit { get { return _componentDropDown != null; } }
|
||||
protected override void OnInit()
|
||||
{
|
||||
_componentDropDown = new ComponentDropDown();
|
||||
|
@ -127,23 +127,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
static ComponentTemplateTypeCache()
|
||||
{
|
||||
List<Type> types = new List<Type>();
|
||||
Type interfaceType = typeof(IComponentTemplate);
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
var targetTypes = assembly.GetTypes().Where(type => !type.IsGenericType && !(type.IsAbstract || type.IsInterface) /*&& type.GetCustomAttribute<SerializableAttribute>() != null*/);
|
||||
|
||||
types.AddRange(targetTypes.Where(type => interfaceType.IsAssignableFrom(type)));
|
||||
|
||||
foreach (var t in targetTypes)
|
||||
{
|
||||
if (t.IsSubclassOf(typeof(ComponentTemplateBase<>)))
|
||||
{
|
||||
types.Add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
_types = types.ToArray();
|
||||
_types = UnityEditorUtility._serializableTypes.Where(type => interfaceType.IsAssignableFrom(type)).ToArray();
|
||||
foreach (var type in _types)
|
||||
{
|
||||
EcsDebugUtility.GetTypeMeta(type);
|
||||
|
Loading…
Reference in New Issue
Block a user