Added Proximity to NetworkedAnimator
This commit is contained in:
parent
cf4db381b7
commit
368d719201
@ -1,16 +1,20 @@
|
|||||||
using System.IO;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MLAPI.MonoBehaviours.Prototyping
|
namespace MLAPI.MonoBehaviours.Prototyping
|
||||||
{
|
{
|
||||||
public class NetworkedAnimator : NetworkedBehaviour
|
public class NetworkedAnimator : NetworkedBehaviour
|
||||||
{
|
{
|
||||||
|
public bool EnableProximity = false;
|
||||||
|
public float ProximityRange = 50f;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Animator _animator;
|
private Animator _animator;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private uint parameterSendBits;
|
private uint parameterSendBits;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float sendRate = 0.1f;
|
private readonly float sendRate = 0.1f;
|
||||||
private AnimatorControllerParameter[] animatorParameters;
|
private AnimatorControllerParameter[] animatorParameters;
|
||||||
|
|
||||||
private int animationHash;
|
private int animationHash;
|
||||||
@ -98,7 +102,18 @@ namespace MLAPI.MonoBehaviours.Prototyping
|
|||||||
}
|
}
|
||||||
if(isServer)
|
if(isServer)
|
||||||
{
|
{
|
||||||
SendToNonLocalClientsTarget("MLAPI_HandleAnimationMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
if(EnableProximity)
|
||||||
|
{
|
||||||
|
List<int> clientsInProximity = new List<int>();
|
||||||
|
foreach (KeyValuePair<int, NetworkedClient> client in NetworkingManager.singleton.connectedClients)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(transform.position, client.Value.PlayerObject.transform.position) <= ProximityRange)
|
||||||
|
clientsInProximity.Add(client.Key);
|
||||||
|
}
|
||||||
|
SendToClientsTarget(clientsInProximity ,"MLAPI_HandleAnimationMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendToNonLocalClientsTarget("MLAPI_HandleAnimationMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -156,7 +171,18 @@ namespace MLAPI.MonoBehaviours.Prototyping
|
|||||||
}
|
}
|
||||||
if (isServer)
|
if (isServer)
|
||||||
{
|
{
|
||||||
SendToNonLocalClientsTarget("MLAPI_HandleAnimationParameterMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
if (EnableProximity)
|
||||||
|
{
|
||||||
|
List<int> clientsInProximity = new List<int>();
|
||||||
|
foreach (KeyValuePair<int, NetworkedClient> client in NetworkingManager.singleton.connectedClients)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(transform.position, client.Value.PlayerObject.transform.position) <= ProximityRange)
|
||||||
|
clientsInProximity.Add(client.Key);
|
||||||
|
}
|
||||||
|
SendToClientsTarget(clientsInProximity, "MLAPI_HandleAnimationParameterMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendToNonLocalClientsTarget("MLAPI_HandleAnimationParameterMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -196,7 +222,18 @@ namespace MLAPI.MonoBehaviours.Prototyping
|
|||||||
|
|
||||||
if(isServer)
|
if(isServer)
|
||||||
{
|
{
|
||||||
SendToNonLocalClientsTarget("MLAPI_HandleAnimationMessage", "MLAPI_ANIMATION_UPDATE", data);
|
if (EnableProximity)
|
||||||
|
{
|
||||||
|
List<int> clientsInProximity = new List<int>();
|
||||||
|
foreach (KeyValuePair<int, NetworkedClient> client in NetworkingManager.singleton.connectedClients)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(transform.position, client.Value.PlayerObject.transform.position) <= ProximityRange)
|
||||||
|
clientsInProximity.Add(client.Key);
|
||||||
|
}
|
||||||
|
SendToClientsTarget(clientsInProximity, "MLAPI_HandleAnimationMessage", "MLAPI_ANIMATION_UPDATE", data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendToNonLocalClientsTarget("MLAPI_HandleAnimationMessage", "MLAPI_ANIMATION_UPDATE", data);
|
||||||
}
|
}
|
||||||
using(MemoryStream stream = new MemoryStream(data))
|
using(MemoryStream stream = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
@ -217,7 +254,18 @@ namespace MLAPI.MonoBehaviours.Prototyping
|
|||||||
{
|
{
|
||||||
if (isServer)
|
if (isServer)
|
||||||
{
|
{
|
||||||
SendToNonLocalClientsTarget("MLAPI_HandleAnimationParameterMessage", "MLAPI_ANIMATION_UPDATE", data);
|
if (EnableProximity)
|
||||||
|
{
|
||||||
|
List<int> clientsInProximity = new List<int>();
|
||||||
|
foreach (KeyValuePair<int, NetworkedClient> client in NetworkingManager.singleton.connectedClients)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(transform.position, client.Value.PlayerObject.transform.position) <= ProximityRange)
|
||||||
|
clientsInProximity.Add(client.Key);
|
||||||
|
}
|
||||||
|
SendToClientsTarget(clientsInProximity, "MLAPI_HandleAnimationParameterMessage", "MLAPI_ANIMATION_UPDATE", data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendToNonLocalClientsTarget("MLAPI_HandleAnimationParameterMessage", "MLAPI_ANIMATION_UPDATE", data);
|
||||||
}
|
}
|
||||||
using (MemoryStream stream = new MemoryStream(data))
|
using (MemoryStream stream = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
@ -232,7 +280,18 @@ namespace MLAPI.MonoBehaviours.Prototyping
|
|||||||
{
|
{
|
||||||
if (isServer)
|
if (isServer)
|
||||||
{
|
{
|
||||||
SendToNonLocalClientsTarget("MLAPI_HandleAnimationTriggerMessage", "MLAPI_ANIMATION_UPDATE", data);
|
if (EnableProximity)
|
||||||
|
{
|
||||||
|
List<int> clientsInProximity = new List<int>();
|
||||||
|
foreach (KeyValuePair<int, NetworkedClient> client in NetworkingManager.singleton.connectedClients)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(transform.position, client.Value.PlayerObject.transform.position) <= ProximityRange)
|
||||||
|
clientsInProximity.Add(client.Key);
|
||||||
|
}
|
||||||
|
SendToClientsTarget(clientsInProximity, "MLAPI_HandleAnimationTriggerMessage", "MLAPI_ANIMATION_UPDATE", data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendToNonLocalClientsTarget("MLAPI_HandleAnimationTriggerMessage", "MLAPI_ANIMATION_UPDATE", data);
|
||||||
}
|
}
|
||||||
using (MemoryStream stream = new MemoryStream(data))
|
using (MemoryStream stream = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
@ -331,7 +390,18 @@ namespace MLAPI.MonoBehaviours.Prototyping
|
|||||||
}
|
}
|
||||||
if (isServer)
|
if (isServer)
|
||||||
{
|
{
|
||||||
SendToNonLocalClientsTarget("MLAPI_HandleAnimationTriggerMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
if (EnableProximity)
|
||||||
|
{
|
||||||
|
List<int> clientsInProximity = new List<int>();
|
||||||
|
foreach (KeyValuePair<int, NetworkedClient> client in NetworkingManager.singleton.connectedClients)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(transform.position, client.Value.PlayerObject.transform.position) <= ProximityRange)
|
||||||
|
clientsInProximity.Add(client.Key);
|
||||||
|
}
|
||||||
|
SendToClientsTarget(clientsInProximity, "MLAPI_HandleAnimationTriggerMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendToNonLocalClientsTarget("MLAPI_HandleAnimationTriggerMessage", "MLAPI_ANIMATION_UPDATE", stream.ToArray());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user