diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/Player.cs |
+ init
Diffstat (limited to 'GameCode/Player.cs')
-rw-r--r-- | GameCode/Player.cs | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/GameCode/Player.cs b/GameCode/Player.cs new file mode 100644 index 0000000..d912f63 --- /dev/null +++ b/GameCode/Player.cs @@ -0,0 +1,153 @@ +using System; +using ExitGames.Client.Photon; +using Photon.Pun; +using UnityEngine; + +public class Player : MonoBehaviour +{ + public int playerID; + + public int teamID; + + [HideInInspector] + public CharacterData data; + + public PlayerSkinBank colors; + + private void Awake() + { + data = GetComponent<CharacterData>(); + } + + private void Start() + { + if (!data.view.IsMine) + { + ReadPlayerID(); + ReadTeamID(); + PlayerAssigner.instance.OtherPlayerWasCreated(); + } + else + { + int num = 0; + if (!PhotonNetwork.OfflineMode) + { + try + { + num = 0; + PlayerFace playerFace = CharacterCreatorHandler.instance.selectedPlayerFaces[num]; + data.view.RPC("RPCA_SetFace", RpcTarget.All, playerFace.eyeID, playerFace.eyeOffset, playerFace.mouthID, playerFace.mouthOffset, playerFace.detailID, playerFace.detailOffset, playerFace.detail2ID, playerFace.detail2Offset); + } + catch + { + } + } + else if (GM_ArmsRace.instance != null) + { + GM_ArmsRace instance = GM_ArmsRace.instance; + instance.StartGameAction = (Action)Delegate.Combine(instance.StartGameAction, new Action(GetFaceOffline)); + } + } + PlayerManager.instance.PlayerJoined(this); + } + + public void GetFaceOffline() + { + PlayerFace playerFace = CharacterCreatorHandler.instance.selectedPlayerFaces[playerID]; + data.view.RPC("RPCA_SetFace", RpcTarget.All, playerFace.eyeID, playerFace.eyeOffset, playerFace.mouthID, playerFace.mouthOffset, playerFace.detailID, playerFace.detailOffset, playerFace.detail2ID, playerFace.detail2Offset); + } + + [PunRPC] + public void RPCA_SetFace(int eyeID, Vector2 eyeOffset, int mouthID, Vector2 mouthOffset, int detailID, Vector2 detailOffset, int detail2ID, Vector2 detail2Offset) + { + PlayerFace face = PlayerFace.CreateFace(eyeID, eyeOffset, mouthID, mouthOffset, detailID, detailOffset, detail2ID, detail2Offset); + GetComponentInChildren<CharacterCreatorItemEquipper>().EquipFace(face); + } + + internal void Call_AllGameFeel(Vector2 vector2) + { + data.view.RPC("RPCA_AllGameFeel", RpcTarget.All, vector2); + } + + [PunRPC] + internal void RPCA_AllGameFeel(Vector2 vector2) + { + GamefeelManager.instance.AddGameFeel(vector2); + } + + public void AssignPlayerID(int ID) + { + playerID = ID; + SetColors(); + if (!PhotonNetwork.OfflineMode) + { + Hashtable customProperties = PhotonNetwork.LocalPlayer.CustomProperties; + if (customProperties.ContainsKey("PlayerID")) + { + customProperties["PlayerID"] = playerID; + } + else + { + customProperties.Add("PlayerID", playerID); + } + PhotonNetwork.LocalPlayer.SetCustomProperties(customProperties); + } + } + + internal float GetRadius() + { + return 5f; + } + + private void ReadPlayerID() + { + if (!PhotonNetwork.OfflineMode) + { + playerID = (int)data.view.Owner.CustomProperties["PlayerID"]; + SetColors(); + } + } + + public void AssignTeamID(int ID) + { + teamID = ID; + if (!PhotonNetwork.OfflineMode) + { + Hashtable customProperties = PhotonNetwork.LocalPlayer.CustomProperties; + if (customProperties.ContainsKey("TeamID")) + { + customProperties["TeamID"] = playerID; + } + else + { + customProperties.Add("TeamID", teamID); + } + PhotonNetwork.LocalPlayer.SetCustomProperties(customProperties); + } + } + + private void ReadTeamID() + { + if (!PhotonNetwork.OfflineMode) + { + teamID = (int)data.view.Owner.CustomProperties["TeamID"]; + } + } + + public void SetColors() + { + SetTeamColor.TeamColorThis(base.gameObject, PlayerSkinBank.GetPlayerSkinColors(playerID)); + } + + public PlayerSkin GetTeamColors() + { + return PlayerSkinBank.GetPlayerSkinColors(playerID); + } + + internal void FullReset() + { + data.weaponHandler.NewGun(); + data.stats.ResetStats(); + data.block.ResetStats(); + } +} |