Ejemplo n.º 1
0
        private void Spawn(SpawnEntity spawnEntity)
        {
            EntityPrefab prefab = null;
            //if (!string.IsNullOrEmpty(spawnEntity.PrefabName))
            //{
            //    var prefabItem = EntityPrefabs.Components.FirstOrDefault(p => p.Name == spawnEntity.PrefabName);
            //    if (prefabItem != null)
            //    {
            //        prefab = prefabItem;
            //    }
            //} else
            if (!string.IsNullOrEmpty(spawnEntity.PoolName))
            {
                var pool = Pools.FirstOrDefault(p => p.Name == spawnEntity.PoolName);
                if (pool == null) throw new Exception(string.Format("Pool {0} not found.", spawnEntity.PoolName));
                prefab = pool.GetComponents<EntityPrefab>().FirstOrDefault(p => p.Name == spawnEntity.PrefabName);
                if (prefab == null)
                {
                    prefab = pool.GetComponents<EntityPrefab>().FirstOrDefault();
                }
            }

            if (prefab == null) return;
            var result = Instantiate(prefab.Prefab.gameObject, spawnEntity.Position,Quaternion.Euler(spawnEntity.Rotation)) as GameObject;
            if (result != null)
            {
                spawnEntity.Result = result.GetComponent<Entity>();
            }


        }
Ejemplo n.º 2
0
 public override void Execute()
 {
     var evt = new SpawnEntity()
     {
         PoolName = PoolName,
         PrefabName = PrefabName,
         Position = Position,
         Rotation = Rotation,
         Result = Result,
     };
     System.Publish(evt);
     Result = evt.Result;
 }
Ejemplo n.º 3
0
        public override void Execute()
        {
            var evt = new SpawnEntity()
            {
                PoolName   = PoolName,
                PrefabName = PrefabName,
                Position   = Position,
                Rotation   = Rotation,
                Result     = Result,
            };

            System.Publish(evt);
            Result = evt.Result;
        }
Ejemplo n.º 4
0
        private void Spawn(SpawnEntity spawnEntity)
        {
            EntityPrefab prefab = null;

            //if (!string.IsNullOrEmpty(spawnEntity.PrefabName))
            //{
            //    var prefabItem = EntityPrefabs.Components.FirstOrDefault(p => p.Name == spawnEntity.PrefabName);
            //    if (prefabItem != null)
            //    {
            //        prefab = prefabItem;
            //    }
            //} else
            if (!string.IsNullOrEmpty(spawnEntity.PoolName))
            {
                var pool = Pools.FirstOrDefault(p => p.Name == spawnEntity.PoolName);
                if (pool == null)
                {
                    throw new Exception(string.Format("Pool {0} not found.", spawnEntity.PoolName));
                }
                prefab = pool.GetComponents <EntityPrefab>().FirstOrDefault(p => p.Name == spawnEntity.PrefabName);
                if (prefab == null)
                {
                    prefab = pool.GetComponents <EntityPrefab>().FirstOrDefault();
                }
            }

            if (prefab == null)
            {
                return;
            }
            var result = Instantiate(prefab.Prefab.gameObject, spawnEntity.Position, Quaternion.Euler(spawnEntity.Rotation)) as GameObject;

            if (result != null)
            {
                spawnEntity.Result = result.GetComponent <Entity>();
            }
        }