public static void CloneDeepTo(this StateMachineBehaviour source, StateMachineBehaviour dest) { if (source.GetType() != dest.GetType()) { throw new ArgumentException($"{nameof(source)} and {nameof(dest)} must be same type."); } switch (source) { #if VRC_SDK_VRCSDK3 case VRCAnimatorLayerControl sourceAlc: { var behaviour = dest as VRCAnimatorLayerControl; sourceAlc.CloneTo(behaviour); break; } case VRCAnimatorLocomotionControl sourceAlc: { var behaviour = dest as VRCAnimatorLocomotionControl; sourceAlc.CloneTo(behaviour); break; } case VRCAnimatorTemporaryPoseSpace sourceTps: { var behaviour = dest as VRCAnimatorTemporaryPoseSpace; sourceTps.CloneTo(behaviour); break; } case VRCAnimatorTrackingControl sourceTc: { var behaviour = dest as VRCAnimatorTrackingControl; sourceTc.CloneTo(behaviour); break; } case VRCAvatarParameterDriver sourceApd: { var behaviour = dest as VRCAvatarParameterDriver; sourceApd.CloneTo(behaviour); break; } case VRCPlayableLayerControl sourcePlc: { var behaviour = dest as VRCPlayableLayerControl; sourcePlc.CloneTo(behaviour); break; } #endif } }
public static void Fix() { VRCAvatarDescriptor[] avatars = FindObjectsOfType(typeof(VRCAvatarDescriptor)) as VRCAvatarDescriptor[]; foreach (VRCAvatarDescriptor avatar in avatars) { foreach (Animator animator in avatar.GetComponentsInChildren <Animator>(true)) { if (animator.runtimeAnimatorController == null || animator.gameObject == avatar.gameObject) { continue; } AnimatorController controller = (AnimatorController)animator.runtimeAnimatorController; bool hasBeenCopied = false; var query = (from AnimatorControllerLayer l in controller.layers where l.name.StartsWith(tag) select l).ToArray(); for (int i = 0; i < query.Length; i++) //foreach (AnimatorControllerLayer l in query) { AnimatorControllerLayer l = query[i]; for (int j = 0; j < l.stateMachine.states.Length; j++) //foreach (ChildAnimatorState state in l.stateMachine.states) { ChildAnimatorState state = l.stateMachine.states[j]; for (int k = 0; k < state.state.behaviours.Length; k++) //foreach (StateMachineBehaviour behaviour in state.state.behaviours) { StateMachineBehaviour behaviour = state.state.behaviours[k]; if (behaviour.GetType() == typeof(VRCAnimatorLayerControl)) { VRCAnimatorLayerControl ctrl = (VRCAnimatorLayerControl)behaviour; int layer = toPlayable[(int)ctrl.playable]; if (avatar.baseAnimationLayers[layer].isDefault == true || avatar.baseAnimationLayers[layer].animatorController == null) { continue; } AnimatorController playable = (AnimatorController)avatar.baseAnimationLayers[layer].animatorController; int index = playable.layers.ToList().FindIndex(x => x.name.Equals(l.name.Substring(tag.Length))); if (index == -1) { continue; } if (ctrl.layer == index) { continue; } if (!hasBeenCopied) { controller = MakeCopy(avatar, controller); hasBeenCopied = true; } ctrl = (VRCAnimatorLayerControl)controller.layers[i].stateMachine.states[j].state.behaviours[k]; ctrl.layer = index; animator.runtimeAnimatorController = controller; count++; } } } } } } if (count != 0) { AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } Debug.Log("Fixed " + count + (count == 1 ? " index" : " indices") + " on " + avatars.Length + (avatars.Length == 1 ? " avatar." : " avatars.")); count = 0; }
public static StateMachineBehaviour CloneBehavior(this StateMachineBehaviour behavior) { StateMachineBehaviour output = (StateMachineBehaviour)ScriptableObject.CreateInstance(behavior.GetType()); EditorUtility.CopySerialized(behavior, output); return(output); }
private static void CloneBehaviourParameters(StateMachineBehaviour old, StateMachineBehaviour n) { if (old.GetType() != n.GetType()) { throw new ArgumentException("2 state machine behaviours that should be of the same type are not."); } switch (n) { case VRCAnimatorLayerControl l: { var o = old as VRCAnimatorLayerControl; l.ApplySettings = o.ApplySettings; l.blendDuration = o.blendDuration; l.debugString = o.debugString; l.goalWeight = o.goalWeight; l.layer = o.layer; l.playable = o.playable; break; } case VRCAnimatorLocomotionControl l: { var o = old as VRCAnimatorLocomotionControl; l.ApplySettings = o.ApplySettings; l.debugString = o.debugString; l.disableLocomotion = o.disableLocomotion; break; } case VRCAnimatorTemporaryPoseSpace l: { var o = old as VRCAnimatorTemporaryPoseSpace; l.ApplySettings = o.ApplySettings; l.debugString = o.debugString; l.delayTime = o.delayTime; l.enterPoseSpace = o.enterPoseSpace; l.fixedDelay = o.fixedDelay; break; } case VRCAnimatorTrackingControl l: { var o = old as VRCAnimatorTrackingControl; l.ApplySettings = o.ApplySettings; l.debugString = o.debugString; l.trackingEyes = o.trackingEyes; l.trackingHead = o.trackingHead; l.trackingHip = o.trackingHip; l.trackingLeftFingers = o.trackingLeftFingers; l.trackingLeftFoot = o.trackingLeftFoot; l.trackingLeftHand = o.trackingLeftHand; l.trackingMouth = o.trackingMouth; l.trackingRightFingers = o.trackingRightFingers; l.trackingRightFoot = o.trackingRightFoot; l.trackingRightHand = o.trackingRightHand; break; } case VRCAvatarParameterDriver l: { var d = old as VRCAvatarParameterDriver; l.ApplySettings = d.ApplySettings; l.debugString = d.debugString; l.localOnly = d.localOnly; l.parameters = d.parameters.ConvertAll(p => { string name = _parametersNewName.ContainsKey(p.name) ? _parametersNewName[p.name] : p.name; return(new VRC_AvatarParameterDriver.Parameter { name = name, value = p.value, chance = p.chance, valueMin = p.valueMin, valueMax = p.valueMax, type = p.type }); }); break; } case VRCPlayableLayerControl l: { var o = old as VRCPlayableLayerControl; l.ApplySettings = o.ApplySettings; l.blendDuration = o.blendDuration; l.debugString = o.debugString; l.goalWeight = o.goalWeight; l.layer = o.layer; l.outputParamHash = o.outputParamHash; break; } } }
private static void CopyBehaivourParameters(StateMachineBehaviour srcBehaivour, StateMachineBehaviour dstBehaivour) { if (srcBehaivour.GetType() != dstBehaivour.GetType()) { throw new ArgumentException("Should be same type"); } #if VRC_SDK_VRCSDK3 if (dstBehaivour is VRCAnimatorLayerControl layerControl) { var srcControl = srcBehaivour as VRCAnimatorLayerControl; layerControl.ApplySettings = srcControl.ApplySettings; layerControl.blendDuration = srcControl.blendDuration; layerControl.debugString = srcControl.debugString; layerControl.goalWeight = srcControl.goalWeight; layerControl.layer = srcControl.layer; layerControl.playable = srcControl.playable; } else if (dstBehaivour is VRCAnimatorLocomotionControl locomotionControl) { var srcControl = srcBehaivour as VRCAnimatorLocomotionControl; locomotionControl.ApplySettings = srcControl.ApplySettings; locomotionControl.debugString = srcControl.debugString; locomotionControl.disableLocomotion = srcControl.disableLocomotion; } /*else if (dstBehaivour is VRCAnimatorRemeasureAvatar remeasureAvatar) * { * var srcRemeasureAvatar = srcBehaivour as VRCAnimatorRemeasureAvatar; * remeasureAvatar.ApplySettings = srcRemeasureAvatar.ApplySettings; * remeasureAvatar.debugString = srcRemeasureAvatar.debugString; * remeasureAvatar.delayTime = srcRemeasureAvatar.delayTime; * remeasureAvatar.fixedDelay = srcRemeasureAvatar.fixedDelay; * }*/ else if (dstBehaivour is VRCAnimatorTemporaryPoseSpace poseSpace) { var srcPoseSpace = srcBehaivour as VRCAnimatorTemporaryPoseSpace; poseSpace.ApplySettings = srcPoseSpace.ApplySettings; poseSpace.debugString = srcPoseSpace.debugString; poseSpace.delayTime = srcPoseSpace.delayTime; poseSpace.enterPoseSpace = srcPoseSpace.enterPoseSpace; poseSpace.fixedDelay = srcPoseSpace.fixedDelay; } else if (dstBehaivour is VRCAnimatorTrackingControl trackingControl) { var srcControl = srcBehaivour as VRCAnimatorTrackingControl; trackingControl.ApplySettings = srcControl.ApplySettings; trackingControl.debugString = srcControl.debugString; trackingControl.trackingEyes = srcControl.trackingEyes; trackingControl.trackingHead = srcControl.trackingHead; trackingControl.trackingHip = srcControl.trackingHip; trackingControl.trackingLeftFingers = srcControl.trackingLeftFingers; trackingControl.trackingLeftFoot = srcControl.trackingLeftFoot; trackingControl.trackingLeftHand = srcControl.trackingLeftHand; trackingControl.trackingMouth = srcControl.trackingMouth; trackingControl.trackingRightFingers = srcControl.trackingRightFingers; trackingControl.trackingRightFoot = srcControl.trackingRightFoot; trackingControl.trackingRightHand = srcControl.trackingRightHand; } else if (dstBehaivour is VRCAvatarParameterDriver parameterDriver) { var srcDriver = srcBehaivour as VRCAvatarParameterDriver; parameterDriver.ApplySettings = srcDriver.ApplySettings; parameterDriver.debugString = srcDriver.debugString; parameterDriver.parameters = srcDriver.parameters .Select(p => new Parameter { name = p.name, value = p.value }) .ToList(); } else if (dstBehaivour is VRCPlayableLayerControl playableLayerControl) { var srcControl = srcBehaivour as VRCPlayableLayerControl; playableLayerControl.ApplySettings = srcControl.ApplySettings; playableLayerControl.blendDuration = srcControl.blendDuration; playableLayerControl.debugString = srcControl.debugString; playableLayerControl.goalWeight = srcControl.goalWeight; playableLayerControl.layer = srcControl.layer; playableLayerControl.outputParamHash = srcControl.outputParamHash; } #endif }