mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-19 02:24:35 +08:00
add repaire refs tool
This commit is contained in:
parent
bb6c2cec43
commit
5e2c03be1e
@ -127,6 +127,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
.Where(type => TypeMeta.IsHasMetaID(type))
|
.Where(type => TypeMeta.IsHasMetaID(type))
|
||||||
.Select(type => type.ToMeta())
|
.Select(type => type.ToMeta())
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
foreach (var item in _serializableTypeWithMetaIDMetas)
|
||||||
|
{
|
||||||
|
_metaIDTypePairs[item.MetaID] = item.Type;
|
||||||
|
}
|
||||||
//Array.Sort(_serializableTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal));
|
//Array.Sort(_serializableTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal));
|
||||||
|
|
||||||
//_noHiddenSerializableTypes = _serializableTypes.Where(o => {
|
//_noHiddenSerializableTypes = _serializableTypes.Where(o => {
|
||||||
|
@ -3,6 +3,7 @@ using DCFApixels.DragonECS.Unity.RefRepairer.Editors;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.SceneManagement;
|
using UnityEditor.SceneManagement;
|
||||||
|
using UnityEditorInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Unity.Editors
|
namespace DCFApixels.DragonECS.Unity.Editors
|
||||||
@ -20,7 +21,20 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
}
|
}
|
||||||
|
|
||||||
private MissingRefContainer _missingRefContainer = new MissingRefContainer();
|
private MissingRefContainer _missingRefContainer = new MissingRefContainer();
|
||||||
|
private MissingsResolvingData[] _cachedMissingsResolvingDatas = null;
|
||||||
|
|
||||||
|
private ReorderableList _reorderableList;
|
||||||
|
|
||||||
|
private void InitList()
|
||||||
|
{
|
||||||
|
if(_reorderableList == null)
|
||||||
|
{
|
||||||
|
_reorderableList = new ReorderableList(_cachedMissingsResolvingDatas, typeof(MissingsResolvingData), false, false, false, false);
|
||||||
|
_reorderableList.headerHeight = 0;
|
||||||
|
_reorderableList.footerHeight = 0;
|
||||||
|
}
|
||||||
|
_reorderableList.list = _cachedMissingsResolvingDatas;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnGUI()
|
private void OnGUI()
|
||||||
{
|
{
|
||||||
@ -31,13 +45,28 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
if (TryInit())
|
if (TryInit())
|
||||||
{
|
{
|
||||||
_missingRefContainer.Collect();
|
_missingRefContainer.Collect();
|
||||||
|
_cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray();
|
||||||
|
InitList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button("Repaire missing references"))
|
||||||
|
{
|
||||||
|
Debug.Log(_missingRefContainer.IsEmplty);
|
||||||
|
var x = _missingRefContainer.collectedMissingTypesBuffer[0];
|
||||||
|
Debug.Log(x.ResolvingData.NewTypeData.AutoToString());
|
||||||
|
RepaireFileUtility.RepaieAsset(_missingRefContainer);
|
||||||
|
}
|
||||||
|
|
||||||
_missingRefContainer.MissingsResolvingDatas
|
if (_missingRefContainer.MissingsResolvingDatas.Count != _cachedMissingsResolvingDatas.Length)
|
||||||
|
{
|
||||||
|
_cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray();
|
||||||
|
InitList();
|
||||||
|
}
|
||||||
|
|
||||||
|
_reorderableList.DoLayoutList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ using DCFApixels.DragonECS.Unity.Editors;
|
|||||||
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -57,33 +56,9 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
var typeMetas = UnityEditorUtility._serializableTypeWithMetaIDMetas;
|
var typeMetas = UnityEditorUtility._serializableTypeWithMetaIDMetas;
|
||||||
StringBuilder sb = null;
|
|
||||||
foreach (var meta in typeMetas)
|
foreach (var meta in typeMetas)
|
||||||
{
|
{
|
||||||
var type = meta.Type;
|
var key = new TypeData(meta.Type);
|
||||||
string name = null;
|
|
||||||
if (type.DeclaringType == null)
|
|
||||||
{
|
|
||||||
name = type.Name;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Type iteratorType = type;
|
|
||||||
if (sb == null)
|
|
||||||
{
|
|
||||||
sb = new StringBuilder();
|
|
||||||
}
|
|
||||||
sb.Clear();
|
|
||||||
sb.Append(iteratorType.Name);
|
|
||||||
while ((iteratorType = iteratorType.DeclaringType) != null)
|
|
||||||
{
|
|
||||||
sb.Insert(0, '/');
|
|
||||||
sb.Insert(0, iteratorType.Name);
|
|
||||||
}
|
|
||||||
name = sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
var key = new TypeData(name, type.Namespace, type.Assembly.GetName().Name);
|
|
||||||
var metaID = meta.MetaID;
|
var metaID = meta.MetaID;
|
||||||
|
|
||||||
//Debug.LogWarning(type + " " + metaID);
|
//Debug.LogWarning(type + " " + metaID);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
using DCFApixels.DragonECS.Unity.Editors;
|
||||||
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -17,7 +18,6 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
public CollectedAssetMissingRecord[] collectedMissingTypesBuffer = null;
|
public CollectedAssetMissingRecord[] collectedMissingTypesBuffer = null;
|
||||||
public int collectedMissingTypesBufferCount = 0;
|
public int collectedMissingTypesBufferCount = 0;
|
||||||
public readonly Dictionary<TypeData, MissingsResolvingData> MissingsResolvingDatas = new Dictionary<TypeData, MissingsResolvingData>();
|
public readonly Dictionary<TypeData, MissingsResolvingData> MissingsResolvingDatas = new Dictionary<TypeData, MissingsResolvingData>();
|
||||||
public MissingsResolvingData[] MissingsResolvingDataValues;
|
|
||||||
public bool IsEmplty
|
public bool IsEmplty
|
||||||
{
|
{
|
||||||
get { return collectedMissingTypesBufferCount == 0; }
|
get { return collectedMissingTypesBufferCount == 0; }
|
||||||
@ -38,6 +38,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
int offset = 0;
|
int offset = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int newLength = collectedMissingTypesBufferCount;
|
int newLength = collectedMissingTypesBufferCount;
|
||||||
|
bool isReturn = true;
|
||||||
for (; i < newLength; i++)
|
for (; i < newLength; i++)
|
||||||
{
|
{
|
||||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[i];
|
ref var collectedMissingType = ref collectedMissingTypesBuffer[i];
|
||||||
@ -49,10 +50,11 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
}
|
}
|
||||||
offset = 1;
|
offset = 1;
|
||||||
newLength--;
|
newLength--;
|
||||||
|
isReturn = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i >= newLength) { return; }
|
if (isReturn) { return; }
|
||||||
|
|
||||||
int nextI = i + offset;
|
int nextI = i + offset;
|
||||||
for (; nextI < newLength; nextI++)
|
for (; nextI < newLength; nextI++)
|
||||||
@ -98,7 +100,6 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
CollectByScriptableObjects();
|
CollectByScriptableObjects();
|
||||||
CollectByScenes();
|
CollectByScenes();
|
||||||
|
|
||||||
MissingsResolvingDataValues = MissingsResolvingDatas.Values.ToArray();
|
|
||||||
for (int i = collectedMissingTypesBufferCount; i < oldCollectedMissingTypesBufferCount; i++)
|
for (int i = collectedMissingTypesBufferCount; i < oldCollectedMissingTypesBufferCount; i++)
|
||||||
{
|
{
|
||||||
collectedMissingTypesBuffer[i] = default;
|
collectedMissingTypesBuffer[i] = default;
|
||||||
@ -107,11 +108,19 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
}
|
}
|
||||||
private void Add(UnityObjectDataBase unityObjectData, ref ManagedReferenceMissingType missing)
|
private void Add(UnityObjectDataBase unityObjectData, ref ManagedReferenceMissingType missing)
|
||||||
{
|
{
|
||||||
var typeData = new TypeData(missing);
|
var oldTypeData = new TypeData(missing);
|
||||||
if (MissingsResolvingDatas.TryGetValue(typeData, out var resolvingData) == false)
|
if (MissingsResolvingDatas.TryGetValue(oldTypeData, out var resolvingData) == false)
|
||||||
{
|
{
|
||||||
resolvingData = new MissingsResolvingData(typeData);
|
resolvingData = new MissingsResolvingData(oldTypeData);
|
||||||
MissingsResolvingDatas.Add(typeData, resolvingData);
|
MissingsResolvingDatas.Add(oldTypeData, resolvingData);
|
||||||
|
|
||||||
|
if (MetaIDRegistry.instance.TryGetMetaID(oldTypeData, out string metaID))
|
||||||
|
{
|
||||||
|
if (UnityEditorUtility.TryGetTypeForMetaID(metaID, out Type type))
|
||||||
|
{
|
||||||
|
resolvingData.NewTypeData = new TypeData(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collectedMissingTypesBufferCount >= collectedMissingTypesBuffer.Length)
|
if (collectedMissingTypesBufferCount >= collectedMissingTypesBuffer.Length)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -38,9 +37,8 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
}
|
}
|
||||||
public static void RepaieAsset(MissingRefContainer container)
|
public static void RepaieAsset(MissingRefContainer container)
|
||||||
{
|
{
|
||||||
if (container.collectedMissingTypesBufferCount <= 0) { return; }
|
if (container.IsEmplty) { return; }
|
||||||
|
|
||||||
//MissingsResolvingData[] missingsResolvingDatas = container.MissingsResolvingDatas.Values.Where(o => o.IsResolved).ToArray();
|
|
||||||
for (int i = 0; i < container.collectedMissingTypesBufferCount; i++)
|
for (int i = 0; i < container.collectedMissingTypesBufferCount; i++)
|
||||||
{
|
{
|
||||||
ref var missing = ref container.collectedMissingTypesBuffer[i];
|
ref var missing = ref container.collectedMissingTypesBuffer[i];
|
||||||
@ -49,13 +47,10 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
var unityObjectData = missing.UnityObject;
|
var unityObjectData = missing.UnityObject;
|
||||||
using (var file = new FileScope(unityObjectData.GetLocalAssetPath()))
|
using (var file = new FileScope(unityObjectData.GetLocalAssetPath()))
|
||||||
{
|
{
|
||||||
int startRepaierLineIndex = 0;//Ýòî íóæíî ÷òîáû ñêèïàòü óæå "îòðåìîíòèðîâàííóþ" ÷àñòü ôàéë.
|
|
||||||
|
|
||||||
// òóò èòåðèðóþñü ïî áëîêó missingsResolvingDatas ñ îäèíàêîâûì þíèòè îáúåêòîì, òàê êàê òàêèå èäåóò ïîäðÿò
|
// òóò èòåðèðóþñü ïî áëîêó missingsResolvingDatas ñ îäèíàêîâûì þíèòè îáúåêòîì, òàê êàê òàêèå èäåóò ïîäðÿò
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
//bool isAnySkiped = false;
|
int lineIndex = NextRefLine(file.lines, 0);
|
||||||
int lineIndex = NextRefLine(file.lines, startRepaierLineIndex);
|
|
||||||
while (lineIndex > 0)
|
while (lineIndex > 0)
|
||||||
{
|
{
|
||||||
var line = file.lines[lineIndex];
|
var line = file.lines[lineIndex];
|
||||||
@ -64,22 +59,14 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
// A string that is equivalent to this instance except that all instances of oldChar are replaced with newChar.
|
// A string that is equivalent to this instance except that all instances of oldChar are replaced with newChar.
|
||||||
// If oldChar is not found in the current instance, the method returns the current instance unchanged.
|
// If oldChar is not found in the current instance, the method returns the current instance unchanged.
|
||||||
// À êîíêðåòíî ñòðî÷êè "returns the current instance unchanged", ìîæíî ñäåëàòü óïðîùåííóþ ïðîâåðêó ÷åðåç ReferenceEquals
|
// À êîíêðåòíî ñòðî÷êè "returns the current instance unchanged", ìîæíî ñäåëàòü óïðîùåííóþ ïðîâåðêó ÷åðåç ReferenceEquals
|
||||||
string oldLine = line;
|
|
||||||
line = line.Replace(missing.ResolvingData.OldSerializedInfoLine, missing.ResolvingData.NewSerializedInfoLine);
|
line = line.Replace(missing.ResolvingData.OldSerializedInfoLine, missing.ResolvingData.NewSerializedInfoLine);
|
||||||
bool isChanged = !ReferenceEquals(oldLine, line);
|
bool isChanged = !ReferenceEquals(file.lines[lineIndex], line);
|
||||||
|
|
||||||
|
|
||||||
if (isChanged == false)
|
if (isChanged)
|
||||||
{
|
|
||||||
//isAnySkiped = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
file.lines[lineIndex] = line;
|
||||||
break;
|
break;
|
||||||
//if (isAnySkiped == false)
|
|
||||||
//{
|
|
||||||
// startRepaierLineIndex = lineIndex;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
lineIndex = NextRefLine(file.lines, lineIndex);
|
lineIndex = NextRefLine(file.lines, lineIndex);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using System;
|
using System;
|
||||||
|
using System.Text;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal
|
namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal
|
||||||
@ -36,6 +37,37 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal
|
|||||||
NamespaceName = namespaceName;
|
NamespaceName = namespaceName;
|
||||||
AssemblyName = assemblyName;
|
AssemblyName = assemblyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ThreadStatic]
|
||||||
|
private static StringBuilder sb;
|
||||||
|
public TypeData(Type type)
|
||||||
|
{
|
||||||
|
string name = null;
|
||||||
|
if (type.DeclaringType == null)
|
||||||
|
{
|
||||||
|
name = type.Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Type iteratorType = type;
|
||||||
|
if (sb == null)
|
||||||
|
{
|
||||||
|
sb = new StringBuilder();
|
||||||
|
}
|
||||||
|
sb.Clear();
|
||||||
|
sb.Append(iteratorType.Name);
|
||||||
|
while ((iteratorType = iteratorType.DeclaringType) != null)
|
||||||
|
{
|
||||||
|
sb.Insert(0, '/');
|
||||||
|
sb.Insert(0, iteratorType.Name);
|
||||||
|
}
|
||||||
|
name = sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassName = name;
|
||||||
|
NamespaceName = type.Namespace;
|
||||||
|
AssemblyName = type.Assembly.GetName().Name;
|
||||||
|
}
|
||||||
public bool Equals(TypeData other)
|
public bool Equals(TypeData other)
|
||||||
{
|
{
|
||||||
return ClassName == other.ClassName &&
|
return ClassName == other.ClassName &&
|
||||||
|
Loading…
Reference in New Issue
Block a user