diff --git a/Shared/Core/BoneController.cs b/Shared/Core/BoneController.cs index ddb58b1..6e245f3 100644 --- a/Shared/Core/BoneController.cs +++ b/Shared/Core/BoneController.cs @@ -509,7 +509,6 @@ private void LateUpdate() } private readonly Dictionary> _effectsToUpdate = new Dictionary>(); - private void ApplyEffects() { foreach (var kv in _effectsToUpdate) @@ -655,7 +654,21 @@ private IEnumerator CollectBaselineCo() ModifiersFillInTransforms(); foreach (var modifier in ModifierDict.Values.SelectMany(x => x)) + { + var dynamicBoneEnabled = false; + + if (modifier.DynamicBone?.enabled == true) + { + dynamicBoneEnabled = true; + modifier.DynamicBone.enabled = false; + } + modifier.CollectBaseline(); + if (dynamicBoneEnabled) + { + modifier.DynamicBone.enabled = true; + } + } yield return CoroutineUtils.WaitForEndOfFrame; @@ -939,6 +952,41 @@ private GameObject FindBone(string name, GameObject rootObject, bool noRetry = f return boneObj; } + /// + /// Finds the dynamic bone that is targeting the bone of the given name in the given location. Currently only supporting accessories. + /// + /// + /// + /// + public DynamicBone FindDynamicBone(string name, BoneLocation location) + { + if (location < BoneLocation.Accessory) + { + return null; + } + + var accId = location - BoneLocation.Accessory; + var rootObj = _ctrl.objAccessory.SafeGet(accId); + + foreach (var dynamicBone in rootObj.GetComponents()) + { + if (dynamicBone.m_Root.name.Equals(name)) + { + return dynamicBone; + } + + foreach (var child in dynamicBone.m_Root.GetComponentsInChildren()) + { + if (child.name.Equals(name)) + { + return dynamicBone; + } + } + } + + return null; + } + /// /// Get a dictionary of all bones and their names in a given location. /// @@ -990,6 +1038,7 @@ public bool AssignBone(BoneModifier modifier) var boneFound = bone != null; modifier.BoneTransform = boneFound ? bone.transform : null; modifier.BoneLocation = loc; + modifier.DynamicBone = FindDynamicBone(modifier.BoneName, modifier.BoneLocation); return boneFound; } diff --git a/Shared/Core/BoneModifier.cs b/Shared/Core/BoneModifier.cs index 54cf701..d5d456d 100644 --- a/Shared/Core/BoneModifier.cs +++ b/Shared/Core/BoneModifier.cs @@ -99,6 +99,12 @@ public BoneModifier(string boneName, BoneModifierData[] coordinateModifiers, Bon [IgnoreMember] public Transform BoneTransform { get; internal set; } + /// + /// DynamicBone component that targets this transform, if any. + /// + [IgnoreMember] + internal DynamicBone DynamicBone { get; set; } + /// /// Actual modifier values, split for different coordinates if required ///