コード例 #1
0
        public Action LoadActionResource(string _actionName)
        {
            Action action = null;

            if (_actionName == null)
            {
                DebugHelper.Assert(_actionName != null, "can't load action with name = null");
                return(null);
            }
            if (this.actionResourceSet.TryGetValue(_actionName, out action))
            {
                if (action != null)
                {
                    return(action);
                }
                this.actionResourceSet.Remove(_actionName);
            }
            CBinaryObject cBinaryObject = ActionManager.Instance.resLoader.LoadAge(_actionName) as CBinaryObject;

            if (cBinaryObject == null)
            {
                return(null);
            }
            SecurityParser securityParser = new SecurityParser();

            try
            {
                securityParser.LoadXml(Encoding.get_UTF8().GetString(cBinaryObject.m_data));
            }
            catch (Exception ex)
            {
                DebugHelper.Assert(false, "Load xml Exception for action name = {0}, exception = {1}", new object[]
                {
                    _actionName,
                    ex.get_Message()
                });
                return(null);
            }
            action            = new Action();
            action.name       = _actionName;
            action.enabled    = false;
            action.actionName = _actionName;
            this.actionResourceSet.Add(_actionName, action);
            Singleton <CResourceManager> .GetInstance().RemoveCachedResource(_actionName);

            SecurityElement securityElement  = securityParser.SelectSingleNode("Project");
            SecurityElement securityElement2 = (securityElement != null) ? securityElement.SearchForChildByTag("TemplateObjectList") : null;
            SecurityElement securityElement3 = (securityElement != null) ? securityElement.SearchForChildByTag("Action") : null;
            SecurityElement securityElement4 = (securityElement != null) ? securityElement.SearchForChildByTag("RefParamList") : null;

            DebugHelper.Assert(securityElement3 != null, "actionNode!=null");
            if (securityElement3 != null)
            {
                action.length = ActionUtility.SecToMs(float.Parse(securityElement3.Attribute("length")));
                action.loop   = bool.Parse(securityElement3.Attribute("loop"));
            }
            if (securityElement2 != null && securityElement2.get_Children() != null)
            {
                for (int i = 0; i < securityElement2.get_Children().get_Count(); i++)
                {
                    SecurityElement securityElement5 = securityElement2.get_Children().get_Item(i) as SecurityElement;
                    string          str  = securityElement5.Attribute("objectName");
                    string          text = securityElement5.Attribute("id");
                    int             id   = int.Parse(text);
                    action.AddTemplateObject(str, id);
                }
            }
            if (securityElement4 != null && securityElement4.get_Children() != null)
            {
                for (int j = 0; j < securityElement4.get_Children().get_Count(); j++)
                {
                    this.LoadRefParamNode(action, securityElement4.get_Children().get_Item(j) as SecurityElement);
                }
            }
            if (securityElement3 != null && securityElement3.get_Children() != null)
            {
                for (int k = 0; k < securityElement3.get_Children().get_Count(); k++)
                {
                    SecurityElement securityElement6 = securityElement3.get_Children().get_Item(k) as SecurityElement;
                    string          text2            = securityElement6.Attribute("eventType");
                    if (!text2.Contains(".") && text2.get_Length() > 0)
                    {
                        text2 = "AGE." + text2;
                    }
                    Type type = Utility.GetType(text2);
                    if (type != null)
                    {
                        string name = string.Empty;
                        bool   flag = false;
                        if (securityElement6.Attribute("refParamName") != null)
                        {
                            name = securityElement6.Attribute("refParamName");
                        }
                        if (securityElement6.Attribute("useRefParam") != null)
                        {
                            flag = bool.Parse(securityElement6.Attribute("useRefParam"));
                        }
                        bool enabled = bool.Parse(securityElement6.Attribute("enabled"));
                        if (flag)
                        {
                            action.refParams.GetRefParam(name, ref enabled);
                        }
                        Track track = action.AddTrack(type);
                        track.enabled   = enabled;
                        track.trackName = securityElement6.Attribute("trackName");
                        if (securityElement6.Attribute("execOnActionCompleted") != null)
                        {
                            track.execOnActionCompleted = bool.Parse(securityElement6.Attribute("execOnActionCompleted"));
                        }
                        if (securityElement6.Attribute("execOnForceStopped") != null)
                        {
                            track.execOnForceStopped = bool.Parse(securityElement6.Attribute("execOnForceStopped"));
                        }
                        if (flag)
                        {
                            FieldInfo field = type.GetField(securityElement6.Attribute("enabled"));
                            action.refParams.AddRefData(name, field, track);
                        }
                        if (securityElement6.Attribute("r") != null)
                        {
                            track.color.r = float.Parse(securityElement6.Attribute("r"));
                        }
                        if (securityElement6.Attribute("g") != null)
                        {
                            track.color.g = float.Parse(securityElement6.Attribute("g"));
                        }
                        if (securityElement6.Attribute("b") != null)
                        {
                            track.color.b = float.Parse(securityElement6.Attribute("b"));
                        }
                        ListView <SecurityElement> listView = new ListView <SecurityElement>();
                        if (securityElement6.get_Children() != null)
                        {
                            for (int l = 0; l < securityElement6.get_Children().get_Count(); l++)
                            {
                                SecurityElement securityElement7 = securityElement6.get_Children().get_Item(l) as SecurityElement;
                                if (securityElement7.get_Tag() != "Event" && securityElement7.get_Tag() != "Condition")
                                {
                                    listView.Add(securityElement7);
                                }
                            }
                            for (int m = 0; m < securityElement6.get_Children().get_Count(); m++)
                            {
                                SecurityElement securityElement8 = securityElement6.get_Children().get_Item(m) as SecurityElement;
                                if (securityElement8.get_Tag() == "Condition")
                                {
                                    SecurityElement securityElement9 = securityElement8;
                                    int             num   = int.Parse(securityElement9.Attribute("id"));
                                    bool            flag2 = bool.Parse(securityElement9.Attribute("status"));
                                    if (track.waitForConditions == null)
                                    {
                                        track.waitForConditions = new Dictionary <int, bool>();
                                    }
                                    track.waitForConditions.Add(num, flag2);
                                }
                                else if (!(securityElement8.get_Tag() != "Event"))
                                {
                                    int time   = ActionUtility.SecToMs(float.Parse(securityElement8.Attribute("time")));
                                    int length = 0;
                                    if (track.IsDurationEvent)
                                    {
                                        length = ActionUtility.SecToMs(float.Parse(securityElement8.Attribute("length")));
                                    }
                                    BaseEvent baseEvent = track.AddEvent(time, length);
                                    for (int n = 0; n < listView.Count; n++)
                                    {
                                        this.SetEventField(action, baseEvent, listView[n]);
                                    }
                                    if (securityElement8.get_Children() != null)
                                    {
                                        for (int num2 = 0; num2 < securityElement8.get_Children().get_Count(); num2++)
                                        {
                                            this.SetEventField(action, baseEvent, securityElement8.get_Children().get_Item(num2) as SecurityElement);
                                        }
                                    }
                                    baseEvent.OnLoaded();
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Invalid event type \"" + securityElement6.Attribute("eventType") + "\"!");
                    }
                }
            }
            return(action);
        }