Exemple #1
0
        private void OnSpawnPlayer(ResponseHandle <PlayerLifeCycle.Commands.SpawnPlayer, SpawnPlayerRequest, SpawnPlayerResponse> responseHandle)
        {
            if (playerEntityIds.ContainsKey(responseHandle.CallerInfo.CallerWorkerId))
            {
                responseHandle.Respond(new SpawnPlayerResponse(playerEntityIds[responseHandle.CallerInfo.CallerWorkerId]));
                return;
            }
            var assignedTeamId  = (nextAvailableTeamId++) % (uint)SimulationSettings.TeamCount;
            var spawningOffset  = new Vector3(Random.value - 0.5f, 0f, Random.value - 0.5f) * SimulationSettings.PlayerSpawnOffsetFactor;
            var hqPos           = SimulationSettings.TeamHQLocations[assignedTeamId].ToVector3();
            var initialPosition = hqPos + spawningOffset;

            var playerEntityTemplate = EntityTemplateFactory.CreatePlayerEntityTemplate(responseHandle.CallerInfo.CallerWorkerId, initialPosition.ToCoordinates(), assignedTeamId);

            SpatialOS.Commands.CreateEntity(playerLifeCycle, SimulationSettings.PlayerPrefabName, playerEntityTemplate, response => OnPlayerCreation(responseHandle, response));
        }