Created
May 7, 2014 10:45
-
-
Save DarkLotus/e94774da97dafb459094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Photon; | |
| using System; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class InteractiveDiceObject : SimpleInteractiveObject | |
| { | |
| private int m_diceValue; | |
| public InteractiveDiceObject() | |
| { | |
| } | |
| [RPC] | |
| public void NetworkDiceEmote(int result) | |
| { | |
| this.Emote(result); | |
| } | |
| [RPC] | |
| public void NetworkRoll(int RollingPlayerID) | |
| { | |
| //Debug.Log("Rolling for Player ID: " + RollingPlayerID); | |
| var result = this.Roll(); | |
| base.RPC("NetworkDiceEmote", PhotonPlayer.Find(RollingPlayerID), result); | |
| } | |
| private void Emote(int result) | |
| { | |
| //Dont think these are exactly right | |
| GameContext.localPlayer.photonView.RPC("SendChatMessage", PhotonTargets.All, new object[] { "Rolled a " + result, (int)UIConversation.ChatType.Local, PhotonNetwork.playerName }); | |
| MonoSingleton<GameManager>.Instance.ConversationUI.AddToChatLog("Rolled a " + result, UIConversation.ChatType.Local, PhotonNetwork.playerName); | |
| } | |
| private int Roll() | |
| { | |
| m_diceValue = UnityEngine.Random.Range(1, 6); | |
| return m_diceValue; | |
| } | |
| public override bool CanInteract(GameEntity source) | |
| { | |
| return true; | |
| } | |
| public override void OnInteract() | |
| { | |
| if (!base.isMine) | |
| base.RPC("NetworkRoll", PhotonTargets.MasterClient, GameContext.localPlayer.PlayerID); | |
| else | |
| this.Emote(this.Roll()); | |
| } | |
| private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) | |
| { | |
| var value = this.m_diceValue; | |
| stream.Serialize(ref value); | |
| if (stream.isReading) | |
| { | |
| this.m_diceValue = value; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment