public T SpawnEntity <T>(CEntitySpawnParameters parameters = null) where T : CEntity, new() { if (LoadedLevel != null) { if (parameters == null) { parameters = new CEntitySpawnParameters(); } T newEntity = new T(); newEntity.Init(this, parameters.userData); newEntity.Id = ++m_entityIdCounter; newEntity.Name = typeof(T).Name.Substring(1) + m_entityIdCounter.ToString(); m_entityIdMap.Add(m_entityIdCounter, newEntity); LoadedLevel.AddEntity(newEntity); newEntity.SetWorldPosition(parameters.position); newEntity.SetWorldRotation(parameters.rotation); newEntity.SetWorldScale(parameters.scale); OnEntitySpawned?.Invoke(newEntity); return(newEntity); } return(default);
private NPCEntity SpawnNPC(TravellerInstance npc, PlanetController planet = null) { var planetToSpawnOn = planet != null ? planet : MissionPlanets[npc.HostPlanet]; var spawnedNpc = GameObject.Instantiate(npc.TravelerPrefab, planetToSpawnOn.SpawnPosition.position, Quaternion.identity); var npcController = spawnedNpc.GetComponent <NPCEntity>(); npcController.Initialize(planetToSpawnOn, MissionPlanets[npc.DestinationPlanet]); npcController.OnReachedDestination.AddListener(() => -- NpcsLeft); OnEntitySpawned?.Invoke(npcController); return(npcController); }
protected void OnSpawned() { OnEntitySpawned?.Invoke(this); }