예제 #1
0
 //! Leaves the visited entity
 public virtual void Leave()
 {
     if(m_Target != null && m_Active)
     {
         m_Target = null;
         VisitorManager.Instance().RemoveVisitor(this);
     }
 }
예제 #2
0
        //! adds a child to the entity
        public virtual void AddChild(Entity child)
        {
            if(child.GetParent() != null)
            {
                child.GetParent().RemoveChild(child);
            }

            m_aChildren.Add(child);
            child.m_Parent = this;
        }
예제 #3
0
        //! recursive read from XML
        void ReadEntity(XmlTextReader xmlReader, Entity parent)
        {
            Entity entity = null;
            string entityTypeName = xmlReader.Name;

            if (parent != null)
            {
                // create entity
                string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
                string fullTypeName = assemblyName + "." + entityTypeName;
                entity = Assembly.GetExecutingAssembly().CreateInstance(fullTypeName) as Entity;
            }
            else
            {
                string thisTypeName = GetType().Name;
                Debug.Assert(thisTypeName == entityTypeName, "Trying to load an entity of type " + entityTypeName + " into an " + thisTypeName);
                entity = this;
            }

            // read children
            while(xmlReader.Read())
            {
                if(xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                else if(xmlReader.NodeType == XmlNodeType.Element)
                {
                    if (xmlReader.Name == "Properties")
                    {
                        // read properties
                        PropertyStream stream = new PropertyStream();
                        stream.ReadFromXML(xmlReader, null);
                        entity.Serialize(stream);
                    }
                    else
                    {
                        ReadEntity(xmlReader, entity);
                    }
                }
            } // end while

            if(parent != null)
            {
                // Add entity after it has been serialized to ensure proper event handling inside of AddChild()
                parent.AddChild(entity);
            }
        }
예제 #4
0
 //! removes a child from this entity
 public virtual void RemoveChild(Entity child)
 {
     m_aChildren.Remove(child);
     child.m_Parent = null;
 }
예제 #5
0
        //! Loads the entity and its hierarchy from an XML
        public void LoadFromXML(string strPath, Entity parent)
        {
            XmlTextReader xmlReader = new XmlTextReader("Content/" + strPath);

            while(xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                else if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    ReadEntity(xmlReader, parent);
                }
            }

            xmlReader.Close();
        }
예제 #6
0
        //! inserts a child into a specific index
        public virtual void InsertChild(Entity child, int index)
        {
            if (child.GetParent() != null)
            {
                child.GetParent().RemoveChild(child);
            }

            m_aChildren.Insert(index, child);
            child.m_Parent = this;
        }
예제 #7
0
 //! visits a particular entity
 public virtual void Visit(Entity target)
 {
     Debug.Assert(target != null, "Cannot Visit a NULL entity");
     m_Target = target;
     VisitorManager.Instance().StartVisitor(this);
 }