using System; using System.Collections.Generic; using BlockSpace.Voxels; using Photon.Pun; using TMPro; using UnityEngine; namespace Photon.VR.Player { public class PhotonVRPlayer : MonoBehaviourPun { [Serializable] public class CosmeticSlot { public string SlotName; public Transform Object; } [Header("Objects")] public Transform Head; public Transform Body; public Transform LeftHand; public Transform RightHand; [Tooltip("The objects that will get the colour of the player applied to them")] public List ColourObjects; [Space] [Tooltip("Feel free to add as many slots as you feel necessary")] public List CosmeticSlots = new List(); [Header("Other")] public TextMeshPro NameText; public bool HideLocalPlayer = true; private void Awake() { PhotonVoxelAvatar photonVoxelAvatar = GetComponent(); if (photonVoxelAvatar == null) { photonVoxelAvatar = base.gameObject.AddComponent(); } photonVoxelAvatar.Configure(Head, LeftHand, RightHand); PhotonVRPlayerName componentInChildren = GetComponentInChildren(includeInactive: true); if (componentInChildren != null) { componentInChildren.Head = Head; } PhotonVRPlayerBody componentInChildren2 = GetComponentInChildren(includeInactive: true); if (componentInChildren2 != null) { componentInChildren2.Head = Head; } if (base.photonView.IsMine) { PhotonVRManager.Manager.LocalPlayer = this; if (HideLocalPlayer) { Head.gameObject.SetActive(value: false); Body.gameObject.SetActive(value: false); RightHand.gameObject.SetActive(value: false); LeftHand.gameObject.SetActive(value: false); NameText.gameObject.SetActive(value: false); } } UnityEngine.Object.DontDestroyOnLoad(base.gameObject); _RefreshPlayerValues(); } private void Update() { if (base.photonView.IsMine) { Head.transform.position = PhotonVRManager.Manager.Head.transform.position; Head.transform.rotation = PhotonVRManager.Manager.Head.transform.rotation; RightHand.transform.position = PhotonVRManager.Manager.RightHand.transform.position; RightHand.transform.rotation = PhotonVRManager.Manager.RightHand.transform.rotation; LeftHand.transform.position = PhotonVRManager.Manager.LeftHand.transform.position; LeftHand.transform.rotation = PhotonVRManager.Manager.LeftHand.transform.rotation; } } public void RefreshPlayerValues() { base.photonView.RPC("RPCRefreshPlayerValues", RpcTarget.All); } [PunRPC] private void RPCRefreshPlayerValues() { _RefreshPlayerValues(); } private void _RefreshPlayerValues() { if (NameText != null) { NameText.text = base.photonView.Owner.NickName; } foreach (MeshRenderer colourObject in ColourObjects) { if (colourObject != null) { colourObject.material.color = JsonUtility.FromJson((string)base.photonView.Owner.CustomProperties["Colour"]); } } foreach (KeyValuePair item in (Dictionary)base.photonView.Owner.CustomProperties["Cosmetics"]) { Debug.Log(item.Key); foreach (CosmeticSlot cosmeticSlot in CosmeticSlots) { if (!(cosmeticSlot.SlotName == item.Key)) { continue; } foreach (Transform item2 in cosmeticSlot.Object) { if (item2.name != item.Value) { item2.gameObject.SetActive(value: false); } else { item2.gameObject.SetActive(value: true); } } } } } } }