EVERYTHING
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 536543be8a47fb88b3978fe43dc7b736
|
||||
timeCreated: 1780325055
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
externalObjects: {}
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.VR.Player
|
||||
{
|
||||
public class PhotonVRPlayerName : MonoBehaviour
|
||||
{
|
||||
[Tooltip("How high the text should be above the players head")]
|
||||
public float Offset = 0.17f;
|
||||
|
||||
public Transform Head;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
base.transform.position = Head.position + new Vector3(0f, Offset, 0f);
|
||||
Vector3 forward = PhotonVRManager.Manager.Head.position - base.transform.position;
|
||||
Quaternion b = new Quaternion(0f, Quaternion.LookRotation(forward).y, 0f, Quaternion.LookRotation(forward).w);
|
||||
base.transform.rotation = Quaternion.Slerp(base.transform.rotation, b, 10f * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 357a5da084861d127acd53e7204ed619
|
||||
timeCreated: 1780325055
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
externalObjects: {}
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using Photon.Pun;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.VR.Player
|
||||
{
|
||||
public class PlayerSpawner : MonoBehaviourPunCallbacks
|
||||
{
|
||||
[Tooltip("The location of the player prefab")]
|
||||
public string PrefabLocation = "PhotonVR/Player";
|
||||
|
||||
private GameObject playerTemp;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Object.DontDestroyOnLoad(base.gameObject);
|
||||
}
|
||||
|
||||
public override void OnJoinedRoom()
|
||||
{
|
||||
playerTemp = PhotonNetwork.Instantiate(PrefabLocation, Vector3.zero, Quaternion.identity, 0);
|
||||
}
|
||||
|
||||
public override void OnLeftRoom()
|
||||
{
|
||||
PhotonNetwork.Destroy(playerTemp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1fba55dd7d354feb034b40d55cf60e1
|
||||
timeCreated: 1780325055
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
externalObjects: {}
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user