108 lines
2.5 KiB
C#
108 lines
2.5 KiB
C#
using HurricaneVR.Framework.Components;
|
|
using HurricaneVR.Framework.Core.Player;
|
|
using Meta.XR.MultiplayerBlocks.NGO;
|
|
using Sirenix.OdinInspector;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.Netcode;
|
|
using Unity.Netcode.Components;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
public class PlayerComponent : NetworkBehaviour
|
|
{
|
|
[SerializeField]
|
|
private NetworkObject networkObject;
|
|
|
|
[SerializeField]
|
|
private HVRTeleporter teleporter;
|
|
|
|
[SerializeField]
|
|
private HVRPlayerController controller;
|
|
|
|
[SerializeField]
|
|
private CharacterController characterController;
|
|
|
|
[ReadOnly]
|
|
[SerializeField]
|
|
private float fadeDuration = 2f;
|
|
|
|
public Vector3 Position
|
|
{
|
|
get { return controller.transform.position; }
|
|
}
|
|
|
|
public Vector3 Rotation
|
|
{
|
|
get { return controller.transform.eulerAngles; }
|
|
}
|
|
|
|
public override void OnNetworkSpawn()
|
|
{
|
|
base.OnNetworkSpawn();
|
|
|
|
name = $"Player - {networkObject.OwnerClientId}"
|
|
+ (networkObject.IsLocalPlayer ? " (local)" : "");
|
|
|
|
if (!networkObject.IsOwner)
|
|
{
|
|
StartCoroutine(DestroyMultiplayerComponents());
|
|
}
|
|
}
|
|
|
|
private IEnumerator DestroyMultiplayerComponents()
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
DestroyDependencies();
|
|
|
|
foreach (var t in new[]
|
|
{
|
|
typeof(UniversalAdditionalCameraData),
|
|
})
|
|
{
|
|
foreach (var component in GetComponentsInChildren(t))
|
|
{
|
|
Destroy(component);
|
|
}
|
|
}
|
|
|
|
controller.RemoveMultiplayerComponents();
|
|
}
|
|
|
|
public void DestroyDependencies()
|
|
{
|
|
Destroy(controller.RightHand.ForceGrabber._anchor.gameObject);
|
|
Destroy(controller.LeftHand.ForceGrabber._anchor.gameObject);
|
|
Destroy(controller.LeftHand._anchor);
|
|
Destroy(controller.RightHand._anchor);
|
|
}
|
|
|
|
public void DestroyWithDependencies()
|
|
{
|
|
DestroyDependencies();
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void Teleport(Vector3 position, Vector3 direction)
|
|
{
|
|
teleporter.Teleport(position, direction);
|
|
}
|
|
|
|
public void FadeScreen(float to, float duration)
|
|
{
|
|
controller.ScreenFader.Fade(to, duration);
|
|
}
|
|
|
|
public void FadeIn()
|
|
{
|
|
controller.ScreenFader.Fade(1, fadeDuration);
|
|
}
|
|
|
|
public void FadeOut()
|
|
{
|
|
controller.ScreenFader.Fade(0, fadeDuration);
|
|
}
|
|
}
|