mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-12 23:48:59 +08:00
MergeArmature: Support moving between avatars in hierarchy
WARNING: Prefab compatibility broken! Fixes #38
This commit is contained in:
parent
7061ab0a8c
commit
922fcb5fb0
@ -187,9 +187,9 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
private void MergeArmature(ModularAvatarMergeArmature mergeArmature)
|
private void MergeArmature(ModularAvatarMergeArmature mergeArmature)
|
||||||
{
|
{
|
||||||
// TODO: error reporting framework?
|
// TODO: error reporting framework?
|
||||||
if (mergeArmature.mergeTarget == null) return;
|
if (mergeArmature.mergeTargetObject == null) return;
|
||||||
|
|
||||||
RecursiveMerge(mergeArmature, mergeArmature.gameObject, mergeArmature.mergeTarget.gameObject, true);
|
RecursiveMerge(mergeArmature, mergeArmature.gameObject, mergeArmature.mergeTargetObject.gameObject, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,13 +4,13 @@ using UnityEngine;
|
|||||||
namespace net.fushizen.modular_avatar.core
|
namespace net.fushizen.modular_avatar.core
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class AvatarObjectReference
|
public struct AvatarObjectReference
|
||||||
{
|
{
|
||||||
public bool isNull = true;
|
public bool isNull;
|
||||||
public string referencePath = "";
|
public string referencePath;
|
||||||
|
|
||||||
private bool _cacheValid = false;
|
private bool _cacheValid;
|
||||||
private string _cachedPath = "";
|
private string _cachedPath;
|
||||||
private GameObject _cachedReference;
|
private GameObject _cachedReference;
|
||||||
|
|
||||||
public GameObject Get(Component container)
|
public GameObject Get(Component container)
|
||||||
|
@ -22,9 +22,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace net.fushizen.modular_avatar.core
|
namespace net.fushizen.modular_avatar.core
|
||||||
@ -35,8 +33,9 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
private const float POS_EPSILON = 0.01f;
|
private const float POS_EPSILON = 0.01f;
|
||||||
private const float ROT_EPSILON = 0.01f;
|
private const float ROT_EPSILON = 0.01f;
|
||||||
|
|
||||||
public GameObject mergeTarget;
|
public AvatarObjectReference mergeTarget;
|
||||||
public string mergeTargetPath;
|
public GameObject mergeTargetObject => mergeTarget.Get(this);
|
||||||
|
|
||||||
public string prefix;
|
public string prefix;
|
||||||
public string suffix;
|
public string suffix;
|
||||||
public bool locked;
|
public bool locked;
|
||||||
@ -52,34 +51,12 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<BoneBinding> lockedBones;
|
private List<BoneBinding> lockedBones;
|
||||||
|
|
||||||
void OnValidate()
|
void OnValidate()
|
||||||
{
|
{
|
||||||
RuntimeUtil.delayCall(() =>
|
RuntimeUtil.delayCall(() =>
|
||||||
{
|
{
|
||||||
if (this == null) return;
|
if (this == null) return;
|
||||||
if (mergeTarget == null && !string.IsNullOrWhiteSpace(mergeTargetPath))
|
|
||||||
{
|
|
||||||
var avatar = RuntimeUtil.FindAvatarInParents(transform);
|
|
||||||
if (avatar != null)
|
|
||||||
{
|
|
||||||
mergeTarget = avatar.transform.Find(mergeTargetPath)?.gameObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mergeTarget != null)
|
|
||||||
{
|
|
||||||
RuntimeUtil.MarkDirty(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckLock();
|
CheckLock();
|
||||||
});
|
});
|
||||||
@ -124,7 +101,7 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
|
|
||||||
var mergeBone = bone.mergeBone;
|
var mergeBone = bone.mergeBone;
|
||||||
var correspondingObject = bone.baseBone;
|
var correspondingObject = bone.baseBone;
|
||||||
bool lockBasePosition = bone.baseBone == mergeTarget.transform;
|
bool lockBasePosition = bone.baseBone == mergeTargetObject.transform;
|
||||||
|
|
||||||
if ((mergeBone.localPosition - bone.lastLocalPos).sqrMagnitude > POS_EPSILON
|
if ((mergeBone.localPosition - bone.lastLocalPos).sqrMagnitude > POS_EPSILON
|
||||||
|| (mergeBone.localScale - bone.lastLocalScale).sqrMagnitude > POS_EPSILON
|
|| (mergeBone.localScale - bone.lastLocalScale).sqrMagnitude > POS_EPSILON
|
||||||
@ -169,7 +146,7 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mergeTarget == null) return;
|
if (mergeTargetObject == null) return;
|
||||||
lockedBones = new List<BoneBinding>();
|
lockedBones = new List<BoneBinding>();
|
||||||
|
|
||||||
foreach (var xform in GetComponentsInChildren<Transform>(true))
|
foreach (var xform in GetComponentsInChildren<Transform>(true))
|
||||||
@ -199,7 +176,7 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
private Transform FindCorresponding(Transform xform)
|
private Transform FindCorresponding(Transform xform)
|
||||||
{
|
{
|
||||||
if (xform == null) return null;
|
if (xform == null) return null;
|
||||||
if (xform == transform) return mergeTarget.transform;
|
if (xform == transform) return mergeTargetObject.transform;
|
||||||
|
|
||||||
var correspondingParent = FindCorresponding(xform.parent);
|
var correspondingParent = FindCorresponding(xform.parent);
|
||||||
if (correspondingParent == null) return null;
|
if (correspondingParent == null) return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user