269 lines
7.4 KiB
C#
269 lines
7.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class FishingPlayerRemote : MonoBehaviour
|
|
{
|
|
public GameObject modelParent;
|
|
|
|
public MeshRenderer modelHead;
|
|
|
|
public MeshRenderer modelCorpus;
|
|
|
|
public Vector3 modelShaderAnim = Vector3.zero;
|
|
|
|
[Space(10f)]
|
|
public MeshRenderer defaultAvatarRenderer;
|
|
|
|
public List<MeshRenderer> avatarRenderers = new List<MeshRenderer>();
|
|
|
|
public MeshRenderer topAvatarRenderer;
|
|
|
|
public MeshRenderer topBorderRenderer;
|
|
|
|
public bool useTopAvatar;
|
|
|
|
[Space(10f)]
|
|
public Material defaultMaterial;
|
|
|
|
public Material avatarMaterial;
|
|
|
|
public Material textDefaultMaterial;
|
|
|
|
public Material textFriendMaterial;
|
|
|
|
[Space(10f)]
|
|
public TextMesh playerNameTextMesh;
|
|
|
|
public TextMeshPro playerNameTextMeshPro;
|
|
|
|
[ReadOnly]
|
|
public FishingPlayer fishingPlayer;
|
|
|
|
[HideInInspector]
|
|
public PhotonView photonView;
|
|
|
|
[ReadOnly]
|
|
public ulong platformIdLong;
|
|
|
|
public SteamStatsManager.SteamUser steamUser;
|
|
|
|
[ReadOnly]
|
|
public bool isVisible = true;
|
|
|
|
[ReadOnly]
|
|
public bool isCrack;
|
|
|
|
public float avatarFade = 0.5f;
|
|
|
|
public float modelFade = 0.4f;
|
|
|
|
public List<Color> stateColors = new List<Color>();
|
|
|
|
private void Awake()
|
|
{
|
|
photonView = GetComponent<PhotonView>();
|
|
if (photonView.isMine && modelParent.activeSelf)
|
|
{
|
|
modelParent.SetActive(false);
|
|
}
|
|
topAvatarRenderer.transform.parent.gameObject.SetActive(useTopAvatar);
|
|
defaultAvatarRenderer.gameObject.SetActive(!useTopAvatar);
|
|
for (int i = 0; i < avatarRenderers.Count; i++)
|
|
{
|
|
avatarRenderers[i].gameObject.SetActive(!useTopAvatar);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
base.transform.parent = MultiplayerManager.Instance.remotePlayersParent.transform;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
playerNameTextMesh.text = string.Empty;
|
|
playerNameTextMeshPro.text = string.Empty;
|
|
if (photonView.owner != null && GlobalSettings.Instance.CheckCrackPhotonPlayer(photonView.owner))
|
|
{
|
|
isCrack = true;
|
|
base.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
}
|
|
if (photonView.owner != null)
|
|
{
|
|
playerNameTextMesh.text = photonView.owner.NickName;
|
|
}
|
|
if (photonView.owner != null && photonView.owner.CustomProperties.ContainsKey("steamId"))
|
|
{
|
|
platformIdLong = Convert.ToUInt64(photonView.owner.CustomProperties["steamId"]);
|
|
}
|
|
SetAvatarFade(true);
|
|
}
|
|
|
|
[PunRPC]
|
|
public void RemoteChangeColor(float[] sendTable)
|
|
{
|
|
Color color = new Color
|
|
{
|
|
r = sendTable[0],
|
|
g = sendTable[1],
|
|
b = sendTable[2],
|
|
a = modelFade
|
|
};
|
|
modelHead.material.color = color;
|
|
modelCorpus.material.color = color;
|
|
}
|
|
|
|
public void SetVisible(bool visible)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.turnOnMyCheats)
|
|
{
|
|
isVisible = visible;
|
|
photonView.RPC("RemoteSetVisible", PhotonTargets.Others, false);
|
|
}
|
|
}
|
|
|
|
[PunRPC]
|
|
public void RemoteSetVisible(bool visible)
|
|
{
|
|
isVisible = visible;
|
|
}
|
|
|
|
public void StateChanged()
|
|
{
|
|
photonView.RPC("RemoteStateChange", PhotonTargets.Others, (int)fishingPlayer.currentState, fishingPlayer.currentHands.baitWasThrown, fishingPlayer.fish != null);
|
|
}
|
|
|
|
[PunRPC]
|
|
public void RemoteStateChange(int playerState, bool baitWasThrown)
|
|
{
|
|
RemoteStateChange(playerState, baitWasThrown, false);
|
|
}
|
|
|
|
[PunRPC]
|
|
public void RemoteStateChange(int playerState, bool baitWasThrown, bool isFighting)
|
|
{
|
|
Color white = Color.white;
|
|
switch (playerState)
|
|
{
|
|
case 3:
|
|
white = stateColors[4];
|
|
break;
|
|
case 4:
|
|
white = stateColors[3];
|
|
break;
|
|
default:
|
|
white = ((!isFighting) ? ((!baitWasThrown && playerState != 6) ? stateColors[0] : stateColors[1]) : stateColors[2]);
|
|
break;
|
|
}
|
|
white.a = modelFade;
|
|
modelHead.material.color = white;
|
|
modelCorpus.material.color = white;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if ((bool)fishingPlayer)
|
|
{
|
|
base.transform.position = fishingPlayer.transform.position;
|
|
base.transform.rotation = fishingPlayer.transform.rotation;
|
|
}
|
|
playerNameTextMesh.transform.LookAt(playerNameTextMesh.transform.position + GameController.Instance.fishingPlayer.ufpsCamera.transform.rotation * Vector3.forward, GameController.Instance.fishingPlayer.ufpsCamera.transform.rotation * Vector3.up);
|
|
topAvatarRenderer.transform.parent.LookAt(topAvatarRenderer.transform.parent.position + GameController.Instance.fishingPlayer.ufpsCamera.transform.rotation * Vector3.forward, GameController.Instance.fishingPlayer.ufpsCamera.transform.rotation * Vector3.up);
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
if (GlobalSettings.Instance.playerSettings.showMultiplayerAvatars != modelParent.activeSelf)
|
|
{
|
|
modelParent.SetActive(GlobalSettings.Instance.playerSettings.showMultiplayerAvatars);
|
|
}
|
|
if ((photonView.isMine || !isVisible) && modelParent.activeSelf)
|
|
{
|
|
modelParent.SetActive(false);
|
|
}
|
|
}
|
|
if ((GlobalSettings.Instance == null || ((bool)GlobalSettings.Instance && GlobalSettings.Instance.turnOnMyCheats)) && Input.GetKey(KeyCode.LeftShift))
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Alpha1))
|
|
{
|
|
playerNameTextMesh.gameObject.SetActive(!playerNameTextMesh.gameObject.activeSelf);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.Alpha2))
|
|
{
|
|
topAvatarRenderer.gameObject.SetActive(!topAvatarRenderer.gameObject.activeSelf);
|
|
topBorderRenderer.gameObject.SetActive(!topBorderRenderer.gameObject.activeSelf);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.Alpha3))
|
|
{
|
|
modelHead.gameObject.SetActive(!modelHead.gameObject.activeSelf);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.Alpha4))
|
|
{
|
|
modelCorpus.gameObject.SetActive(!modelCorpus.gameObject.activeSelf);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetAvatarFade(bool fade)
|
|
{
|
|
Color color = topAvatarRenderer.material.GetColor("_Color");
|
|
color.a = ((!fade) ? 1f : avatarFade);
|
|
topAvatarRenderer.material.SetColor("_Color", color);
|
|
color = topBorderRenderer.material.GetColor("_Color");
|
|
color = ((!fade) ? Color.black : Color.white);
|
|
color.a = ((!fade) ? 1f : avatarFade);
|
|
topBorderRenderer.material.SetColor("_Color", color);
|
|
}
|
|
|
|
[Button]
|
|
public void RefreshSteamUser()
|
|
{
|
|
if (!SteamStatsManager.Instance || !SteamManager.Initialized)
|
|
{
|
|
return;
|
|
}
|
|
if (photonView.owner.CustomProperties.ContainsKey("steamId"))
|
|
{
|
|
steamUser = SteamStatsManager.Instance.CreatePlatformUser(Convert.ToUInt64(photonView.owner.CustomProperties["steamId"]));
|
|
}
|
|
if (steamUser != null)
|
|
{
|
|
SteamStatsManager.Instance.PhotonPlayerToSteamUser(steamUser, photonView.owner);
|
|
RefreshAvatar();
|
|
playerNameTextMesh.text = string.Empty;
|
|
if (SteamStatsManager.Instance.IsUserAFriend(steamUser))
|
|
{
|
|
playerNameTextMesh.text = "[" + Utilities.GetTranslation("MULTIPLAYER/FRIEND").ToLower() + "] ";
|
|
playerNameTextMesh.GetComponent<MeshRenderer>().material = textFriendMaterial;
|
|
}
|
|
playerNameTextMesh.text += steamUser.friendName;
|
|
playerNameTextMesh.GetComponent<TextOutline>().UpdateText();
|
|
}
|
|
}
|
|
|
|
public void RefreshAvatar()
|
|
{
|
|
if (!useTopAvatar)
|
|
{
|
|
for (int i = 0; i < avatarRenderers.Count; i++)
|
|
{
|
|
avatarRenderers[i].material.mainTexture = ((!(steamUser.avatarLarge != null)) ? steamUser.avatarMedium : steamUser.avatarLarge);
|
|
avatarRenderers[i].gameObject.SetActive(true);
|
|
}
|
|
defaultAvatarRenderer.gameObject.SetActive(false);
|
|
}
|
|
topAvatarRenderer.material = avatarMaterial;
|
|
topAvatarRenderer.material.mainTexture = ((!(steamUser.avatarLarge != null)) ? steamUser.avatarMedium : steamUser.avatarLarge);
|
|
}
|
|
|
|
public void RequestSteamStats()
|
|
{
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
SteamStatsManager.Instance.RequestUserStats(steamUser);
|
|
SteamStatsManager.Instance.RequestUserInformation(steamUser, false);
|
|
}
|
|
}
|
|
}
|