Example #1
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);
        }
Example #2
0
 public Event_FSM_EF_Event(eFsmEvent FsmEvent)
 {
     m_iEventID   = (int)Event_FSM.EF_Event;
     m_FsmEventID = FsmEvent;
     m_EventArgs  = new ArrayList();
 }