Пример #1
0
        public override void Init(GameObjBase gobj)
        {
            base.Init(gobj);
            Assembly asm          = Assembly.GetExecutingAssembly();
            string   statemapname = "FSM_" + gobj.GetType().Name;

            if (gobj.GetType().Name == "NpcPlayer" || gobj.GetType().Name == "Pet")
            {
                statemapname = "FSM_" + "NetPlayer";
            }
            ClashFsmStateMap stateMap = DBManager.m_DBFsm.GetFsmStateMap(statemapname);

            //  Debug.Log("class nema===================================================================================================" + statemapname);
            if (stateMap == null)
            {
                Debug.LogError("<FSM not exist>:FSM.name = " + statemapname);
                return;
            }

            foreach (ClashFsmStateMap.State state in stateMap.States)
            {
                ClashFsmStateBase newState = (ClashFsmStateBase)asm.CreateInstance(GDefine.m_GameNamespace + state.Name);
                //Debug.Log("class nemastate name=" + newState.GetType().Name);
                if (newState == null)
                {
                    Debug.LogError("<FSM error>:state not exist: fsm.name = " + statemapname + "state.name = " + state.Name);
                    continue;
                }
                newState.SetGameObject(m_Owner);

                foreach (ClashFsmStateMap.Dest dest in state.Dests)
                {
                    LinkState newLink = new LinkState();
                    newLink.m_StateName = dest.Name;
                    newLink.m_EventId   = dest.EventID;
                    // TODO Add Conditions
                    foreach (ClashFsmStateMap.Condition cond in dest.Conditions)
                    {
                        if (!newLink.m_AllConditions.ContainsKey(cond.Name))
                        {
                            newLink.m_AllConditions.Add(cond.Name, cond.Params);
                        }
                        else
                        {
                            Debug.LogError("<FSM error>: same condition can't be added in one dest twice!");
                        }
                    }

                    newState.m_LinkStateList.Add(newLink);
                }
                AddState(newState);
            }
        }
Пример #2
0
        public ClashFsmStateMap GetFsmStateMap(string strFilename)
        {
            ClashFsmStateMap stateMap = null;

            if (BnBFsmStateMapDic.TryGetValue(strFilename, out stateMap))
            {
                return(stateMap);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        private void LoadData(string strFilename)
        {
            XmlDocument xmlDoc    = new XmlDocument();
            TextAsset   textAsset = (TextAsset)Resources.Load(strFilename, typeof(TextAsset));

            if (textAsset == null)
            {
                Debug.LogError("<Load FSM DB Failed>:filename = " + strFilename + "SDFF");
                return;
            }
            xmlDoc.Load(new StringReader(textAsset.text));
            XmlElement       xmlRoot = xmlDoc.DocumentElement;
            ClashFsmStateMap newFsm  = new ClashFsmStateMap();

            // <State>...
            XmlNodeList stateNodes = xmlRoot.ChildNodes;

            foreach (XmlNode stateNode in stateNodes)
            {
                // <State>
                if (!(stateNode is XmlElement))
                {
                    continue;
                }
                XmlElement             xmlElem  = (XmlElement)stateNode;
                ClashFsmStateMap.State newState = new ClashFsmStateMap.State();

                // <State.Name>
                newState.Name = xmlElem.GetAttribute("Name");

                // <State.Dest> <State.Dest> <State.Dest>
                XmlNodeList destNodes = xmlElem.ChildNodes;
                foreach (XmlNode destNode in destNodes)
                {
                    // <State.Dest>
                    if (!(destNode is XmlElement))
                    {
                        continue;
                    }
                    XmlElement            xmlDest = (XmlElement)destNode;
                    ClashFsmStateMap.Dest newDest = new ClashFsmStateMap.Dest();

                    // <State.Dest.Name>
                    newDest.Name = xmlDest.GetAttribute("Name");
                    // <State.Dest.EventID>
                    string    eventID     = xmlDest.GetAttribute("EventID");
                    eFsmEvent enumEventID = (eFsmEvent)Enum.Parse(typeof(eFsmEvent), eventID);
                    if (eventID != "")
                    {
                        //newDest.EventID = XmlConvert.ToInt32(eventID);
                        newDest.EventID = (int)enumEventID;
                    }
                    else
                    {
                        Debug.LogError("<FSM error>:State.Dest.Event can not be empty");
                    }

                    //<State.Dest.Conditions>
                    XmlElement xmlConditions = (XmlElement)xmlDest.SelectSingleNode("Conditions");
                    if (xmlConditions != null)
                    {
                        // <State.Dest.Conditions.Condition>...
                        XmlNodeList condNodes = xmlConditions.ChildNodes;
                        foreach (XmlNode condNode in condNodes)
                        {
                            // <State.Dest.Conditions.Condition>
                            if (!(condNode is XmlElement))
                            {
                                continue;
                            }
                            XmlElement xmlCond = (XmlElement)condNode;
                            ClashFsmStateMap.Condition newCond = new ClashFsmStateMap.Condition();

                            // <State.Dest.Conditions.Condition.Name>
                            newCond.Name = xmlCond.GetAttribute("Name");

                            // <State.Dest.Conditions.Condition.Param>...
                            XmlNodeList paramNodes = xmlCond.ChildNodes;
                            foreach (XmlNode paramNode in paramNodes)
                            {
                                // <State.Dest.Conditions.Condition.Param>
                                if (!(paramNode is XmlElement))
                                {
                                    continue;
                                }
                                XmlElement xmlParam = (XmlElement)paramNode;

                                string Value = xmlParam.GetAttribute("Value");
                                newCond.Params.Add(Value);
                            }
                            newDest.Conditions.Add(newCond);
                        }
                    }
                    newState.Dests.Add(newDest);
                }
                newFsm.States.Add(newState);
            }
            string fsmName = strFilename.Substring(strFilename.LastIndexOf('/') + 1, strFilename.Length - strFilename.LastIndexOf('/') - 1);

            BnBFsmStateMapDic.Add(fsmName, newFsm);
        }