Adapting Unity Shooter example to Ready Player Me: avatar skins
Posted: 30 Mar 2024, 23:33
Hello, per the title I'm working out loading RPM avatar skins in the Unity Shooter example (actually in my own project adapting Shooter Unity + Java).
I'm more familiar with Photon, so I'm working out how to do this in SF2X.
TL;DR: Can I send the RPM avatar URL from the Unity side as a network method, call to load the avatar skin, or does this need to go through the Shooter java extension?
Use Case:
1. User provides a RPM avatar ID or URL with the RPM SDK 6.0.1
2. This ID/URL is saved on the local player's computer and sent as a buffered network call to the room.
3. On Joined Room, the local and remote versions of this player load their avatar, using the ID/URL.
Question: Can I send SF2X network method calls to load the avatar skin, or, is it necessary to use User Variables and code into the java extension?
Long Description
The RPM Photon example attaches a 'network' script to load the avatar. There may be other code in their runtime dll I can't access.
RPM Photon example:
Unity game: Photon world controller:
Unity player prefab: Network code, attached to the avatar prefab itself:
So Photon, being non-authorative, sends the load avatar command to its local and remote instances in the same room other players are in, so remote players see the new player's Ready Player Me skin. This approach appears not store the RPM ID/URL, but just passes that string value along through the network as a function.
SmartFox Server 2X
Smartfox has the User Variable. When updated, all players in the same room receive the updated value. In the Shooter example, this appears to be used for health as an example. My initial thought was to add a string variable to CombatPlayer.java and possibly a handler in World.java.
However there's no need to keep the Ready Player Me URL stored with the player on the java server side once the skin is loaded. It only needs to be stored on the local player's computer and sent when joining the room to update that player's avatar appearance in the room.
If a player disconnects and reconnects, they've rejoined the room and so the local stored RPM ID/URL would be sent again.
I'm more familiar with Photon, so I'm working out how to do this in SF2X.
TL;DR: Can I send the RPM avatar URL from the Unity side as a network method, call to load the avatar skin, or does this need to go through the Shooter java extension?
Use Case:
1. User provides a RPM avatar ID or URL with the RPM SDK 6.0.1
2. This ID/URL is saved on the local player's computer and sent as a buffered network call to the room.
3. On Joined Room, the local and remote versions of this player load their avatar, using the ID/URL.
Question: Can I send SF2X network method calls to load the avatar skin, or, is it necessary to use User Variables and code into the java extension?
Long Description
The RPM Photon example attaches a 'network' script to load the avatar. There may be other code in their runtime dll I can't access.
RPM Photon example:
Unity game: Photon world controller:
Code: Select all
public override void OnJoinedRoom()
{
Debug.Log("Joined room");
UI.SetActive(false);
GameObject character = PhotonNetwork.Instantiate("RPM_Photon_Test_Character", Vector3.zero, Quaternion.identity);
character.GetComponent<NetworkPlayer>().LoadAvatar(inputField.text);
}
Unity player prefab: Network code, attached to the avatar prefab itself:
Code: Select all
public void LoadAvatar(string url)
{
photonView.RPC(SET_PLAYER_METHOD, RpcTarget.AllBuffered, url);
}
[PunRPC]
private void SetPlayer(string incomingUrl)
{
AvatarObjectLoader loader = new AvatarObjectLoader();
loader.LoadAvatar(incomingUrl);
loader.AvatarConfig = config;
loader.OnCompleted += (sender, args) =>
{
leftEye.transform.localPosition = AvatarBoneHelper.GetLeftEyeBone(args.Avatar.transform, true).localPosition;
rightEye.transform.localPosition = AvatarBoneHelper.GetRightEyeBone(args.Avatar.transform, true).localPosition;
AvatarMeshHelper.TransferMesh(args.Avatar, gameObject);
Destroy(args.Avatar);
};
}So Photon, being non-authorative, sends the load avatar command to its local and remote instances in the same room other players are in, so remote players see the new player's Ready Player Me skin. This approach appears not store the RPM ID/URL, but just passes that string value along through the network as a function.
SmartFox Server 2X
Smartfox has the User Variable. When updated, all players in the same room receive the updated value. In the Shooter example, this appears to be used for health as an example. My initial thought was to add a string variable to CombatPlayer.java and possibly a handler in World.java.
However there's no need to keep the Ready Player Me URL stored with the player on the java server side once the skin is loaded. It only needs to be stored on the local player's computer and sent when joining the room to update that player's avatar appearance in the room.
If a player disconnects and reconnects, they've rejoined the room and so the local stored RPM ID/URL would be sent again.