Пример #1
0
        public static bool AddClipToAnimatorComponent(Animator animator, AnimationClip newClip)
        {
            AnimatorController effectiveAnimatorController = AnimatorController.GetEffectiveAnimatorController(animator);

            if (effectiveAnimatorController == null)
            {
                effectiveAnimatorController = AnimatorController.CreateAnimatorControllerForClip(newClip, animator.gameObject);
                AnimatorController.SetAnimatorController(animator, effectiveAnimatorController);
                return(effectiveAnimatorController != null);
            }
            ChildAnimatorState state = effectiveAnimatorController.layers[0].stateMachine.FindState(newClip.name);

            if (state.Equals(new ChildAnimatorState()))
            {
                effectiveAnimatorController.AddMotion(newClip);
            }
            else if ((state.state != null) && (state.state.motion == null))
            {
                state.state.motion = newClip;
            }
            else if ((state.state != null) && (state.state.motion != newClip))
            {
                effectiveAnimatorController.AddMotion(newClip);
            }
            return(true);
        }
Пример #2
0
        /// <param name="parentPath"></param>
        /// <param name="caState"></param>
        /// <param name="lNum">レイヤー番号</param>
        /// <param name="smNum">ステートマシン番号</param>
        /// <param name="sNum">ステート番号</param>
        /// <returns></returns>
        public override bool OnState(string parentPath, ChildAnimatorState caState, int lNum, int smNum, int sNum)
        {
            StateRecord stateRecord = StateRecord.CreateInstance(
                lNum,
                smNum,
                sNum,
                parentPath,
                caState, AconDocument.positions);

            AconDocument.states.Add(stateRecord);

            // モーション・スキャン
            if (null != caState.state.motion)
            {
                Motion motion    = caState.state.motion;
                string assetPath = AssetDatabase.GetAssetPath(motion.GetInstanceID());
                //ebug.Log(" motion.GetType()=[" + motion.GetType().ToString() + "] assetPath=["+ assetPath + "]");

                if (m_motionCounter_.ContainsKey(assetPath))
                {
                    // 既存のモーションを複数回使うことはある。
                    m_motionCounter_[assetPath].CountOfAttachDestination++;
                }
                else
                {
                    m_motionCounter_.Add(assetPath, new MotionRecord.Wrapper(caState.state.motion, 1));
                }
            }

            return(true);
        }
        public static bool AddClipToAnimatorComponent(Animator animator, AnimationClip newClip)
        {
            UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(animator);
            if ((UnityEngine.Object)animatorController == (UnityEngine.Object)null)
            {
                UnityEditor.Animations.AnimatorController controllerForClip = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerForClip(newClip, animator.gameObject);
                UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, controllerForClip);
                return((UnityEngine.Object)controllerForClip != (UnityEngine.Object)null);
            }
            ChildAnimatorState state = animatorController.layers[0].stateMachine.FindState(newClip.name);

            if (state.Equals((object)new ChildAnimatorState()))
            {
                animatorController.AddMotion((Motion)newClip);
            }
            else if ((bool)((UnityEngine.Object)state.state) && (UnityEngine.Object)state.state.motion == (UnityEngine.Object)null)
            {
                state.state.motion = (Motion)newClip;
            }
            else if ((bool)((UnityEngine.Object)state.state) && (UnityEngine.Object)state.state.motion != (UnityEngine.Object)newClip)
            {
                animatorController.AddMotion((Motion)newClip);
            }
            return(true);
        }
        void TraverseStates(AnimatorStateMachine machine)
        {
            if (machine == null)
            {
                return;
            }

            ChildAnimatorState[] targetStates = machine.states;

            if ((targetStates.Length < 1) && (machine.stateMachines.Length < 1))
            {
                AddResult(string.Format("State Machine \"{0}\" is empty", machine.name), MessageType.Warning);
            }

            for (int i = 0; i < targetStates.Length; i++)
            {
                ChildAnimatorState target = targetStates[i];
                var clip = target.state.motion as AnimationClip;
                if (clip != null)
                {
                    // animation clip in root?
                    // original implementation did nothing here (shouldnt this also be attempting to replace clip?).
                    target.state.motion = TryGetReplacementClip(clip, target.state);
                    continue;
                }

                TraverseClips(target.state.motion as BlendTree);
            }

            ChildAnimatorStateMachine[] subStates = machine.stateMachines;
            for (int i = 0; i < subStates.Length; i++)
            {
                TraverseStates(subStates[i].stateMachine);
            }
        }
        internal static void GridLayout(AnimatorStateMachine stateMachine)
        {
            var max       = stateMachine.states.Length;
            var positions = new Vector3[max];

            // 初期位置
            for (int i = 0; i < max; i++)
            {
                positions[i] = new Vector3((i % 5) * 300, 100 * (i / 5));
            }

            //-----   新しい配置に上書き  ---------
            var newStates = new ChildAnimatorState[stateMachine.states.Length];

            for (int i = 0; i < max; i++)
            {
                var c = stateMachine.states[i];
                newStates[i] = new ChildAnimatorState
                {
                    position = positions[i],
                    state    = c.state
                };
            }

            stateMachine.states = newStates;
        }
Пример #6
0
        public static bool AddClipToAnimatorComponent(Animator animator, AnimationClip newClip)
        {
            UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(animator);
            if (animatorController == null)
            {
                animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerForClip(newClip, animator.gameObject);
                UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
                return(animatorController != null);
            }
            ChildAnimatorState childAnimatorState = animatorController.layers[0].stateMachine.FindState(newClip.name);

            if (childAnimatorState.Equals(default(ChildAnimatorState)))
            {
                animatorController.AddMotion(newClip);
            }
            else if (childAnimatorState.state && childAnimatorState.state.motion == null)
            {
                childAnimatorState.state.motion = newClip;
            }
            else if (childAnimatorState.state && childAnimatorState.state.motion != newClip)
            {
                animatorController.AddMotion(newClip);
            }
            return(true);
        }
Пример #7
0
        /// <summary>
        /// TODO: 子ステートをディープコピーして欲しい。
        /// </summary>
        public static ChildAnimatorState DeepcopyChildstate(ChildAnimatorState old)
        {
            ChildAnimatorState n = new ChildAnimatorState();

            n.position = old.position;
            n.state    = AconDeepcopy.DeepcopyState(old.state);
            return(n);
        }
Пример #8
0
        public override bool OnState(string parentPath, ChildAnimatorState caState, int lNum, int smNum, int sNum)
        {
            FullpathSet.Add(parentPath + caState.state.name);

            // モーション・スキャン
            MotionScanner.OnState(caState);

            return(false);
        }
Пример #9
0
        public static PositionRecord.PositionWrapper FetchPosition_OfState(AnimatorController ac, string fullpath, string propertyname_ofFullpath)
        {
            AnimatorStateMachine parentStatemachine;

            // 構造体
            ChildAnimatorState caState = AconFetcher.FetchChildstate(ac, fullpath, out parentStatemachine);

            return(AconFetcher.FetchPosition_OfState(parentStatemachine, caState, propertyname_ofFullpath));
        }
            public static ChildAnimatorState DeepClone(this ChildAnimatorState childState)
            {
                ChildAnimatorState output = new ChildAnimatorState
                {
                    position = childState.position,
                    state    = childState.state.DeepClone()
                };

                return(output);
            }
Пример #11
0
        private void CreateNodeFromState(ChildAnimatorState state)
        {
            StateNode stateNode = this.CreateAndAddNode <StateNode>(string.Empty, state.position);

            stateNode.state = state.state;
            if (this.rootStateMachine.defaultState == state.state)
            {
                stateNode.color = Styles.Color.Orange;
            }
            this.m_StateNodeLookup.Add(state.state, stateNode);
        }
Пример #12
0
        private void CreateNodeFromState(ChildAnimatorState state)
        {
            StateNode node = this.CreateAndAddNode <StateNode>("", state.position);

            node.state = state.state;
            if (this.rootStateMachine.defaultState == state.state)
            {
                node.color = UnityEditor.Graphs.Styles.Color.Orange;
            }
            this.m_StateNodeLookup.Add(state.state, node);
        }
Пример #13
0
        public void Toggle(Transform[] items)
        {
            var itemsName = string.Join(" ", items.Select(item => item.name));

            var layer = NewLayer(
                $"{MethodBase.GetCurrentMethod().Name} {itemsName}");

            //var scene = new Grid(layer.stateMachine);

            var toggle = NewBoolParameter(layer.name);

            AnimationClip TogglingClip(bool active)
            {
                var clip = NewClip($"{layer.name}_{active}");

                foreach (var item in items)
                {
                    AnimationUtility.SetEditorCurve(
                        clip,
                        EditorCurveBinding.DiscreteCurve(
                            Path(item),
                            typeof(GameObject),
                            "m_IsActive"),
                        AnimationCurve.Constant(0, 1, active ? 1 : 0));
                }
                return(clip);
            }

            // states
            ChildAnimatorState entry  = New.State("Entry");
            ChildAnimatorState shown  = New.State("Shown", TogglingClip(true));
            ChildAnimatorState hidden = New.State("Hidden", TogglingClip(false));

            // position states
            entry.position  = layer.stateMachine.GetEntryPosition() - Grid.down;
            shown.position  = entry.position - Grid.down - 0.5f * Grid.left;
            hidden.position = entry.position - Grid.down - 0.5f * Grid.right;
            layer.stateMachine.SetExitPosition(entry.position - 2 * Grid.down);

            layer.stateMachine.states = Util.Array(entry, shown, hidden);

            var showWhen = Util.Array(New.BoolCondition(toggle, true));
            var hideWhen = Util.Array(New.BoolCondition(toggle, false));

            // transitions
            entry.state.transitions = Util.Array(
                New.Transition(shown.state, showWhen),
                New.Transition(hidden.state, hideWhen));
            shown.state.transitions =
                Util.Array(New.Transition(conditions: hideWhen));
            hidden.state.transitions =
                Util.Array(New.Transition(conditions: showWhen));
        }
Пример #14
0
        public static UnityEditor.Animations.AnimatorState GetStateBy(this UnityEditor.Animations.AnimatorController controller, int nameHash, int layerIndex = 0)
        {
            ChildAnimatorState child = controller.layers [layerIndex].stateMachine.states.FirstOrDefault(itm => itm.state.nameHash == nameHash);

            if (child.state != null)
            {
                return(child.state);
            }



            return(null);
        }
Пример #15
0
        /// <summary>
        /// Creates <c>ChildAnimatorState</c> with automatically generated position.
        /// </summary>
        /// <param name="name">Name of the new <c>AnimatorState</c>.</param>
        /// <param name="motion"><c>Motion</c> of the new <c>AnimatorState</c>.</param>
        /// <returns><c>ChildAnimatorState</c> with automatically generated position.</returns>
        protected ChildAnimatorState NewChildAnimatorState(string name, Motion motion)
        {
            var childState = new ChildAnimatorState()
            {
                position = pos.New(),
                state    = new AnimatorState()
                {
                    name   = name,
                    motion = motion
                }
            };

            return(childState);
        }
        public static void ChangeTransition(AnimatorStateTransition transition, ChildAnimatorState childState, int name, bool value)
        {
            transition.destinationState = childState.state;
            transition.conditions       = new AnimatorCondition[0];
            switch (value)
            {
            case true:
                transition.AddCondition(AnimatorConditionMode.If, 0, "Inventory " + name);
                break;

            case false:
                transition.AddCondition(AnimatorConditionMode.IfNot, 0, "Inventory " + name);
                break;
            }
        }
Пример #17
0
        private static ChildAnimatorState CloneChildAnimatorState(ChildAnimatorState old)
        {
            var n = new ChildAnimatorState
            {
                position = old.position,
                state    = CloneAnimatorState(old.state)
            };

            foreach (var oldb in old.state.behaviours)
            {
                var behaviour = n.state.AddStateMachineBehaviour(oldb.GetType());
                CloneBehaviourParameters(oldb, behaviour);
            }
            return(n);
        }
Пример #18
0
	private void GetBehaviours(RuntimeAnimatorController runController, AnimatorController controller, TEA_PlayableLayerData layerData, VRCAvatarDescriptor.AnimLayerType type) {
	 AnimatorController runCont = AssetDatabase.LoadAssetAtPath<AnimatorController>(AssetDatabase.GetAssetPath(runController));
	 int layerC = 0;
	 foreach(AnimatorControllerLayer layer in runCont.layers) {
		AnimatorControllerLayer copyLayer = controller.layers[layerC];
		int stateC = 0;
		foreach(ChildAnimatorState state in layer.stateMachine.states) {
		 ChildAnimatorState copyState = copyLayer.stateMachine.states[stateC];
		 int behC = 0;
		 foreach(StateMachineBehaviour beh in state.state.behaviours) {
			//Debug.Log($"getting avatar[{currentAvatar.name}] copyState[{copyState.state.name}] state[{state.state.name}] behC[{behC}] count[{copyState.state.behaviours.Length}]");
			if(beh is VRCPlayableLayerControl) {
			 VRCPlayableLayerControl pc = (VRCPlayableLayerControl)beh;
			 TEA_PlayableLayerControl tc = copyState.state.AddStateMachineBehaviour<TEA_PlayableLayerControl>();
			 tc.blendDuration = pc.blendDuration;
			 tc.debugString = pc.debugString;
			 tc.goalWeight = pc.goalWeight;
			 tc.layer = pc.layer;
			 tc.state = copyState.state.name;
			} else if(beh is VRCAvatarParameterDriver) {
			 VRCAvatarParameterDriver vd = (VRCAvatarParameterDriver)beh;
			 TEA_AvatarParameterDriver td = copyState.state.AddStateMachineBehaviour<TEA_AvatarParameterDriver>();
			 td.name = vd.name;
			 td.debugString = vd.debugString;
			 td.localOnly = vd.localOnly;
			 td.parameters = new List<VRC.SDKBase.VRC_AvatarParameterDriver.Parameter>();
			 foreach(VRCAvatarParameterDriver.Parameter param in vd.parameters) {
				td.parameters.Add(new VRCAvatarParameterDriver.Parameter() {
				 chance = param.chance,
				 name = param.name,
				 type = param.type,
				 value = param.value,
				 valueMax = param.valueMax,
				 valueMin = param.valueMin
				});
				td.state = copyState.state.name;
				//--- validation ---
			 }
			 ValidateParameterDriver((VRCAvatarParameterDriver)beh, type, layer, state.state);
			}
			behC++;
		 }//for behavior
		 stateC++;
		}//for state
		layerC++;
	 }//for layer

	}
Пример #19
0
 private void FillStateMachineLookupFromStateMachine(AnimatorStateMachine stateMachine)
 {
     ChildAnimatorStateMachine[] stateMachines = stateMachine.stateMachines;
     for (int i = 0; i < stateMachines.Length; i++)
     {
         ChildAnimatorStateMachine childAnimatorStateMachine = stateMachines[i];
         this.FillStateMachineLookupFromStateMachine(childAnimatorStateMachine.stateMachine);
         this.m_StateMachineLookup.Add(childAnimatorStateMachine.stateMachine, stateMachine);
     }
     ChildAnimatorState[] states = stateMachine.states;
     for (int j = 0; j < states.Length; j++)
     {
         ChildAnimatorState childAnimatorState = states[j];
         this.m_StateMachineProxyLookup.Add(childAnimatorState.state, stateMachine);
     }
 }
Пример #20
0
    public void OnDropDownChanged()
    {
        string               value               = dropDown.options[dropDown.value].text;
        Animator             animator            = modelRoot.GetComponentInChildren <Animator>();
        AnimatorController   animationController = animator.runtimeAnimatorController as AnimatorController;
        AnimatorStateMachine stateMachine        = animationController.layers[0].stateMachine;

        foreach (var s in stateMachine.states)
        {
            if (s.state.name == value)
            {
                curState = s;
                return;
            }
        }
    }
Пример #21
0
        /// <param name="parentPath"></param>
        /// <param name="caState"></param>
        /// <param name="lNum">レイヤー番号</param>
        /// <param name="smNum">ステートマシン番号</param>
        /// <param name="sNum">ステート番号</param>
        /// <returns></returns>
        public override bool OnState(string parentPath, ChildAnimatorState caState, int lNum, int smNum, int sNum)
        {
            StateRecord stateRecord = StateRecord.CreateInstance(
                lNum,
                smNum,
                sNum,
                parentPath,
                caState, AconDocument.positions);

            AconDocument.states.Add(stateRecord);

            // モーション・スキャン
            motionScanner.OnState(caState);

            return(true);
        }
Пример #22
0
        private AnimatorStateMachine AddStateMachine(StateMachine stateMachine)
        {
            AnimatorStateMachine controllerStateMachine;

            if (stateMachine.overrideExistingStateMachine)
            {
                List <ChildAnimatorState>        newStates        = new List <ChildAnimatorState>();
                List <ChildAnimatorStateMachine> newStateMachines = new List <ChildAnimatorStateMachine>();
                controllerStateMachine = stateMachine.controllerStateMachine != null
                                        ? stateMachine.controllerStateMachine
                                        : new AnimatorStateMachine();
                stateMachine.controllerStateMachine = controllerStateMachine;
                controllerStateMachine.name         = stateMachine.Name;
                foreach (var state in stateMachine.states)
                {
                    switch (state.type)
                    {
                    case StateType.State: {
                        var temp = new ChildAnimatorState();
                        temp.state        = new UnityEditor.Animations.AnimatorState();
                        temp.state.motion = state.state.motion;
                        temp.state.name   = state.state.Name;
                        newStates.Add(temp);
                        break;
                    }

                    case StateType.StateMachine:
                    default: {
                        var temp = new ChildAnimatorStateMachine();
                        temp.stateMachine = AddStateMachine(state.stateMachine);
                        newStateMachines.Add(temp);
                        break;
                    }
                    }
                }

                controllerStateMachine.stateMachines = newStateMachines.ToArray();
                controllerStateMachine.states        = newStates.ToArray();
            }
            else
            {
                controllerStateMachine = stateMachine.controllerStateMachine;
            }

            return(controllerStateMachine);
        }
Пример #23
0
 /// <summary>
 /// Collects all fields that will be serialized.
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="info"></param>
 /// <param name="context"></param>
 public override void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
 {
     if (obj == null)
     {
         return;
     }
     if (obj is ChildAnimatorStateMachine)
     {
         ChildAnimatorStateMachine fsm = (ChildAnimatorStateMachine)obj;
         info.AddValue("position", (object)fsm.position);
         info.AddValue("stateMachine", (object)fsm.stateMachine);
     }
     else if (obj is ChildAnimatorState)
     {
         ChildAnimatorState state = (ChildAnimatorState)obj;
         info.AddValue("position", (object)state.position);
         info.AddValue("state", (object)state.state);
     }
 }
Пример #24
0
        public void OnState(ChildAnimatorState caState)
        {
            if (null != caState.state.motion)
            {
                Motion motion    = caState.state.motion;
                string assetPath = AssetDatabase.GetAssetPath(motion.GetInstanceID());
                //ebug.Log(" motion.GetType()=[" + motion.GetType().ToString() + "] assetPath=["+ assetPath + "]");

                if (motionCounter.ContainsKey(assetPath))
                {
                    // 既存のモーションを複数回使うことはある。
                    motionCounter[assetPath].CountOfAttachDestination++;
                }
                else
                {
                    motionCounter.Add(assetPath, new MotionRecord.Wrapper(caState.state.motion, 1));
                }
            }
        }
        public void HandleStatesPositionInfo(AnimatorControllerLayer[] layers)
        {
            int       num         = layers.Length;
            int       statesCount = controllerInfo.states.dict.Count;
            ArrayList myArryList  = new ArrayList();

            for (int i = 0; i < statesCount; i++)
            {
                myArryList.Add(new JSONObject(JSONObject.Type.OBJECT));
            }
            for (int i = 0; i < num; i++)
            {
                AnimatorControllerLayer layer   = layers[i];
                AnimatorStateMachine    machine = layer.stateMachine;
                ChildAnimatorState[]    states  = machine.states;
                for (int j = 0; j < states.Length; j++)
                {
                    ChildAnimatorState state = states[j];
                    bool stateExist;
                    var  stateInfo = controllerInfo.states.AddObject(state.state, out stateExist);
                    if (stateExist)
                    {
                        JSONObject statePositionJSON = new JSONObject(JSONObject.Type.OBJECT);
                        statePositionJSON.AddField("name", state.state.name);
                        JSONObject pos = new JSONObject(JSONObject.Type.ARRAY);
                        pos.Add(state.position.x);
                        pos.Add(state.position.y);
                        statePositionJSON.AddField("position", pos);
                        myArryList[stateInfo.Key] = statePositionJSON;
                    }
                    else
                    {
                        Debug.LogError("state count is not match");
                    }
                }
            }
            foreach (JSONObject statePosInfo in myArryList)
            {
                controllerInfo.statesPositionInfo.Add(statePosInfo);
            }
        }
Пример #26
0
    private void Start()
    {
        if (ID == 0)
        {
            ID = IdGenerater.GenerateId();
        }

        UnitManager.Instance.Add(this);

        Animator = GetComponent <Animator>();

        Collider = GetComponent <Collider>();

        AnimatorController   animatorController   = Animator.runtimeAnimatorController as AnimatorController;
        AnimatorStateMachine animatorStateMachine = animatorController.layers[0].stateMachine;

        for (int i = 0; i < animatorStateMachine.states.Length; i++)
        {
            ChildAnimatorState childAnimatorState = animatorStateMachine.states[i];
            string             stateName          = childAnimatorState.state.name;
            int nameHash = childAnimatorState.state.nameHash;
            StateDic.Add(nameHash, stateName);

            if (childAnimatorState.state.behaviours.Length == 0)
            {
                childAnimatorState.state.AddStateMachineBehaviour <UnitStateBehaviour>();
            }

            AnimatorStateTransition[] transitions = childAnimatorState.state.transitions;
            if (transitions.Length > 1)
            {
                throw new Exception($"State:{stateName},不能包含多个Tansition");
            }

            if (transitions.Length == 1)
            {
                AnimatorStateTransition transition = transitions[0];
                TransitionStateDic.Add(nameHash, transition.destinationState.name);
            }
        }
    }
Пример #27
0
    /// <summary>
    /// 替换动画控制器中使用的Clip
    /// </summary>
    public static void replaceStateMotion(AnimatorController ctrl, AnimationClip oldClip, AnimationClip newClip, bool replaceAll = false)
    {
        var e = ctrl.layers.GetEnumerator();

        while (e.MoveNext())
        {
            AnimatorControllerLayer layer = (AnimatorControllerLayer)e.Current;
            var child = layer.stateMachine.states.GetEnumerator();
            while (child.MoveNext())
            {
                ChildAnimatorState childState = (ChildAnimatorState)child.Current;
                if (childState.state.motion == oldClip)
                {
                    ctrl.SetStateEffectiveMotion(childState.state, newClip);
                    if (!replaceAll)
                    {
                        return;
                    }
                }
            }
        }
    }
Пример #28
0
 private void CreateNodes()
 {
     this.m_StateNodeLookup.Clear();
     this.m_StateMachineNodeLookup.Clear();
     ChildAnimatorState[] states = this.activeStateMachine.states;
     for (int i = 0; i < states.Length; i++)
     {
         ChildAnimatorState state = states[i];
         this.CreateNodeFromState(state);
     }
     ChildAnimatorStateMachine[] stateMachines = this.activeStateMachine.stateMachines;
     for (int j = 0; j < stateMachines.Length; j++)
     {
         ChildAnimatorStateMachine subStateMachine = stateMachines[j];
         this.CreateNodeFromStateMachine(subStateMachine);
     }
     this.CreateAnyStateNode();
     this.CreateEntryExitNodes();
     if (this.parentStateMachine)
     {
         this.CreateParentStateMachineNode();
     }
 }
Пример #29
0
        private static ChildAnimatorState[] DuplicateChildStates(ChildAnimatorState[] srcChildStates)
        {
            var dstStates = new ChildAnimatorState[srcChildStates.Length];

            for (int i = 0; i < srcChildStates.Length; i++)
            {
                var srcState = srcChildStates[i].state;
                dstStates[i] = new ChildAnimatorState
                {
                    position = srcChildStates[i].position,
                    state    = DuplicateAnimatorState(srcState)
                };

                // behavioursを設定
                foreach (var srcBehaivour in srcChildStates[i].state.behaviours)
                {
                    var behaivour = dstStates[i].state.AddStateMachineBehaviour(srcBehaivour.GetType());
                    CopyBehaivourParameters(srcBehaivour, behaivour);
                }
            }

            return(dstStates);
        }
Пример #30
0
        public static void ProcessAnimations(Animator animator, string[] nodeNames, System.Action <AnimationClip> fn)
        {
            // iterate over the animator graph's node, checking if the node is one we'll be triggering as a power animation
            // and stick a
            AnimatorController ac = animator.runtimeAnimatorController as AnimatorController;

            for (int i = 0; i < animator.layerCount; i++)
            {
                ChildAnimatorState[] aStates = ac.layers[i].stateMachine.states;
                for (int j = 0; j < aStates.Length; j++)
                {
                    ChildAnimatorState aState = aStates[j];

                    // check if its a power anim, by comparing the node name with known power anim names
                    bool onList = false;
                    for (int k = 0; k < nodeNames.Length; k++)
                    {
                        if (aState.state.name == nodeNames[k])
                        {
                            onList = true;
                        }
                    }

                    if (onList)
                    {
                        // see if the node has an animation
                        AnimationClip clip = aState.state.motion as AnimationClip;

                        if (clip)
                        {
                            fn.Invoke(clip);
                        }
                    }
                }
            }
        }