Files
BlockSpace-v1.5.0b/Assets/Scripts/Assembly-CSharp/Photon/VR/Player/PhotonVRPlayer.cs
T
2026-06-01 17:19:55 +02:00

137 lines
3.6 KiB
C#

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<MeshRenderer> ColourObjects;
[Space]
[Tooltip("Feel free to add as many slots as you feel necessary")]
public List<CosmeticSlot> CosmeticSlots = new List<CosmeticSlot>();
[Header("Other")]
public TextMeshPro NameText;
public bool HideLocalPlayer = true;
private void Awake()
{
PhotonVoxelAvatar photonVoxelAvatar = GetComponent<PhotonVoxelAvatar>();
if (photonVoxelAvatar == null)
{
photonVoxelAvatar = base.gameObject.AddComponent<PhotonVoxelAvatar>();
}
photonVoxelAvatar.Configure(Head, LeftHand, RightHand);
PhotonVRPlayerName componentInChildren = GetComponentInChildren<PhotonVRPlayerName>(includeInactive: true);
if (componentInChildren != null)
{
componentInChildren.Head = Head;
}
PhotonVRPlayerBody componentInChildren2 = GetComponentInChildren<PhotonVRPlayerBody>(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<Color>((string)base.photonView.Owner.CustomProperties["Colour"]);
}
}
foreach (KeyValuePair<string, string> item in (Dictionary<string, string>)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);
}
}
}
}
}
}
}