Example #1
0
        protected void load_attachments(int version, string agentType, BsonDeserizer d, bool bIsTransition)
        {
            d.OpenDocument();

            BsonDeserizer.BsonTypes type = d.ReadType();

            while (type == BsonDeserizer.BsonTypes.BT_AttachmentElement)
            {
                d.OpenDocument();

                if (bIsTransition)
                {
                    this.m_loadAttachment = true;
                    this.load_properties_pars_attachments_children(version, agentType, d, false);
                    this.m_loadAttachment = false;
                }
                else
                {
                    string attachClassName = d.ReadString();

                    BehaviorNode pAttachment = BehaviorNode.Create(attachClassName);
                    Debug.Check(pAttachment != null, attachClassName);

                    if (pAttachment != null)
                    {
                        pAttachment.SetClassNameString(attachClassName);

                        string idString = d.ReadString();
                        pAttachment.SetId(Convert.ToInt32(idString));

                        bool bIsPrecondition = d.ReadBool();
                        bool bIsEffector = d.ReadBool();
                        bool bAttachmentIsTransition = d.ReadBool();

                        pAttachment.load_properties_pars_attachments_children(version, agentType, d, bAttachmentIsTransition);

                        this.Attach(pAttachment, bIsPrecondition, bIsEffector, bAttachmentIsTransition);

                        this.m_bHasEvents |= (pAttachment is Event);
                    }
                }

                d.CloseDocument(false);

                type = d.ReadType();
            }

            if (type != BsonDeserizer.BsonTypes.BT_None)
            {
                if (type == BsonDeserizer.BsonTypes.BT_ParsElement)
                {
                    this.load_pars(version, agentType, d);
                }
                else if (type == BsonDeserizer.BsonTypes.BT_AttachmentsElement)
                {
                    this.load_attachments(version, agentType, d, bIsTransition);

                    this.m_bHasEvents |= this.HasEvents();
                }
                else
                {
                    Debug.Check(false);
                }

                type = d.ReadType();
            }

            Debug.Check(type == BsonDeserizer.BsonTypes.BT_None);
            d.CloseDocument(false);
        }
Example #2
0
        public bool load_bson(byte[] pBuffer)
        {
            try
            {
                BsonDeserizer d = new BsonDeserizer();

                if (d.Init(pBuffer))
                {
                    BsonDeserizer.BsonTypes type = d.ReadType();

                    if (type == BsonDeserizer.BsonTypes.BT_BehaviorElement)
                    {
                        bool bOk = d.OpenDocument();
                        Debug.Check(bOk);

                        this.m_name = d.ReadString();
                        string agentType = d.ReadString().Replace("::", ".");
                        bool bFsm = d.ReadBool();
                        string versionStr = d.ReadString();
                        int version = Convert.ToInt32(versionStr);

                        if (version != SupportedVersion)
                        {
                            Debug.LogError(string.Format("'{0}' Version({1}), while Version({2}) is supported, please update runtime or rexport data using the latest designer", this.m_name, version, SupportedVersion));
                        }

                        this.SetClassNameString("BehaviorTree");
                        this.SetId(-1);

                        this.m_bIsFSM = bFsm;

                        this.load_properties_pars_attachments_children(version, agentType, d, false);

                        d.CloseDocument(false);

                        return true;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Check(false, e.Message);
            }

            Debug.Check(false);
            return false;
        }