EVERYTHING

This commit is contained in:
niko
2026-06-01 17:19:55 +02:00
parent d063b81359
commit b62bac090b
1081 changed files with 1716544 additions and 0 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9e899b486ec72b54880aec82039ff6a0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
namespace Photon.VR
{
public enum ConnectionState
{
Disconnected = 0,
Connecting = 1,
Connected = 2,
JoiningRoom = 3,
InRoom = 4
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 46962e474d931b145a1f2a1267ab209a
@@ -0,0 +1,305 @@
using System;
using System.Collections.Generic;
using BlockSpace.Worlds;
using ExitGames.Client.Photon;
using Photon.Pun;
using Photon.Realtime;
using Photon.VR.Player;
using Photon.VR.Saving;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Photon.VR
{
public class PhotonVRManager : MonoBehaviourPunCallbacks
{
[Header("Photon")]
public string AppId;
public string VoiceAppId;
[Tooltip("Please read https://doc.photonengine.com/en-us/pun/current/connection-and-authentication/regions for more information")]
public string Region = "eu";
[Header("Player")]
public Transform Head;
public Transform LeftHand;
public Transform RightHand;
public Color Colour;
[Header("Networking")]
public string DefaultQueue = "Default";
public int DefaultRoomLimit = 16;
[Header("Other")]
[Tooltip("If the user shall connect when this object has awoken")]
public bool ConnectOnAwake = true;
[Tooltip("If the user shall join a room when they connect")]
public bool JoinRoomOnConnect = true;
[NonSerialized]
public PhotonVRPlayer LocalPlayer;
private RoomOptions options;
private ConnectionState State;
public static PhotonVRManager Manager { get; private set; }
public Dictionary<string, string> Cosmetics { get; private set; } = new Dictionary<string, string>();
private void Start()
{
if (Manager == null)
{
Manager = this;
}
else
{
Debug.LogError("There can't be multiple PhotonVRManagers in a scene");
Application.Quit();
}
if (GetComponent<CreatorFlightController>() == null)
{
base.gameObject.AddComponent<CreatorFlightController>();
}
UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
if (ConnectOnAwake)
{
Connect();
}
if (!string.IsNullOrEmpty(PlayerPrefs.GetString("Colour")))
{
Colour = JsonUtility.FromJson<Color>(PlayerPrefs.GetString("Colour"));
}
if (!string.IsNullOrEmpty(PlayerPrefs.GetString("Cosmetics")))
{
Cosmetics = PhotonVRValueSaver.GetDictionary("Cosmetics");
}
}
public static bool Connect()
{
if (string.IsNullOrEmpty(Manager.AppId) || string.IsNullOrEmpty(Manager.VoiceAppId))
{
Debug.LogError("Please input an app id");
return false;
}
PhotonNetwork.AuthValues = null;
Manager.State = ConnectionState.Connecting;
PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime = Manager.AppId;
PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice = Manager.VoiceAppId;
PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = Manager.Region;
PhotonNetwork.ConnectUsingSettings();
Debug.Log("Connecting - AppId: " + PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime + " VoiceAppId: " + PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice);
return true;
}
public static bool ConnectAuthenticated(string username, string token)
{
if (string.IsNullOrEmpty(Manager.AppId) || string.IsNullOrEmpty(Manager.VoiceAppId))
{
Debug.LogError("Please input an app id");
return false;
}
AuthenticationValues authenticationValues = new AuthenticationValues();
authenticationValues.AuthType = CustomAuthenticationType.Custom;
authenticationValues.AddAuthParameter("username", username);
authenticationValues.AddAuthParameter("token", token);
PhotonNetwork.AuthValues = authenticationValues;
Manager.State = ConnectionState.Connecting;
PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime = Manager.AppId;
PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice = Manager.VoiceAppId;
PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = Manager.Region;
PhotonNetwork.ConnectUsingSettings();
Debug.Log("Connecting - AppId: " + PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime + " VoiceAppId: " + PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice);
return true;
}
public void Disconnect()
{
PhotonNetwork.Disconnect();
}
public static void ChangeServers(string Id, string VoiceId)
{
PhotonNetwork.Disconnect();
Manager.AppId = Id;
Manager.VoiceAppId = VoiceId;
Connect();
}
public static void ChangeServersAuthenticated(string Id, string VoiceId, string username, string token)
{
PhotonNetwork.Disconnect();
Manager.AppId = Id;
Manager.VoiceAppId = VoiceId;
ConnectAuthenticated(username, token);
}
public static void SetUsername(string Name)
{
PhotonNetwork.LocalPlayer.NickName = Name;
PlayerPrefs.SetString("Username", Name);
if (PhotonNetwork.InRoom && Manager.LocalPlayer != null)
{
Manager.LocalPlayer.RefreshPlayerValues();
}
}
public static void SetColour(Color PlayerColour)
{
Manager.Colour = PlayerColour;
Hashtable customProperties = PhotonNetwork.LocalPlayer.CustomProperties;
customProperties["Colour"] = JsonUtility.ToJson(PlayerColour);
PhotonNetwork.LocalPlayer.SetCustomProperties(customProperties);
PlayerPrefs.SetString("Colour", JsonUtility.ToJson(PlayerColour));
if (PhotonNetwork.InRoom && Manager.LocalPlayer != null)
{
Manager.LocalPlayer.RefreshPlayerValues();
}
}
public static void SetCosmetics(Dictionary<string, string> PlayerCosmetics)
{
Manager.Cosmetics = PlayerCosmetics;
Hashtable customProperties = PhotonNetwork.LocalPlayer.CustomProperties;
customProperties["Cosmetics"] = Manager.Cosmetics;
PhotonNetwork.LocalPlayer.SetCustomProperties(customProperties);
PhotonVRValueSaver.SaveDictionary("Cosmetics", Manager.Cosmetics);
if (PhotonNetwork.InRoom && Manager.LocalPlayer != null)
{
Manager.LocalPlayer.RefreshPlayerValues();
}
}
public static void SetCosmetic(string Type, string CosmeticId)
{
Manager.Cosmetics[Type] = CosmeticId;
Hashtable customProperties = PhotonNetwork.LocalPlayer.CustomProperties;
customProperties["Cosmetics"] = Manager.Cosmetics;
PhotonNetwork.LocalPlayer.SetCustomProperties(customProperties);
PhotonVRValueSaver.SaveDictionary("Cosmetics", Manager.Cosmetics);
if (PhotonNetwork.InRoom && Manager.LocalPlayer != null)
{
Manager.LocalPlayer.RefreshPlayerValues();
}
}
public override void OnConnectedToMaster()
{
State = ConnectionState.Connected;
Debug.Log("Connected");
string text = PlayerPrefs.GetString("BlockSpace.Account.DiscordDisplayName");
string nickName = ((!string.IsNullOrEmpty(text)) ? text : PlayerPrefs.GetString("Username"));
PhotonNetwork.LocalPlayer.NickName = nickName;
PhotonNetwork.LocalPlayer.CustomProperties["Colour"] = JsonUtility.ToJson(Colour);
PhotonNetwork.LocalPlayer.CustomProperties["Cosmetics"] = Cosmetics;
if (JoinRoomOnConnect)
{
JoinRandomRoom(DefaultQueue, DefaultRoomLimit);
}
}
public static ConnectionState GetConnectionState()
{
return Manager.State;
}
public static void SwitchScenes(int SceneIndex, int MaxPlayers)
{
SceneManager.LoadScene(SceneIndex);
JoinRandomRoom(SceneIndex.ToString(), MaxPlayers);
}
public static void SwitchScenes(int SceneIndex)
{
SceneManager.LoadScene(SceneIndex);
JoinRandomRoom(SceneIndex.ToString(), Manager.DefaultRoomLimit);
}
public static void JoinRandomRoom(string Queue, int MaxPlayers)
{
_JoinRandomRoom(Queue, MaxPlayers);
}
public static void JoinRandomRoom(string Queue)
{
_JoinRandomRoom(Queue, Manager.DefaultRoomLimit);
}
private static void _JoinRandomRoom(string Queue, int MaxPlayers)
{
Manager.State = ConnectionState.JoiningRoom;
Hashtable hashtable = new Hashtable();
hashtable.Add("queue", Queue);
hashtable.Add("version", Application.version);
RoomOptions roomOptions = new RoomOptions();
roomOptions.MaxPlayers = (byte)MaxPlayers;
roomOptions.IsVisible = true;
roomOptions.IsOpen = true;
roomOptions.CustomRoomProperties = hashtable;
roomOptions.CustomRoomPropertiesForLobby = new string[2] { "queue", "version" };
Manager.options = roomOptions;
PhotonNetwork.JoinRandomRoom(hashtable, (byte)roomOptions.MaxPlayers, MatchmakingMode.RandomMatching, null, null);
Debug.Log(string.Format("Joining random with type {0}", hashtable["queue"]));
}
public static void JoinPrivateRoom(string RoomId, int MaxPlayers)
{
_JoinPrivateRoom(RoomId, MaxPlayers);
}
public static void JoinPrivateRoom(string RoomId)
{
_JoinPrivateRoom(RoomId, Manager.DefaultRoomLimit);
}
public static void _JoinPrivateRoom(string RoomId, int MaxPlayers)
{
PhotonNetwork.JoinOrCreateRoom(RoomId, new RoomOptions
{
IsVisible = false,
IsOpen = true,
MaxPlayers = (byte)MaxPlayers
}, null);
Debug.Log("Joining a private room: " + RoomId);
}
public override void OnJoinedRoom()
{
Debug.Log("Joined a room");
State = ConnectionState.InRoom;
}
public override void OnDisconnected(DisconnectCause cause)
{
base.OnDisconnected(cause);
State = ConnectionState.Disconnected;
Debug.Log("Disconnected from server");
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
HandleJoinError();
}
private void HandleJoinError()
{
Debug.Log("Failed to join room - creating a new one");
string text = CreateRoomCode();
Debug.Log("Joining " + text);
PhotonNetwork.CreateRoom(text, options);
}
public string CreateRoomCode()
{
return new System.Random().Next(99999).ToString();
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 61f5e0ff097a1d35cf36feb26f3e91c4
timeCreated: 1780325055
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8c773b5960cff27418e75c511bf2127c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -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:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 703683037ee983048b00e77ff8ad6fdf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using UnityEngine;
namespace Photon.VR.Saving
{
public class PhotonVRValueSaver : MonoBehaviour
{
public static void SaveDictionary(string location, Dictionary<string, string> value)
{
PlayerPrefs.SetString(location, string.Join(",", value.Keys));
foreach (KeyValuePair<string, string> item in value)
{
PlayerPrefs.SetString(location + item.Key, item.Value.ToString());
}
}
public static Dictionary<string, string> GetDictionary(string location)
{
string[] array = PlayerPrefs.GetString(location).Split(',');
Dictionary<string, string> dictionary = new Dictionary<string, string>();
string[] array2 = array;
foreach (string text in array2)
{
dictionary[text] = PlayerPrefs.GetString(location + text);
}
return dictionary;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 01c33e603f201051f9f526ffa939780d
timeCreated: 1780325055
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8d2276436b52cb8458cec58cf86626b0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
using UnityEngine;
namespace Photon.VR.Testing
{
public class PhotonVRColourChanger : MonoBehaviour
{
public Color Colour;
public void ChangeColour(Color Colour)
{
PhotonVRManager.SetColour(Colour);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c9dff8106e4a7f0ba4ef2501a7090ebe
timeCreated: 1780325055
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Photon.VR.Testing
{
public class PhotonVRCosmeticsChanger : MonoBehaviour
{
[Serializable]
public class PhotonVRCosmeticTest
{
public string SlotName;
public string Cosmetic;
}
public List<PhotonVRCosmeticTest> Cosmetics = new List<PhotonVRCosmeticTest>();
public void ChangeCosmetics(Dictionary<string, string> Cosmetics)
{
PhotonVRManager.SetCosmetics(Cosmetics);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e27d5a41a3ab6aba6fa06ca56486ea3c
timeCreated: 1780325055
licenseType: Free
MonoImporter:
serializedVersion: 2
externalObjects: {}
defaultReferences: []
executionOrder: 0
icon: {fileID: 0}
userData:
assetBundleName:
assetBundleVariant: