Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
#12 Addressable guid parse
Browse files Browse the repository at this point in the history
  • Loading branch information
shaderqu committed Sep 24, 2021
1 parent a858221 commit 0800240
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 24 deletions.
22 changes: 7 additions & 15 deletions Editor/Reference/Callback/ReferenceCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ internal static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAsse
}
catch (Exception e)
{
Debug.LogError(asset);
Debug.LogException(e);
}
#endif
Expand Down Expand Up @@ -200,10 +199,14 @@ private static void OnAssetDelete(string path)
// 이 에셋이 레퍼런스하는 에셋 정보들 편집
foreach (string ownGuid in refAsset.ownGuids)
{
RefData referedAsset = RefData.Get(ownGuid);
// 존재하는 파일만 수정
if (RefData.Exist(ownGuid))
{
RefData referedAsset = RefData.Get(ownGuid);

referedAsset.referedByGuids.Remove(guid);
referedAsset.Save();
referedAsset.referedByGuids.Remove(guid);
referedAsset.Save();
}
}

refAsset.Remove();
Expand All @@ -213,17 +216,6 @@ private static void OnAssetDelete(string path)

private static void OnAssetCreate(string path, string guid)
{
// @TODO :: 커스텀 패키지도 관리되게

// if (path.Contains("Packages/Reference"))
// {
// return;
// }
//
// #if !DEBUG_ASSETLENS
// if (path.Contains("Packages/")) return;
// #endif

// 새로 만들었으면 이 에셋을 레퍼런스된게 있을 수 없으므로 그냥 프로필만 생성 ctrl-z로 복구하는거면 문제생길수있음...
if (string.IsNullOrWhiteSpace(path))
{
Expand Down
33 changes: 32 additions & 1 deletion Editor/Reference/Core/ReferenceDevelopmentMenu.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -84,7 +85,37 @@ private static async void TryParseGuids()
string value = await reader.ReadToEndAsync();

List<string> parsed = RefData.ParseOwnGuids(value);
Debug.Log(parsed.ToString());
foreach (string guid in parsed)
{
Debug.Log($"{AssetDatabase.GUIDToAssetPath(guid)}, {guid}");
}
}

[MenuItem(ReferenceMenuName.TOOL + "_DEV/Try Parse Selection 2")]
private static async void TryParseGuids2()
{
HashSet<string> owningGuids = new HashSet<string>();

Object target = Selection.activeObject;

string path = AssetDatabase.GetAssetPath(target);
StreamReader reader = new StreamReader(File.OpenRead(path));
string value = await reader.ReadToEndAsync();

Regex guidRegx = new Regex("GUID:\\s?([a-fA-F0-9]+)");
MatchCollection matches = guidRegx.Matches(value);
foreach (Match match in matches)
{
if (match.Success)
{
owningGuids.Add(match.Groups[1].Value);
}
}

foreach (string guid in owningGuids)
{
Debug.Log($"{AssetDatabase.GUIDToAssetPath(guid)}, {guid}");
}
}
}
#endif
Expand Down
36 changes: 28 additions & 8 deletions Editor/Reference/Model/RefData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace AssetLens.Reference
{
internal class RefData
{
private const string UNITY_DEFAULT_RESOURCE = "0000000000000000e000000000000000";
private const string UNITY_BUILTIN_EXTRA = "0000000000000000f000000000000000";

/// <summary>
/// from file name
/// </summary>
Expand Down Expand Up @@ -91,6 +94,16 @@ public void Remove()
File.Delete(path);
}

public bool IsBuiltInExtra()
{
return guid == UNITY_BUILTIN_EXTRA;
}

public bool IsDefaultResource()
{
return guid == UNITY_DEFAULT_RESOURCE;
}

public static RefData Get(string guid)
{
string path = FileSystem.ReferenceCacheDirectory + $"/{guid}.ref";
Expand All @@ -104,9 +117,6 @@ public static RefData Get(string guid)
return ReferenceSerializer.Deseriallize(guid);
}

private const string UNITY_DEFAULT_RESOURCE = "0000000000000000e000000000000000";
private const string UNITY_BUILTIN_EXTRA = "0000000000000000f000000000000000";

public static RefData New(string guid)
{
RefData asset = new RefData(guid, Setting.INDEX_VERSION);
Expand All @@ -130,13 +140,12 @@ public static RefData New(string guid)
}
else
{
if (owningGuid == UNITY_BUILTIN_EXTRA)
{

}
else if (owningGuid == UNITY_DEFAULT_RESOURCE)
if (owningGuid == UNITY_BUILTIN_EXTRA || owningGuid == UNITY_DEFAULT_RESOURCE)
{
RefData builtinExtra = new RefData(owningGuid, Setting.INDEX_VERSION);

builtinExtra.referedByGuids.Add(guid);
builtinExtra.Save();
}
else
{
Expand Down Expand Up @@ -167,6 +176,17 @@ public static List<string> ParseOwnGuids(string assetContent)
}
}

// 어드레서블
guidRegx = new Regex("m_GUID:\\s?([a-fA-F0-9]+)");
matches = guidRegx.Matches(assetContent);
foreach (Match match in matches)
{
if (match.Success)
{
owningGuids.Add(match.Groups[1].Value);
}
}

return owningGuids.ToList();
}

Expand Down

0 comments on commit 0800240

Please sign in to comment.