modular-avatar/Runtime/MAMoveIndependently.cs
bd_ a7ef0d6635
fix: multiple issues with MAMoveIndependently (#1369)
* fix: multiple issues with MAMoveIndependently

Fixed issues with nested Move Independently components (Closes #1367).

Fixed MAMoveIndependently not being saved (Supercedes #1366)

Reduce jittering when moving MAMI bones.

* chore: fix some namespaces

* chore: fix non-editor buil
2024-11-24 18:24:38 -08:00

57 lines
1.5 KiB
C#

using System;
using nadena.dev.modular_avatar.core.armature_lock;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if MA_VRCSDK3_AVATARS
using VRC.SDKBase;
#endif
namespace nadena.dev.modular_avatar.core
{
[ExecuteInEditMode]
[AddComponentMenu("Modular Avatar/MA Move Independently")]
[DisallowMultipleComponent]
[HelpURL("https://modular-avatar.nadena.dev/docs/reference/move-independently?lang=auto")]
class MAMoveIndependently : MonoBehaviour, IEditorOnly
{
private float EPSILON = 0.0000001f;
[SerializeField]
private GameObject[] m_groupedBones;
public GameObject[] GroupedBones
{
get => m_groupedBones?.Clone() as GameObject[] ?? Array.Empty<GameObject>();
set
{
m_groupedBones = value.Clone() as GameObject[];
MaMoveIndependentlyManager.Instance.Activate(this);
}
}
private void OnValidate()
{
#if UNITY_EDITOR
if (!PrefabUtility.IsPartOfPrefabAsset(this))
{
EditorApplication.delayCall += () =>
{
if (this != null) MaMoveIndependentlyManager.Instance.Activate(this);
};
}
#endif
}
private void OnEnable()
{
MaMoveIndependentlyManager.Instance.Activate(this);
}
private void OnDisable()
{
MaMoveIndependentlyManager.Instance.Deactivate(this);
}
}
}