2022-08-21 04:40:05 +02:00
|
|
|
using Unity.Netcode;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem.XR;
|
|
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
2022-08-29 02:53:00 +02:00
|
|
|
using Unity.XR.CoreUtils;
|
2022-08-21 04:40:05 +02:00
|
|
|
|
|
|
|
public class NetworkPlayer : NetworkBehaviour
|
|
|
|
{
|
2022-08-27 02:19:29 +02:00
|
|
|
public Vector2 Player1Position = new Vector2(-0.6f, 0.5f);
|
|
|
|
public Vector2 Player2Position = new Vector2(0.6f, 0.5f);
|
|
|
|
public Material MaterialP1 = null;
|
|
|
|
public Material MaterialP2 = null;
|
|
|
|
public float HandHueShift = 0.2f;
|
2022-08-21 04:40:05 +02:00
|
|
|
public override void OnNetworkSpawn()
|
|
|
|
{
|
|
|
|
DisableClientInput();
|
2022-08-27 02:19:29 +02:00
|
|
|
SetMaterials();
|
2022-08-21 04:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void DisableClientInput()
|
|
|
|
{
|
2022-08-27 02:19:29 +02:00
|
|
|
|
2022-08-26 22:06:45 +02:00
|
|
|
if (!IsOwner)
|
2022-08-21 04:40:05 +02:00
|
|
|
{
|
2022-08-29 02:53:00 +02:00
|
|
|
var clientXROrigin = GetComponent<XROrigin>();
|
|
|
|
var clientLocomotion = GetComponent<LocomotionSystem>();
|
2022-08-21 04:40:05 +02:00
|
|
|
var clientMoveProvider = GetComponent<ActionBasedContinuousMoveProvider>();
|
|
|
|
var clientTurnProvider = GetComponent<ActionBasedContinuousTurnProvider>();
|
|
|
|
var clientControllers = GetComponentsInChildren<ActionBasedController>();
|
|
|
|
var clientRays = GetComponentsInChildren<RayManager>();
|
2022-08-22 04:21:51 +02:00
|
|
|
var clientHaptics = GetComponentsInChildren<ControllerHapticManager>();
|
2022-08-21 04:40:05 +02:00
|
|
|
var clientHead = GetComponentInChildren<TrackedPoseDriver>();
|
|
|
|
var clientCamera = GetComponentInChildren<Camera>();
|
|
|
|
var clientAudioListener = GetComponentInChildren<AudioListener>();
|
|
|
|
var clientLIV = GetComponent<LIV.SDK.Unity.LIV>();
|
2022-08-29 02:53:00 +02:00
|
|
|
var clientWindowEncoder = GetComponent<WindowEncoder>();
|
2022-08-21 04:40:05 +02:00
|
|
|
//var clientOVRManager = gameObject.transform.Find("OVRManager").gameObject;
|
|
|
|
|
2022-08-29 02:53:00 +02:00
|
|
|
clientXROrigin.enabled = false;
|
|
|
|
clientLocomotion.enabled = false;
|
2022-08-21 04:40:05 +02:00
|
|
|
clientCamera.enabled = false;
|
|
|
|
clientAudioListener.enabled = false;
|
|
|
|
clientMoveProvider.enabled = false;
|
|
|
|
clientTurnProvider.enabled = false;
|
|
|
|
clientHead.enabled = false;
|
2022-08-29 02:53:00 +02:00
|
|
|
clientLIV.enabled = false;
|
|
|
|
clientWindowEncoder.enabled = false;
|
2022-08-21 04:40:05 +02:00
|
|
|
foreach (var ray in clientRays)
|
|
|
|
{
|
|
|
|
ray.RaySwitch = false;
|
|
|
|
}
|
|
|
|
foreach (var controller in clientControllers)
|
|
|
|
{
|
|
|
|
controller.enabled = false;
|
|
|
|
}
|
2022-08-22 04:21:51 +02:00
|
|
|
foreach (var haptic in clientHaptics)
|
|
|
|
{
|
2022-08-26 22:06:45 +02:00
|
|
|
Destroy(haptic);
|
2022-08-22 04:21:51 +02:00
|
|
|
}
|
2022-08-21 04:40:05 +02:00
|
|
|
clientLIV.enabled = false;
|
|
|
|
//clientOVRManager.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
2022-08-27 02:19:29 +02:00
|
|
|
private void SetMaterials()
|
|
|
|
{
|
2022-08-29 02:53:00 +02:00
|
|
|
var HeadRenderer = transform.Find("Camera Offset").Find("Main Camera").Find("HeadCube").gameObject.GetComponent<Renderer>();
|
2022-08-27 02:19:29 +02:00
|
|
|
var LHandMat = transform.Find("Camera Offset").Find("LeftHand Controller").Find("LHand").GetComponent<Renderer>().material;
|
|
|
|
var RHandMat = transform.Find("Camera Offset").Find("RightHand Controller").Find("RHand").GetComponent<Renderer>().material;
|
|
|
|
if (IsOwnedByServer)
|
|
|
|
{
|
2022-08-29 02:53:00 +02:00
|
|
|
HeadRenderer.material = MaterialP1;
|
2022-08-27 02:19:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-29 02:53:00 +02:00
|
|
|
HeadRenderer.material = MaterialP2;
|
2022-08-27 02:19:29 +02:00
|
|
|
float LH, LS, LV; float RH, RS, RV;
|
|
|
|
Color.RGBToHSV(LHandMat.color, out LH, out LS, out LV);
|
|
|
|
Color.RGBToHSV(RHandMat.color, out RH, out RS, out RV);
|
2022-08-27 02:28:53 +02:00
|
|
|
var LColor = Color.HSVToRGB(LH + HandHueShift, RS, RV);
|
|
|
|
var RColor = Color.HSVToRGB(RH + HandHueShift, RS, RV);
|
|
|
|
LColor.a = LHandMat.color.a; RColor.a = RHandMat.color.a;
|
|
|
|
LHandMat.color = LColor;
|
|
|
|
RHandMat.color = RColor;
|
2022-08-27 02:19:29 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-21 04:40:05 +02:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
if (IsHost)
|
|
|
|
{
|
2022-08-29 02:53:00 +02:00
|
|
|
transform.position = new Vector3(Player1Position.x, transform.position.y, transform.position.z + Player1Position.y);
|
2022-08-21 04:40:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-27 02:19:29 +02:00
|
|
|
transform.position = new Vector3(Player2Position.x, transform.position.y, transform.position.z + Player2Position.y);
|
2022-08-21 04:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|