1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-12-18 11:55:52 +01:00
MaiDXR/Assets/Scripts/Networks/NetworkPlayer.cs

64 lines
2.2 KiB
C#
Raw Normal View History

2022-08-21 04:40:05 +02:00
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem.XR;
using UnityEngine.XR.Interaction.Toolkit;
public class NetworkPlayer : NetworkBehaviour
{
2022-08-22 04:21:51 +02:00
public Vector2 Player1Position = new Vector2(-0.75f, 0);
public Vector2 Player2Position = new Vector2(0.75f, 0);
2022-08-21 04:40:05 +02:00
public override void OnNetworkSpawn()
{
//base.OnNetworkSpawn();
DisableClientInput();
}
private void DisableClientInput()
{
if (!IsOwner)
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>();
//var clientOVRManager = gameObject.transform.Find("OVRManager").gameObject;
clientCamera.enabled = false;
clientAudioListener.enabled = false;
clientMoveProvider.enabled = false;
clientTurnProvider.enabled = false;
clientHead.enabled = false;
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)
{
Destroy(haptic);
2022-08-22 04:21:51 +02:00
}
2022-08-21 04:40:05 +02:00
clientLIV.enabled = false;
//clientOVRManager.SetActive(false);
}
}
private void Start()
{
if (IsHost)
{
transform.position = new Vector3(Player1Position.x, transform.position.y, Player1Position.y);
}
else
{
transform.position = new Vector3(Player2Position.x, transform.position.y, Player2Position.y);
}
}
}