modular-avatar/Packages/net.fushizen.modular-avatar/Runtime/ModularAvatarMergeArmature.cs

47 lines
1.6 KiB
C#
Raw Normal View History

2022-08-28 04:38:52 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace net.fushizen.modular_avatar.core
{
public class ModularAvatarMergeArmature : AvatarTagComponent
{
public GameObject mergeTarget;
public string mergeTargetPath;
public string prefix;
public string suffix;
#if UNITY_EDITOR
2022-08-28 04:38:52 +08:00
void OnValidate()
{
EditorApplication.delayCall += () =>
{
2022-08-30 05:00:01 +08:00
if (this == null) return;
2022-08-28 04:38:52 +08:00
if (mergeTarget == null && !string.IsNullOrWhiteSpace(mergeTargetPath))
{
var avatar = RuntimeUtil.FindAvatarInParents(transform);
if (avatar != null)
{
mergeTarget = avatar.transform.Find(mergeTargetPath)?.gameObject;
}
2022-08-30 05:00:01 +08:00
if (mergeTarget != null) {
RuntimeUtil.MarkDirty(this);
}
2022-08-28 04:38:52 +08:00
}
else if (mergeTarget != null && mergeTargetPath != RuntimeUtil.AvatarRootPath(mergeTarget))
{
mergeTargetPath = RuntimeUtil.AvatarRootPath(mergeTarget);
int insetPos = gameObject.name.IndexOf(mergeTarget.name, StringComparison.Ordinal);
if (insetPos != -1)
{
prefix = gameObject.name.Substring(0, insetPos);
suffix = gameObject.name.Substring(insetPos + mergeTarget.name.Length);
}
}
};
}
#endif
2022-08-28 04:38:52 +08:00
}
}