/// <summary>
        /// "Base Layer.Alpaca" や、"Base Layer.Alpaca.Bear" などがOK。
        ///
        /// ステートマシン名は無いこともある。
        /// </summary>
        /// <param name="query"></param>
        /// <param name="ref_caret"></param>
        /// <param name="maxFt"></param>
        /// <returns></returns>
        public static bool Fixed_LayerName_And_StatemachineNames_And_StateName(string query, ref int ref_caret, ref FullpathTokens maxFt)
        {
            FullpathTokens ft    = new FullpathTokens("LayerName_And_StatemachineNames_And_StateName");
            int            caret = ref_caret;
            string         layerNameEndsWithoutDot;
            List <string>  statemachineNamesEndsWithoutDot;
            string         stateName;

            if (!FullpathLexcalP.VarLayerName(query, ref caret, out layerNameEndsWithoutDot))
            {
                return(NotMatched(maxFt, caret, ref maxFt));
            }
            ft.LayerNameEndsWithoutDot = layerNameEndsWithoutDot;

            // ステートマシン名はオプション。
            if (FullpathLexcalP.VarStatemachineNames(query, ref caret, out statemachineNamesEndsWithoutDot))
            {
                ft.StatemachineNamesEndsWithoutDot = statemachineNamesEndsWithoutDot;
            }

            if (!FullpathLexcalP.VarStateName(query, ref caret, out stateName))
            {
                return(NotMatched(maxFt, caret, ref maxFt));
            }
            ft.StateName = stateName;

            maxFt = ft; ref_caret = caret; return(true);
        }
        /// <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 static bool NotMatched(FullpathTokens current, int caret, ref FullpathTokens max)
 {
     if (max.MatchedSyntaxCaret < caret)
     {
         current.MatchedSyntaxCaret = caret; max = current;
     }
     return(false);
 }
 // クローン
 public FullpathTokens(FullpathTokens source)
 {
     LayerNameEndsWithoutDot         = source.LayerNameEndsWithoutDot;
     MatchedSyntaxCaret              = source.MatchedSyntaxCaret;
     MatchedSyntaxName               = source.MatchedSyntaxName;
     StatemachineNamesEndsWithoutDot = new List <string>(source.StatemachineNamesEndsWithoutDot);
     StateName = source.StateName;
 }
        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);
        }
        /// <summary>
        /// ドット(.) または文末までがレイヤー名。
        ///
        /// (FIXME: 実際はレイヤー名にはドットを含むことができるが、運用で避けるものとする)
        /// </summary>
        /// <param name="query"></param>
        /// <param name="caret"></param>
        /// <returns></returns>
        public static bool Fixed_LayerName(string query, ref int ref_caret, ref FullpathTokens maxFt)
        {
            FullpathTokens ft    = new FullpathTokens("LayerName");
            int            caret = ref_caret;
            string         layerNameEndsWithoutDot;

            if (!FullpathLexcalP.VarLayerName(query, ref caret, out layerNameEndsWithoutDot))
            {
                return(NotMatched(maxFt, caret, ref maxFt));
            }
            ft.LayerNameEndsWithoutDot = layerNameEndsWithoutDot;

            maxFt = ft; ref_caret = caret; return(true);
        }
        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]);
        }
        /// <summary>
        /// "Base Layer.Alpaca" や、"Base Layer.Alpaca.Bear" などがOK。
        ///
        /// ステートマシン名は無いこともある。
        /// </summary>
        /// <param name="query"></param>
        /// <param name="ref_caret"></param>
        /// <param name="maxFt"></param>
        /// <returns></returns>
        public static bool Continued_Fixed_StateName(string query, ref int ref_caret, FullpathTokens baseFt, ref FullpathTokens maxFt)
        {
            // クローンし、追加していく。
            FullpathTokens ft    = new FullpathTokens(baseFt);
            int            caret = ref_caret;
            string         stateName;

            if (!FullpathLexcalP.VarStateName(query, ref caret, out stateName))
            {
                return(NotMatched(maxFt, caret, ref maxFt));
            }
            ft.StateName = stateName;

            maxFt = ft; ref_caret = caret; return(true);
        }
        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);
        }
        /// <summary>
        /// パス・トークンを指定すると ステートを返す。
        /// </summary>
        public static AnimatorState FetchState(AnimatorController ac, FullpathTokens ft)
        {
            AnimatorControllerLayer layer          = AconFetcher.FetchLayer_JustLayerName(ac, ft.LayerNameEndsWithoutDot);
            AnimatorStateMachine    currentMachine = layer.stateMachine;

            if (null == currentMachine)
            {
                throw new UnityException("Not found layer. nodes=[" + ft.StatemachinePath + "]");
            }

            // ステートマシンが途中にある場合、最後のステートマシンまで降りていく。
            if (0 < ft.StatemachineNamesEndsWithoutDot.Count)
            {
                currentMachine = FetchLeafMachine_ofState(currentMachine, ft.StatemachineNamesEndsWithoutDot);
                if (null == currentMachine)
                {
                    throw new UnityException("Not found node. currentMachine.name=[" + currentMachine.name + "] nodes=[" + ft.StatemachinePath + "]");
                }
            }

            return(FetchChildState_ofState(currentMachine, ft.StateName));
        }
Example #12
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.");
        }