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

59 lines
2.0 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
{
public Vector2 Player1Position = new Vector2(-1f, 0);
public Vector2 Player2Position = new Vector2(1f, 0);
public override void OnNetworkSpawn()
{
//base.OnNetworkSpawn();
DisableClientInput();
}
private void DisableClientInput()
{
if (!IsOwner && IsClient)
{
var clientMoveProvider = GetComponent<ActionBasedContinuousMoveProvider>();
var clientTurnProvider = GetComponent<ActionBasedContinuousTurnProvider>();
var clientControllers = GetComponentsInChildren<ActionBasedController>();
var clientRays = GetComponentsInChildren<RayManager>();
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;
}
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);
}
}
}