Ufps Photon Choosing Classes

How would i go about being able to chose a class before entering the room. Such as an assult class which contains the guns (Machine gun and pistol only) or recon (Sniper and pistol). Thanks in advance

Save Selected class name in playerprefs, weapon manager will read the class name on player instantiate and load the weapons for selected class from resources folder, and instantiate them. That’s the easiest way

Right so ive chosen the class (preselected the pistol and machine gun), but this will do it for every player that spawns. He doesnt get the option to chose which gun class he wants. I want it so the player at the menu gets to preselect what class he wants

Yes simple because the the other players do not know which weapons you have quiped this means you have to send your own “loadout” to them so when you call the remote procedure call with your loadout settings the other players will know which weapons they have to load.

So how will i go about doing this, sorry im abit new to the whole ufps scene :slight_smile:

Im not using pun, but photon.

That’s where you set up your load out items and call loadallaviliableweapons:

if (photonView.isMine)
        {
            LoadoutManager SerializedLoadOut = new LoadoutManager("PistolGun33","SergaSniper","WaveShotgun12","SergaSniper");
            byte[] loadOutBuff = SerializedLoadOutView.SerializeLoadOut(SerializedLoadOut);
            photonView.RPC("LoadAllAviliableWeapons", PhotonTargets.AllBuffered,loadOutBuff);
        }

Here you load the content:

[PunRPC]
    private void LoadAllAviliableWeapons(byte[] loadOutDataStream,PhotonMessageInfo actorInfo)
    {
        for(int j =1; j < weaponSlot.Length; j++)
        {
            if(weaponSlot[j] != null)
            {
                weaponSlot[j] = null;
            }
        }
        for (int i = 1; i < weaponSlot.Length; i++)
        {
            KamoUnityItem UnityItem;
            LoadoutManager DeserializedLoadOut = (LoadoutManager)SerializedLoadOutView.DeserializeLoadOut(loadOutDataStream);
            if (DeserializedLoadOut.TryGetWeaponItem(i, out UnityItem))
            {
                weaponSlot[i] = new WeaponSlot(UnityItem, this.WeaponCameraPoint.transform, NetworkPoint.transform, actorInfo.sender.name);
            }
            else
            {
                Debug.LogError(string.Format("Couldn't initialize weapon slot: {0}", i));
            }
        }
    }

Serialize & Deserialize your load out:

public static class SerializedLoadOutView
{
    public static byte[] SerializeLoadOut(System.Object loadOutObject)
    {
        BinaryFormatter binaryF = new BinaryFormatter();
        using (MemoryStream memoryStream = new MemoryStream())
        {
            binaryF.Serialize(memoryStream, loadOutObject);

            return memoryStream.ToArray();
        }
    }

    public static System.Object DeserializeLoadOut(byte[] dataStream)
    {
        using (MemoryStream memoryStream = new MemoryStream())
        {
            BinaryFormatter binaryF = new BinaryFormatter();

            memoryStream.Write(dataStream, 0, dataStream.Length);
            memoryStream.Seek(0, SeekOrigin.Begin);

            return (System.Object)binaryF.Deserialize(memoryStream);
        }
    }
}

I can’t explain all or give more code about the core functions but this should give you small over view how it works!

this is all in one new script or what?

There are few classes that working together but as I said, it’s only for over view