feat: basic online working with relay

This commit is contained in:
Chris
2025-09-03 19:37:27 -04:00
parent 5be9c06cf2
commit a13f10564b
11 changed files with 299 additions and 75 deletions

View File

@@ -1,26 +1,55 @@
using System;
using System.Collections;
using Reset;
using Reset.Core.Tools;
using UnityEngine;
using Sirenix.OdinInspector;
using Unity.Netcode;
public class Player : MonoBehaviour{
public class Player : NetworkBehaviour{
[HideInInspector] public PlayerControls controls;
[HideInInspector] public new PlayerCamera camera;
void Awake(){
GameManager.Player = gameObject;
controls = GetComponent<PlayerControls>();
GameManager.RequestNewController();
}
void Start()
{
Debug.Log(GameManager.Player);
if (!NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost) {
Attach();
} else {
StartCoroutine(WaitForOnline());
}
}
private IEnumerator WaitForOnline(){
while (!NetworkManager.Singleton.didAwake) {
Debug.Log("waiting");
yield return null;
}
// Debug.Log($"{IsHost}, {IsClient}, {IsLocalPlayer}");
if (IsLocalPlayer){
GameManager.Player = gameObject;
Attach();
}
}
public void Attach(){
if (GameManager.Player == gameObject){
GameManager.RequestNewController();
GetComponent<LockOnManager>().AttachCamera(gameObject);
}
}
protected override void OnNetworkPostSpawn(){
// GetComponent<LockOnManager>().AttachCamera(gameObject);
}
// Update is called once per frame
void Update()
{