You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
|
|
using TMPro;
|
|
using Fusion;
|
|
using UnityEngine;
|
|
using Cinemachine;
|
|
using Sirenix.OdinInspector;
|
|
|
|
public class NetworkPlayer : NetworkBehaviour
|
|
{
|
|
//===================================================
|
|
// FIELDS
|
|
//===================================================
|
|
// public static NetworkPlayer Local { get; set; }
|
|
// [Networked(OnChanged = nameof(OnUserNameChanged))]
|
|
// [OnChangedRender(nameof(OnUserNameChanged))]
|
|
[Networked]
|
|
[DisplayAsString]
|
|
public string UserName { get; private set; }
|
|
// public NetworkString<_16> UserName { get; private set; }
|
|
[SerializeField] TopDownPlayer _player = null;
|
|
[SerializeField] TopDownPlayerInput _input = null;
|
|
[SerializeField] AnimationController _animator = null;
|
|
[Space]
|
|
[SerializeField] CinemachineVirtualCamera _virtualCamPrefab = null;
|
|
[SerializeField] TMP_Text _userText = null;
|
|
|
|
//===================================================
|
|
// METHODS
|
|
//===================================================
|
|
public override void Spawned()
|
|
{
|
|
if (Object.HasInputAuthority)
|
|
{
|
|
Instantiate(_virtualCamPrefab).m_Follow = transform;
|
|
|
|
if(GameManager.Instance)
|
|
RPC_SetUserName(GameManager.Instance.UserName);
|
|
else
|
|
_userText.gameObject.SetActive(false);
|
|
|
|
if(AudioManager.Instance)
|
|
AudioManager.Instance.PlaySFX(SFX.Spawn);
|
|
|
|
GameLog.ShowMessage($"Spawned Local Player_{Object.Id}");
|
|
}//if end
|
|
else
|
|
{
|
|
if(Runner.GameMode == GameMode.Client)
|
|
{
|
|
Destroy(_player);
|
|
Destroy(_input);
|
|
Destroy(_animator);
|
|
}//if end
|
|
transform.name = Object.HasInputAuthority ? "Local" : "Remote" + $"{UserName}_{Object.Id}";
|
|
GameLog.ShowMessage($"Spawned Remote Player_{Object.Id}");
|
|
}//else end
|
|
|
|
}//Spawned() end
|
|
|
|
[Rpc(RpcSources.InputAuthority, RpcTargets.StateAuthority)]
|
|
public void RPC_SetUserName(string userName, RpcInfo info = default) => this.UserName = userName;
|
|
|
|
public override void Render()
|
|
{
|
|
if(_userText.text.Equals(UserName.ToString()) is false)
|
|
{
|
|
_userText.text = UserName.ToString();
|
|
}//if end
|
|
}//Render() end
|
|
|
|
}//class end |