Example #1
0
        public GameObject CreateGameObjectFromContainer(ObjectGenerationContainer ogc)
        {
            if (ogc.IsEntity)
            {
                var ent = engine.CreateEntity(ogc.EntityToGenerate);
                return(ent.Wrapper.gameObject);
            }

            GameObject go = Resources.Load <GameObject>(ogc.PrefabToGenerate);

            if (ogc.ShouldPool)
            {
                return(go.InstantiateFromPool());
            }
            return(UnityEngine.Object.Instantiate(go));
        }
Example #2
0
        void CreateNewObject(ObjectGenerationContainer ogc, Transform parentObj = null)
        {
            if (ogc.numberToSpawn <= 0)
            {
                return;
            }

            for (int i = 0; i < ogc.numberToSpawn; i++)
            {
                do
                {
                    pos.Set(srng.Next(sectorMin, sectorMax), srng.Next(-sg.sectorHeight / 2, sg.sectorHeight / 2), srng.Next(sectorMin, sectorMax));
                } while (arrayObjs[(int)pos.x + sectorMax, (int)pos.y + sectorMax] == 1);
                arrayObjs[(int)pos.x + sectorMax, (int)pos.y + sectorMax] = 1;

                current = CreateGameObjectFromContainer(ogc);
                current.transform.position = pos;

                if (parentObj != null)
                {
                    current.transform.parent = parentObj.transform;
                }
            }
        }