Example #1
0
        public void LoadSpecificChunk(int index)
        {
            //Debug.Log(ExceptionUtils.GetCurrentMethod() + "(" + index + ")");
            var selectedChunk = chunks[index];

            var max    = ObjectPoolList.FarthestX(poolManager.ObjectPooler);
            var offset = new Vector3(max, 0);

            foreach (var piece in selectedChunk.Pieces)
            {
                // Figure out which pool to get the object from
                var name = piece.Prefab.name;
                var pool = poolManager.ObjectPooler.GetPoolByName(name);

                //Debug.Log(string.Format("{0} - max being set to {1}", ExceptionUtils.GetCurrentClass(this) + "." + ExceptionUtils.GetCurrentMethod(), max));

                // Now add in all objects required to fill out the chunk.
                // Also note that the objects will (should) be parented to
                // appropriate objects so it should just be a matter of applying the transforms
                foreach (var t in piece.Transforms)
                {
                    var instance = pool.GetObjectFromPool();
                    if (instance == null)
                    {
                        Debug.Log("Oh crap! We ran out of " + pool.objectToPool.name + "'s!");
                        return;
                    }
                    // Set the instanced game object's local transform
                    instance.transform.localPosition = (t.Position + offset);
                    instance.transform.localRotation = t.Rotation;
                    instance.transform.localScale    = t.Scale;
                    //Debug.Log(string.Format("Creating instance {0} at local position: {1}", instance.name, instance.transform.localPosition));
                }
            }
        }
Example #2
0
 public static float FarthestX(ObjectPoolList pooler)
 {
     return(pooler.ObjectPools.Min(pool => pool.FarthestX()));
 }