/// <summary>
        /// 2つのステートを結んでいる全てのトランジション。
        /// </summary>
        /// <param name="path_src">"Base Layer.JMove.JMove0" といった文字列</param>
        public static List <AnimatorStateTransition> FetchTransition_SrcDst(AnimatorController ac, string path_src, string path_dst)
        {
            List <AnimatorStateTransition> hit = new List <AnimatorStateTransition>();

            AnimatorState state_src;
            {
                int            caret = 0;
                FullpathTokens ft    = new FullpathTokens();
                if (!FullpathSyntaxP.Fixed_LayerName_And_StatemachineNames_And_StateName(path_src, ref caret, ref ft))
                {
                    throw new UnityException("Parse failure. [" + path_src + "] ac=[" + ac.name + "]");
                }
                state_src = AconFetcher.FetchState(ac, ft);
            }
            AnimatorState state_dst;

            {
                int            caret = 0;
                FullpathTokens ft    = new FullpathTokens();
                if (!FullpathSyntaxP.Fixed_LayerName_And_StatemachineNames_And_StateName(path_dst, ref caret, ref ft))
                {
                    throw new UnityException("Parse failure. [" + path_dst + "] ac=[" + ac.name + "]");
                }
                state_dst = AconFetcher.FetchState(ac, ft);
            }

            foreach (AnimatorStateTransition transition in state_src.transitions)
            {
                if (transition.destinationState == state_dst)
                {
                    hit.Add(transition);
                }
            }
            return(hit);
        }
        public static AnimatorStateTransition FetchTransition_ByFullpath(AnimatorController ac, string fullpath, int transitionNum_ofFullpath)
        {
            int            caret = 0;
            FullpathTokens ft    = new FullpathTokens();

            if (!FullpathSyntaxP.Fixed_LayerName_And_StatemachineNames_And_StateName(fullpath, ref caret, ref ft))
            {
                throw new UnityException("Parse failure. [" + fullpath + "] ac=[" + ac.name + "]");
            }

            AnimatorState state = AconFetcher.FetchState(ac, ft);

            if (null == state)
            {
                throw new UnityException("Not found state. [" + fullpath + "] ac=[" + ac.name + "]");
            }

            int tNum = 0;

            foreach (AnimatorStateTransition transition in state.transitions)
            {
                if (transitionNum_ofFullpath == tNum)
                {
                    return(transition);
                }
                tNum++;
            }

            return(null);// TODO:
        }
        public void N80_Syntax_Fixed_LayerName()
        {
            string         query = "Base Layer.Alpaca.Bear.Cat";
            int            caret = 0;
            FullpathTokens ft    = new FullpathTokens();

            bool successful = FullpathSyntaxP.Fixed_LayerName(query, ref caret, ref ft);

            Assert.IsTrue(successful);
            Assert.AreEqual(11, caret);
            Assert.AreEqual("Base Layer", ft.LayerNameEndsWithoutDot);
        }
        public void N80_Syntax_Fixed_LayerName_And_StatemachineNames()
        {
            string         query = "Base Layer.Alpaca.Bear.Cat";
            int            caret = 0;
            FullpathTokens ft    = new FullpathTokens();

            bool successful = FullpathSyntaxP.Fixed_LayerName_And_StatemachineNames(query, ref caret, ref ft);

            Assert.IsTrue(successful);
            Assert.AreEqual(23, caret);
            Assert.AreEqual("Base Layer", ft.LayerNameEndsWithoutDot);
            Assert.AreEqual(2, ft.StatemachineNamesEndsWithoutDot.Count);
            Assert.AreEqual("Alpaca", ft.StatemachineNamesEndsWithoutDot[0]);
            Assert.AreEqual("Bear", ft.StatemachineNamesEndsWithoutDot[1]);
        }
        public void N80_Syntax_Continued_Fixed_LayerName_And_StatemachineNames_And_StateName()
        {
            string         query = "Base Layer.Alpaca.Bear.Cat";
            int            caret = 0;
            FullpathTokens ft    = new FullpathTokens();

            // "~ Bear." まで読む
            bool successful1 = FullpathSyntaxP.Fixed_LayerName_And_StatemachineNames(query, ref caret, ref ft);

            Assert.IsTrue(successful1);

            // 続きから "Cat" まで読む
            bool successful2 = FullpathSyntaxP.Continued_Fixed_StateName(query, ref caret, ft, ref ft);

            Assert.IsTrue(successful2);
            Assert.AreEqual(26, caret);
            Assert.AreEqual("Base Layer", ft.LayerNameEndsWithoutDot);
            Assert.AreEqual(2, ft.StatemachineNamesEndsWithoutDot.Count);
            Assert.AreEqual("Alpaca", ft.StatemachineNamesEndsWithoutDot[0]);
            Assert.AreEqual("Bear", ft.StatemachineNamesEndsWithoutDot[1]);
            Assert.AreEqual("Cat", ft.StateName);
        }
Example #6
0
        public void ScanAnimatorController(AnimatorController ac, StringBuilder info_message)
        {
            info_message.AppendLine("Animator controller Scanning...");

            // パラメーター
            if (parameterScan)
            {
                AnimatorControllerParameter[] acpArray = ac.parameters;
                int num = 0;
                foreach (AnimatorControllerParameter acp in acpArray)
                {
                    OnParameter(num, acp);
                    num++;
                }
            }

            int lNum = 0;

            // レイヤー
            foreach (AnimatorControllerLayer layer in ac.layers)
            {
                if (OnLayer(layer, lNum))
                {
                    // フルパス, ステートマシン
                    Dictionary <string, AnimatorStateMachine> statemachineList_flat = new Dictionary <string, AnimatorStateMachine>();

                    // レイヤーは、ステートマシンを持っていないことがある。他のレイヤーのステートマシンを参照してるのだろう。

                    // 次のレイヤーへ
                    if (null == layer.stateMachine)
                    {
                        continue;
                    }

                    // 再帰をスキャンして、フラットにする。
                    ScanRecursive("", layer.stateMachine, statemachineList_flat);

                    int smNum = 0;
                    foreach (KeyValuePair <string, AnimatorStateMachine> statemachine_pair in statemachineList_flat)
                    {
                        // ステート・マシン

                        FullpathTokens ft1    = new FullpathTokens();
                        int            caret1 = 0;
                        if (!FullpathSyntaxP.Fixed_LayerName_And_StatemachineNames(statemachine_pair.Key, ref caret1, ref ft1))
                        {
                            throw new UnityException("Parse failure. [" + statemachine_pair.Key + "] ac=[" + ac.name + "]");
                        }

                        if (OnStatemachine(
                                statemachine_pair.Key,

                                // 例えばフルパスが "Base Layer.Alpaca.Bear.Cat.Dog" のとき、"Alpaca.Bear.Cat"。
                                ft1.StatemachinePath,

                                statemachine_pair.Value, lNum, smNum))
                        {
                            int sNum = 0;
                            foreach (ChildAnimatorState caState in statemachine_pair.Value.states)
                            {
                                // ステート(ラッパー)

                                if (OnState(statemachine_pair.Key, caState, lNum, smNum, sNum))
                                {
                                    // トランジション番号
                                    int tNum = 0;
                                    foreach (AnimatorStateTransition transition in caState.state.transitions)
                                    {
                                        if (OnTransition(transition, lNum, smNum, sNum, tNum))
                                        {
                                            // コンディション番号
                                            int cNum = 0;
                                            foreach (AnimatorCondition condition in transition.conditions)
                                            {
                                                OnCondition(condition, lNum, smNum, sNum, tNum, cNum);
                                                cNum++;
                                            }
                                        }
                                        tNum++;
                                    }// トランジション
                                }
                                sNum++;
                            }// ステート(ラッパー)
                        }
                        smNum++;
                    }// ステートマシン
                }
                lNum++;
            }// レイヤー

            OnScanned(info_message);
            info_message.AppendLine("Scanned.");
        }