diff --git a/theProject/Assets/Input System.meta b/theProject/Assets/Input System.meta new file mode 100644 index 00000000..8adc5b0b --- /dev/null +++ b/theProject/Assets/Input System.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 13d87264ef46bb94e8c5feefffc1e816 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/theProject/Assets/Input System/BetterInput.cs b/theProject/Assets/Input System/BetterInput.cs new file mode 100644 index 00000000..4372a80b --- /dev/null +++ b/theProject/Assets/Input System/BetterInput.cs @@ -0,0 +1,208 @@ +//------------------------------------------------------------------------------ +// +// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator +// version 1.3.0 +// from Assets/Input System/BetterInput.inputactions +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine.InputSystem; +using UnityEngine.InputSystem.Utilities; + +public partial class @BetterInput : IInputActionCollection2, IDisposable +{ + public InputActionAsset asset { get; } + public @BetterInput() + { + asset = InputActionAsset.FromJson(@"{ + ""name"": ""BetterInput"", + ""maps"": [ + { + ""name"": ""Main"", + ""id"": ""4b18db26-1517-44fd-a720-3375a87d3e57"", + ""actions"": [ + { + ""name"": ""MouseLeftClick"", + ""type"": ""Button"", + ""id"": ""8d155000-3a72-43d3-8bfe-93d72a796753"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false + }, + { + ""name"": ""MousePosition"", + ""type"": ""PassThrough"", + ""id"": ""77dce579-48e8-463c-9642-2c6546293638"", + ""expectedControlType"": ""Vector2"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false + } + ], + ""bindings"": [ + { + ""name"": """", + ""id"": ""a5b53ba7-9040-447d-9a40-5d3ef675189c"", + ""path"": ""/leftButton"", + ""interactions"": """", + ""processors"": """", + ""groups"": ""Keyboard+Mouse"", + ""action"": ""MouseLeftClick"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""67d09b79-2555-46f8-b8f8-d1475b59116a"", + ""path"": ""/position"", + ""interactions"": """", + ""processors"": """", + ""groups"": ""Keyboard+Mouse"", + ""action"": ""MousePosition"", + ""isComposite"": false, + ""isPartOfComposite"": false + } + ] + } + ], + ""controlSchemes"": [ + { + ""name"": ""Keyboard+Mouse"", + ""bindingGroup"": ""Keyboard+Mouse"", + ""devices"": [ + { + ""devicePath"": """", + ""isOptional"": false, + ""isOR"": false + }, + { + ""devicePath"": """", + ""isOptional"": false, + ""isOR"": false + } + ] + } + ] +}"); + // Main + m_Main = asset.FindActionMap("Main", throwIfNotFound: true); + m_Main_MouseLeftClick = m_Main.FindAction("MouseLeftClick", throwIfNotFound: true); + m_Main_MousePosition = m_Main.FindAction("MousePosition", throwIfNotFound: true); + } + + public void Dispose() + { + UnityEngine.Object.Destroy(asset); + } + + public InputBinding? bindingMask + { + get => asset.bindingMask; + set => asset.bindingMask = value; + } + + public ReadOnlyArray? devices + { + get => asset.devices; + set => asset.devices = value; + } + + public ReadOnlyArray controlSchemes => asset.controlSchemes; + + public bool Contains(InputAction action) + { + return asset.Contains(action); + } + + public IEnumerator GetEnumerator() + { + return asset.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Enable() + { + asset.Enable(); + } + + public void Disable() + { + asset.Disable(); + } + public IEnumerable bindings => asset.bindings; + + public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false) + { + return asset.FindAction(actionNameOrId, throwIfNotFound); + } + public int FindBinding(InputBinding bindingMask, out InputAction action) + { + return asset.FindBinding(bindingMask, out action); + } + + // Main + private readonly InputActionMap m_Main; + private IMainActions m_MainActionsCallbackInterface; + private readonly InputAction m_Main_MouseLeftClick; + private readonly InputAction m_Main_MousePosition; + public struct MainActions + { + private @BetterInput m_Wrapper; + public MainActions(@BetterInput wrapper) { m_Wrapper = wrapper; } + public InputAction @MouseLeftClick => m_Wrapper.m_Main_MouseLeftClick; + public InputAction @MousePosition => m_Wrapper.m_Main_MousePosition; + public InputActionMap Get() { return m_Wrapper.m_Main; } + public void Enable() { Get().Enable(); } + public void Disable() { Get().Disable(); } + public bool enabled => Get().enabled; + public static implicit operator InputActionMap(MainActions set) { return set.Get(); } + public void SetCallbacks(IMainActions instance) + { + if (m_Wrapper.m_MainActionsCallbackInterface != null) + { + @MouseLeftClick.started -= m_Wrapper.m_MainActionsCallbackInterface.OnMouseLeftClick; + @MouseLeftClick.performed -= m_Wrapper.m_MainActionsCallbackInterface.OnMouseLeftClick; + @MouseLeftClick.canceled -= m_Wrapper.m_MainActionsCallbackInterface.OnMouseLeftClick; + @MousePosition.started -= m_Wrapper.m_MainActionsCallbackInterface.OnMousePosition; + @MousePosition.performed -= m_Wrapper.m_MainActionsCallbackInterface.OnMousePosition; + @MousePosition.canceled -= m_Wrapper.m_MainActionsCallbackInterface.OnMousePosition; + } + m_Wrapper.m_MainActionsCallbackInterface = instance; + if (instance != null) + { + @MouseLeftClick.started += instance.OnMouseLeftClick; + @MouseLeftClick.performed += instance.OnMouseLeftClick; + @MouseLeftClick.canceled += instance.OnMouseLeftClick; + @MousePosition.started += instance.OnMousePosition; + @MousePosition.performed += instance.OnMousePosition; + @MousePosition.canceled += instance.OnMousePosition; + } + } + } + public MainActions @Main => new MainActions(this); + private int m_KeyboardMouseSchemeIndex = -1; + public InputControlScheme KeyboardMouseScheme + { + get + { + if (m_KeyboardMouseSchemeIndex == -1) m_KeyboardMouseSchemeIndex = asset.FindControlSchemeIndex("Keyboard+Mouse"); + return asset.controlSchemes[m_KeyboardMouseSchemeIndex]; + } + } + public interface IMainActions + { + void OnMouseLeftClick(InputAction.CallbackContext context); + void OnMousePosition(InputAction.CallbackContext context); + } +} diff --git a/theProject/Assets/Input System/BetterInput.cs.meta b/theProject/Assets/Input System/BetterInput.cs.meta new file mode 100644 index 00000000..0ebe4744 --- /dev/null +++ b/theProject/Assets/Input System/BetterInput.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c6563552628476d4c8891087a2b11032 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/theProject/Assets/Input System/BetterInput.inputactions b/theProject/Assets/Input System/BetterInput.inputactions new file mode 100644 index 00000000..44e5d392 --- /dev/null +++ b/theProject/Assets/Input System/BetterInput.inputactions @@ -0,0 +1,71 @@ +{ + "name": "BetterInput", + "maps": [ + { + "name": "Main", + "id": "4b18db26-1517-44fd-a720-3375a87d3e57", + "actions": [ + { + "name": "MouseLeftClick", + "type": "Button", + "id": "8d155000-3a72-43d3-8bfe-93d72a796753", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "MousePosition", + "type": "PassThrough", + "id": "77dce579-48e8-463c-9642-2c6546293638", + "expectedControlType": "Vector2", + "processors": "", + "interactions": "", + "initialStateCheck": false + } + ], + "bindings": [ + { + "name": "", + "id": "a5b53ba7-9040-447d-9a40-5d3ef675189c", + "path": "/leftButton", + "interactions": "", + "processors": "", + "groups": "Keyboard+Mouse", + "action": "MouseLeftClick", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "67d09b79-2555-46f8-b8f8-d1475b59116a", + "path": "/position", + "interactions": "", + "processors": "", + "groups": "Keyboard+Mouse", + "action": "MousePosition", + "isComposite": false, + "isPartOfComposite": false + } + ] + } + ], + "controlSchemes": [ + { + "name": "Keyboard+Mouse", + "bindingGroup": "Keyboard+Mouse", + "devices": [ + { + "devicePath": "", + "isOptional": false, + "isOR": false + }, + { + "devicePath": "", + "isOptional": false, + "isOR": false + } + ] + } + ] +} \ No newline at end of file diff --git a/theProject/Assets/Input System/BetterInput.inputactions.meta b/theProject/Assets/Input System/BetterInput.inputactions.meta new file mode 100644 index 00000000..878d8023 --- /dev/null +++ b/theProject/Assets/Input System/BetterInput.inputactions.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: f833a28ff10011644bc4c405b370325c +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} + generateWrapperCode: 1 + wrapperCodePath: + wrapperClassName: + wrapperCodeNamespace: diff --git a/theProject/Assets/Scripts/Player/PlayerClickSystem.cs b/theProject/Assets/Scripts/Player/PlayerClickSystem.cs index e3594056..1709a062 100644 --- a/theProject/Assets/Scripts/Player/PlayerClickSystem.cs +++ b/theProject/Assets/Scripts/Player/PlayerClickSystem.cs @@ -5,8 +5,20 @@ using UnityEngine; public class PlayerClickSystem : MonoBehaviour { [SerializeField] TilemapManager tilemapManager; + + private BetterInput bInput; + private bool leftMouseClicked = false; + private Vector2 mousePos = Vector2.zero; + private void Awake() { + bInput = new BetterInput(); + + bInput.Main.MouseLeftClick.started += (ctx) => { leftMouseClicked = true; }; + bInput.Main.MouseLeftClick.canceled += (ctx) => { leftMouseClicked = false; }; + + bInput.Main.MousePosition.performed += (ctx) => { mousePos = ctx.ReadValue(); }; + tilemapManager = FindObjectOfType(); if(tilemapManager == null) { @@ -16,12 +28,13 @@ public class PlayerClickSystem : MonoBehaviour // Update is called once per frame void Update() { - if(Input.GetMouseButton(0)) // Change to new input system + if(leftMouseClicked) // Change to new input system { + leftMouseClicked = false; //Debug.Log("CLICK"); Camera camera = Camera.main; RaycastHit hit; - Ray ray = camera.ScreenPointToRay(Input.mousePosition); + Ray ray = camera.ScreenPointToRay(mousePos); if (Physics.Raycast(ray, out hit)) { @@ -43,4 +56,14 @@ public class PlayerClickSystem : MonoBehaviour } } } + + private void OnEnable() + { + bInput.Main.Enable(); + } + + private void OnDisable() + { + bInput.Main.Disable(); + } } diff --git a/theProject/Packages/manifest.json b/theProject/Packages/manifest.json index b92b6a05..ced2430f 100644 --- a/theProject/Packages/manifest.json +++ b/theProject/Packages/manifest.json @@ -6,6 +6,7 @@ "com.unity.ide.rider": "3.0.13", "com.unity.ide.visualstudio": "2.0.14", "com.unity.ide.vscode": "1.2.5", + "com.unity.inputsystem": "1.3.0", "com.unity.render-pipelines.universal": "12.1.6", "com.unity.test-framework": "1.1.31", "com.unity.textmeshpro": "3.0.6", diff --git a/theProject/Packages/packages-lock.json b/theProject/Packages/packages-lock.json index 42510d6d..cf2371bf 100644 --- a/theProject/Packages/packages-lock.json +++ b/theProject/Packages/packages-lock.json @@ -68,6 +68,15 @@ "dependencies": {}, "url": "https://packages.unity.com" }, + "com.unity.inputsystem": { + "version": "1.3.0", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.modules.uielements": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.mathematics": { "version": "1.2.6", "depth": 1, diff --git a/theProject/ProjectSettings/ProjectSettings.asset b/theProject/ProjectSettings/ProjectSettings.asset index 94efce3a..a345c73b 100644 --- a/theProject/ProjectSettings/ProjectSettings.asset +++ b/theProject/ProjectSettings/ProjectSettings.asset @@ -853,7 +853,7 @@ PlayerSettings: m_VersionCode: 1 m_VersionName: apiCompatibilityLevel: 6 - activeInputHandler: 0 + activeInputHandler: 1 cloudProjectId: framebufferDepthMemorylessMode: 0 qualitySettingsNames: []