Ejemplo n.º 1
0
        private void SpawnModel(Transform parent)
        {
            var model = ItemPool.Spawn(_modelName);

            if (parent != null)
            {
                model.transform.SetParentResetPos(parent);
            }
            _loadedModel = model.GetComponent <IModelComponent>();
            if (_loadedModel == null)
            {
                ItemPool.Despawn(model.gameObject);
                return;
            }
            var entity = this.GetEntity();

            MonoBehaviourToEntity.RegisterToEntity(model.gameObject, entity);
            _loadedComponents.Add(entity.Add(new ModelComponent(_loadedModel)));
            entity.Tr = model.Transform;
            _loadedComponents.Add(entity.Add(new FloatingTextStatusComponent(model.Transform, new Vector3(0, 1.5f, 0))));
            var animTr = model.GetComponent <IAnimTr>();

            if (animTr != null)
            {
                _loadedComponents.Add(entity.Add(new AnimTr(animTr.AnimTr)));
            }
            var rb = model.GetComponent <Rigidbody>();

            if (rb != null)
            {
                _loadedComponents.Add(entity.Add(new RigidbodyComponent(rb)));
            }
        }
Ejemplo n.º 2
0
        public Entity SpawnProjectile(Entity owner)
        {
            var spawnComponent = owner.Get <ActionSpawnComponent>();
            var entity         = GetProjectile(spawnComponent.Data);

            entity.Get <DespawnTimer>().StartTimer();
            if (string.IsNullOrEmpty(spawnComponent.Prefab))
            {
                return(entity);
            }
            owner.FindSpawn(out var spawnPos, out var spawnRot);
            var spawn = ItemPool.Spawn(UnityDirs.Projectiles, spawnComponent.Prefab, spawnPos, spawnRot);

            if (spawn == null)
            {
                return(entity);
            }
            entity.Tr = spawn.Transform;
            entity.Add(new RigidbodyComponent(spawn.GetComponent <Rigidbody>()));
            entity.Get <ModelComponent>().Model = spawn.GetComponent <IModelComponent>();
            MonoBehaviourToEntity.RegisterToEntity(spawn.gameObject, entity);
            entity.ParentId = owner.Id;
            return(entity);
        }