Restore Merge Armature locked mode references on prefab instantiation

This commit is contained in:
bd_ 2022-09-10 10:47:41 -07:00
parent b889bc7323
commit 5c0b62f295
3 changed files with 33 additions and 13 deletions

View File

@ -37,11 +37,17 @@ namespace net.fushizen.modular_avatar.core.editor
} }
} }
[InitializeOnLoad]
public static class Util public static class Util
{ {
internal const string generatedAssetsSubdirectory = "999_Modular_Avatar_Generated"; internal const string generatedAssetsSubdirectory = "999_Modular_Avatar_Generated";
internal const string generatedAssetsPath = "Assets/" + generatedAssetsSubdirectory; internal const string generatedAssetsPath = "Assets/" + generatedAssetsSubdirectory;
static Util()
{
RuntimeUtil.delayCall = (cb) => EditorApplication.delayCall += cb.Invoke;
}
static internal AnimatorController CreateContainer() static internal AnimatorController CreateContainer()
{ {
var container = new AnimatorController(); var container = new AnimatorController();
@ -74,7 +80,7 @@ namespace net.fushizen.modular_avatar.core.editor
var subdir = generatedAssetsPath; var subdir = generatedAssetsPath;
AssetDatabase.DeleteAsset(subdir); AssetDatabase.DeleteAsset(subdir);
//FileUtil.DeleteFileOrDirectory(subdir); FileUtil.DeleteFileOrDirectory(subdir);
}; };
} }
} }

View File

@ -23,9 +23,6 @@
*/ */
using System; using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine; using UnityEngine;
namespace net.fushizen.modular_avatar.core namespace net.fushizen.modular_avatar.core
@ -40,10 +37,9 @@ namespace net.fushizen.modular_avatar.core
public bool locked; public bool locked;
private bool wasLocked; private bool wasLocked;
#if UNITY_EDITOR
void OnValidate() void OnValidate()
{ {
EditorApplication.delayCall += () => RuntimeUtil.delayCall(() =>
{ {
if (this == null) return; if (this == null) return;
if (mergeTarget == null && !string.IsNullOrWhiteSpace(mergeTargetPath)) if (mergeTarget == null && !string.IsNullOrWhiteSpace(mergeTargetPath))
@ -53,7 +49,9 @@ namespace net.fushizen.modular_avatar.core
{ {
mergeTarget = avatar.transform.Find(mergeTargetPath)?.gameObject; mergeTarget = avatar.transform.Find(mergeTargetPath)?.gameObject;
} }
if (mergeTarget != null) {
if (mergeTarget != null)
{
RuntimeUtil.MarkDirty(this); RuntimeUtil.MarkDirty(this);
} }
} }
@ -69,9 +67,8 @@ namespace net.fushizen.modular_avatar.core
} }
CheckLock(); CheckLock();
}; });
} }
#endif
void CheckLock() void CheckLock()
{ {
@ -94,11 +91,23 @@ namespace net.fushizen.modular_avatar.core
foreach (var xform in GetComponentsInChildren<Transform>(true)) foreach (var xform in GetComponentsInChildren<Transform>(true))
{ {
Transform baseObject = FindCorresponding(xform); Transform baseObject = FindCorresponding(xform);
if (baseObject != null && xform.gameObject.GetComponent<MAInternalOffsetMarker>() == null) var marker = xform.gameObject.GetComponent<MAInternalOffsetMarker>();
if (baseObject == null)
{ {
var comp = xform.gameObject.AddComponent<MAInternalOffsetMarker>(); if (marker != null)
comp.correspondingObject = baseObject; {
comp.lockBasePosition = baseObject.gameObject == mergeTarget; DestroyImmediate(marker);
}
}
else
{
if (marker == null)
{
marker = xform.gameObject.AddComponent<MAInternalOffsetMarker>();
}
marker.correspondingObject = baseObject;
marker.lockBasePosition = baseObject.gameObject == mergeTarget;
} }
} }

View File

@ -33,6 +33,11 @@ namespace net.fushizen.modular_avatar.core
{ {
public static class RuntimeUtil public static class RuntimeUtil
{ {
public delegate void NullCallback();
// Initialized in Util
public static Action<NullCallback> delayCall = (_) => { };
[CanBeNull] [CanBeNull]
public static string RelativePath(GameObject root, GameObject child) public static string RelativePath(GameObject root, GameObject child)
{ {