mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
[AvatarScaleMod] Mod Network attempt 2.
I lost the first attempt when switching branches. Lot of this still needs to be redone, as it is just quickly slapped together atm.
This commit is contained in:
parent
69cb3b7804
commit
d599f57973
13 changed files with 850 additions and 544 deletions
112
AvatarScale/AvatarScaling/AvatarScaleManager.cs
Normal file
112
AvatarScale/AvatarScaling/AvatarScaleManager.cs
Normal file
|
@ -0,0 +1,112 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using NAK.AvatarScaleMod.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AvatarScaleMod.AvatarScaling;
|
||||
|
||||
public class AvatarScaleManager : MonoBehaviour
|
||||
{
|
||||
public static AvatarScaleManager Instance;
|
||||
|
||||
private Dictionary<string, UniversalAvatarScaler> _networkedScalers;
|
||||
private UniversalAvatarScaler _localAvatarScaler;
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
_networkedScalers = new Dictionary<string, UniversalAvatarScaler>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Local Methods
|
||||
|
||||
public void OnAvatarInstantiated(PlayerSetup playerSetup)
|
||||
{
|
||||
if (playerSetup._avatar == null)
|
||||
return;
|
||||
|
||||
if (_localAvatarScaler != null)
|
||||
Destroy(_localAvatarScaler);
|
||||
|
||||
_localAvatarScaler = playerSetup._avatar.AddComponent<UniversalAvatarScaler>();
|
||||
_localAvatarScaler.Initialize(playerSetup._initialAvatarHeight, playerSetup.initialScale);
|
||||
}
|
||||
|
||||
public void OnAvatarDestroyed()
|
||||
{
|
||||
if (_localAvatarScaler != null)
|
||||
Destroy(_localAvatarScaler);
|
||||
}
|
||||
|
||||
public void SetHeight(float targetHeight)
|
||||
{
|
||||
if (_localAvatarScaler == null)
|
||||
return;
|
||||
|
||||
_localAvatarScaler.SetHeight(targetHeight);
|
||||
ModNetwork.SendNetworkHeight(targetHeight);
|
||||
|
||||
// immediately update play space scale
|
||||
PlayerSetup.Instance.CheckUpdateAvatarScaleToPlaySpaceRelation();
|
||||
}
|
||||
|
||||
public void ResetHeight()
|
||||
{
|
||||
if (_localAvatarScaler != null)
|
||||
_localAvatarScaler.ResetHeight();
|
||||
}
|
||||
|
||||
public float GetHeight()
|
||||
{
|
||||
return (_localAvatarScaler != null) ? _localAvatarScaler.GetHeight() : -1f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Network Methods
|
||||
|
||||
public void OnNetworkAvatarInstantiated(PuppetMaster puppetMaster)
|
||||
{
|
||||
if (puppetMaster.avatarObject == null)
|
||||
return;
|
||||
|
||||
string playerId = puppetMaster._playerDescriptor.ownerId;
|
||||
|
||||
if (_networkedScalers.ContainsKey(playerId))
|
||||
_networkedScalers.Remove(playerId);
|
||||
|
||||
UniversalAvatarScaler scaler = puppetMaster.avatarObject.AddComponent<UniversalAvatarScaler>();
|
||||
scaler.Initialize(puppetMaster._initialAvatarHeight, puppetMaster.initialAvatarScale);
|
||||
_networkedScalers[playerId] = scaler;
|
||||
}
|
||||
|
||||
public void OnNetworkAvatarDestroyed(string playerId)
|
||||
{
|
||||
if (_networkedScalers.ContainsKey(playerId))
|
||||
_networkedScalers.Remove(playerId);
|
||||
}
|
||||
|
||||
public void OnNetworkHeightUpdateReceived(string playerId, float targetHeight)
|
||||
{
|
||||
if (_networkedScalers.TryGetValue(playerId, out UniversalAvatarScaler scaler))
|
||||
scaler.SetHeight(targetHeight);
|
||||
}
|
||||
|
||||
public float GetNetworkHeight(string playerId)
|
||||
{
|
||||
if (_networkedScalers.TryGetValue(playerId, out UniversalAvatarScaler scaler))
|
||||
return scaler.GetHeight();
|
||||
return -1f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue