EVERYTHING
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Photon.VR.Player;
|
||||
using UnityEngine;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class GetNearestPlayerBehavior : GuardedValueNodeBehavior
|
||||
{
|
||||
protected override void Start()
|
||||
{
|
||||
RecomputeCore();
|
||||
}
|
||||
|
||||
public override void OnGraphUpdate()
|
||||
{
|
||||
RecomputeCore();
|
||||
}
|
||||
|
||||
protected override void RecomputeCore()
|
||||
{
|
||||
int num = ((GetInputValue("From").Normalize().Kind == BSValueKind.None) ? NodePlayerUtility.ResolveLocalPlayerId() : GetInputPlayerId("From"));
|
||||
Transform transform = NodePlayerUtility.ResolveHeadTransform(NodePlayerUtility.ResolvePlayer(num));
|
||||
if (transform == null)
|
||||
{
|
||||
SetLocalOutputValueIfChanged("Player", BSValue.None);
|
||||
return;
|
||||
}
|
||||
PhotonVRPlayer[] array = Object.FindObjectsByType<PhotonVRPlayer>(FindObjectsInactive.Include);
|
||||
float num2 = float.PositiveInfinity;
|
||||
int num3 = 0;
|
||||
Vector3 position = transform.position;
|
||||
foreach (PhotonVRPlayer photonVRPlayer in array)
|
||||
{
|
||||
if (photonVRPlayer == null || photonVRPlayer.photonView == null || photonVRPlayer.photonView.Owner == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int actorNumber = photonVRPlayer.photonView.Owner.ActorNumber;
|
||||
if (actorNumber <= 0 || actorNumber == num)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Transform transform2 = NodePlayerUtility.ResolveHeadTransform(photonVRPlayer);
|
||||
if (!(transform2 == null))
|
||||
{
|
||||
float num4 = Vector3.SqrMagnitude(transform2.position - position);
|
||||
if (num4 < num2)
|
||||
{
|
||||
num2 = num4;
|
||||
num3 = actorNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
SetLocalOutputValueIfChanged("Player", (num3 > 0) ? BSValue.FromPlayer(num3) : BSValue.None);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user