mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
fix references repairer
This commit is contained in:
parent
45c9c0a24c
commit
ac5b7ddbac
@ -67,6 +67,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
|
|
||||||
if (componentProperty == null)
|
if (componentProperty == null)
|
||||||
{
|
{
|
||||||
|
//Debug.Log(prop.displayName);
|
||||||
throw new NullReferenceException();
|
throw new NullReferenceException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace DCFApixels.DragonECS
|
|||||||
if (_components == null) { return; }
|
if (_components == null) { return; }
|
||||||
foreach (var item in _components)
|
foreach (var item in _components)
|
||||||
{
|
{
|
||||||
item.OnValidate(this);
|
item?.OnValidate(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -160,6 +160,15 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
}
|
}
|
||||||
using (EcsGUI.Layout.BeginVertical(_panel))
|
using (EcsGUI.Layout.BeginVertical(_panel))
|
||||||
{
|
{
|
||||||
|
if (_missingRefContainer != null)
|
||||||
|
{
|
||||||
|
Debug.Log(_missingRefContainer.IsEmptyX);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("NULL");
|
||||||
|
}
|
||||||
|
|
||||||
const string LIST_EMPTY_MESSAGE = "List of Missings is Empty";
|
const string LIST_EMPTY_MESSAGE = "List of Missings is Empty";
|
||||||
const string COLLECT_BUTTON = "Collect Missings";
|
const string COLLECT_BUTTON = "Collect Missings";
|
||||||
if (_missingRefContainer.IsEmpty)
|
if (_missingRefContainer.IsEmpty)
|
||||||
@ -287,6 +296,11 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
{
|
{
|
||||||
_selectedMissingsResolvingData = null;
|
_selectedMissingsResolvingData = null;
|
||||||
RepaireFileUtility.RepaieAsset(_missingRefContainer);
|
RepaireFileUtility.RepaieAsset(_missingRefContainer);
|
||||||
|
if (_missingRefContainer.IsEmpty)
|
||||||
|
{
|
||||||
|
_isNoFound = true;
|
||||||
|
MetaIDRegistry.instance.Reinit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
{
|
{
|
||||||
internal class MissingRefContainer
|
internal class MissingRefContainer
|
||||||
{
|
{
|
||||||
|
// обязательно распологать так чтобы записи сссылающиеся на один и тот же ассет шли подряд друг за другом
|
||||||
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>();
|
||||||
@ -22,6 +23,10 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
{
|
{
|
||||||
get { return collectedMissingTypesBufferCount == 0; }
|
get { return collectedMissingTypesBufferCount == 0; }
|
||||||
}
|
}
|
||||||
|
public int IsEmptyX
|
||||||
|
{
|
||||||
|
get { return collectedMissingTypesBufferCount; }
|
||||||
|
}
|
||||||
|
|
||||||
#region Clear/RemoveResolved
|
#region Clear/RemoveResolved
|
||||||
public void Clear()
|
public void Clear()
|
||||||
@ -35,53 +40,57 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
}
|
}
|
||||||
public void RemoveResolved()
|
public void RemoveResolved()
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int startI = 0;
|
||||||
int i = 0;
|
int newCollectedMissingTypesBufferCount = collectedMissingTypesBufferCount;
|
||||||
int newLength = collectedMissingTypesBufferCount;
|
bool isNoResolved = true;
|
||||||
bool isReturn = true;
|
// тут проверяется что есть разрешенные миссинги
|
||||||
for (; i < newLength; i++)
|
// или просто скипается часть с не разрешенными миссингами
|
||||||
|
for (; startI < collectedMissingTypesBufferCount; startI++)
|
||||||
{
|
{
|
||||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[i];
|
ref var collectedMissingType = ref collectedMissingTypesBuffer[startI];
|
||||||
if (collectedMissingType.IsResolvedOrNull)
|
if (collectedMissingType.IsResolvedOrNull)
|
||||||
{
|
{
|
||||||
if (collectedMissingType.ResolvingData != null)
|
if (collectedMissingType.ResolvingData != null)
|
||||||
{
|
{
|
||||||
MissingsResolvingDatas.Remove(collectedMissingType.ResolvingData.OldTypeData);
|
MissingsResolvingDatas.Remove(collectedMissingType.ResolvingData.OldTypeData);
|
||||||
}
|
}
|
||||||
offset = 1;
|
newCollectedMissingTypesBufferCount--;
|
||||||
newLength--;
|
isNoResolved = false;
|
||||||
isReturn = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isReturn) { return; }
|
if (isNoResolved) { return; }
|
||||||
|
// тут один разрешенный миссинг уже найден
|
||||||
|
|
||||||
int nextI = i + offset;
|
int nextI = startI + 1;
|
||||||
for (; nextI < newLength; nextI++)
|
for (; nextI < collectedMissingTypesBufferCount;)
|
||||||
{
|
{
|
||||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[i];
|
ref var collectedMissingType = ref collectedMissingTypesBuffer[nextI];
|
||||||
if (collectedMissingType.IsResolvedOrNull)
|
if (collectedMissingType.IsResolvedOrNull)
|
||||||
{
|
{
|
||||||
if (collectedMissingType.ResolvingData != null)
|
if (collectedMissingType.ResolvingData != null)
|
||||||
{
|
{
|
||||||
MissingsResolvingDatas.Remove(collectedMissingType.ResolvingData.OldTypeData);
|
MissingsResolvingDatas.Remove(collectedMissingType.ResolvingData.OldTypeData);
|
||||||
}
|
}
|
||||||
offset++;
|
newCollectedMissingTypesBufferCount--;
|
||||||
newLength--;
|
nextI++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
collectedMissingTypesBuffer[i] = collectedMissingTypesBuffer[nextI];
|
collectedMissingTypesBuffer[startI] = collectedMissingTypesBuffer[nextI];
|
||||||
i++;
|
startI++;
|
||||||
|
nextI++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = newLength; i < collectedMissingTypesBufferCount; i++)
|
|
||||||
|
//очистка хвостовой части откуда все уехало
|
||||||
|
for (startI = newCollectedMissingTypesBufferCount; startI < collectedMissingTypesBufferCount; startI++)
|
||||||
{
|
{
|
||||||
collectedMissingTypesBuffer[i] = default;
|
collectedMissingTypesBuffer[startI] = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
collectedMissingTypesBufferCount = newLength;
|
collectedMissingTypesBufferCount = newCollectedMissingTypesBufferCount;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -39,43 +39,40 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
{
|
{
|
||||||
if (container.IsEmpty) { return; }
|
if (container.IsEmpty) { return; }
|
||||||
|
|
||||||
|
UnityObjectDataBase unityObjectData = null;
|
||||||
|
FileScope fileScope = default;
|
||||||
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];
|
||||||
if (missing.IsNull) { continue; }
|
if (unityObjectData != missing.UnityObject)
|
||||||
|
{
|
||||||
|
unityObjectData = missing.UnityObject;
|
||||||
|
fileScope.Dispose();
|
||||||
|
fileScope = new FileScope(unityObjectData.GetLocalAssetPath());
|
||||||
|
}
|
||||||
|
|
||||||
var unityObjectData = missing.UnityObject;
|
int lineIndex = NextRefLine(fileScope.lines, 0);
|
||||||
using (var file = new FileScope(unityObjectData.GetLocalAssetPath()))
|
|
||||||
{
|
|
||||||
// òóò èòåðèðóþñü ïî áëîêó missingsResolvingDatas ñ îäèíàêîâûì þíèòè îáúåêòîì, òàê êàê òàêèå èäåóò ïîäðÿò
|
|
||||||
do
|
|
||||||
{
|
|
||||||
int lineIndex = NextRefLine(file.lines, 0);
|
|
||||||
while (lineIndex > 0)
|
while (lineIndex > 0)
|
||||||
{
|
{
|
||||||
var line = file.lines[lineIndex];
|
var line = fileScope.lines[lineIndex];
|
||||||
|
|
||||||
// Êàê ñêàçàííî â äîêóìåíòàöèè ê ìåòîäó Replace
|
// Êàê ñêàçàííî â äîêóìåíòàöèè ê ìåòîäó Replace
|
||||||
// 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
|
||||||
line = line.Replace(missing.ResolvingData.OldSerializedInfoLine, missing.ResolvingData.NewSerializedInfoLine);
|
line = line.Replace(missing.ResolvingData.OldSerializedInfoLine, missing.ResolvingData.NewSerializedInfoLine);
|
||||||
bool isChanged = !ReferenceEquals(file.lines[lineIndex], line);
|
bool isChanged = !ReferenceEquals(fileScope.lines[lineIndex], line);
|
||||||
|
|
||||||
|
|
||||||
if (isChanged)
|
if (isChanged)
|
||||||
{
|
{
|
||||||
file.lines[lineIndex] = line;
|
fileScope.lines[lineIndex] = line;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lineIndex = NextRefLine(file.lines, lineIndex);
|
lineIndex = NextRefLine(fileScope.lines, lineIndex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
fileScope.Dispose();
|
||||||
|
|
||||||
missing = ref container.collectedMissingTypesBuffer[i++];
|
|
||||||
} while (unityObjectData == missing.UnityObject);
|
|
||||||
i--;//÷òîáû èòåðàöèÿ íå ïîëîìàëàñü
|
|
||||||
}
|
|
||||||
}
|
|
||||||
container.RemoveResolved();
|
container.RemoveResolved();
|
||||||
}
|
}
|
||||||
public struct FileScope : IDisposable
|
public struct FileScope : IDisposable
|
||||||
@ -92,6 +89,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(FilePath)) { return; }
|
||||||
File.WriteAllLines(FilePath, lines);
|
File.WriteAllLines(FilePath, lines);
|
||||||
AssetDatabase.ImportAsset(LocalAssetPath, ImportAssetOptions.ForceUpdate);
|
AssetDatabase.ImportAsset(LocalAssetPath, ImportAssetOptions.ForceUpdate);
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
|
Loading…
Reference in New Issue
Block a user