Skip to content

A Unity Package containing all the necessary components to do VR networking with Photon

License

Notifications You must be signed in to change notification settings

TMTimeVR/PhotonVR

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Unity Package containing all the necessary components to do VR networking with Photon. And more customisation.

Disclaimer

There might be some bugs in the code. Please have mercy with me.

I tested it in my game and it worked normally.

I only edited PhotonVRManager so just copy and paste this into your PhotonVRManager.

I DID NOT MAKE THIS. I JUST MODIFIED THE CODE!

I added a dev region choice. Meaning if your apk is a development build, it's going to connect to the dev region.

        [Tooltip("The region that people connect to if the apk is a development build (check your build settings).")]
        public string DevRegion = "";

I also added a Offline mode bool. Meaning that it simulates an online connection. PUN can be used as if it was in an online connection.

        [Tooltip("Simulates an online connection.\nPUN can be used as usual.")]
        public bool StartInOfflineMode = false;

I also also added more connection states for more debugging.

    public enum ConnectionState
    {
        Disconnected,
        Connecting,
        Connected,
        JoiningRoom,
        InRoom,
        Error,
        Generating_Roomcode,
        Switching_Scenes,
        Setting_Up_Settings
    }

I also also ALSO added a TMP that you can assign and it will say what's going on.

        [Tooltip("Basically a tmp that says what PhotonVRManager is doing.")]
        public static TextMeshPro LogText;
            if (Manager == null)
            {
                Manager = this;
                Manager.State = ConnectionState.Setting_Up_Settings;
                LogText.text = "Setting Up Settings..."; //Here
                PhotonNetwork.PhotonServerSettings.DevRegion = DevRegion;
            }
            else if (StartInOfflineMode == true)
            {
                PhotonNetwork.PhotonServerSettings.StartInOfflineMode = true;
            }
            else if (StartInOfflineMode == false)
            {
                PhotonNetwork.PhotonServerSettings.StartInOfflineMode = false;
            }
            else
            {
                Debug.LogError("There can't be multiple PhotonVRManagers in a scene");
                Manager.State = ConnectionState.Error;
                LogText.text = "ERROR: There can't be multiple PhotonVRManagers in a scene."; //Also here
                Application.Quit();
            }

I just basically made it more easy so you don't have to go manually into the Photon server settings and just be able to control Photon from one script.

Credits to fchb1239 for making Photon VR.

Download Discord

Documentation

By default everything is set up for a super simple system, obviously you can code some stuff yourself to make everything work for your application.

You need to have PUN 2 and Photon Voice 2 in your project before importing this You also need TextMeshPro - that's built into unity, you just gotta go into the Player prefab and press Import TMP Essentials.

Start off by going in Resources/PhotonVR/Prefabs and dragging everything in there into the scene.

Then, put your Photon AppId into AppId and Photon Voice AppId into VoiceAppId, then put in a region - the default is "eu". Click here to see a list of regions

Then drag in your controllers and headset into Head, Left Hand and Right Hand - set the colour to the default colour.

Set Default Queue to the queue you want to automatically load into when the game starts and set the Default Room Limit to the maximum amount of players you want in a default room.

Connect On Awake makes it so when the game loads you instantly try to connect, Join Room On Connect makes it so it instantly joins the Default Queue with the Default Room Limit when you connect to the server.

Including Photon.VR

using Photon.VR;

Connecting to the servers

PhotonVRManager.Connect();

Switching Photon servers

PhotonVRManager.ChangeServers("AppId", "VoiceAppId");

Connecting to the servers authenticated

// These will not actually work, you need to set this up with PlayFab or something else
string username = "MYID";
string token = "MYTOKEN";
PhotonVRManager.ConnectAuthenticated(username, token);

Switching Photon servers authenticated

// These will not actually work, you need to set this up with PlayFab or something else
string username = "MYID";
string token = "MYTOKEN";
PhotonVRManager.ChangeServersAuthenticated("AppId", "VoiceAppId", username, token);

PlayFab Photon authentication documentation

Joining rooms

// It will only join people on the same queue but the room codes themselves are random
string queue = "Space";
// Optional
int maxPlayers = 8;
PhotonVRManager.JoinRandomRoom(queue, maxPlayers);

Joining private rooms

string roomCode = "1234";
// Optional
int maxPlayers = 8;
PhotonVRManager.JoinPrivateRoom(roomCode, maxPlayers);

Switching scenes

int sceneIndex = 1;
// Optional
int maxPlayers = 8;
PhotonVRManager.SwitchScenes(SceneIndex, maxPlayers);

Setting name

PhotonVRManager.SetUsername("fchb1239");

Setting colour

Color myColour = new Color(0, 0, 1);
PhotonVRManager.SetColour(myColour);

Cosmetics

To put on cosmetics you can use two functions to do the job. You can put on an entire set like so

PhotonVRManager.SetCosmetics(new Dictionary<string, string>
{
    { "Head", "VRTopHat" },
    { "Face", "VRSunglasses" }
    // And so on
});

Or if you want to do one at a time (like if you have a button with a specefic cosmetic) then do like so

PhotonVRManager.SetCosmetic("Head", "VRTopHat");

If you set a cosmetic part to a cosmetic that doesn't exit, it won't equip anything. So if you want to clear the head of cosmetics do like so

PhotonVRManager.SetCosmetic("Head", "");

It's the same story with SetCosmetics.

Every body part on the player has a child named something with "Cosmetics", under those you put the models of the cosmetics you want. You have to rename the object to the ID of the cosmetic, let's say you put on a hat with the ID "VRTopHat" then under the Cosmetics child of the head you put your model and name it "VRTopHat", like this:

About

A Unity Package containing all the necessary components to do VR networking with Photon

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%