/************************************************************************************************************************/ /// <summary>Re-scales the <see cref="AnimancerNode.Weight"/> of all children to add up to 1.</summary> public static void NormalizeChildWeights(this IPlayableWrapper parent) { var totalWeight = 0f; var childCount = parent.ChildCount; for (int i = 0; i < childCount; i++) { var child = parent.GetChild(i); if (child.IsValid()) { totalWeight += child.Weight; } } if (totalWeight == 0 || // Can't normalize. Mathf.Approximately(totalWeight, 1)) // Already normalized. { return; } totalWeight = 1f / totalWeight; for (int i = 0; i < childCount; i++) { var child = parent.GetChild(i); if (child.IsValid()) { child.Weight *= totalWeight; } } }
/************************************************************************************************************************/ /// <summary> /// Adds functions to show and set <see cref="IPlayableWrapper.ApplyAnimatorIK"/> and /// <see cref="IPlayableWrapper.ApplyFootIK"/>. /// </summary> public static void AddContextMenuIK(UnityEditor.GenericMenu menu, IPlayableWrapper ik) { menu.AddItem(new GUIContent("Inverse Kinematics/Apply Animator IK ?"), ik.ApplyAnimatorIK, () => ik.ApplyAnimatorIK = !ik.ApplyAnimatorIK); menu.AddItem(new GUIContent("Inverse Kinematics/Apply Foot IK ?"), ik.ApplyFootIK, () => ik.ApplyFootIK = !ik.ApplyFootIK); }
/************************************************************************************************************************/ private void ApplyConnectedState(IPlayableWrapper parent) { #if UNITY_ASSERTIONS if (Index < 0) { throw new InvalidOperationException("Invalid AnimancerNode.Index when attempting to connect to its parent:" + "\n Node: " + this + "\n Parent: " + parent); } #endif _IsWeightDirty = true; if (_Weight != 0 || parent.KeepChildrenConnected) { ConnectToGraph(); } else { Root.RequireUpdate(this); } }