Esempio n. 1
0
        /// <summary>
        /// Implementation of a callback that's used by the Photon library to update the application / game of operation responses by server.
        /// </summary>
        /// <remarks>When you override this method, it's very important to call base.OnEvent to keep the state.</remarks>
        /// <param name="operationResponse">The response to some operation we called on the server.</param>
        public override void OnOperationResponse(Photon.OperationResponse operationResponse)
        {
            base.OnOperationResponse(operationResponse);  // important to call, to keep state up to date

            if (operationResponse.ReturnCode != ErrorCode.Ok)
            {
                //this.DebugReturn(DebugLevel.ERROR, operationResponse.ToStringFull() + " " + this.State);
            }

            // this demo connects when you call start and then it automatically executes a certain operation workflow to get you in a room
            switch (operationResponse.OperationCode)
            {
            case OperationCode.Authenticate:
                // Unlike before, the game-joining can now be triggered by the simpler OnStateChangeAction delegate: OnStateChanged(ClientState newState)
                break;

            case OperationCode.JoinRandomGame:
                // OpJoinRandomRoom is called above. the response to that is handled here
                // if the Master Server didn't find a room, simply create one. the result is handled below
                if (this.JoinRandomGame && operationResponse.ReturnCode != ErrorCode.Ok)
                {
                    this.CreateParticleDemoRoom(DemoConstants.MapType.Forest, 4);
                }
                break;

            case OperationCode.JoinGame:
            case OperationCode.CreateGame:
                // the master server will respond to join and create but this is handled in the base class
                if (this.State == ClientState.Joined)
                {
                    // no matter if we joined or created a game, when we arrived in state "Joined", we are on the game server in a room and
                    // this client could start moving and update others of it's color
                    this.LocalPlayer.RandomizePosition();
                    //this.loadBalancingPeer.OpRaiseEvent(DemoConstants.EvColor, this.LocalPlayer.WriteEvColor(), true, 0, null, EventCaching.AddToRoomCache);
                    this.LoadBalancingPeer.OpRaiseEvent(DemoConstants.EvColor, this.LocalPlayer.WriteEvColor(), new RaiseEventOptions()
                    {
                        CachingOption = EventCaching.AddToRoomCache
                    }, new SendOptions()
                    {
                        Reliability = this.SendReliable
                    });
                }
                break;
            }

            UpdateVisuals = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Implementation of a callback that's used by the Photon library to update the application / game of operation responses by server.
        /// </summary>
        /// <remarks>When you override this method, it's very important to call base.OnEvent to keep the state.</remarks>
        /// <param name="operationResponse">The response to some operation we called on the server.</param>
        public override void OnOperationResponse(Photon.OperationResponse operationResponse)
        {
            base.OnOperationResponse(operationResponse);  // important to call, to keep state up to date

            if (operationResponse.ReturnCode != ErrorCode.Ok)
            {
                //this.DebugReturn(DebugLevel.ERROR, operationResponse.ToStringFull() + " " + this.State);
            }

            // this demo connects when you call start and then it automatically executes a certain operation workflow to get you in a room
            switch (operationResponse.OperationCode)
            {
            case OperationCode.Authenticate:
                // authentication concludes connecting to the master server (it sends the appId and identifies your game)
                // when that's done, this demo asks the Master for any game. the result is handled below
                if (this.JoinRandomGame && this.State == ClientState.Authenticated)
                {
                    this.OpJoinRandomRoom(null, 0);
                }
                break;

            case OperationCode.JoinRandomGame:
                // OpJoinRandomRoom is called above. the response to that is handled here
                // if the Master Server didn't find a room, simply create one. the result is handled below
                if (this.JoinRandomGame && operationResponse.ReturnCode != ErrorCode.Ok)
                {
                    this.CreateParticleDemoRoom(DemoConstants.MapType.Forest, 4);
                }
                break;

            case OperationCode.JoinGame:
            case OperationCode.CreateGame:
                // the master server will respond to join and create but this is handled in the base class
                if (this.State == ClientState.Joined)
                {
                    // no matter if we joined or created a game, when we arrived in state "Joined", we are on the game server in a room and
                    // this client could start moving and update others of it's color
                    this.LocalPlayer.RandomizePosition();
                    this.loadBalancingPeer.OpRaiseEvent(DemoConstants.EvColor, this.LocalPlayer.WriteEvColor(), true, 0, null, EventCaching.AddToRoomCache);
                }
                break;
            }

            UpdateVisuals = true;
        }