refactor: moved a lot of player related scripts to the Reset.Units namespace
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
|
namespace Reset.Units{
|
||||||
|
public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
|
||||||
public float lockonTargetRadius{ get; set; } = 1f;
|
public float lockonTargetRadius{ get; set; } = 1f;
|
||||||
public bool lockonDebug{ get; set; } = false;
|
public bool lockonDebug{ get; set; } = false;
|
||||||
public float lockonRaycastVerticalOffset{ get; set; }
|
public float lockonRaycastVerticalOffset{ get; set; }
|
||||||
@@ -13,4 +14,5 @@ public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
|
|||||||
void OnDestroy(){
|
void OnDestroy(){
|
||||||
OnTargetDelete();
|
OnTargetDelete();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using ParadoxNotion.Serialization.FullSerializer;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = ParadoxNotion.Services.Logger;
|
using Logger = ParadoxNotion.Services.Logger;
|
||||||
|
|
||||||
namespace NodeCanvas.Tasks.Actions {
|
namespace Reset.Units {
|
||||||
[Category("Reset")]
|
[Category("Reset")]
|
||||||
public class UpdateObjectCameraTracking : ActionTask<LockOnManager> {
|
public class UpdateObjectCameraTracking : ActionTask<LockOnManager> {
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ using UnityEngine;
|
|||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
public class InputFinder : MonoBehaviour{
|
namespace Reset.Units{
|
||||||
|
public class InputFinder : MonoBehaviour{
|
||||||
public InputActionMap actionMap;
|
public InputActionMap actionMap;
|
||||||
|
|
||||||
void Start(){
|
void Start(){
|
||||||
@@ -14,7 +15,7 @@ public class InputFinder : MonoBehaviour{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void AwaitNewInput(){
|
public void AwaitNewInput(){
|
||||||
GameManager.ClearCurrentController();
|
PlayerManager.ClearCurrentController();
|
||||||
|
|
||||||
GetComponent<UIDocument>().enabled = true;
|
GetComponent<UIDocument>().enabled = true;
|
||||||
actionMap.Enable();
|
actionMap.Enable();
|
||||||
@@ -22,8 +23,7 @@ public class InputFinder : MonoBehaviour{
|
|||||||
|
|
||||||
void InputPressed(InputAction.CallbackContext context){
|
void InputPressed(InputAction.CallbackContext context){
|
||||||
try {
|
try {
|
||||||
GameManager.AttachControllerToPlayer(context.control.device);
|
PlayerManager.AttachControllerToPlayer(context.control.device);
|
||||||
Debug.Log(context.control.device);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
|
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
|
||||||
return;
|
return;
|
||||||
@@ -32,4 +32,5 @@ public class InputFinder : MonoBehaviour{
|
|||||||
GetComponent<UIDocument>().enabled = false;
|
GetComponent<UIDocument>().enabled = false;
|
||||||
actionMap.Disable();
|
actionMap.Disable();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Reset;
|
using Reset;
|
||||||
|
using Reset.Core;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
using Unity.Cinemachine;
|
using Unity.Cinemachine;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -13,7 +14,8 @@ using UnityEngine.UIElements;
|
|||||||
using Vector2 = UnityEngine.Vector2;
|
using Vector2 = UnityEngine.Vector2;
|
||||||
using Vector3 = UnityEngine.Vector3;
|
using Vector3 = UnityEngine.Vector3;
|
||||||
|
|
||||||
public class LockOnManager : MonoBehaviour{
|
namespace Reset.Units{
|
||||||
|
public class LockOnManager : MonoBehaviour{
|
||||||
public class ActiveLockOnTarget{
|
public class ActiveLockOnTarget{
|
||||||
public GameObject gameObject;
|
public GameObject gameObject;
|
||||||
public float targetWeight;
|
public float targetWeight;
|
||||||
@@ -26,13 +28,11 @@ public class LockOnManager : MonoBehaviour{
|
|||||||
// Lock On settings
|
// Lock On settings
|
||||||
[Space(5)] public float lockOnRange = 40f;
|
[Space(5)] public float lockOnRange = 40f;
|
||||||
public float lockOnMaxAngle = 70f;
|
public float lockOnMaxAngle = 70f;
|
||||||
[Range(0,1)] public float mainTargetWeight = .15f;
|
[Range(0, 1)] public float mainTargetWeight = .15f;
|
||||||
[FormerlySerializedAs("smoothing")] public float smoothTime = 1f;
|
[FormerlySerializedAs("smoothing")] public float smoothTime = 1f;
|
||||||
|
|
||||||
// Lock On Tracking
|
// Lock On Tracking
|
||||||
[Space(10)]
|
[Space(10)] public ActiveLockOnTarget mainTarget;
|
||||||
|
|
||||||
public ActiveLockOnTarget mainTarget;
|
|
||||||
|
|
||||||
public List<ActiveLockOnTarget> activeTargets = new List<ActiveLockOnTarget>();
|
public List<ActiveLockOnTarget> activeTargets = new List<ActiveLockOnTarget>();
|
||||||
|
|
||||||
@@ -56,8 +56,8 @@ public class LockOnManager : MonoBehaviour{
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// References from camera
|
// References from camera
|
||||||
targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
targetGroup = PlayerManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||||
lockOnDocument = GameManager.UI.transform.Find("Lock On").GetComponent<UIDocument>();
|
lockOnDocument = UIManager.UI.transform.Find("Lock On").GetComponent<UIDocument>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
// 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
|
// Quick check for things in lock-on target that aren't lock-onable
|
||||||
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
||||||
mainTarget.gameObject.AddComponent<GenericLockOnTarget>();
|
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");
|
elementRoot = lockOnDocument.rootVisualElement.Query<VisualElement>("LockOnGroup");
|
||||||
elementLabelName = lockOnDocument.rootVisualElement.Query<Label>("LockOnName").First();
|
elementLabelName = lockOnDocument.rootVisualElement.Query<Label>("LockOnName").First();
|
||||||
|
|
||||||
// Add all nearby game objects to lock-on eligible list
|
// 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) {
|
foreach (GameObject thisObject in allGameObjects) {
|
||||||
Debug.Log($"{thisObject.name}: {thisObject.GetComponent<ILockOnTarget>() != null}");
|
|
||||||
|
|
||||||
if (thisObject.GetComponent<ILockOnTarget>() != null) {
|
if (thisObject.GetComponent<ILockOnTarget>() != null) {
|
||||||
acceptedTargets.Add(thisObject);
|
acceptedTargets.Add(thisObject);
|
||||||
}
|
}
|
||||||
@@ -84,21 +83,24 @@ public class LockOnManager : MonoBehaviour{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void AttachCamera(GameObject target){
|
public void AttachCamera(GameObject target){
|
||||||
targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
targetGroup = PlayerManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||||
Debug.Log($"{GameManager.Camera}");
|
Debug.Log($"{PlayerManager.Camera}");
|
||||||
|
|
||||||
// Set the camera's target as the player
|
// Set the camera's target as the player
|
||||||
targetGroup.Targets.Add(new CinemachineTargetGroup.Target{Object = target.transform, Radius = 3.5f, Weight = 1f});
|
targetGroup.Targets.Add(new CinemachineTargetGroup.Target
|
||||||
GameManager.Camera.transform.Find("Cinemachine").GetComponent<CinemachineCamera>().Target.TrackingTarget = target.transform;
|
{ Object = target.transform, Radius = 3.5f, Weight = 1f });
|
||||||
GameManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().PlayerInput =
|
PlayerManager.Camera.transform.Find("Cinemachine").GetComponent<CinemachineCamera>().Target.TrackingTarget =
|
||||||
|
target.transform;
|
||||||
|
PlayerManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().PlayerInput =
|
||||||
GetComponent<PlayerInput>();
|
GetComponent<PlayerInput>();
|
||||||
GameManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().AddEvents();
|
PlayerManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().AddEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update(){
|
void Update(){
|
||||||
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
||||||
mainTarget.gameObject.AddComponent<GenericLockOnTarget>();
|
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.
|
// 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
|
// Skip the current target if one exists
|
||||||
if (mainTarget != null && mainTarget.gameObject == target) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip targets currently behind objects.
|
// Skip targets currently behind objects.
|
||||||
Physics.Raycast(cameraTransform.position,
|
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 (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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skips targets too far
|
// Skips targets too far
|
||||||
if (Vector3.Distance(transform.position, target.transform.position) > lockOnRange) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip targets outside lock on angle
|
// 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 (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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find how close this target is from the center of the screen
|
// Find how close this target is from the center of the screen
|
||||||
Vector3 targetScreenPoint = Camera.main.WorldToScreenPoint(target.transform.position);
|
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);
|
distanceFromScreenCenter = Mathf.Abs(distanceFromScreenCenter);
|
||||||
|
|
||||||
// Debug.Log($"{target.name}: {distanceFromScreenCenter} pixels, {angleFromCameraForward} degrees");
|
// Debug.Log($"{target.name}: {distanceFromScreenCenter} pixels, {angleFromCameraForward} degrees");
|
||||||
@@ -278,7 +299,8 @@ public class LockOnManager : MonoBehaviour{
|
|||||||
elementLabelName.text = mainTarget.gameObject.name;
|
elementLabelName.text = mainTarget.gameObject.name;
|
||||||
|
|
||||||
// Set position (add the width/height of the element)
|
// 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);
|
elementRoot.style.left = new StyleLength(screenPos.x - elementRoot.resolvedStyle.width / 2f);
|
||||||
|
|
||||||
// Set enabled
|
// Set enabled
|
||||||
@@ -287,4 +309,6 @@ public class LockOnManager : MonoBehaviour{
|
|||||||
elementRoot.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
|
elementRoot.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Reset;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
using Unity.Netcode;
|
using Unity.Netcode;
|
||||||
using Unity.Netcode.Transports.UTP;
|
using Unity.Netcode.Transports.UTP;
|
||||||
@@ -17,7 +18,7 @@ public class SessionManager : MonoBehaviour{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartOfflineSession(){
|
public void StartSession(){
|
||||||
Instantiate(playerPrefab);
|
Instantiate(playerPrefab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,29 +6,28 @@ using UnityEngine;
|
|||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
using UnityEngine.InputSystem.Users;
|
using UnityEngine.InputSystem.Users;
|
||||||
|
|
||||||
namespace Reset{
|
namespace Reset.Units{
|
||||||
public static class GameManager{
|
public static class PlayerManager{
|
||||||
public static GameObject UI;
|
|
||||||
public static GameObject Camera;
|
public static GameObject Camera;
|
||||||
public static GameObject Input;
|
public static GameObject Input;
|
||||||
public static SessionManager Session;
|
public static SessionManager Session;
|
||||||
|
|
||||||
private static GameObject player;
|
private static GameObject _player;
|
||||||
|
|
||||||
public static GameObject Player{
|
public static GameObject Player{
|
||||||
get{ return player; }
|
get{ return _player; }
|
||||||
set{ player = value; }
|
set{ _player = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[RuntimeInitializeOnLoadMethod]
|
[RuntimeInitializeOnLoadMethod]
|
||||||
static void Reset(){
|
static void Reset(){
|
||||||
player = null;
|
Player = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[RuntimeInitializeOnLoadMethod]
|
[RuntimeInitializeOnLoadMethod]
|
||||||
static void PopulateSceneReferences(){
|
static void PopulatePlayerSceneReferences(){
|
||||||
try {
|
try {
|
||||||
UI = GameObject.Find("UICanvas");
|
|
||||||
Camera = GameObject.Find("CameraGroup");
|
Camera = GameObject.Find("CameraGroup");
|
||||||
Input = GameObject.Find("InputManager");
|
Input = GameObject.Find("InputManager");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -43,7 +42,9 @@ namespace Reset{
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputUser playerUser = Player.GetComponent<PlayerInput>().user;
|
InputUser playerUser = Player.GetComponent<PlayerInput>().user;
|
||||||
|
|
||||||
playerUser = InputUser.PerformPairingWithDevice(device, playerUser, InputUserPairingOptions.UnpairCurrentDevicesFromUser);
|
playerUser = InputUser.PerformPairingWithDevice(device, playerUser, InputUserPairingOptions.UnpairCurrentDevicesFromUser);
|
||||||
|
Debug.Log($"Attached {device.displayName} to {Player}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameObject FindNewPlayer(){
|
public static GameObject FindNewPlayer(){
|
||||||
@@ -55,7 +55,7 @@ namespace Reset.Core.Tools{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Start(){
|
void Start(){
|
||||||
canvasRootGameObject = GameManager.UI;
|
canvasRootGameObject = UIManager.UI;
|
||||||
root = canvasRootGameObject.transform.Find("Debug Overlay").GetComponent<UIDocument>();
|
root = canvasRootGameObject.transform.Find("Debug Overlay").GetComponent<UIDocument>();
|
||||||
|
|
||||||
SetCurrentPageVisible();
|
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 System.Collections.Generic;
|
||||||
using Reset.Core.Tools;
|
using Reset.Core.Tools;
|
||||||
using Reset.Units;
|
using Reset.Units;
|
||||||
|
using Unity.Netcode;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
public class UnitCombat : MonoBehaviour{
|
public class UnitCombat : UnitComponent {
|
||||||
public List<Collider> draggedUnits = new List<Collider>();
|
public List<Collider> draggedUnits = new List<Collider>();
|
||||||
|
|
||||||
private UnitMovementHandler movement;
|
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();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update(){
|
|
||||||
GetComponent<IKillable>().DrawHealthDebug();
|
|
||||||
lockonDebug = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float maxHealth{ get; set; }
|
public float maxHealth{ get; set; }
|
||||||
public float currentHealth{ get; set; }
|
public float currentHealth{ get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Reset.Units{
|
|||||||
|
|
||||||
private void SetMaxHealth(){
|
private void SetMaxHealth(){
|
||||||
if (maxHealth == 0f) {
|
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;
|
currentHealth = 10000f;
|
||||||
} else {
|
} else {
|
||||||
currentHealth = maxHealth;
|
currentHealth = maxHealth;
|
||||||
|
|||||||
@@ -10,25 +10,42 @@ using Sirenix.OdinInspector;
|
|||||||
using Sirenix.Serialization;
|
using Sirenix.Serialization;
|
||||||
using Unity.Netcode;
|
using Unity.Netcode;
|
||||||
|
|
||||||
public class Player : Unit, IKillable{
|
namespace Reset.Units{
|
||||||
|
public class Player : Unit, IKillable{
|
||||||
[HideInInspector] public PlayerControls controls;
|
[HideInInspector] public PlayerControls controls;
|
||||||
|
|
||||||
float IKillable.maxHealth{ get; set; }
|
float IKillable.maxHealth{ get; set; }
|
||||||
float IKillable.currentHealth{ get; set; }
|
float IKillable.currentHealth{ get; set; }
|
||||||
|
|
||||||
void Awake(){
|
void Awake(){
|
||||||
GameManager.Player = gameObject;
|
|
||||||
controls = GetComponent<PlayerControls>();
|
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(){
|
public override void UnitStart(){
|
||||||
base.UnitStart();
|
base.UnitStart();
|
||||||
|
|
||||||
|
Attach();
|
||||||
((IKillable)this).IKillableInitialize();
|
((IKillable)this).IKillableInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
protected override void Update(){
|
||||||
void Update(){
|
base.Update();
|
||||||
|
|
||||||
GetComponent<IKillable>().DrawHealthDebug();
|
GetComponent<IKillable>().DrawHealthDebug();
|
||||||
|
Debug.Log(PlayerManager.Player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TakeDamage(DamageSource[] sources){
|
public void TakeDamage(DamageSource[] sources){
|
||||||
@@ -49,4 +66,5 @@ public class Player : Unit, IKillable{
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public interface ILockOnTarget {
|
namespace Reset.Units{
|
||||||
public float lockonTargetRadius { set; get; }
|
public interface ILockOnTarget{
|
||||||
public bool lockonDebug { set; get; }
|
public float lockonTargetRadius{ set; get; }
|
||||||
|
public bool lockonDebug{ set; get; }
|
||||||
|
|
||||||
public float lockonRaycastVerticalOffset { set; get; }
|
public float lockonRaycastVerticalOffset{ set; get; }
|
||||||
|
|
||||||
Transform transform {get;}
|
Transform transform{ get; }
|
||||||
GameObject gameObject{ get; }
|
GameObject gameObject{ get; }
|
||||||
|
|
||||||
abstract void OnTargetDelete();
|
abstract void OnTargetDelete();
|
||||||
@@ -19,13 +20,14 @@ public interface ILockOnTarget {
|
|||||||
public Vector3 GetReticlePosition(){
|
public Vector3 GetReticlePosition(){
|
||||||
float upValue = 0f;
|
float upValue = 0f;
|
||||||
|
|
||||||
if (gameObject.GetComponent<Renderer>()){
|
if (gameObject.GetComponent<Renderer>()) {
|
||||||
Bounds objectBounds = gameObject.GetComponent<Renderer>().bounds;
|
Bounds objectBounds = gameObject.GetComponent<Renderer>().bounds;
|
||||||
upValue = objectBounds.size.y;
|
upValue = objectBounds.size.y;
|
||||||
upValue = 4f;
|
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;
|
return reticlePosition;
|
||||||
}
|
}
|
||||||
@@ -34,7 +36,8 @@ public interface ILockOnTarget {
|
|||||||
// gameObject.
|
// gameObject.
|
||||||
foreach (LockOnManager.ActiveLockOnTarget target in LockOnManager.Instance.activeTargets) {
|
foreach (LockOnManager.ActiveLockOnTarget target in LockOnManager.Instance.activeTargets) {
|
||||||
if (target.gameObject == this.gameObject) {
|
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.gameObject = clone;
|
||||||
target.cinemachineTarget.Object = clone.transform;
|
target.cinemachineTarget.Object = clone.transform;
|
||||||
@@ -43,6 +46,7 @@ public interface ILockOnTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerCamera : MonoBehaviour{
|
public class PlayerCamera : MonoBehaviour{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using NodeCanvas;
|
|||||||
using NodeCanvas.Framework;
|
using NodeCanvas.Framework;
|
||||||
using ParadoxNotion;
|
using ParadoxNotion;
|
||||||
using Reset;
|
using Reset;
|
||||||
|
using Reset.Units;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
using Unity.Cinemachine;
|
using Unity.Cinemachine;
|
||||||
using Object = UnityEngine.Object;
|
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;
|
||||||
|
using Reset.Units;
|
||||||
using Unity.Netcode;
|
using Unity.Netcode;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Unit : NetworkBehaviour{
|
namespace Reset.Units{
|
||||||
|
public class Unit : NetworkBehaviour{
|
||||||
public virtual void Start(){
|
public virtual void Start(){
|
||||||
UnitStart();
|
UnitStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void UnitStart(){
|
public virtual async void UnitStart(){
|
||||||
OnlineStart();
|
try {
|
||||||
|
var netWaitResult = await WaitForNetwork();
|
||||||
|
|
||||||
|
if (netWaitResult) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnlineStart(){
|
// OnlineStart();
|
||||||
if (!NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost) {
|
Debug.Log("Done");
|
||||||
Attach();
|
} catch {
|
||||||
} else {
|
throw;
|
||||||
StartCoroutine(WaitForOnline());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator WaitForOnline(){
|
public async Task<bool> WaitForNetwork(){
|
||||||
while (!NetworkManager.Singleton.didAwake) {
|
while (!NetworkManager.Singleton.IsConnectedClient) {
|
||||||
Debug.Log("waiting");
|
await Awaitable.NextFrameAsync();
|
||||||
yield return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug.Log($"{IsHost}, {IsClient}, {IsLocalPlayer}");
|
return (NetworkManager.Singleton.IsConnectedClient);
|
||||||
if (IsLocalPlayer){
|
}
|
||||||
GameManager.Player = gameObject;
|
|
||||||
Attach();
|
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(){
|
void UpdateGizmos(){
|
||||||
if (GameManager.Player == gameObject){
|
string onlineStatus = "Not Online";
|
||||||
GameManager.RequestNewController();
|
Color onlineColor = Color.gray;
|
||||||
GetComponent<LockOnManager>().AttachCamera(gameObject);
|
|
||||||
}
|
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(){
|
protected override void OnNetworkPostSpawn(){
|
||||||
// GetComponent<LockOnManager>().AttachCamera(gameObject);
|
// GetComponent<LockOnManager>().AttachCamera(gameObject);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user