Last active
August 29, 2024 10:28
-
-
Save Aqueuse/20ce875bcddeaa2b9bbedbe077523ec3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////////////// | |
// the data class on each prefab player | |
/////////////////////////////////////// | |
public class PlayerData : NetworkBehaviour { | |
[Networked] public int playerId { get; set; } // ID unique pour chaque joueur | |
[Networked, OnChangedRender(nameof(UpdateLocalRender))] public NetworkBool hasPhillipeKaterine { get; set; } | |
public void UpdateLocalRender() { | |
foreach (var player in ObjectsReference.instance.RPCmanager.playerDataByPlayerId) { | |
if (player.Key == playerId) { | |
GetComponent<Spaceship>().phillipeKaterineSpriteRenderer.enabled = player.Value.hasPhillipeKaterine; | |
} | |
} | |
} | |
} | |
///////////////////////////////////// | |
// le RPC manager | |
///////////////////////////////////// | |
public class RPCmanager : MonoBehaviour { | |
public GenericDictionary<int, PlayerData> playerDataByPlayerId; | |
private void Start() { | |
playerDataByPlayerId = new GenericDictionary<int, PlayerData>(); | |
} | |
[Rpc(RpcSources.All, RpcTargets.StateAuthority)] | |
public void RPC_PlayerSendDataToServer(int playerId, bool hasPhillipeKaterine) { | |
ObjectsReference.instance.RPCmanager.playerDataByPlayerId[playerId].hasPhillipeKaterine = hasPhillipeKaterine; | |
foreach (var playerData in playerDataByPlayerId) { | |
RPC_UpdatePlayerDataOnClient(playerData.Value.playerId, playerData.Value.hasPhillipeKaterine); | |
} | |
} | |
[Rpc(RpcSources.StateAuthority, RpcTargets.All)] | |
private void RPC_UpdatePlayerDataOnClient(int playerId, bool hasPhillipeKaterine) { | |
var localPlayerId = ObjectsReference.instance.gameManager.localPlayerId; | |
if (playerId == localPlayerId) { | |
playerDataByPlayerId[playerId].hasPhillipeKaterine = hasPhillipeKaterine; | |
} | |
} | |
} | |
/////////////////////////////////////////////// | |
// le game manager qui donne Phillipe Katerine | |
//////////////////////////////////////////////// | |
public class GameManager() { | |
public void GivePlayerPhillipeKaterine() { | |
try { | |
ObjectsReference.instance.RPCmanager.RPC_PlayerSendDataToServer(localPlayerId, true); | |
} | |
catch (Exception e) { | |
Debug.Log(e); | |
throw; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment