refactor: moved a lot of player related scripts to the Reset.Units namespace
This commit is contained in:
@@ -1,16 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
|
namespace Reset.Units{
|
||||||
public float lockonTargetRadius{ get; set; } = 1f;
|
public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{
|
||||||
public bool lockonDebug{ get; set; } = false;
|
public float lockonTargetRadius{ get; set; } = 1f;
|
||||||
public float lockonRaycastVerticalOffset{ get; set; }
|
public bool lockonDebug{ get; set; } = false;
|
||||||
|
public float lockonRaycastVerticalOffset{ get; set; }
|
||||||
|
|
||||||
public void OnTargetDelete(){
|
public void OnTargetDelete(){
|
||||||
GetComponent<ILockOnTarget>().SafelyDeleteTarget();
|
GetComponent<ILockOnTarget>().SafelyDeleteTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
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,32 +4,33 @@ using UnityEngine;
|
|||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
public class InputFinder : MonoBehaviour{
|
namespace Reset.Units{
|
||||||
public InputActionMap actionMap;
|
public class InputFinder : MonoBehaviour{
|
||||||
|
public InputActionMap actionMap;
|
||||||
|
|
||||||
void Start(){
|
void Start(){
|
||||||
actionMap.actions[0].performed += ctx => { InputPressed(ctx); };
|
actionMap.actions[0].performed += ctx => { InputPressed(ctx); };
|
||||||
|
|
||||||
GetComponent<UIDocument>().enabled = false;
|
GetComponent<UIDocument>().enabled = false;
|
||||||
}
|
|
||||||
|
|
||||||
public void AwaitNewInput(){
|
|
||||||
GameManager.ClearCurrentController();
|
|
||||||
|
|
||||||
GetComponent<UIDocument>().enabled = true;
|
|
||||||
actionMap.Enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputPressed(InputAction.CallbackContext context){
|
|
||||||
try {
|
|
||||||
GameManager.AttachControllerToPlayer(context.control.device);
|
|
||||||
Debug.Log(context.control.device);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GetComponent<UIDocument>().enabled = false;
|
public void AwaitNewInput(){
|
||||||
actionMap.Disable();
|
PlayerManager.ClearCurrentController();
|
||||||
|
|
||||||
|
GetComponent<UIDocument>().enabled = true;
|
||||||
|
actionMap.Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputPressed(InputAction.CallbackContext context){
|
||||||
|
try {
|
||||||
|
PlayerManager.AttachControllerToPlayer(context.control.device);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetComponent<UIDocument>().enabled = false;
|
||||||
|
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,278 +14,301 @@ 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 ActiveLockOnTarget{
|
public class LockOnManager : MonoBehaviour{
|
||||||
public GameObject gameObject;
|
public class ActiveLockOnTarget{
|
||||||
public float targetWeight;
|
public GameObject gameObject;
|
||||||
public float refVelocity;
|
public float targetWeight;
|
||||||
public CinemachineTargetGroup.Target cinemachineTarget;
|
public float refVelocity;
|
||||||
}
|
public CinemachineTargetGroup.Target cinemachineTarget;
|
||||||
|
|
||||||
public static LockOnManager Instance;
|
|
||||||
|
|
||||||
// Lock On settings
|
|
||||||
[Space(5)] public float lockOnRange = 40f;
|
|
||||||
public float lockOnMaxAngle = 70f;
|
|
||||||
[Range(0,1)] public float mainTargetWeight = .15f;
|
|
||||||
[FormerlySerializedAs("smoothing")] public float smoothTime = 1f;
|
|
||||||
|
|
||||||
// Lock On Tracking
|
|
||||||
[Space(10)]
|
|
||||||
|
|
||||||
public ActiveLockOnTarget mainTarget;
|
|
||||||
|
|
||||||
public List<ActiveLockOnTarget> activeTargets = new List<ActiveLockOnTarget>();
|
|
||||||
|
|
||||||
[ReadOnly] public CinemachineTargetGroup.Target lockonTarget;
|
|
||||||
public CinemachineTargetGroup targetGroup;
|
|
||||||
|
|
||||||
public List<GameObject> acceptedTargets = new List<GameObject>();
|
|
||||||
|
|
||||||
// UI
|
|
||||||
[ShowInInspector] public UIDocument lockOnDocument;
|
|
||||||
private Label elementLabelName;
|
|
||||||
private VisualElement elementRoot;
|
|
||||||
|
|
||||||
private void Awake(){
|
|
||||||
// // Register as singleton
|
|
||||||
// if (Instance == null) {
|
|
||||||
// Instance = this;
|
|
||||||
// } else {
|
|
||||||
// this.enabled = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// References from camera
|
|
||||||
targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
|
||||||
lockOnDocument = GameManager.UI.transform.Find("Lock On").GetComponent<UIDocument>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
||||||
void Start(){
|
|
||||||
// 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.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elementRoot = lockOnDocument.rootVisualElement.Query<VisualElement>("LockOnGroup");
|
public static LockOnManager Instance;
|
||||||
elementLabelName = lockOnDocument.rootVisualElement.Query<Label>("LockOnName").First();
|
|
||||||
|
|
||||||
// Add all nearby game objects to lock-on eligible list
|
// Lock On settings
|
||||||
GameObject[] allGameObjects = GameObject.FindObjectsByType<GameObject>(0, 0);
|
[Space(5)] public float lockOnRange = 40f;
|
||||||
|
public float lockOnMaxAngle = 70f;
|
||||||
|
[Range(0, 1)] public float mainTargetWeight = .15f;
|
||||||
|
[FormerlySerializedAs("smoothing")] public float smoothTime = 1f;
|
||||||
|
|
||||||
foreach (GameObject thisObject in allGameObjects) {
|
// Lock On Tracking
|
||||||
Debug.Log($"{thisObject.name}: {thisObject.GetComponent<ILockOnTarget>() != null}");
|
[Space(10)] public ActiveLockOnTarget mainTarget;
|
||||||
|
|
||||||
if (thisObject.GetComponent<ILockOnTarget>() != null) {
|
public List<ActiveLockOnTarget> activeTargets = new List<ActiveLockOnTarget>();
|
||||||
acceptedTargets.Add(thisObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AttachCamera(GameObject target){
|
[ReadOnly] public CinemachineTargetGroup.Target lockonTarget;
|
||||||
targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
public CinemachineTargetGroup targetGroup;
|
||||||
Debug.Log($"{GameManager.Camera}");
|
|
||||||
|
|
||||||
// Set the camera's target as the player
|
public List<GameObject> acceptedTargets = new List<GameObject>();
|
||||||
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 =
|
|
||||||
GetComponent<PlayerInput>();
|
|
||||||
GameManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().AddEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update(){
|
// UI
|
||||||
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
[ShowInInspector] public UIDocument lockOnDocument;
|
||||||
mainTarget.gameObject.AddComponent<GenericLockOnTarget>();
|
private Label elementLabelName;
|
||||||
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.");
|
private VisualElement elementRoot;
|
||||||
|
|
||||||
|
private void Awake(){
|
||||||
|
// // Register as singleton
|
||||||
|
// if (Instance == null) {
|
||||||
|
// Instance = this;
|
||||||
|
// } else {
|
||||||
|
// this.enabled = false;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// References from camera
|
||||||
|
targetGroup = PlayerManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||||
|
lockOnDocument = UIManager.UI.transform.Find("Lock On").GetComponent<UIDocument>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through targets, pushing their Target Group weight towards their goal weight, or removing them if they get too low.
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
for (int i = 0; i < activeTargets.Count; i++) {
|
void Start(){
|
||||||
if (activeTargets[i].gameObject == this.gameObject) {
|
// Quick check for things in lock-on target that aren't lock-onable
|
||||||
continue;
|
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
activeTargets[i].cinemachineTarget.Weight =
|
elementRoot = lockOnDocument.rootVisualElement.Query<VisualElement>("LockOnGroup");
|
||||||
Mathf.SmoothDamp(
|
elementLabelName = lockOnDocument.rootVisualElement.Query<Label>("LockOnName").First();
|
||||||
activeTargets[i].cinemachineTarget.Weight,
|
|
||||||
activeTargets[i].targetWeight,
|
|
||||||
ref activeTargets[i].refVelocity,
|
|
||||||
smoothTime * Time.deltaTime);
|
|
||||||
|
|
||||||
if (activeTargets[i].cinemachineTarget.Weight < 0.0001f) {
|
// Add all nearby game objects to lock-on eligible list
|
||||||
StartCoroutine(RemoveFromTargetAtFrameEnd(activeTargets[i]));
|
GameObject[] allGameObjects = FindObjectsByType<GameObject>(0, 0);
|
||||||
|
|
||||||
|
foreach (GameObject thisObject in allGameObjects) {
|
||||||
|
if (thisObject.GetComponent<ILockOnTarget>() != null) {
|
||||||
|
acceptedTargets.Add(thisObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator RemoveFromTargetAtFrameEnd(ActiveLockOnTarget target){
|
public void AttachCamera(GameObject target){
|
||||||
yield return new WaitForEndOfFrame();
|
targetGroup = PlayerManager.Camera.transform.Find("Target Group").GetComponent<CinemachineTargetGroup>();
|
||||||
|
Debug.Log($"{PlayerManager.Camera}");
|
||||||
|
|
||||||
activeTargets.Remove(target);
|
// Set the camera's target as the player
|
||||||
targetGroup.Targets.Remove(target.cinemachineTarget);
|
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>();
|
||||||
|
PlayerManager.Camera.transform.Find("Cinemachine").GetComponent<CustomInputHandler>().AddEvents();
|
||||||
|
}
|
||||||
|
|
||||||
public void AddNewTarget(GameObject targetObject, float targetWeight, bool isMain = false){
|
void Update(){
|
||||||
// Check that the target doesn't already exist- if it does, just change it's weight/make it main
|
if (mainTarget != null && mainTarget.gameObject.GetComponent<ILockOnTarget>() == null) {
|
||||||
foreach (ActiveLockOnTarget target in activeTargets) {
|
mainTarget.gameObject.AddComponent<GenericLockOnTarget>();
|
||||||
if (target.gameObject == targetObject) {
|
Debug.LogWarning(
|
||||||
target.targetWeight = targetWeight;
|
$"The object <b>{mainTarget.gameObject.name}</b> has no ILockOnTarget interface. This isn't hyper critical, but adding one as a GenericLockOnTarget anyways.");
|
||||||
|
}
|
||||||
|
|
||||||
if (isMain) {
|
// Iterate through targets, pushing their Target Group weight towards their goal weight, or removing them if they get too low.
|
||||||
mainTarget = target;
|
for (int i = 0; i < activeTargets.Count; i++) {
|
||||||
|
if (activeTargets[i].gameObject == this.gameObject) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
activeTargets[i].cinemachineTarget.Weight =
|
||||||
|
Mathf.SmoothDamp(
|
||||||
|
activeTargets[i].cinemachineTarget.Weight,
|
||||||
|
activeTargets[i].targetWeight,
|
||||||
|
ref activeTargets[i].refVelocity,
|
||||||
|
smoothTime * Time.deltaTime);
|
||||||
|
|
||||||
|
if (activeTargets[i].cinemachineTarget.Weight < 0.0001f) {
|
||||||
|
StartCoroutine(RemoveFromTargetAtFrameEnd(activeTargets[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator RemoveFromTargetAtFrameEnd(ActiveLockOnTarget target){
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
|
||||||
|
activeTargets.Remove(target);
|
||||||
|
targetGroup.Targets.Remove(target.cinemachineTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddNewTarget(GameObject targetObject, float targetWeight, bool isMain = false){
|
||||||
|
// Check that the target doesn't already exist- if it does, just change it's weight/make it main
|
||||||
|
foreach (ActiveLockOnTarget target in activeTargets) {
|
||||||
|
if (target.gameObject == targetObject) {
|
||||||
|
target.targetWeight = targetWeight;
|
||||||
|
|
||||||
|
if (isMain) {
|
||||||
|
mainTarget = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it doesn't exist in the list of targets, add it
|
||||||
|
ActiveLockOnTarget newTarget = new ActiveLockOnTarget{
|
||||||
|
gameObject = targetObject,
|
||||||
|
targetWeight = mainTargetWeight,
|
||||||
|
cinemachineTarget = new CinemachineTargetGroup.Target{
|
||||||
|
Object = targetObject.transform,
|
||||||
|
Radius = 1f,
|
||||||
|
Weight = 0f
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//Set as main
|
||||||
|
if (isMain) {
|
||||||
|
mainTarget = newTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finalize
|
||||||
|
activeTargets.Add(newTarget);
|
||||||
|
targetGroup.Targets.Add(newTarget.cinemachineTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QueueTargetRemoval(GameObject targetObject, bool deleteAfterRemoved = false){
|
||||||
|
// Ostensibly removes targest by setting their target weight to 0. Update loop finds targets with no weight and reduces their impact on the camera
|
||||||
|
// After it smooths their current weight to 0, it removes them
|
||||||
|
activeTargets.Find(target => target.gameObject == targetObject).targetWeight = 0f;
|
||||||
|
|
||||||
|
if (deleteAfterRemoved) {
|
||||||
|
StartCoroutine(DeleteGameObjectPostRemoval(targetObject));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove as main target if it is
|
||||||
|
if (mainTarget == activeTargets.Find(target => target.gameObject == targetObject)) {
|
||||||
|
mainTarget = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator DeleteGameObjectPostRemoval(GameObject targetObject){
|
||||||
|
ActiveLockOnTarget thisTarget = activeTargets.Find(target => target.gameObject == targetObject);
|
||||||
|
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
|
||||||
|
while (activeTargets.Contains(thisTarget)) {
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Destroy(thisTarget.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeLockOnTarget(){
|
||||||
|
Transform cameraTransform = Camera.main.transform;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// If there is no target, simply find the closest to the center of the camera
|
||||||
|
GameObject closestTarget = null;
|
||||||
|
float lowestDistanceToCenter = Mathf.Infinity;
|
||||||
|
|
||||||
|
foreach (GameObject target in acceptedTargets) {
|
||||||
|
// Find out if this target wants to be debugged on it's selection process
|
||||||
|
bool debugThisTarget = target.GetComponent<ILockOnTarget>().lockonDebug;
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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}");
|
||||||
|
}
|
||||||
|
|
||||||
|
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)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip targets outside lock on angle
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
distanceFromScreenCenter = Mathf.Abs(distanceFromScreenCenter);
|
||||||
|
|
||||||
|
// Debug.Log($"{target.name}: {distanceFromScreenCenter} pixels, {angleFromCameraForward} degrees");
|
||||||
|
|
||||||
|
// Set the new target to closest to screen
|
||||||
|
if (distanceFromScreenCenter < lowestDistanceToCenter) {
|
||||||
|
lowestDistanceToCenter = distanceFromScreenCenter;
|
||||||
|
closestTarget = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Catch exception from nothing being found
|
||||||
|
if (!closestTarget) {
|
||||||
|
Debug.LogWarning("Lock-on attempted, but no lock on target was found viable.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If it doesn't exist in the list of targets, add it
|
// Remove the main target that currently exists, if there is one.
|
||||||
ActiveLockOnTarget newTarget = new ActiveLockOnTarget{
|
if (mainTarget != null) {
|
||||||
gameObject = targetObject,
|
QueueTargetRemoval(mainTarget.gameObject);
|
||||||
targetWeight = mainTargetWeight,
|
|
||||||
cinemachineTarget = new CinemachineTargetGroup.Target{
|
|
||||||
Object = targetObject.transform,
|
|
||||||
Radius = 1f,
|
|
||||||
Weight = 0f
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//Set as main
|
|
||||||
if (isMain) {
|
|
||||||
mainTarget = newTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finalize
|
|
||||||
activeTargets.Add(newTarget);
|
|
||||||
targetGroup.Targets.Add(newTarget.cinemachineTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void QueueTargetRemoval(GameObject targetObject, bool deleteAfterRemoved = false){
|
|
||||||
// Ostensibly removes targest by setting their target weight to 0. Update loop finds targets with no weight and reduces their impact on the camera
|
|
||||||
// After it smooths their current weight to 0, it removes them
|
|
||||||
activeTargets.Find(target => target.gameObject == targetObject).targetWeight = 0f;
|
|
||||||
|
|
||||||
if (deleteAfterRemoved) {
|
|
||||||
StartCoroutine(DeleteGameObjectPostRemoval(targetObject));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove as main target if it is
|
|
||||||
if (mainTarget == activeTargets.Find(target => target.gameObject == targetObject)) {
|
|
||||||
mainTarget = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator DeleteGameObjectPostRemoval(GameObject targetObject){
|
|
||||||
ActiveLockOnTarget thisTarget = activeTargets.Find(target => target.gameObject == targetObject);
|
|
||||||
|
|
||||||
yield return new WaitForEndOfFrame();
|
|
||||||
|
|
||||||
while (activeTargets.Contains(thisTarget)) {
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Destroy(thisTarget.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ChangeLockOnTarget(){
|
|
||||||
Transform cameraTransform = Camera.main.transform;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If there is no target, simply find the closest to the center of the camera
|
|
||||||
GameObject closestTarget = null;
|
|
||||||
float lowestDistanceToCenter = Mathf.Infinity;
|
|
||||||
|
|
||||||
foreach (GameObject target in acceptedTargets) {
|
|
||||||
// Find out if this target wants to be debugged on it's selection process
|
|
||||||
bool debugThisTarget = target.GetComponent<ILockOnTarget>().lockonDebug;
|
|
||||||
|
|
||||||
// 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");}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip targets currently behind objects.
|
// Begin tracking target, set as main
|
||||||
Physics.Raycast(cameraTransform.position,
|
AddNewTarget(closestTarget.gameObject, mainTargetWeight, true);
|
||||||
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}");}
|
|
||||||
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)}");}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip targets outside lock on angle
|
|
||||||
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");}
|
|
||||||
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;
|
|
||||||
distanceFromScreenCenter = Mathf.Abs(distanceFromScreenCenter);
|
|
||||||
|
|
||||||
// Debug.Log($"{target.name}: {distanceFromScreenCenter} pixels, {angleFromCameraForward} degrees");
|
|
||||||
|
|
||||||
// Set the new target to closest to screen
|
|
||||||
if (distanceFromScreenCenter < lowestDistanceToCenter) {
|
|
||||||
lowestDistanceToCenter = distanceFromScreenCenter;
|
|
||||||
closestTarget = target;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch exception from nothing being found
|
// Used by outside sources such as input to cancel lock-on.
|
||||||
if (!closestTarget) {
|
public void RemoveMainTarget(){
|
||||||
Debug.LogWarning("Lock-on attempted, but no lock on target was found viable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the main target that currently exists, if there is one.
|
|
||||||
if (mainTarget != null) {
|
|
||||||
QueueTargetRemoval(mainTarget.gameObject);
|
QueueTargetRemoval(mainTarget.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin tracking target, set as main
|
void LateUpdate(){
|
||||||
AddNewTarget(closestTarget.gameObject, mainTargetWeight, true);
|
if (mainTarget != null) {
|
||||||
}
|
// This is just test logic to get an image above a lock on.
|
||||||
|
// TODO: Replace with something less silly
|
||||||
|
Vector2 screenPos = RuntimePanelUtils.CameraTransformWorldToPanel(
|
||||||
|
lockOnDocument.rootVisualElement.panel,
|
||||||
|
mainTarget.gameObject.GetComponent<ILockOnTarget>().GetReticlePosition(),
|
||||||
|
Camera.main
|
||||||
|
);
|
||||||
|
|
||||||
// Used by outside sources such as input to cancel lock-on.
|
// Set name
|
||||||
public void RemoveMainTarget(){
|
elementLabelName.text = mainTarget.gameObject.name;
|
||||||
QueueTargetRemoval(mainTarget.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LateUpdate(){
|
// Set position (add the width/height of the element)
|
||||||
if (mainTarget != null) {
|
elementRoot.style.top =
|
||||||
// This is just test logic to get an image above a lock on.
|
new StyleLength(screenPos.y - 25f); // Was elementRoot.resolvedStyle.height * .7f
|
||||||
// TODO: Replace with something less silly
|
elementRoot.style.left = new StyleLength(screenPos.x - elementRoot.resolvedStyle.width / 2f);
|
||||||
Vector2 screenPos = RuntimePanelUtils.CameraTransformWorldToPanel(
|
|
||||||
lockOnDocument.rootVisualElement.panel,
|
|
||||||
mainTarget.gameObject.GetComponent<ILockOnTarget>().GetReticlePosition(),
|
|
||||||
Camera.main
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set name
|
// Set enabled
|
||||||
elementLabelName.text = mainTarget.gameObject.name;
|
elementRoot.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
|
||||||
|
} else {
|
||||||
// Set position (add the width/height of the element)
|
elementRoot.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
|
||||||
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
|
|
||||||
elementRoot.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
|
|
||||||
} else {
|
|
||||||
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,43 +10,61 @@ using Sirenix.OdinInspector;
|
|||||||
using Sirenix.Serialization;
|
using Sirenix.Serialization;
|
||||||
using Unity.Netcode;
|
using Unity.Netcode;
|
||||||
|
|
||||||
public class Player : Unit, IKillable{
|
namespace Reset.Units{
|
||||||
[HideInInspector] public PlayerControls controls;
|
public class Player : Unit, IKillable{
|
||||||
|
[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 override void UnitStart(){
|
|
||||||
base.UnitStart();
|
|
||||||
((IKillable)this).IKillableInitialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update(){
|
|
||||||
GetComponent<IKillable>().DrawHealthDebug();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TakeDamage(DamageSource[] sources){
|
|
||||||
foreach (DamageSource source in sources) {
|
|
||||||
TakeDamage(source);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void TakeDamage(DamageSource source){
|
public void Attach(){
|
||||||
((IKillable)this).currentHealth -= source.damageDealt;
|
name = "Player";
|
||||||
|
name += IsLocalPlayer ? ", Local" : ", Network";
|
||||||
|
|
||||||
if (((IKillable)this).currentHealth <= 0) {
|
if (IsLocalPlayer || !UnitIsNetworked()) { //
|
||||||
Kill();
|
PlayerManager.Player = gameObject;
|
||||||
|
|
||||||
|
Debug.Log($"Player is set to {PlayerManager.Player.name}");
|
||||||
|
PlayerManager.RequestNewController();
|
||||||
|
GetComponent<LockOnManager>().AttachCamera(gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void Kill(){
|
public override void UnitStart(){
|
||||||
throw new NotImplementedException();
|
base.UnitStart();
|
||||||
}
|
|
||||||
|
|
||||||
|
Attach();
|
||||||
|
((IKillable)this).IKillableInitialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update(){
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
GetComponent<IKillable>().DrawHealthDebug();
|
||||||
|
Debug.Log(PlayerManager.Player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TakeDamage(DamageSource[] sources){
|
||||||
|
foreach (DamageSource source in sources) {
|
||||||
|
TakeDamage(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TakeDamage(DamageSource source){
|
||||||
|
((IKillable)this).currentHealth -= source.damageDealt;
|
||||||
|
|
||||||
|
if (((IKillable)this).currentHealth <= 0) {
|
||||||
|
Kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Kill(){
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,49 @@
|
|||||||
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();
|
||||||
|
|
||||||
void Help(){
|
void Help(){
|
||||||
SafelyDeleteTarget();
|
SafelyDeleteTarget();
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 GetReticlePosition(){
|
|
||||||
float upValue = 0f;
|
|
||||||
|
|
||||||
if (gameObject.GetComponent<Renderer>()){
|
|
||||||
Bounds objectBounds = gameObject.GetComponent<Renderer>().bounds;
|
|
||||||
upValue = objectBounds.size.y;
|
|
||||||
upValue = 4f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 reticlePosition = new Vector3(transform.position.x, transform.position.y + upValue, transform.position.z);
|
public Vector3 GetReticlePosition(){
|
||||||
|
float upValue = 0f;
|
||||||
|
|
||||||
return reticlePosition;
|
if (gameObject.GetComponent<Renderer>()) {
|
||||||
}
|
Bounds objectBounds = gameObject.GetComponent<Renderer>().bounds;
|
||||||
|
upValue = objectBounds.size.y;
|
||||||
|
upValue = 4f;
|
||||||
|
}
|
||||||
|
|
||||||
public void SafelyDeleteTarget(){
|
Vector3 reticlePosition =
|
||||||
// gameObject.
|
new Vector3(transform.position.x, transform.position.y + upValue, transform.position.z);
|
||||||
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}};
|
|
||||||
|
|
||||||
target.gameObject = clone;
|
return reticlePosition;
|
||||||
target.cinemachineTarget.Object = clone.transform;
|
}
|
||||||
|
|
||||||
LockOnManager.Instance.QueueTargetRemoval(clone, true);
|
public void SafelyDeleteTarget(){
|
||||||
|
// 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 } };
|
||||||
|
|
||||||
|
target.gameObject = clone;
|
||||||
|
target.cinemachineTarget.Object = clone.transform;
|
||||||
|
|
||||||
|
LockOnManager.Instance.QueueTargetRemoval(clone, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 virtual void Start(){
|
public class Unit : NetworkBehaviour{
|
||||||
UnitStart();
|
public virtual void Start(){
|
||||||
}
|
UnitStart();
|
||||||
|
|
||||||
public virtual void UnitStart(){
|
|
||||||
OnlineStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnlineStart(){
|
|
||||||
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}");
|
public virtual async void UnitStart(){
|
||||||
if (IsLocalPlayer){
|
try {
|
||||||
GameManager.Player = gameObject;
|
var netWaitResult = await WaitForNetwork();
|
||||||
Attach();
|
|
||||||
|
if (netWaitResult) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlineStart();
|
||||||
|
Debug.Log("Done");
|
||||||
|
} catch {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void Attach(){
|
public async Task<bool> WaitForNetwork(){
|
||||||
if (GameManager.Player == gameObject){
|
while (!NetworkManager.Singleton.IsConnectedClient) {
|
||||||
GameManager.RequestNewController();
|
await Awaitable.NextFrameAsync();
|
||||||
GetComponent<LockOnManager>().AttachCamera(gameObject);
|
}
|
||||||
|
|
||||||
|
return (NetworkManager.Singleton.IsConnectedClient);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Update(){
|
public bool UnitIsNetworked(){
|
||||||
|
return NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsHost;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public bool UnitIsLocal(){
|
||||||
|
if (UnitIsNetworked()) {
|
||||||
|
return IsOwner;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnNetworkPostSpawn(){
|
return true;
|
||||||
// GetComponent<LockOnManager>().AttachCamera(gameObject);
|
}
|
||||||
|
|
||||||
|
protected virtual void Update(){
|
||||||
|
UpdateGizmos();
|
||||||
|
|
||||||
|
if (GetComponent<IKillable>() != null) {
|
||||||
|
GetComponent<IKillable>().DrawHealthDebug();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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