mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 18:03:14 +02:00
merloj: added input system
This commit is contained in:
parent
cc06fd99d9
commit
f1fe305d79
8
theProject/Assets/Input System.meta
Normal file
8
theProject/Assets/Input System.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13d87264ef46bb94e8c5feefffc1e816
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
208
theProject/Assets/Input System/BetterInput.cs
Normal file
208
theProject/Assets/Input System/BetterInput.cs
Normal file
@ -0,0 +1,208 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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"": ""<Mouse>/leftButton"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": ""Keyboard+Mouse"",
|
||||
""action"": ""MouseLeftClick"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""67d09b79-2555-46f8-b8f8-d1475b59116a"",
|
||||
""path"": ""<Mouse>/position"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": ""Keyboard+Mouse"",
|
||||
""action"": ""MousePosition"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
""controlSchemes"": [
|
||||
{
|
||||
""name"": ""Keyboard+Mouse"",
|
||||
""bindingGroup"": ""Keyboard+Mouse"",
|
||||
""devices"": [
|
||||
{
|
||||
""devicePath"": ""<Keyboard>"",
|
||||
""isOptional"": false,
|
||||
""isOR"": false
|
||||
},
|
||||
{
|
||||
""devicePath"": ""<Mouse>"",
|
||||
""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<InputDevice>? devices
|
||||
{
|
||||
get => asset.devices;
|
||||
set => asset.devices = value;
|
||||
}
|
||||
|
||||
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
|
||||
|
||||
public bool Contains(InputAction action)
|
||||
{
|
||||
return asset.Contains(action);
|
||||
}
|
||||
|
||||
public IEnumerator<InputAction> GetEnumerator()
|
||||
{
|
||||
return asset.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
asset.Enable();
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
asset.Disable();
|
||||
}
|
||||
public IEnumerable<InputBinding> 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);
|
||||
}
|
||||
}
|
||||
11
theProject/Assets/Input System/BetterInput.cs.meta
Normal file
11
theProject/Assets/Input System/BetterInput.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6563552628476d4c8891087a2b11032
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
theProject/Assets/Input System/BetterInput.inputactions
Normal file
71
theProject/Assets/Input System/BetterInput.inputactions
Normal file
@ -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": "<Mouse>/leftButton",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard+Mouse",
|
||||
"action": "MouseLeftClick",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "67d09b79-2555-46f8-b8f8-d1475b59116a",
|
||||
"path": "<Mouse>/position",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard+Mouse",
|
||||
"action": "MousePosition",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": [
|
||||
{
|
||||
"name": "Keyboard+Mouse",
|
||||
"bindingGroup": "Keyboard+Mouse",
|
||||
"devices": [
|
||||
{
|
||||
"devicePath": "<Keyboard>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
},
|
||||
{
|
||||
"devicePath": "<Mouse>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
14
theProject/Assets/Input System/BetterInput.inputactions.meta
Normal file
14
theProject/Assets/Input System/BetterInput.inputactions.meta
Normal file
@ -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:
|
||||
@ -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<Vector2>(); };
|
||||
|
||||
tilemapManager = FindObjectOfType<TilemapManager>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -853,7 +853,7 @@ PlayerSettings:
|
||||
m_VersionCode: 1
|
||||
m_VersionName:
|
||||
apiCompatibilityLevel: 6
|
||||
activeInputHandler: 0
|
||||
activeInputHandler: 1
|
||||
cloudProjectId:
|
||||
framebufferDepthMemorylessMode: 0
|
||||
qualitySettingsNames: []
|
||||
|
||||
Loading…
Reference in New Issue
Block a user