Example #1
0
 void Awake()
 {
     generator           = new ChunkGenerator(new QuadMapper(), function);
     gameObjectGenerator = new GameObjectGenerator(new PlaneMeshGenerator(scale), this.transform, material);
     map        = new Map(grid, 20, generator, gameObjectGenerator);
     map.player = player;
 }
Example #2
0
 public Map(int grid, int viewDistance, IChunkGenerator generator, GameObjectGenerator gameObjectGenerator)
 {
     Chunks              = new Dictionary <Vector2, Chunk> ();
     Grid                = grid;
     ViewDistance        = viewDistance;
     Generator           = generator;
     GameObjectGenerator = gameObjectGenerator;
 }
Example #3
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 #4
0
 /// <summary>
 /// Register a prototype from a function to generate a GameObject.
 /// </summary>
 /// <param name="generator">A function to return a new GameObject instance.</param>
 /// <param name="name">Name from prototype.</param>
 public void Register(GameObjectGenerator generator, string name)
 {
     _prototypes[name] = generator;
 }