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; }
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 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; }