private void SpawnPlayerCharacter(SpawnCharacterCommand command) { Entity entity = World.EntityManager.CreateEntity(playerArchtype); int id; bool isLoadingPlayer = false; if (command.characterID != 0) { id = command.characterID; isLoadingPlayer = true; } else { id = Bootstrap.GenerateUniqueID(); } if (SetCharacter(entity, id, isLoadingPlayer, command.world, command.metaID, command.classID, command.clanID, command.position)) { SetPlayerCharacter(entity, id, command.world, command.metaID, command.position); cameraSystem.ConnectCameraToCharacter(command.camera, entity); playerSpawnSystem.SetPlayerCharacter(entity, command.playerID); if (isLoadingPlayer) { saveSystem.LoadPlayer(entity); } Entity gameEntity = command.game; var game = World.EntityManager.GetComponentData <Game>(gameEntity); game.AddPlayerCharacter(id); World.EntityManager.SetComponentData(gameEntity, game); worldSpawnSystem.OnAddedStreamer(entity, command.world); } }
private void SpawnNPCCharacter(SpawnCharacterCommand command) { Entity entity = World.EntityManager.CreateEntity(npcArchtype); int id = Bootstrap.GenerateUniqueID(); SetCharacter(entity, id, false, command.world, command.metaID, command.classID, command.clanID, command.position); SetNPCCharacter(entity, id, command.metaID, command.position); }
private void SpawnNPCCharacters(SpawnCharacterCommand command) { NativeArray <Entity> entities = new NativeArray <Entity>(command.amount, Allocator.Temp); World.EntityManager.Instantiate(npcPrefab, entities); for (int i = 0; i < command.amount; i++) { Entity entity = entities[i]; SetCharacter(entity, command.characterIDs[i], false, command.world, command.metaID, command.classID, command.clanID, command.position, command.creatorID); SetNPCCharacter(entity, command.characterIDs[i], command.metaID, command.position); // command.world, } }
public static int[] SpawnNPCs(EntityManager EntityManager, Entity world, int metaID, int clanID, float3 position, int amount) { SpawnCharacterCommand command = new SpawnCharacterCommand { world = world, metaID = metaID, position = position, amount = amount, clanID = clanID, characterIDs = new BlitableArray <int>(amount, Allocator.Persistent) }; for (int i = 0; i < amount; i++) { command.characterIDs[i] = (Bootstrap.GenerateUniqueID()); } Entity e = EntityManager.CreateEntity(); EntityManager.AddComponentData(e, command); return(command.characterIDs.ToArray()); }
/// <summary> /// 按照刷新表动态刷新场景活动单元 /// </summary> void RefreshCharacter() { while (true) { int refreshID = 100000 + ((int)mStageSystem.sceneID) * 10000 + mStageSystem.refreshIndex; CharacterRefreshPO characterRefreshPO = CharacterRefreshData.Instance.GetCharacterRefreshPO(refreshID); if (characterRefreshPO == null) { break; } if (characterRefreshPO.Stage != mLv) { break; } if (characterRefreshPO.AppeareTime > mStageTimer) { return; } CharacterBaseAttr baseAttr = FactoryManager.attrFactory.GetCharacterBaseAttr(characterRefreshPO.CharacterID); if (characterRefreshPO.Loop == 1) { LoopRefresh lr = new LoopRefresh(characterRefreshPO.CharacterID, baseAttr.name, baseAttr.characterType, characterRefreshPO); mLoopList.Add(lr); ++mStageSystem.refreshIndex; continue; } E_CharacterType characterType = baseAttr.characterType; switch (characterType) { case E_CharacterType.Player: ISpawnCommand command = new SpawnCharacterCommand(baseAttr.id, characterRefreshPO); mCommands.Add(command); break; case E_CharacterType.Map: command = new SpawnMapCommand(baseAttr.id, characterRefreshPO); mCommands.Add(command); break; case E_CharacterType.Citizen0: case E_CharacterType.Citizen1: case E_CharacterType.Citizen2: command = new SpawnCitizenCommand(baseAttr.id, characterRefreshPO); mCommands.Add(command); break; case E_CharacterType.Npc: for (int i = 0; i < characterRefreshPO.StepCount; ++i) { command = new SpawnNpcCommand(baseAttr.id, characterRefreshPO); mCommands.Add(command); } break; case E_CharacterType.SandBox: case E_CharacterType.Bucket: command = new SpawnPropCommand(baseAttr.id, characterRefreshPO, Vector3.zero); mCommands.Add(command); break; case E_CharacterType.BullDemonKing: command = new SpawnBullDemonKingCommand(baseAttr.id, characterRefreshPO); mCommands.Add(command); break; case E_CharacterType.AngerBear: command = new SpawnBearCommand(baseAttr.id, characterRefreshPO); mCommands.Add(command); break; case E_CharacterType.Wolf: command = new SpawnWolfCommand(baseAttr.id, characterRefreshPO); mCommands.Add(command); break; } ++mStageSystem.refreshIndex; } }