2022-08-28 10:04:53 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using VRC.SDKBase.Editor.BuildPipeline;
|
|
|
|
|
|
|
|
|
|
namespace net.fushizen.modular_avatar.core.editor
|
|
|
|
|
{
|
|
|
|
|
public static class PathMappings
|
|
|
|
|
{
|
2022-08-30 06:13:26 +08:00
|
|
|
|
private static SortedDictionary<string, MappingEntry> Mappings = new SortedDictionary<string, MappingEntry>();
|
2022-08-28 10:04:53 +08:00
|
|
|
|
private static List<string> CachedMappingKeys = null;
|
|
|
|
|
|
2022-08-30 06:13:26 +08:00
|
|
|
|
public struct MappingEntry
|
|
|
|
|
{
|
|
|
|
|
public string path;
|
|
|
|
|
public string transformPath;
|
|
|
|
|
|
|
|
|
|
public string Get(bool isTransformMapping)
|
|
|
|
|
{
|
|
|
|
|
return isTransformMapping ? transformPath : path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-28 10:04:53 +08:00
|
|
|
|
internal static void Clear()
|
|
|
|
|
{
|
|
|
|
|
Mappings.Clear();
|
|
|
|
|
CachedMappingKeys = null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 06:13:26 +08:00
|
|
|
|
internal static void Remap(string from, MappingEntry to)
|
2022-08-28 10:04:53 +08:00
|
|
|
|
{
|
|
|
|
|
Mappings[from] = to;
|
|
|
|
|
CachedMappingKeys = null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 06:13:26 +08:00
|
|
|
|
internal static string MapPath(string path, bool isTransformMapping = false)
|
2022-08-28 10:04:53 +08:00
|
|
|
|
{
|
|
|
|
|
if (CachedMappingKeys == null) CachedMappingKeys = new List<string>(Mappings.Keys);
|
|
|
|
|
var bsResult = CachedMappingKeys.BinarySearch(path);
|
2022-08-30 06:13:26 +08:00
|
|
|
|
if (bsResult >= 0) return Mappings[path].Get(isTransformMapping);
|
2022-08-28 10:04:53 +08:00
|
|
|
|
|
|
|
|
|
int index = ~bsResult;
|
|
|
|
|
if (index == 0) return path;
|
|
|
|
|
|
|
|
|
|
var priorKey = CachedMappingKeys[index - 1];
|
|
|
|
|
if (path.StartsWith(priorKey + "/"))
|
|
|
|
|
{
|
2022-08-30 06:13:26 +08:00
|
|
|
|
return Mappings[priorKey].Get(isTransformMapping) + path.Substring(priorKey.Length);
|
2022-08-28 10:04:53 +08:00
|
|
|
|
}
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class ClearPathMappings : IVRCSDKPreprocessAvatarCallback
|
|
|
|
|
{
|
|
|
|
|
public int callbackOrder => HookSequence.SEQ_RESETTERS;
|
|
|
|
|
public bool OnPreprocessAvatar(GameObject avatarGameObject)
|
|
|
|
|
{
|
|
|
|
|
PathMappings.Clear();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|