Esempio n. 1
0
        public void Build(EnemySpawnData enemySpawnData, ref EnemyAttackStruct enemyAttackstruct)
        {
            // Find a random index between zero and one less than the number of spawn points.
            int spawnPointIndex = UnityEngine.Random.Range(0, enemySpawnData.spawnPoints.Length);
            // Create an instance of the enemy prefab at the randomly selected spawn point position and rotation.
            var go           = _gameobjectFactory.Build(enemySpawnData.enemyPrefab);
            var implementors = go.GetComponentsInChildren <IImplementor>();

            var initializer = _entityFactory.BuildEntity <EnemyEntityDescriptor>(go.GetInstanceID(),
                                                                                 implementors);

            var playerTargetTypeEntityStruct = new PlayerTargetTypeEntityStruct {
                targetType = enemySpawnData.targetType
            };
            var healthEntityStruct = new HealthEntityStruct {
                currentHealth = 100
            };

            initializer.Init(enemyAttackstruct);
            initializer.Init(healthEntityStruct);
            initializer.Init(playerTargetTypeEntityStruct);

            var transform = go.transform;
            var spawnInfo = enemySpawnData.spawnPoints[spawnPointIndex];

            transform.position = spawnInfo.position;
            transform.rotation = spawnInfo.rotation;
        }
Esempio n. 2
0
        public void Build(EnemySpawnData enemySpawnData, ref EnemyAttackStruct enemyAttackstruct)
        {
            // Find a random index between zero and one less than the number of spawn points.
            int spawnPointIndex = UnityEngine.Random.Range(0, enemySpawnData.spawnPoints.Length);
            // Create an instance of the enemy prefab at the randomly selected spawn point position and rotation.
            var go           = _gameobjectFactory.Build(enemySpawnData.enemyPrefab);
            var implementors = go.GetComponentsInChildren <IImplementor>();
            //using the GameObject GetInstanceID() will help to directly use the result of Unity functions
            //to index the entity in the Svelto database
            var initializer = _entityFactory.BuildEntity <EnemyEntityDescriptor>(new EGID(go.GetInstanceID(), ECSGroups.ActiveEnemies),
                                                                                 implementors);

            initializer.Init(enemyAttackstruct);
            initializer.Init(new HealthEntityStruct {
                currentHealth = 100
            });
            initializer.Init(new ScoreValueEntityStruct {
                scoreValue = (int)(enemySpawnData.targetType + 1) * 10
            });
            initializer.Init(new EnemyEntityStruct {
                enemyType = enemySpawnData.targetType
            });

            var transform = go.transform;
            var spawnInfo = enemySpawnData.spawnPoints[spawnPointIndex];

            transform.position = spawnInfo.position;
            transform.rotation = spawnInfo.rotation;
        }
        public JSonEnemySpawnData(EnemySpawnData spawnData)
        {
            enemyPrefab = spawnData.enemyPrefab;
            spawnPoints = new SpawningStruct[spawnData.spawnPoints.Length];

            for (int i = 0; i < spawnPoints.Length; i++)
            {
                spawnPoints[i].position = spawnData.spawnPoints[i].position;
                spawnPoints[i].rotation = spawnData.spawnPoints[i].rotation;
            }

            spawnTime = spawnData.spawnTime;
            timeLeft  = spawnTime;
        }
Esempio n. 4
0
        public IEnumerator Build(EnemySpawnData enemySpawnData, EnemyAttackComponent EnemyAttackComponent)
        {
            var build = _gameobjectFactory.Build(enemySpawnData.enemyPrefab, false);

            while (build.MoveNext())
            {
                yield return(null);
            }

            GameObject enemyGO = build.Current;

            //implementors are ONLY necessary if you need to wrap objects around entity view structs. In the case
            //of Unity, they are needed to wrap Monobehaviours and not used in any other case

            List <IImplementor> implementors = new List <IImplementor>();

            enemyGO.GetComponentsInChildren(implementors);
            implementors.Add(enemyGO.AddComponent <EGIDHolderImplementor>());

            //using the GameObject GetInstanceID() as entityID would help to directly use the result of Unity functions
            //to index the entity in the Svelto database. However I want in this demo how to not rely on it.
            var initializer =
                _entityFactory.BuildEntity <EnemyEntityDescriptor>(new EGID(_enemiesCreated++, ECSGroups.EnemiesGroup)
                                                                   , implementors);

            //Initialize the pure EntityStructs. This should be the preferred pattern, there is much less boiler plate
            //too
            initializer.Init(EnemyAttackComponent);
            initializer.Init(new HealthComponent
            {
                currentHealth = 100
            });
            initializer.Init(new ScoreValueComponent
            {
                scoreValue = (int)(enemySpawnData.targetType + 1) * 10
            });
            initializer.Init(new EnemyComponent
            {
                enemyType = enemySpawnData.targetType
            });

            var transform  = enemyGO.transform;
            var spawnPoint = enemySpawnData.spawnPoint;

            enemyGO.SetActive(true);
            transform.position = spawnPoint;
        }
        public IEnumerator Build(EnemySpawnData enemySpawnData, EnemyAttackStruct enemyAttackstruct)
        {
            var enumerator = _gameobjectFactory.Build(enemySpawnData.enemyPrefab);

            yield return(enumerator);

            GameObject enemyGO = enumerator.Current;

            //implementors are ONLY necessary if you need to wrap objects around entity view structs. In the case
            //of Unity, they are needed to wrap Monobehaviours and not used in any other case

            var implementors = enemyGO.GetComponentsInChildren <IImplementor>();

            //using the GameObject GetInstanceID() as entityID will help to directly use the result of Unity functions
            //to index the entity in the Svelto database.
            var initializer = _entityFactory
                              .BuildEntity <EnemyEntityDescriptor>(new EGID((uint)enemyGO.GetInstanceID(), ECSGroups.ActiveEnemies),
                                                                   implementors);

            //Initialize the pure EntityStructs. This should be the preferred pattern, there is much less boiler plate
            //too
            initializer.Init(enemyAttackstruct);
            initializer.Init(new HealthEntityStruct {
                currentHealth = 100
            });
            initializer.Init(new ScoreValueEntityStruct {
                scoreValue = (int)(enemySpawnData.targetType + 1) * 10
            });
            initializer.Init(new EnemyEntityStruct {
                enemyType = enemySpawnData.targetType
            });
            initializer.Init(new EnemySinkStruct {
                sinkAnimSpeed = 2.5f
            });

            var transform = enemyGO.transform;
            var spawnInfo = enemySpawnData.spawnPoint;

            transform.position = spawnInfo;
        }
 public JSonEnemySpawnData(EnemySpawnData spawnData)
 {
     enemySpawnData = spawnData;
 }