Example #1
0
        /// <summary>
        /// Spawn a prototype instance.
        /// Note: parent of new GameObject will be null.
        /// </summary>
        /// <param name="name">Prototype identifier.</param>
        /// <returns>New GameObject instance, built from prototype.</returns>
        public ECS.GameObject Spawn(string name)
        {
            // get prototype from dictionary
            object prototype = _prototypes[name];

            // try to use as a gameobject
            ECS.GameObject asGameObject = prototype as ECS.GameObject;
            if (asGameObject != null)
            {
                return(asGameObject.Clone());
            }
            // if not a game object, use as a function
            else
            {
                GameObjectGenerator func = prototype as GameObjectGenerator;
                return(func());
            }
        }
Example #2
0
 /// <summary>
 /// Register a prototype from a GameObject instance.
 /// </summary>
 /// <param name="gameObject">GameObject to register as a prototype (note: instance will not be affected, it will be cloned).</param>
 /// <param name="name">Name from prototype. If not defined, will use GameObject name.</param>
 public void Register(ECS.GameObject gameObject, string name = null)
 {
     _prototypes[name ?? gameObject.Name ?? "untitled"] = gameObject.Clone(name, false);
 }