Skip to content

Instantly share code, notes, and snippets.

@DarkLotus
Created May 7, 2014 10:45
Show Gist options
  • Select an option

  • Save DarkLotus/e94774da97dafb459094 to your computer and use it in GitHub Desktop.

Select an option

Save DarkLotus/e94774da97dafb459094 to your computer and use it in GitHub Desktop.
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