internal static void Remove(MenuCommand command)
        {
            StateMachineBehaviour context = command.context as StateMachineBehaviour;

            StateMachineBehaviourContext[] contextArray = AnimatorController.FindStateMachineBehaviourContext(context);
            for (int i = 0; i < contextArray.Length; i++)
            {
                AnimatorController   animatorController = contextArray[i].animatorController;
                AnimatorState        animatorObject     = contextArray[i].animatorObject as AnimatorState;
                AnimatorStateMachine machine            = contextArray[i].animatorObject as AnimatorStateMachine;
                if (animatorObject != null)
                {
                    StateMachineBehaviour[] array = (animatorController == null) ? animatorObject.behaviours : animatorController.GetStateEffectiveBehaviours(animatorObject, contextArray[i].layerIndex);
                    ArrayUtility.Remove <StateMachineBehaviour>(ref array, context);
                    if (animatorController != null)
                    {
                        animatorController.SetStateEffectiveBehaviours(animatorObject, contextArray[i].layerIndex, array);
                    }
                    else
                    {
                        animatorObject.behaviours = array;
                    }
                }
                else if (machine != null)
                {
                    StateMachineBehaviour[] behaviours = machine.behaviours;
                    ArrayUtility.Remove <StateMachineBehaviour>(ref behaviours, context);
                    machine.behaviours = behaviours;
                }
            }
            UnityEngine.Object.DestroyImmediate(context, true);
        }
Ejemplo n.º 2
0
    protected void PasteAsNew()
    {
        if (AnimatorStateEventBehaviourCopier.copiedBehaviours == null)
        {
            return;
        }

        StateMachineBehaviourContext[] contexts = AnimatorController.FindStateMachineBehaviourContext(this);
        if (contexts == null)
        {
            return;
        }

        StateMachineBehaviour copiedTarget = null;

        AnimatorState state = contexts[0].animatorObject as AnimatorState;

        if (state != null)
        {
            copiedTarget = state.AddStateMachineBehaviour(AnimatorStateEventBehaviourCopier.copiedBehaviours.GetType());
        }
        else
        {
            AnimatorStateMachine subMachine = contexts[0].animatorObject as AnimatorStateMachine;
            if (subMachine != null)
            {
                copiedTarget = subMachine.AddStateMachineBehaviour(AnimatorStateEventBehaviourCopier.copiedBehaviours.GetType());
            }
        }

        if (copiedTarget != null)
        {
            EditorUtility.CopySerialized(AnimatorStateEventBehaviourCopier.copiedBehaviours, copiedTarget);
        }
    }
        internal static void Remove(MenuCommand command)
        {
            StateMachineBehaviour stateMachineBehaviour = command.context as StateMachineBehaviour;

            StateMachineBehaviourContext[] array = AnimatorController.FindStateMachineBehaviourContext(stateMachineBehaviour);
            for (int i = 0; i < array.Length; i++)
            {
                AnimatorController   animatorController   = array[i].animatorController;
                AnimatorState        animatorState        = array[i].animatorObject as AnimatorState;
                AnimatorStateMachine animatorStateMachine = array[i].animatorObject as AnimatorStateMachine;
                if (animatorState != null)
                {
                    StateMachineBehaviour[] behaviours = (!(animatorController != null)) ? animatorState.behaviours : animatorController.GetStateEffectiveBehaviours(animatorState, array[i].layerIndex);
                    ArrayUtility.Remove <StateMachineBehaviour>(ref behaviours, stateMachineBehaviour);
                    if (animatorController != null)
                    {
                        animatorController.SetStateEffectiveBehaviours(animatorState, array[i].layerIndex, behaviours);
                    }
                    else
                    {
                        animatorState.behaviours = behaviours;
                    }
                }
                else if (animatorStateMachine != null)
                {
                    StateMachineBehaviour[] behaviours2 = animatorStateMachine.behaviours;
                    ArrayUtility.Remove <StateMachineBehaviour>(ref behaviours2, stateMachineBehaviour);
                    animatorStateMachine.behaviours = behaviours2;
                }
            }
            UnityEngine.Object.DestroyImmediate(stateMachineBehaviour, true);
        }
Ejemplo n.º 4
0
        public static StateMachineBehaviour CloneBehavior(this StateMachineBehaviour behavior)
        {
            StateMachineBehaviour output = (StateMachineBehaviour)ScriptableObject.CreateInstance(behavior.GetType());

            EditorUtility.CopySerialized(behavior, output);
            return(output);
        }
        public static void ApplyTo(this StateMachineBehaviour source, StateMachineBehaviour dest)
        {
            switch (source)
            {
            case VRCAnimatorLayerControl layer:
                layer.ApplyTo((VRCAnimatorLayerControl)dest);
                break;

            case VRCAnimatorLocomotionControl locomotion:
                locomotion.ApplyTo((VRCAnimatorLocomotionControl)dest);
                break;

            case VRCAnimatorTemporaryPoseSpace temporaryPoseSpace:
                temporaryPoseSpace.ApplyTo((VRCAnimatorTemporaryPoseSpace)dest);
                break;

            case VRCAnimatorTrackingControl tracking:
                tracking.ApplyTo((VRCAnimatorTrackingControl)dest);
                break;

            case VRCAvatarParameterDriver parameterDriver:
                parameterDriver.ApplyTo((VRCAvatarParameterDriver)dest);
                break;

            case VRCPlayableLayerControl playableLayer:
                playableLayer.ApplyTo((VRCPlayableLayerControl)dest);
                break;
            }
        }
Ejemplo n.º 6
0
 public void SwitchToState <T> (T behaviour) where T : StateMachineBehaviour
 {
     if (_currentBehaviour != null)
     {
         _currentBehaviour.ExitState();
     }
     behaviour.EnterState();
     _currentBehaviour = behaviour;
 }
        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
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Draw a timeline that can be scrubbed to allow picking a specific normalized time of an animation
        /// </summary>
        public static void DrawScrub(Rect rect, StateMachineBehaviour target, SerializedProperty normalizedTime, SerializedProperty repeat, SerializedProperty atLeastOnce, SerializedProperty neverWhileExit)
        {
            bool  updatePreview = false;
            float timeBefore    = normalizedTime.floatValue;

            GUI.Label(new Rect(rect.x, rect.y, 50, 20), "Time");
            EditorGUI.PropertyField(new Rect(rect.x + 50, rect.y, rect.width - 50 - 42, 20), normalizedTime, GUIContent.none);
            if (GUI.Button(new Rect(rect.x + rect.width - 40, rect.y, 40, 20), "View"))
            {
                updatePreview = true;
            }

            DrawSmallProperty(new Rect(rect.x, rect.y + 20, rect.width / 3f, 20), new GUIContent("Loop", "Enable this to allow execution every time the state loops. Otherwise it will only happen once."), repeat);
            DrawSmallProperty(new Rect(rect.x + rect.width / 3f, rect.y + 20, rect.width / 3f, 20), new GUIContent("At Least Once", "Execute when the exit transition ends if this hasn't been executed yet."), atLeastOnce);
            DrawSmallProperty(new Rect(rect.x + rect.width * 2f / 3f, rect.y + 20, rect.width / 3f, 20), new GUIContent("Never While Exit", "Prevent executing during the exit transition."), neverWhileExit);

            if (timeBefore != normalizedTime.floatValue)
            {
                updatePreview = true;
            }

            if (updatePreview)
            {
                if (!AnimationMode.InAnimationMode())
                {
                    AnimationMode.StartAnimationMode();
                }

                AnimatorController ignore;
                Animator           animator;
                GetCurrentAnimatorAndController(out ignore, out animator);

                var contexts = AnimatorController.FindStateMachineBehaviourContext(target);

                foreach (var context in contexts)
                {
                    AnimatorState state = context.animatorObject as AnimatorState;
                    if (null == state)
                    {
                        continue;
                    }

                    AnimationClip previewClip = GetFirstAvailableClip(state.motion);
                    if (null == previewClip)
                    {
                        continue;
                    }

                    AnimationMode.BeginSampling();
                    AnimationMode.SampleAnimationClip(animator.gameObject, previewClip, normalizedTime.floatValue * previewClip.length);
                    AnimationMode.EndSampling();
                }
            }
        }
Ejemplo n.º 9
0
	public static void RemoveBehaviour(AnimatorState state, StateMachineBehaviour behaviour) {

	 if(state != null) {
		StateMachineBehaviour[] theBehaviours = state.behaviours;

		ArrayUtility.Remove(ref theBehaviours, behaviour);

		Undo.RegisterCompleteObjectUndo(state, "Removed behaviour");

		Undo.DestroyObjectImmediate(behaviour);

		state.behaviours = theBehaviours;
	 }
	}
Ejemplo n.º 10
0
        public static AnimatorState CloneState(this AnimatorState state)
        {
            AnimatorState output = new AnimatorState();

            EditorUtility.CopySerialized(state, output);

            StateMachineBehaviour[] outBehaviors = new StateMachineBehaviour[state.behaviours.Length];
            for (int i = 0; i < outBehaviors.Length; i++)
            {
                outBehaviors[i] = CloneBehavior(state.behaviours[i]);
            }
            output.behaviours = outBehaviors;

            return(output);
        }
 public static bool IsBehaviourOnAnimatorState(AnimatorState state, StateMachineBehaviour behaviour)
 {
     if (state != null)
     {
         var behaviours = state.behaviours;
         foreach (var child in behaviours)
         {
             if (child == behaviour)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
    public static int OnStateUpdate(IntPtr l)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(l);
            if (num == 4)
            {
                StateMachineBehaviour stateMachineBehaviour = (StateMachineBehaviour)LuaObject.checkSelf(l);
                Animator animator;
                LuaObject.checkType <Animator>(l, 2, out animator);
                AnimatorStateInfo stateInfo;
                LuaObject.checkValueType <AnimatorStateInfo>(l, 3, out stateInfo);
                int layerIndex;
                LuaObject.checkType(l, 4, out layerIndex);
                stateMachineBehaviour.OnStateUpdate(animator, stateInfo, layerIndex);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else if (num == 5)
            {
                StateMachineBehaviour stateMachineBehaviour2 = (StateMachineBehaviour)LuaObject.checkSelf(l);
                Animator animator2;
                LuaObject.checkType <Animator>(l, 2, out animator2);
                AnimatorStateInfo stateInfo2;
                LuaObject.checkValueType <AnimatorStateInfo>(l, 3, out stateInfo2);
                int layerIndex2;
                LuaObject.checkType(l, 4, out layerIndex2);
                AnimatorControllerPlayable controller;
                LuaObject.checkValueType <AnimatorControllerPlayable>(l, 5, out controller);
                stateMachineBehaviour2.OnStateUpdate(animator2, stateInfo2, layerIndex2, controller);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else
            {
                LuaObject.pushValue(l, false);
                LuaDLL.lua_pushstring(l, "No matched override function OnStateUpdate to call");
                result = 2;
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
        internal static void MoveUp(MenuCommand command)
        {
            StateMachineBehaviour context = command.context as StateMachineBehaviour;

            StateMachineBehaviourContext[] contextArray = AnimatorController.FindStateMachineBehaviourContext(context);
            for (int i = 0; i < contextArray.Length; i++)
            {
                AnimatorController   animatorController = contextArray[i].animatorController;
                AnimatorState        animatorObject     = contextArray[i].animatorObject as AnimatorState;
                AnimatorStateMachine machine            = contextArray[i].animatorObject as AnimatorStateMachine;
                if (animatorObject != null)
                {
                    StateMachineBehaviour[] behaviours = (animatorController == null) ? animatorObject.behaviours : animatorController.GetStateEffectiveBehaviours(animatorObject, contextArray[i].layerIndex);
                    for (int j = 0; j < behaviours.Length; j++)
                    {
                        if ((behaviours[j] == context) && (j > 0))
                        {
                            behaviours[j]     = behaviours[j - 1];
                            behaviours[j - 1] = context;
                            break;
                        }
                    }
                    if (animatorController != null)
                    {
                        animatorController.SetStateEffectiveBehaviours(animatorObject, contextArray[i].layerIndex, behaviours);
                    }
                    else
                    {
                        animatorObject.behaviours = behaviours;
                    }
                    continue;
                }
                if (machine != null)
                {
                    StateMachineBehaviour[] behaviourArray2 = machine.behaviours;
                    for (int k = 0; k < behaviourArray2.Length; k++)
                    {
                        if ((behaviourArray2[k] == context) && (k > 0))
                        {
                            behaviourArray2[k]     = behaviourArray2[k - 1];
                            behaviourArray2[k - 1] = context;
                            break;
                        }
                    }
                    machine.behaviours = behaviourArray2;
                }
            }
        }
        internal static void MoveUp(MenuCommand command)
        {
            StateMachineBehaviour stateMachineBehaviour = command.context as StateMachineBehaviour;

            StateMachineBehaviourContext[] array = AnimatorController.FindStateMachineBehaviourContext(stateMachineBehaviour);
            for (int i = 0; i < array.Length; i++)
            {
                AnimatorController   animatorController   = array[i].animatorController;
                AnimatorState        animatorState        = array[i].animatorObject as AnimatorState;
                AnimatorStateMachine animatorStateMachine = array[i].animatorObject as AnimatorStateMachine;
                if (animatorState != null)
                {
                    StateMachineBehaviour[] array2 = (!(animatorController != null)) ? animatorState.behaviours : animatorController.GetStateEffectiveBehaviours(animatorState, array[i].layerIndex);
                    for (int j = 0; j < array2.Length; j++)
                    {
                        if (array2[j] == stateMachineBehaviour && j > 0)
                        {
                            array2[j]     = array2[j - 1];
                            array2[j - 1] = stateMachineBehaviour;
                            break;
                        }
                    }
                    if (animatorController != null)
                    {
                        animatorController.SetStateEffectiveBehaviours(animatorState, array[i].layerIndex, array2);
                    }
                    else
                    {
                        animatorState.behaviours = array2;
                    }
                }
                else if (animatorStateMachine != null)
                {
                    StateMachineBehaviour[] behaviours = animatorStateMachine.behaviours;
                    for (int k = 0; k < behaviours.Length; k++)
                    {
                        if (behaviours[k] == stateMachineBehaviour && k > 0)
                        {
                            behaviours[k]     = behaviours[k - 1];
                            behaviours[k - 1] = stateMachineBehaviour;
                            break;
                        }
                    }
                    animatorStateMachine.behaviours = behaviours;
                }
            }
        }
    public static int OnStateMachineEnter(IntPtr l)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(l);
            if (num == 3)
            {
                StateMachineBehaviour stateMachineBehaviour = (StateMachineBehaviour)LuaObject.checkSelf(l);
                Animator animator;
                LuaObject.checkType <Animator>(l, 2, out animator);
                int stateMachinePathHash;
                LuaObject.checkType(l, 3, out stateMachinePathHash);
                stateMachineBehaviour.OnStateMachineEnter(animator, stateMachinePathHash);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else if (num == 4)
            {
                StateMachineBehaviour stateMachineBehaviour2 = (StateMachineBehaviour)LuaObject.checkSelf(l);
                Animator animator2;
                LuaObject.checkType <Animator>(l, 2, out animator2);
                int stateMachinePathHash2;
                LuaObject.checkType(l, 3, out stateMachinePathHash2);
                AnimatorControllerPlayable controller;
                LuaObject.checkValueType <AnimatorControllerPlayable>(l, 4, out controller);
                stateMachineBehaviour2.OnStateMachineEnter(animator2, stateMachinePathHash2, controller);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else
            {
                LuaObject.pushValue(l, false);
                LuaDLL.lua_pushstring(l, "No matched override function OnStateMachineEnter to call");
                result = 2;
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Ejemplo n.º 16
0
 public StateMachineBehaviour[] GetOverrideBehaviours(AnimatorState state)
 {
     StateMachineBehaviour[] result;
     if (this.m_Behaviours != null)
     {
         StateBehavioursPair[] behaviours = this.m_Behaviours;
         for (int i = 0; i < behaviours.Length; i++)
         {
             StateBehavioursPair stateBehavioursPair = behaviours[i];
             if (stateBehavioursPair.m_State == state)
             {
                 result = (stateBehavioursPair.m_Behaviours as StateMachineBehaviour[]);
                 return(result);
             }
         }
     }
     result = new StateMachineBehaviour[0];
     return(result);
 }
            public static AnimatorState DeepClone(this AnimatorState state)
            {
                AnimatorState output = new AnimatorState();

                EditorUtility.CopySerialized(state, output);

                if (state.motion != null && state.motion.GetType() == typeof(BlendTree) && AssetDatabase.GetAssetPath(((BlendTree)state.motion).GetInstanceID()) == AssetDatabase.GetAssetPath(state.GetInstanceID()))
                {
                    output.motion = ((BlendTree)state.motion).DeepClone();
                }

                StateMachineBehaviour[] outBehaviors = new StateMachineBehaviour[state.behaviours.Length];
                for (int i = 0; i < outBehaviors.Length; i++)
                {
                    outBehaviors[i] = DeepClone(state.behaviours[i]);
                }
                output.behaviours = outBehaviors;

                return(output);
            }
        internal static bool ValidateMenucommand(MenuCommand command)
        {
            if (!AnimatorController.CanAddStateMachineBehaviours())
            {
                return(false);
            }
            StateMachineBehaviour behaviour = command.context as StateMachineBehaviour;

            StateMachineBehaviourContext[] array = AnimatorController.FindStateMachineBehaviourContext(behaviour);
            for (int i = 0; i < array.Length; i++)
            {
                AnimatorController      animatorController   = array[i].animatorController;
                AnimatorState           animatorState        = array[i].animatorObject as AnimatorState;
                AnimatorStateMachine    animatorStateMachine = array[i].animatorObject as AnimatorStateMachine;
                StateMachineBehaviour[] array2 = null;
                if (animatorState != null)
                {
                    array2 = ((!(animatorController != null)) ? animatorState.behaviours : animatorController.GetStateEffectiveBehaviours(animatorState, array[i].layerIndex));
                }
                else if (animatorStateMachine != null)
                {
                    array2 = animatorStateMachine.behaviours;
                }
                if (array2 != null)
                {
                    for (int j = 0; j < array2.Length; j++)
                    {
                        if (array2[j] == null)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        internal static bool ValidateMenucommand(MenuCommand command)
        {
            if (!AnimatorController.CanAddStateMachineBehaviours())
            {
                return(false);
            }
            StateMachineBehaviour context = command.context as StateMachineBehaviour;

            StateMachineBehaviourContext[] contextArray = AnimatorController.FindStateMachineBehaviourContext(context);
            for (int i = 0; i < contextArray.Length; i++)
            {
                AnimatorController      animatorController = contextArray[i].animatorController;
                AnimatorState           animatorObject     = contextArray[i].animatorObject as AnimatorState;
                AnimatorStateMachine    machine            = contextArray[i].animatorObject as AnimatorStateMachine;
                StateMachineBehaviour[] behaviours         = null;
                if (animatorObject != null)
                {
                    behaviours = (animatorController == null) ? animatorObject.behaviours : animatorController.GetStateEffectiveBehaviours(animatorObject, contextArray[i].layerIndex);
                }
                else if (machine != null)
                {
                    behaviours = machine.behaviours;
                }
                if (behaviours != null)
                {
                    for (int j = 0; j < behaviours.Length; j++)
                    {
                        if (behaviours[j] == null)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 20
0
        public static AnimatorStateMachine CloneMachine(this AnimatorStateMachine machine)
        {
            AnimatorStateMachine output = new AnimatorStateMachine();

            //All Serializable Fields (ex. Primitives)
            EditorUtility.CopySerialized(machine, output);

            //State Machines
            ChildAnimatorStateMachine[] outMachines = new ChildAnimatorStateMachine[machine.stateMachines.Length];
            for (int i = 0; i < outMachines.Length; i++)
            {
                outMachines[i] = new ChildAnimatorStateMachine
                {
                    position     = machine.stateMachines[i].position,
                    stateMachine = CloneMachine(machine.stateMachines[i].stateMachine)
                };
            }
            output.stateMachines = outMachines;

            //States
            ChildAnimatorState[] outStates = new ChildAnimatorState[machine.states.Length];
            for (int i = 0; i < outStates.Length; i++)
            {
                outStates[i] = new ChildAnimatorState
                {
                    position = machine.states[i].position,
                    state    = CloneState(machine.states[i].state)
                };
            }

            //State Transitions
            for (int i = 0; i < outStates.Length; i++)
            {
                AnimatorStateTransition[] outTransitions = new AnimatorStateTransition[machine.states[i].state.transitions.Length];
                for (int j = 0; j < outTransitions.Length; j++)
                {
                    outTransitions[j] = (AnimatorStateTransition)CloneTransition(machine.states[i].state.transitions[j], outStates);
                }
                outStates[i].state.transitions = outTransitions;
            }
            output.states = outStates;

            //Any Transitions
            AnimatorStateTransition[] outAnyTransitions = new AnimatorStateTransition[machine.anyStateTransitions.Length];
            for (int i = 0; i < outAnyTransitions.Length; i++)
            {
                outAnyTransitions[i] = (AnimatorStateTransition)CloneTransition(machine.anyStateTransitions[i], outStates);
            }
            output.anyStateTransitions = outAnyTransitions;

            //Entry Transitions
            AnimatorTransition[] outEntryTransitions = new AnimatorTransition[machine.entryTransitions.Length];
            for (int i = 0; i < outEntryTransitions.Length; i++)
            {
                outEntryTransitions[i] = (AnimatorTransition)CloneTransition(machine.entryTransitions[i], outStates);
            }
            output.entryTransitions = outEntryTransitions;

            //Behaviors
            StateMachineBehaviour[] outBehaviors = new StateMachineBehaviour[machine.behaviours.Length];
            for (int i = 0; i < outBehaviors.Length; i++)
            {
                outBehaviors[i] = CloneBehavior(machine.behaviours[i]);
            }
            output.behaviours = outBehaviors;

            //Default State
            foreach (ChildAnimatorState childState in outStates)
            {
                if (childState.state.name == machine.defaultState.name)
                {
                    output.defaultState = childState.state;
                    break;
                }
            }

            return(output);
        }
Ejemplo n.º 21
0
 public static void InitComponents(this StateMachineBehaviour behaviour, Animator animator)
 {
     InitComponents(animator.gameObject, behaviour);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// <para>Use this function to retrieve the owner of this behaviour.</para>
 /// </summary>
 /// <param name="behaviour">The State Machine Behaviour to get context for.</param>
 /// <returns>
 /// <para>Returns the State Machine Behaviour edition context.</para>
 /// </returns>
 public static StateMachineBehaviourContext[] FindStateMachineBehaviourContext(StateMachineBehaviour behaviour) =>
 Internal_FindStateMachineBehaviourContext(behaviour);
Ejemplo n.º 23
0
        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;
            }
            }
        }
Ejemplo n.º 24
0
 public static StateMachineBehaviourContext[] FindStateMachineBehaviourContext(StateMachineBehaviour behaviour)
 {
     return(AnimatorController.Internal_FindStateMachineBehaviourContext(behaviour));
 }
Ejemplo n.º 25
0
        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
        }
 public void Init()
 {
     go        = CreateGameObject("stateTest");
     behaviour = go.AddComponent <StateMachineBehaviour>();
     engine    = go.GetComponent <StateMachineEngine>();
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 注入方法
 /// </summary>
 public static void Inject(this StateMachineBehaviour script)
 {
     InjectionUtil.Inject(script);
 }
Ejemplo n.º 28
0
 public static float GetRandomVoiceDelay(this StateMachineBehaviour stateMachineBehaviour)
 {
     return(Random.Range(AIConfig.minTalkInterval, AIConfig.maxTalkInterval));
 }
Ejemplo n.º 29
0
        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;
        }
Ejemplo n.º 30
0
 static public StateMachineBehaviourContext[] FindStateMachineBehaviourContext(StateMachineBehaviour behaviour)
 {
     return(Internal_FindStateMachineBehaviourContext(behaviour));
 }