Example #1
0
        public virtual void Load(XmlElement element)
        {
            if (element == null)
            {
                Debug.LogError("XmlElement is null" + this.GetType().ToString());
            }

            for (int i = 0; i < element.Attributes.Count; i++)
            {
                XmlAttribute attr = element.Attributes[i];
                ReadAttribute(attr.Name, attr.Value);
            }

            XmlNode child = element.FirstChild;

            while (child != null)
            {
                Type classType = null;
                try
                {
                    classType = Type.GetType("BT." + child.Name, true);
                }
                catch (Exception)
                {
                    throw new Exception("XmlElement is null:" + this.GetType() + "." + child.Name);
                }

                if (classType == null)
                {
                    Debug.LogError("XmlElement is null:" + this.GetType() + "." + child.Name);
                    return;
                }

                BTNode node = Activator.CreateInstance(classType) as BTNode;
                if (node == null)
                {
                    Debug.LogError("Can no create node bt type:" + classType);
                    return;
                }

                node.Load(child as XmlElement);
                this.AddChild(node);
                child = child.NextSibling;
            }
        }
Example #2
0
        public virtual void Load(XmlElement xe)
        {
            //Util.Instance.Log("=======加载BT数据======");
            if (xe == null)
            {
                Debug.LogError("XmlElement is null" + this.GetType().ToString());
                return;
            }
            for (int i = 0; i < xe.Attributes.Count; i++)
            {
                XmlAttribute attr = xe.Attributes[i];
                this.ReadAttribute(attr.Name, attr.Value);
            }
            XmlNode child = xe.FirstChild;

            while (child != null)
            {
                Type classType = null;
                try
                {
                    classType = Type.GetType("BT." + child.Name, true);
                }
                catch
                {
                    Debug.LogError("XmlElement is null:" + this.GetType().ToString() + "." + child.Name);
                    break;
                }

                BTNode node = Activator.CreateInstance(classType) as BTNode;
                if (node == null)
                {
                    Debug.LogError(classType);
                    return;
                }
                node.Load(child as XmlElement);
                this.AddChild(node);
                child = child.NextSibling;
            }
        }