/// <summary> /// Raises an event with the player's position data. /// "isSendReliable" decides if these events are reliable or unreliable. /// "Game.RaiseEncrypted" decided if the event is encrypted. /// /// Once more: Neither sending reliable nor encrypting this event makes sense in a game. /// Both is just done as showcase! /// </summary> /// <remarks> /// Each running client will know many players, but only one is the "local" one, which /// actually sends it's position! See Game.SendPostion(), which choses the local player only. /// </remarks> /// <param name="peer"></param> internal void SendEvMove(LitePeer peer) { if (peer == null) { return; } // prepare the event data we want to send // this could contain more key-values as needed by a game (think: rotation, y-coordinate) Hashtable eventContent = new Hashtable(); eventContent.Add((byte)DemoEventKey.PlayerPositionX, (byte)this.posX); eventContent.Add((byte)DemoEventKey.PlayerPositionY, (byte)this.posY); // if encryption is turned off, we simply use OpRaiseEvent peer.OpRaiseEvent((byte)DemoEventCode.PlayerMove, eventContent, isSendReliable, (byte)0); }
/// <summary> /// This method puts the "player info" into a Hashtable (a serializable Datatype for Photon) /// and calls LitePeer.OpRaiseEvent() to make the server send an event to others in the room. /// </summary> /// <remarks>The event we send here is handled by each client's Game.OnEvent().</remarks> /// <param name="peer"></param> internal void SendPlayerInfo(LitePeer peer) { if (peer == null) { return; } // Setting up the content of the event. Here we want to send a player's info: name and color. Hashtable evInfo = new Hashtable(); evInfo.Add((byte)DemoEventKey.PlayerName, this.name); evInfo.Add((byte)DemoEventKey.PlayerColor, this.color); // The event's code must be of type byte, so we have to cast it. We do this above as well, to get routine ;) peer.OpRaiseEvent((byte)DemoEventCode.PlayerInfo, evInfo, true); }
/// <summary> /// Called by Unity on start. We create and connect a new LiteLobbyPeer. /// This makes the PhotonClient relatively autonomous. /// </summary> public virtual void Start() { this.Peer = new LitePeer(this); this.Connect(); }