EVERYTHING
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using BlockSpace.Voxels;
|
||||
using BlockSpace.Worlds;
|
||||
using Photon.Pun;
|
||||
using Photon.Realtime;
|
||||
using Photon.VR;
|
||||
using UnityEngine;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class NodePlayerTransformRpc : MonoBehaviourPun
|
||||
{
|
||||
public static NodePlayerTransformRpc Ensure()
|
||||
{
|
||||
NodePlayerTransformRpc nodePlayerTransformRpc = Object.FindAnyObjectByType<NodePlayerTransformRpc>();
|
||||
if (nodePlayerTransformRpc != null)
|
||||
{
|
||||
return nodePlayerTransformRpc;
|
||||
}
|
||||
GameObject gameObject = ((NodeGraphManager.Instance != null) ? NodeGraphManager.Instance.gameObject : null);
|
||||
if (gameObject == null || gameObject.GetComponent<PhotonView>() == null)
|
||||
{
|
||||
VoxelGroupPhotonSync voxelGroupPhotonSync = Object.FindAnyObjectByType<VoxelGroupPhotonSync>();
|
||||
if (voxelGroupPhotonSync != null)
|
||||
{
|
||||
gameObject = voxelGroupPhotonSync.gameObject;
|
||||
}
|
||||
}
|
||||
if (gameObject == null)
|
||||
{
|
||||
gameObject = ((PhotonVRManager.Manager != null) ? PhotonVRManager.Manager.gameObject : null);
|
||||
}
|
||||
if (gameObject == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return gameObject.GetComponent<NodePlayerTransformRpc>() ?? gameObject.AddComponent<NodePlayerTransformRpc>();
|
||||
}
|
||||
|
||||
public bool TryMovePlayer(int playerId, Vector3 position)
|
||||
{
|
||||
if (playerId <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (NodePlayerUtility.IsLocalPlayerId(playerId))
|
||||
{
|
||||
return PlayerTeleportUtil.TryTeleportLocalPlayer(position);
|
||||
}
|
||||
if (!PhotonNetwork.InRoom || base.photonView == null || base.photonView.ViewID == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Player player = PhotonNetwork.CurrentRoom?.GetPlayer(playerId);
|
||||
if (player == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
base.photonView.RPC("RPC_MoveLocalPlayer", player, position.x, position.y, position.z);
|
||||
return true;
|
||||
}
|
||||
|
||||
[PunRPC]
|
||||
private void RPC_MoveLocalPlayer(float x, float y, float z)
|
||||
{
|
||||
PlayerTeleportUtil.TryTeleportLocalPlayer(new Vector3(x, y, z));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user