refactor: moved a lot of player related scripts to the Reset.Units namespace
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
|
||||
public float lockonTargetRadius{ get; set; } = 1f;
|
||||
public bool lockonDebug{ get; set; } = false;
|
||||
@@ -14,3 +15,4 @@ public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
|
||||
OnTargetDelete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using ParadoxNotion.Serialization.FullSerializer;
|
||||
using UnityEngine;
|
||||
using Logger = ParadoxNotion.Services.Logger;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions {
|
||||
namespace Reset.Units {
|
||||
[Category("Reset")]
|
||||
public class UpdateObjectCameraTracking : ActionTask<LockOnManager> {
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class InputFinder : MonoBehaviour{
|
||||
public InputActionMap actionMap;
|
||||
|
||||
@@ -14,7 +15,7 @@ public class InputFinder : MonoBehaviour{
|
||||
}
|
||||
|
||||
public void AwaitNewInput(){
|
||||
GameManager.ClearCurrentController();
|
||||
PlayerManager.ClearCurrentController();
|
||||
|
||||
GetComponent<UIDocument>().enabled = true;
|
||||
actionMap.Enable();
|
||||
@@ -22,8 +23,7 @@ public class InputFinder : MonoBehaviour{
|
||||
|
||||
void InputPressed(InputAction.CallbackContext context){
|
||||
try {
|
||||
GameManager.AttachControllerToPlayer(context.control.device);
|
||||
Debug.Log(context.control.device);
|
||||
PlayerManager.AttachControllerToPlayer(context.control.device);
|
||||
} catch (Exception e) {
|
||||
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
|
||||
return;
|
||||
@@ -33,3 +33,4 @@ public class InputFinder : MonoBehaviour{
|
||||
actionMap.Disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Reset;
|
||||
using Reset.Core;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
@@ -13,6 +14,7 @@ using UnityEngine.UIElements;
|
||||
using Vector2 = UnityEngine.Vector2;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class LockOnManager : MonoBehaviour{
|
||||
public class ActiveLockOnTarget{
|
||||
public GameObject gameObject;
|
||||
@@ -30,9 +32,7 @@ public class LockOnManager : MonoBehaviour{
|
||||
[FormerlySerializedAs("smoothing")] public float smoothTime = 1f;
|
||||
|
||||
// Lock On Tracking
|
||||
[Space(10)]
|
||||
|
||||
public ActiveLockOnTarget mainTarget;
|
||||
[Space(10)] public ActiveLockOnTarget mainTarget;
|
||||
|
||||
public List<ActiveLockOnTarget> activeTargets = new List<ActiveLockOnTarget>();
|
||||
|
||||
@@ -56,8 +56,8 @@ public class LockOnManager : MonoBehaviour{
|
||||
// }
|
||||
|
||||
// References from camera
|
||||
targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||
lockOnDocument = GameManager.UI.transform.Find("Lock On").GetComponent<UIDocument>();
|
||||
targetGroup = PlayerManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||
lockOnDocument = UIManager.UI.transform.Find("Lock On").GetComponent<UIDocument>();
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
@@ -65,18 +65,17 @@ public class LockOnManager : MonoBehaviour{
|
||||
// Quick check for things in lock-on target that aren't lock-onable
|
||||
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
||||
mainTarget.gameObject.AddComponent<GenericLockOnTarget>();
|
||||
Debug.LogWarning($"The object <b>{mainTarget.gameObject.name}</b> has no ILockOnTarget interface. This isn't hyper critical, but adding one as a GenericLockOnTarget anyways.");
|
||||
Debug.LogWarning(
|
||||
$"The object <b>{mainTarget.gameObject.name}</b> has no ILockOnTarget interface. This isn't hyper critical, but adding one as a GenericLockOnTarget anyways.");
|
||||
}
|
||||
|
||||
elementRoot = lockOnDocument.rootVisualElement.Query<VisualElement>("LockOnGroup");
|
||||
elementLabelName = lockOnDocument.rootVisualElement.Query<Label>("LockOnName").First();
|
||||
|
||||
// Add all nearby game objects to lock-on eligible list
|
||||
GameObject[] allGameObjects = GameObject.FindObjectsByType<GameObject>(0, 0);
|
||||
GameObject[] allGameObjects = FindObjectsByType<GameObject>(0, 0);
|
||||
|
||||
foreach (GameObject thisObject in allGameObjects) {
|
||||
Debug.Log($"{thisObject.name}: {thisObject.GetComponent<ILockOnTarget>() != null}");
|
||||
|
||||
if (thisObject.GetComponent<ILockOnTarget>() != null) {
|
||||
acceptedTargets.Add(thisObject);
|
||||
}
|
||||
@@ -84,21 +83,24 @@ public class LockOnManager : MonoBehaviour{
|
||||
}
|
||||
|
||||
public void AttachCamera(GameObject target){
|
||||
targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||
Debug.Log($"{GameManager.Camera}");
|
||||
targetGroup = PlayerManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||
Debug.Log($"{PlayerManager.Camera}");
|
||||
|
||||
// Set the camera's target as the player
|
||||
targetGroup.Targets.Add(new CinemachineTargetGroup.Target{Object = target.transform, Radius = 3.5f, Weight = 1f});
|
||||
GameManager.Camera.transform.Find("Cinemachine").GetComponent<CinemachineCamera>().Target.TrackingTarget = target.transform;
|
||||
GameManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().PlayerInput =
|
||||
targetGroup.Targets.Add(new CinemachineTargetGroup.Target
|
||||
{ Object = target.transform, Radius = 3.5f, Weight = 1f });
|
||||
PlayerManager.Camera.transform.Find("Cinemachine").GetComponent<CinemachineCamera>().Target.TrackingTarget =
|
||||
target.transform;
|
||||
PlayerManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().PlayerInput =
|
||||
GetComponent<PlayerInput>();
|
||||
GameManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().AddEvents();
|
||||
PlayerManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().AddEvents();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
||||
mainTarget.gameObject.AddComponent<GenericLockOnTarget>();
|
||||
Debug.LogWarning($"The object <b>{mainTarget.gameObject.name}</b> has no ILockOnTarget interface. This isn't hyper critical, but adding one as a GenericLockOnTarget anyways.");
|
||||
Debug.LogWarning(
|
||||
$"The object <b>{mainTarget.gameObject.name}</b> has no ILockOnTarget interface. This isn't hyper critical, but adding one as a GenericLockOnTarget anyways.");
|
||||
}
|
||||
|
||||
// Iterate through targets, pushing their Target Group weight towards their goal weight, or removing them if they get too low.
|
||||
@@ -204,35 +206,54 @@ public class LockOnManager : MonoBehaviour{
|
||||
|
||||
// Skip the current target if one exists
|
||||
if (mainTarget != null && mainTarget.gameObject == target) {
|
||||
if (debugThisTarget){Debug.Log($"Not selected by {name}: I'm already the main target");}
|
||||
if (debugThisTarget) {
|
||||
Debug.Log($"Not selected by {name}: I'm already the main target");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip targets currently behind objects.
|
||||
Physics.Raycast(cameraTransform.position,
|
||||
cameraTransform.position.DirectionTo(target.transform.position + target.GetComponent<ILockOnTarget>().lockonRaycastVerticalOffset * Vector3.up), out RaycastHit hit);
|
||||
cameraTransform.position.DirectionTo(target.transform.position +
|
||||
target.GetComponent<ILockOnTarget>()
|
||||
.lockonRaycastVerticalOffset * Vector3.up),
|
||||
out RaycastHit hit);
|
||||
|
||||
if (hit.transform != target.transform) {
|
||||
if (debugThisTarget){Debug.Log($"Not selected by {name}: Line of sight to me is blocked by {hit.collider.gameObject.name}");}
|
||||
if (debugThisTarget) {
|
||||
Debug.Log(
|
||||
$"Not selected by {name}: Line of sight to me is blocked by {hit.collider.gameObject.name}");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skips targets too far
|
||||
if (Vector3.Distance(transform.position, target.transform.position) > lockOnRange) {
|
||||
if (debugThisTarget){Debug.Log($"Not selected by {name}: I'm too far! My distance is {Vector3.Distance(transform.position, target.transform.position)}");}
|
||||
if (debugThisTarget) {
|
||||
Debug.Log(
|
||||
$"Not selected by {name}: I'm too far! My distance is {Vector3.Distance(transform.position, target.transform.position)}");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip targets outside lock on angle
|
||||
float angleFromCameraForward = Vector3.Angle(cameraTransform.forward, cameraTransform.position.DirectionTo(target.transform.position));
|
||||
float angleFromCameraForward = Vector3.Angle(cameraTransform.forward,
|
||||
cameraTransform.position.DirectionTo(target.transform.position));
|
||||
if (angleFromCameraForward > lockOnMaxAngle) {
|
||||
if (debugThisTarget){Debug.Log($"Not selected by {name}: I'm not forward enough in front of the camera");}
|
||||
if (debugThisTarget) {
|
||||
Debug.Log($"Not selected by {name}: I'm not forward enough in front of the camera");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find how close this target is from the center of the screen
|
||||
Vector3 targetScreenPoint = Camera.main.WorldToScreenPoint(target.transform.position);
|
||||
float distanceFromScreenCenter = targetScreenPoint.Flatten(null, null, 0f).magnitude - new Vector3(Screen.width, Screen.height, 0f).magnitude / 2f;
|
||||
float distanceFromScreenCenter = targetScreenPoint.Flatten(null, null, 0f).magnitude -
|
||||
new Vector3(Screen.width, Screen.height, 0f).magnitude / 2f;
|
||||
distanceFromScreenCenter = Mathf.Abs(distanceFromScreenCenter);
|
||||
|
||||
// Debug.Log($"{target.name}: {distanceFromScreenCenter} pixels, {angleFromCameraForward} degrees");
|
||||
@@ -278,7 +299,8 @@ public class LockOnManager : MonoBehaviour{
|
||||
elementLabelName.text = mainTarget.gameObject.name;
|
||||
|
||||
// Set position (add the width/height of the element)
|
||||
elementRoot.style.top = new StyleLength(screenPos.y - 25f); // Was elementRoot.resolvedStyle.height * .7f
|
||||
elementRoot.style.top =
|
||||
new StyleLength(screenPos.y - 25f); // Was elementRoot.resolvedStyle.height * .7f
|
||||
elementRoot.style.left = new StyleLength(screenPos.x - elementRoot.resolvedStyle.width / 2f);
|
||||
|
||||
// Set enabled
|
||||
@@ -288,3 +310,5 @@ public class LockOnManager : MonoBehaviour{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Reset;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Netcode;
|
||||
using Unity.Netcode.Transports.UTP;
|
||||
@@ -17,7 +18,7 @@ public class SessionManager : MonoBehaviour{
|
||||
|
||||
}
|
||||
|
||||
public void StartOfflineSession(){
|
||||
public void StartSession(){
|
||||
Instantiate(playerPrefab);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,29 +6,28 @@ using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Users;
|
||||
|
||||
namespace Reset{
|
||||
public static class GameManager{
|
||||
public static GameObject UI;
|
||||
namespace Reset.Units{
|
||||
public static class PlayerManager{
|
||||
|
||||
public static GameObject Camera;
|
||||
public static GameObject Input;
|
||||
public static SessionManager Session;
|
||||
|
||||
private static GameObject player;
|
||||
private static GameObject _player;
|
||||
|
||||
public static GameObject Player{
|
||||
get{ return player; }
|
||||
set{ player = value; }
|
||||
get{ return _player; }
|
||||
set{ _player = value; }
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void Reset(){
|
||||
player = null;
|
||||
Player = null;
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void PopulateSceneReferences(){
|
||||
static void PopulatePlayerSceneReferences(){
|
||||
try {
|
||||
UI = GameObject.Find("UICanvas");
|
||||
Camera = GameObject.Find("CameraGroup");
|
||||
Input = GameObject.Find("InputManager");
|
||||
} catch (Exception e) {
|
||||
@@ -43,7 +42,9 @@ namespace Reset{
|
||||
}
|
||||
|
||||
InputUser playerUser = Player.GetComponent<PlayerInput>().user;
|
||||
|
||||
playerUser = InputUser.PerformPairingWithDevice(device, playerUser, InputUserPairingOptions.UnpairCurrentDevicesFromUser);
|
||||
Debug.Log($"Attached {device.displayName} to {Player}");
|
||||
}
|
||||
|
||||
public static GameObject FindNewPlayer(){
|
||||
@@ -55,7 +55,7 @@ namespace Reset.Core.Tools{
|
||||
}
|
||||
|
||||
void Start(){
|
||||
canvasRootGameObject = GameManager.UI;
|
||||
canvasRootGameObject = UIManager.UI;
|
||||
root = canvasRootGameObject.transform.Find("Debug Overlay").GetComponent<UIDocument>();
|
||||
|
||||
SetCurrentPageVisible();
|
||||
|
||||
20
Assets/Scripts/Core/UIManager.cs
Normal file
20
Assets/Scripts/Core/UIManager.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Core{
|
||||
public class UIManager{
|
||||
public static GameObject UI;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void PopulateUISceneReferences(){
|
||||
try {
|
||||
UI = GameObject.Find("UICanvas");
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/Core/UIManager.cs.meta
Normal file
3
Assets/Scripts/Core/UIManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e4068f140fc43378708cf682bf60ca0
|
||||
timeCreated: 1759875321
|
||||
@@ -2,10 +2,11 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Reset.Core.Tools;
|
||||
using Reset.Units;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class UnitCombat : MonoBehaviour{
|
||||
public class UnitCombat : UnitComponent {
|
||||
public List<Collider> draggedUnits = new List<Collider>();
|
||||
|
||||
private UnitMovementHandler movement;
|
||||
|
||||
13
Assets/Scripts/Units/Combat/UnitComponent.cs
Normal file
13
Assets/Scripts/Units/Combat/UnitComponent.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Unity.Netcode;
|
||||
|
||||
public class UnitComponent : NetworkBehaviour{
|
||||
private bool enabledAsHost = true;
|
||||
|
||||
void DisableComponents(){
|
||||
enabledAsHost = false;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Units/Combat/UnitComponent.cs.meta
Normal file
3
Assets/Scripts/Units/Combat/UnitComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fcd80e1ad994ff4976dcaf3a6564c87
|
||||
timeCreated: 1759768163
|
||||
@@ -45,11 +45,6 @@ namespace Reset.Units{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
GetComponent<IKillable>().DrawHealthDebug();
|
||||
lockonDebug = true;
|
||||
}
|
||||
|
||||
public float maxHealth{ get; set; }
|
||||
public float currentHealth{ get; set; }
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Reset.Units{
|
||||
|
||||
private void SetMaxHealth(){
|
||||
if (maxHealth == 0f) {
|
||||
Debug.LogError($"Max health is not set for type of <b>{((object)this)}</b>. Setting to 10000.");
|
||||
Debug.LogError($"Max health is not set for <b>{((MonoBehaviour)this).name}</b>. Setting to 10000.");
|
||||
currentHealth = 10000f;
|
||||
} else {
|
||||
currentHealth = maxHealth;
|
||||
|
||||
@@ -10,6 +10,7 @@ using Sirenix.OdinInspector;
|
||||
using Sirenix.Serialization;
|
||||
using Unity.Netcode;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class Player : Unit, IKillable{
|
||||
[HideInInspector] public PlayerControls controls;
|
||||
|
||||
@@ -17,18 +18,34 @@ public class Player : Unit, IKillable{
|
||||
float IKillable.currentHealth{ get; set; }
|
||||
|
||||
void Awake(){
|
||||
GameManager.Player = gameObject;
|
||||
controls = GetComponent<PlayerControls>();
|
||||
}
|
||||
|
||||
public void Attach(){
|
||||
name = "Player";
|
||||
name += IsLocalPlayer ? ", Local" : ", Network";
|
||||
|
||||
if (IsLocalPlayer || !UnitIsNetworked()) { //
|
||||
PlayerManager.Player = gameObject;
|
||||
|
||||
Debug.Log($"Player is set to {PlayerManager.Player.name}");
|
||||
PlayerManager.RequestNewController();
|
||||
GetComponent<LockOnManager>().AttachCamera(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UnitStart(){
|
||||
base.UnitStart();
|
||||
|
||||
Attach();
|
||||
((IKillable)this).IKillableInitialize();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
protected override void Update(){
|
||||
base.Update();
|
||||
|
||||
GetComponent<IKillable>().DrawHealthDebug();
|
||||
Debug.Log(PlayerManager.Player);
|
||||
}
|
||||
|
||||
public void TakeDamage(DamageSource[] sources){
|
||||
@@ -50,3 +67,4 @@ public class Player : Unit, IKillable{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Units{
|
||||
public interface ILockOnTarget{
|
||||
public float lockonTargetRadius{ set; get; }
|
||||
public bool lockonDebug{ set; get; }
|
||||
@@ -25,7 +26,8 @@ public interface ILockOnTarget {
|
||||
upValue = 4f;
|
||||
}
|
||||
|
||||
Vector3 reticlePosition = new Vector3(transform.position.x, transform.position.y + upValue, transform.position.z);
|
||||
Vector3 reticlePosition =
|
||||
new Vector3(transform.position.x, transform.position.y + upValue, transform.position.z);
|
||||
|
||||
return reticlePosition;
|
||||
}
|
||||
@@ -34,7 +36,8 @@ public interface ILockOnTarget {
|
||||
// gameObject.
|
||||
foreach (LockOnManager.ActiveLockOnTarget target in LockOnManager.Instance.activeTargets) {
|
||||
if (target.gameObject == this.gameObject) {
|
||||
GameObject clone = new GameObject{name = $"Target Clone of {gameObject.name}", transform = { position = transform.position}};
|
||||
GameObject clone = new GameObject
|
||||
{ name = $"Target Clone of {gameObject.name}", transform = { position = transform.position } };
|
||||
|
||||
target.gameObject = clone;
|
||||
target.cinemachineTarget.Object = clone.transform;
|
||||
@@ -44,6 +47,7 @@ public interface ILockOnTarget {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerCamera : MonoBehaviour{
|
||||
void Start(){
|
||||
|
||||
@@ -8,6 +8,7 @@ using NodeCanvas;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion;
|
||||
using Reset;
|
||||
using Reset.Units;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Cinemachine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -1,50 +1,80 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using Drawing;
|
||||
using Reset;
|
||||
using Reset.Units;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class Unit : NetworkBehaviour{
|
||||
public virtual void Start(){
|
||||
UnitStart();
|
||||
}
|
||||
|
||||
public virtual void UnitStart(){
|
||||
OnlineStart();
|
||||
public virtual async void UnitStart(){
|
||||
try {
|
||||
var netWaitResult = await WaitForNetwork();
|
||||
|
||||
if (netWaitResult) {
|
||||
|
||||
}
|
||||
|
||||
protected void OnlineStart(){
|
||||
if (!NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost) {
|
||||
Attach();
|
||||
} else {
|
||||
StartCoroutine(WaitForOnline());
|
||||
// OnlineStart();
|
||||
Debug.Log("Done");
|
||||
} catch {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator WaitForOnline(){
|
||||
while (!NetworkManager.Singleton.didAwake) {
|
||||
Debug.Log("waiting");
|
||||
yield return null;
|
||||
public async Task<bool> WaitForNetwork(){
|
||||
while (!NetworkManager.Singleton.IsConnectedClient) {
|
||||
await Awaitable.NextFrameAsync();
|
||||
}
|
||||
|
||||
// Debug.Log($"{IsHost}, {IsClient}, {IsLocalPlayer}");
|
||||
if (IsLocalPlayer){
|
||||
GameManager.Player = gameObject;
|
||||
Attach();
|
||||
return (NetworkManager.Singleton.IsConnectedClient);
|
||||
}
|
||||
|
||||
public bool UnitIsNetworked(){
|
||||
return NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsHost;
|
||||
}
|
||||
|
||||
public bool UnitIsLocal(){
|
||||
if (UnitIsNetworked()) {
|
||||
return IsOwner;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void Update(){
|
||||
UpdateGizmos();
|
||||
|
||||
if (GetComponent<IKillable>() != null) {
|
||||
GetComponent<IKillable>().DrawHealthDebug();
|
||||
}
|
||||
}
|
||||
|
||||
public void Attach(){
|
||||
if (GameManager.Player == gameObject){
|
||||
GameManager.RequestNewController();
|
||||
GetComponent<LockOnManager>().AttachCamera(gameObject);
|
||||
}
|
||||
void UpdateGizmos(){
|
||||
string onlineStatus = "Not Online";
|
||||
Color onlineColor = Color.gray;
|
||||
|
||||
if (UnitIsNetworked() && UnitIsLocal()) {
|
||||
onlineStatus = "Online, Owned";
|
||||
onlineColor = Color.mediumSeaGreen;
|
||||
} else if (UnitIsNetworked() && !IsSpawned) {
|
||||
onlineStatus = "Not Spawned";
|
||||
} else if (UnitIsNetworked()) {
|
||||
onlineStatus = "Online, Not Owned";
|
||||
onlineColor = Color.gold;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
|
||||
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor);
|
||||
}
|
||||
|
||||
protected override void OnNetworkPostSpawn(){
|
||||
// GetComponent<LockOnManager>().AttachCamera(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user