示例#1
0
        public static void SetPlayerToRole(PhotonServer photonServer, GameState gameState, int actorNumber, PlayerRole newRole)
        {
            var photonPlayer = photonServer.CurrentRoom.Players[actorNumber];

            _hashtable.Clear();
            _hashtable[RoomDataConstants.PlayerRole] = (byte)newRole;
            photonPlayer.SetCustomProperties(_hashtable);
            gameState.Roles[actorNumber] = newRole;
            UnityEngine.Debug.Log($"Assign player {actorNumber} to {newRole}");

            _hashtable.Clear();
            _hashtable[RoomDataConstants.PlayerRole] = gameState.Roles.Serialize();
            photonServer.CurrentRoom.SetCustomProperties(_hashtable);
        }
示例#2
0
        void OnEnable()
        {
            _world              = new EcsWorld();
            _systems            = new EcsSystems(_world);
            _fixedUpdateSystems = new EcsSystems(_world);
            _lateUpdateSystems  = new EcsSystems(_world);
#if UNITY_EDITOR
            Leopotam.Ecs.UnityIntegration.EcsWorldObserver.Create(_world);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_systems);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_fixedUpdateSystems);
            Leopotam.Ecs.UnityIntegration.EcsSystemsObserver.Create(_lateUpdateSystems);
#endif
            var playerCache  = new PlayerCache();
            var photonServer = new PhotonServer();
            var gameState    = new GameState();

            var ship = SceneDescription.CreateShip(_world);
            gameState.ShipEntity = ship;

            SceneDescription.UI.MenuUI.gameObject.SetActive(true);

            _systems
            // Register your systems here, for example:
            .Add(SceneDescription.UI.MenuUI)
            .Add(SceneDescription.Radar)
            .Add(new ConnectToPhotonSystem())
            .Add(new ServerSystem())
            .Add(new LocalPlayerSystem())
            .Add(new UpdateShipPositionSystem())
            .Add(new ShowRolesSystem())
            .Add(new MakeMasterSystem())
            .Add(new CallForChangeRoleSystem())
            .Add(new ControlShootSystem())
            .Add(new UpdateHealthSystem())
            .Add(new SpawnAsteroidsSystem())
            .Add(new ChangeRoleSystem())
            .Add(new UpdateCannonDirectionSystem())
            .Add(new SpawnWeaponRaysSystem())
            .Add(new KillAsteroidSystem())
            .Add(new AsteroidMoveSystem())
            .Add(new LerpPositionSystem())
            .Add(new LerpRotationSystem())
            .Add(new ShootSystem())
            .Add(new DestroyTransformSystem())
            .Inject(GameConfig)
            .Inject(SceneDescription)
            .Inject(playerCache)
            .Inject(photonServer)
            .Inject(gameState)
            .Inject(SoundManager)
            .Initialize();

            _fixedUpdateSystems
            .Add(new ControlShipSystem())
            .Inject(GameConfig)
            .Inject(SceneDescription)
            .Inject(playerCache)
            .Inject(photonServer)
            .Inject(gameState)
            .Inject(SoundManager)
            .Initialize();

            _lateUpdateSystems
            .Add(new SyncShipPosition())
            .Add(new SyncRigidbodyPositionToShipSystem())
            .Inject(GameConfig)
            .Inject(SceneDescription)
            .Inject(playerCache)
            .Inject(photonServer)
            .Inject(gameState)
            .Inject(SoundManager)
            .Initialize();
        }