Handlers updates

*Updated Input system for handlers, now scripts are not depentent on being a child of input system in the hierarchy
*Minor cleanups
*Changed hierarchy in scene (no longer children of inputsystem)
This commit is contained in:
Stedd 2022-09-18 10:18:49 +02:00
parent 6cf37cbb19
commit 18a2fd7ef7
11 changed files with 1287 additions and 140 deletions

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using AsteroidGame.Entities.Structures.Scripts;
using UnityEngine;
@ -6,42 +5,51 @@ using UnityEngine.InputSystem;
namespace AsteroidGame.Handlers
{
public class BuildingHandler : MonoBehaviour
public class BuildingHandler : HandlerBase
{
[Header("Connections")] [SerializeField]
private Camera _camera;
[Header("Connections")]
[SerializeField] private new Camera camera ;
[Header("Assigned on start")] [SerializeField]
int buildingSelector = 0;
[Header("State")]
[SerializeField] private int buildingSelector;
[Header("Prefabs")] [SerializeField] private List<StructureBase> buildings = new List<StructureBase>();
[Header("Prefabs")]
[SerializeField] private List<StructureBase> buildings = new();
#region Private
[SerializeField] private List<StructureBase> activeBuildings;
private Vector3 _tempVec;
private Plane _buildPlane;
private StructureBase _tempSB;
private StructureBase _tempSb;
#endregion
private void OnEnable()
protected override void OnEnable()
{
base.OnEnable();
activeBuildings.Clear();
camera = Camera.main;
}
private void OnClick(InputValue value)
protected override void OnClick(InputAction.CallbackContext a)
{
PlaceBuilding();
}
private void PlaceBuilding()
{
_buildPlane = new Plane(Vector3.up, Vector3.zero);
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
Ray ray = camera.ScreenPointToRay(Mouse.current.position.ReadValue());
if (_buildPlane.Raycast(ray, out float distance))
{
_tempVec = ray.GetPoint(distance);
}
_tempSB = Instantiate(buildings[buildingSelector], _tempVec, Quaternion.identity, transform);
_tempSb = Instantiate(buildings[buildingSelector], _tempVec, Quaternion.identity, transform);
activeBuildings.Add(_tempSB);
activeBuildings.Add(_tempSb);
}
}
}

View File

@ -4,7 +4,7 @@ using UnityEngine.Pool;
namespace AsteroidGame.Handlers
{
public class EnemyHandler : MonoBehaviour
public class EnemyHandler : HandlerBase
{
[Header("Parameters")]
[SerializeField] [Range(0.1f, 60f)] float spawnRate = 60f;

View File

@ -0,0 +1,33 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace AsteroidGame.Handlers
{
public class HandlerBase : MonoBehaviour
{
private HandlerControls _handlerControls;
private void Awake()
{
_handlerControls = new HandlerControls();
}
protected virtual void OnEnable()
{
_handlerControls.Player.Enable();
_handlerControls.Player.Click.performed += OnClick;
}
protected virtual void OnDisable()
{
_handlerControls.Player.Click.performed -= OnClick;
_handlerControls.Player.Disable();
}
protected virtual void OnClick(InputAction.CallbackContext a)
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6e5fa0aaf29861743b120f4e08c5306d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,7 +5,8 @@
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:f26d68a0bdefa1043b120b820f55e190",
"GUID:bc7863ca0989b494d84426bfd28432fa",
"GUID:75469ad4d38634e559750d17036d5f7c"
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:f008ecc6829887e478aeb5eb004eb01b"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -1,23 +1,29 @@
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Serialization;
namespace AsteroidGame.Handlers
{
public class ScoreHandler : MonoBehaviour
public class ScoreHandler : HandlerBase
{
[Header("UI")]
[SerializeField] TextMeshProUGUI dispayBalance;
[SerializeField]
private TextMeshProUGUI displayBalance;
[Header("Parameters")]
[SerializeField] int startHealth = 5;
[SerializeField] int startBalance = 100;
[SerializeField]
private int startHealth = 5;
[SerializeField]
private int startBalance = 100;
[Header("Stats")]
[SerializeField] int currentHealth;
[SerializeField] int currentBalance;
public int CurrentBalance {get {return currentBalance;}}
[SerializeField]
private int currentHealth;
[SerializeField]
private int currentBalance;
public int CurrentBalance => currentBalance;
void Start()
private void Start()
{
currentHealth = startHealth;
currentBalance = startBalance;
@ -30,13 +36,13 @@ namespace AsteroidGame.Handlers
CheckIfYouLost();
}
public void ModifyHealth(int _amount)
public void ModifyHealth(int amount)
{
currentHealth += _amount;
currentHealth += amount;
CheckIfYouLost();
}
void CheckIfYouLost(){
private void CheckIfYouLost(){
if(currentHealth <= 0)
{
Debug.Log("You lost");
@ -44,20 +50,20 @@ namespace AsteroidGame.Handlers
}
}
public void ModifyWealth(int _amount){
currentBalance += _amount;
public void ModifyWealth(int amount){
currentBalance += amount;
UpdateGUI();
// Debug.Log($"Wealth modification. Change:{_amount}. Current: {wealthAmount}");
}
void Reload()
private void Reload()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
void UpdateGUI(){
dispayBalance.text = $"Gold: {currentBalance.ToString()}";
private void UpdateGUI(){
displayBalance.text = $"Gold: {currentBalance.ToString()}";
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e2384c91225c2604da02a052608c9e03
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -8,7 +8,7 @@ ScriptedImporter:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
generateWrapperCode: 1
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace:
wrapperCodeNamespace: AsteroidGame

View File

@ -123,7 +123,7 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &142965237
--- !u!1 &38176945
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -131,120 +131,31 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 142965241}
- component: {fileID: 142965240}
- component: {fileID: 38176946}
m_Layer: 0
m_Name: InputSystem
m_Name: Handlers
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &142965240
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 142965237}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: d126f168386ad6b4986b0d51ca34c3ca, type: 3}
m_NotificationBehavior: 1
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
m_Calls: []
m_DeviceRegainedEvent:
m_PersistentCalls:
m_Calls: []
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_ActionEvents:
- m_PersistentCalls:
m_Calls: []
m_ActionId: 7a6c0190-d56d-4da5-bc75-c47ee4143d4c
m_ActionName: Player/Move[/XInputControllerWindows/leftStick,/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 7a8d4301-f9d3-4c1d-9691-a6080f8ae66f
m_ActionName: Player/Look[/XInputControllerWindows/rightStick,/Mouse/delta]
- m_PersistentCalls:
m_Calls: []
m_ActionId: c7463e6d-1380-4e73-9edf-f690e3eabd4e
m_ActionName: Player/Click[/XInputControllerWindows/rightTrigger,/Mouse/leftButton]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 20ae2f11-0cff-4b9e-a8bc-9e4991614bbb
m_ActionName: UI/Navigate[/XInputControllerWindows/leftStick/up,/XInputControllerWindows/rightStick/up,/XInputControllerWindows/leftStick/down,/XInputControllerWindows/rightStick/down,/XInputControllerWindows/leftStick/left,/XInputControllerWindows/rightStick/left,/XInputControllerWindows/leftStick/right,/XInputControllerWindows/rightStick/right,/XInputControllerWindows/dpad,/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]
- m_PersistentCalls:
m_Calls: []
m_ActionId: a852f158-148f-4764-923f-82ab136e1f9c
m_ActionName: UI/Submit[/Keyboard/enter,/XInputControllerWindows/buttonSouth]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 2c8b2d4b-b9a6-4167-9b1c-c253dfb90ca1
m_ActionName: UI/Cancel[/Keyboard/escape,/XInputControllerWindows/buttonEast]
- m_PersistentCalls:
m_Calls: []
m_ActionId: fdeb066f-411a-48b2-9896-9409fee8baf3
m_ActionName: UI/Point[/Mouse/position]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 05c47259-ced4-4daa-8dc2-9ccf26ff9632
m_ActionName: UI/Click[/Mouse/leftButton]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 87290d81-61b6-491c-859f-4a1a31f60f1f
m_ActionName: UI/ScrollWheel[/Mouse/scroll]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 97ad60d8-d5db-4a14-8a83-c27358422a2e
m_ActionName: UI/MiddleClick[/Mouse/middleButton]
- m_PersistentCalls:
m_Calls: []
m_ActionId: fa3293a2-4bbc-4f63-b1e8-aa0a7d75ea96
m_ActionName: UI/RightClick[/Mouse/rightButton]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 35072b0b-93e9-4d04-bfe6-5ccaaae85338
m_ActionName: UI/TrackedDevicePosition
- m_PersistentCalls:
m_Calls: []
m_ActionId: e0014bd4-6f96-428c-abdb-daf443019be7
m_ActionName: UI/TrackedDeviceOrientation
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: Player
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!4 &142965241
--- !u!4 &38176946
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 142965237}
m_GameObject: {fileID: 38176945}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 436649171}
- {fileID: 1158682046}
- {fileID: 1047643964}
- {fileID: 1158682046}
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &436649171 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8083988910661828847, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
m_PrefabInstance: {fileID: 1191794244}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1047643963
GameObject:
m_ObjectHideFlags: 0
@ -274,8 +185,8 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 142965241}
m_RootOrder: 2
m_Father: {fileID: 38176946}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1047643965
MonoBehaviour:
@ -319,12 +230,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1158682045}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 142965241}
m_Father: {fileID: 38176946}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1158682047
@ -349,7 +260,7 @@ PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 142965241}
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 8083988910661828845, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
propertyPath: m_Name
@ -357,7 +268,19 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8083988910661828847, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
propertyPath: m_RootOrder
value: 0
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8083988910661828847, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8083988910661828847, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8083988910661828847, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8083988910661828847, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
@ -604,7 +527,7 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 8324879816836607384, guid: 534f8d15e0c83c646887bebfda2bdfd6, type: 3}
propertyPath: m_RootOrder
value: 2
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8324879816836607384, guid: 534f8d15e0c83c646887bebfda2bdfd6, type: 3}
propertyPath: m_LocalPosition.x