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(); if (nodePlayerTransformRpc != null) { return nodePlayerTransformRpc; } GameObject gameObject = ((NodeGraphManager.Instance != null) ? NodeGraphManager.Instance.gameObject : null); if (gameObject == null || gameObject.GetComponent() == null) { VoxelGroupPhotonSync voxelGroupPhotonSync = Object.FindAnyObjectByType(); 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() ?? gameObject.AddComponent(); } 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)); } }