Beispiel #1
0
        /// <summary>
        /// Loads the entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="name">Name.</param>
        static public ZEntity LoadEntity(string name, int ID, string strData)
        {
            //create the entity
            ZEntity newEntity = new ZEntity();

            newEntity.Name = name;
            newEntity.ID   = ID;
            if (strData != null)
            {
                StringReader sr = new StringReader(strData);

                string sl = "";

                sl = sr.ReadLine();
                //newEntity.ID = Convert.ToInt32(sl);
                //read type
                sl = sr.ReadLine();
                newEntity.EType = (EntityType)Enum.Parse(typeof(EntityType), sl);

                while (sl != null)
                {
                    sl = sr.ReadLine();
                    if (sl != null && sl.CompareTo(ComponentPrefix) == 0)
                    {
                        var c = LoadAComponent(sr);
                        if (c != null)
                        {
                            newEntity.AddComponent(c);
                        }
                    }
                }
                sr.Close();
            }
            return(newEntity);
        }
Beispiel #2
0
        /// <summary>
        /// Adds the component.
        /// </summary>
        /// <returns>The component.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public T AddComponent <T>() where T : IZComponent
        {
            T a = (T)Activator.CreateInstance(typeof(T));

            entity.AddComponent(a);
            return(a);
        }
Beispiel #3
0
        /// <summary>
        /// Clone this instance.
        /// </summary>
        public ZEntity Clone()
        {
            ZEntity newEntity = new ZEntity();

            newEntity.Name = Name;
            newEntity.ID   = ID;

            foreach (var e in components)
            {
                var newCom = EntityPoolRuntimeBuildUtils.CloneObject(e);
                if (newCom != null)
                {
                    newEntity.AddComponent((IZComponent)newCom);
                }
            }

            return(newEntity);
        }