新增动态水物理插件

This commit is contained in:
Bob.Song
2026-02-27 17:44:21 +08:00
parent a6e061d9ce
commit 60744d113d
2218 changed files with 698551 additions and 189 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7fe077b4c52343fa8e5847a73b494315
timeCreated: 1593368872

View File

@@ -0,0 +1,110 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
#if UNITY_EDITOR
using NWH.NUI;
using UnityEditor;
#endif
#endregion
namespace NWH.Common.Input
{
/// <summary>
/// Scene input provider using Unity's legacy Input Manager system.
/// Requires input axes and buttons to be configured in Project Settings > Input Manager.
/// </summary>
public class InputManagerSceneInputProvider : SceneInputProviderBase
{
public override bool ChangeCamera()
{
return InputUtils.TryGetButtonDown("ChangeCamera", KeyCode.C);
}
public override Vector2 CameraRotation()
{
return new Vector2(InputUtils.TryGetAxis("CameraRotationX"), InputUtils.TryGetAxis("CameraRotationY"));
}
public override Vector2 CameraPanning()
{
return new Vector2(InputUtils.TryGetAxis("CameraPanningX"), InputUtils.TryGetAxis("CameraPanningY"));
}
public override bool CameraRotationModifier()
{
return InputUtils.TryGetButton("CameraRotationModifier", KeyCode.Mouse0) || !requireCameraRotationModifier;
}
public override bool CameraPanningModifier()
{
return InputUtils.TryGetButton("CameraPanningModifier", KeyCode.Mouse1) || !requireCameraPanningModifier;
}
public override float CameraZoom()
{
return InputUtils.TryGetAxis("CameraZoom");
}
public override bool ChangeVehicle()
{
return InputUtils.TryGetButtonDown("ChangeVehicle", KeyCode.V);
}
public override Vector2 CharacterMovement()
{
return new Vector2(InputUtils.TryGetAxis("FPSMovementX"), InputUtils.TryGetAxis("FPSMovementY"));
}
public override bool ToggleGUI()
{
return InputUtils.TryGetButtonDown("ToggleGUI", KeyCode.Tab);
}
}
}
#if UNITY_EDITOR
namespace NWH.Common.Input
{
[CustomEditor(typeof(InputManagerSceneInputProvider))]
public class InputManagerSceneInputProviderEditor : NUIEditor
{
public override bool OnInspectorNUI()
{
if (!base.OnInspectorNUI())
{
return false;
}
drawer.Field("requireCameraRotationModifier");
drawer.Field("requireCameraPanningModifier");
drawer.EndEditor(this);
return true;
}
public override bool UseDefaultMargins()
{
return false;
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ec707ef612184d5e9a0dfbf4bdba1e7d
timeCreated: 1593368891

View File

@@ -0,0 +1,148 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using System;
using System.Collections.Generic;
using UnityEngine;
#endregion
namespace NWH.Common.Input
{
/// <summary>
/// Base class from which all input providers inherit.
/// </summary>
public abstract class InputProvider : MonoBehaviour
{
/// <summary>
/// List of all InputProviders in the scene.
/// </summary>
public static List<InputProvider> Instances = new();
public virtual void Awake()
{
Instances.Add(this);
}
public virtual void OnDestroy()
{
Instances.Remove(this);
}
/// <summary>
/// Returns combined input of all InputProviders present in the scene.
/// Result will be a sum of all inputs of the selected type.
/// T is a type of InputProvider that the input will be retrieved from.
/// </summary>
public static int CombinedInput<T>(Func<T, int> selector) where T : InputProvider
{
int sum = 0;
int count = Instances.Count;
for (int i = 0; i < count; i++)
{
if (i >= Instances.Count)
{
break;
}
InputProvider ip = Instances[i];
if (ip != null && ip is T provider)
{
sum += selector(provider);
}
}
return sum;
}
/// <summary>
/// Returns combined input of all InputProviders present in the scene.
/// Result will be a sum of all inputs of the selected type.
/// T is a type of InputProvider that the input will be retrieved from.
/// </summary>
public static float CombinedInput<T>(Func<T, float> selector) where T : InputProvider
{
float sum = 0;
int count = Instances.Count;
for (int i = 0; i < count; i++)
{
if (i >= Instances.Count)
{
break;
}
InputProvider ip = Instances[i];
if (ip != null && ip is T provider)
{
sum += selector(provider);
}
}
return sum;
}
/// <summary>
/// Returns combined input of all InputProviders present in the scene.
/// Result will be positive if any InputProvider has the selected input set to true.
/// T is a type of InputProvider that the input will be retrieved from.
/// </summary>
public static bool CombinedInput<T>(Func<T, bool> selector) where T : InputProvider
{
int count = Instances.Count;
for (int i = 0; i < count; i++)
{
if (i >= Instances.Count)
{
break;
}
InputProvider ip = Instances[i];
if (ip != null && ip is T provider && selector(provider))
{
return true;
}
}
return false;
}
/// <summary>
/// Returns combined input of all InputProviders present in the scene.
/// Result will be a sum of all inputs of the selected type.
/// T is a type of InputProvider that the input will be retrieved from.
/// </summary>
public static Vector2 CombinedInput<T>(Func<T, Vector2> selector) where T : InputProvider
{
Vector2 sum = Vector2.zero;
int count = Instances.Count;
for (int i = 0; i < count; i++)
{
if (i >= Instances.Count)
{
break;
}
InputProvider ip = Instances[i];
if (ip != null && ip is T provider)
{
sum += selector(provider);
}
}
return sum;
}
}
}

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4c1d12a1d99348ce902816a92f250e14
timeCreated: 1593369086

View File

@@ -0,0 +1,135 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
#if UNITY_EDITOR
using NWH.NUI;
using UnityEditor;
#endif
#endregion
namespace NWH.Common.Input
{
/// <summary>
/// Unity Input System implementation of scene input provider.
/// Handles camera controls and scene navigation using the new Input System.
/// </summary>
public class InputSystemSceneInputProvider : SceneInputProviderBase
{
public SceneInputActions sceneInputActions;
private bool _panningModifier;
private bool _rotationModifier;
public override void Awake()
{
base.Awake();
sceneInputActions = new SceneInputActions();
sceneInputActions.Enable();
sceneInputActions.CameraControls.CameraRotationModifier.started += ctx => _rotationModifier = true;
sceneInputActions.CameraControls.CameraRotationModifier.canceled += ctx => _rotationModifier = false;
sceneInputActions.CameraControls.CameraPanningModifier.started += ctx => _panningModifier = true;
sceneInputActions.CameraControls.CameraPanningModifier.canceled += ctx => _panningModifier = false;
}
public override bool ChangeCamera()
{
return sceneInputActions.CameraControls.ChangeCamera.triggered;
}
public override Vector2 CameraRotation()
{
return sceneInputActions.CameraControls.CameraRotation.ReadValue<Vector2>();
}
public override Vector2 CameraPanning()
{
return sceneInputActions.CameraControls.CameraPanning.ReadValue<Vector2>();
}
public override bool CameraRotationModifier()
{
return _rotationModifier || !requireCameraRotationModifier;
}
public override bool CameraPanningModifier()
{
return _panningModifier || !requireCameraPanningModifier;
}
public override float CameraZoom()
{
return sceneInputActions.CameraControls.CameraZoom.ReadValue<float>() * 0.1f;
}
public override bool ChangeVehicle()
{
return sceneInputActions.SceneControls.ChangeVehicle.triggered;
}
public override Vector2 CharacterMovement()
{
return sceneInputActions.SceneControls.FPSMovement.ReadValue<Vector2>();
}
public override bool ToggleGUI()
{
return sceneInputActions.SceneControls.ToggleGUI.triggered;
}
}
}
#if UNITY_EDITOR
namespace NWH.Common.Input
{
[CustomEditor(typeof(InputSystemSceneInputProvider))]
public class InputSystemSceneInputProviderEditor : NUIEditor
{
public override bool OnInspectorNUI()
{
if (!base.OnInspectorNUI())
{
return false;
}
drawer.Info("Input settings for Unity's new input system can be changed by modifying 'SceneInputActions' " +
"file (double click on it to open).");
drawer.Field("requireCameraRotationModifier");
drawer.Field("requireCameraPanningModifier");
drawer.EndEditor(this);
return true;
}
public override bool UseDefaultMargins()
{
return false;
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9c48880c19d04dabb53da07d15024184
timeCreated: 1593369107

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -0,0 +1,528 @@
{
"name": "SceneInputActions",
"maps": [
{
"name": "CameraControls",
"id": "f9b2c2eb-8265-4430-a0ac-4cf8495a2002",
"actions": [
{
"name": "ChangeCamera",
"type": "Button",
"id": "71ec0b0c-0911-4b04-a2cc-424b01ebe88e",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "CameraRotation",
"type": "Value",
"id": "8f870466-b390-4fae-a439-ccb19a4537c2",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "CameraPanning",
"type": "Value",
"id": "08d3e09d-7ab8-4f42-976a-530f947fe4c8",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "CameraRotationModifier",
"type": "Button",
"id": "124e3374-e4a2-4e74-b0cf-c8959a11ac39",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "CameraPanningModifier",
"type": "Button",
"id": "ce8eda53-b48a-45c4-83c7-3f0b44ad36f7",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "CameraZoom",
"type": "Value",
"id": "018cdf61-e865-49da-9064-33dc2ae63580",
"expectedControlType": "Analog",
"processors": "",
"interactions": "",
"initialStateCheck": true
}
],
"bindings": [
{
"name": "",
"id": "24fa1b4b-fa43-49bc-ba60-3aedbe8d6c1f",
"path": "<Keyboard>/c",
"interactions": "",
"processors": "",
"groups": "",
"action": "ChangeCamera",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "530b85ac-4cae-49f9-804b-3a0dbaeb4a7b",
"path": "<Gamepad>/start",
"interactions": "",
"processors": "",
"groups": "",
"action": "ChangeCamera",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "6d0ae04c-f252-4dd6-824a-27baa3d26db7",
"path": "<Mouse>/delta",
"interactions": "",
"processors": "ScaleVector2(x=0.2,y=0.2)",
"groups": "",
"action": "CameraRotation",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "Gamepad",
"id": "2cb8a8bc-5e28-4393-bc30-fe55c9d9ffc7",
"path": "2DVector(mode=2)",
"interactions": "",
"processors": "InvertVector2",
"groups": "",
"action": "CameraRotation",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "a144950a-0314-41fb-b0a3-0fa7943d12f1",
"path": "<Gamepad>/rightStick/up",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotation",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "a039c90a-129d-43ea-b2ec-bffde20e618a",
"path": "<Gamepad>/rightStick/down",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotation",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "e78f01bc-414a-4ba8-83e0-02deb5f631c6",
"path": "<Gamepad>/rightStick/left",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotation",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "3cd6cbde-a6f8-4da4-8cc2-9c8c1edc133e",
"path": "<Gamepad>/rightStick/right",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotation",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "9e78c527-4641-4f9b-98e4-fb7f87edf64d",
"path": "<Mouse>/delta",
"interactions": "",
"processors": "ScaleVector2(x=0.2,y=0.2)",
"groups": "",
"action": "CameraPanning",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "3968d956-a143-403b-87e5-0b91afb999eb",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotationModifier",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "8f3a4e0e-6782-4b53-8c26-e06e68d8e1ee",
"path": "<Gamepad>/rightStickPress",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotationModifier",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "8a15b75c-fd20-4def-8b73-5d8273fe3364",
"path": "<Mouse>/rightButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraPanningModifier",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "dee7ac85-80d0-4018-bbe7-114eecc930ae",
"path": "<Gamepad>/leftStickPress",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraPanningModifier",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "Gamepad",
"id": "93e86e22-3ea3-4e7f-b800-9fc9575e9190",
"path": "2DVector",
"interactions": "",
"processors": "InvertVector2",
"groups": "",
"action": "CameraPanning",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "9e35bef4-dec2-47ce-a040-063273bd2183",
"path": "<Gamepad>/rightStick/up",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraPanning",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "ca312712-12f3-438c-a542-d998b4fca387",
"path": "<Gamepad>/rightStick/down",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraPanning",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "16a19e86-eb75-40ef-a937-cc69f5c57971",
"path": "<Gamepad>/rightStick/left",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraPanning",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "338131ba-47f8-4fc8-b137-39be986200ed",
"path": "<Gamepad>/rightStick/right",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraPanning",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "2553a5ac-0892-4d77-a408-8b5fced329a8",
"path": "<Mouse>/scroll/y",
"interactions": "",
"processors": "Scale(factor=0.1)",
"groups": "",
"action": "CameraZoom",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "Gamepad",
"id": "aeaabcc3-6825-4a24-b1b3-13b3a70fff59",
"path": "1DAxis(whichSideWins=1)",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraZoom",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "negative",
"id": "d55890ea-00d2-483e-9b0a-e2ba85f4b2dd",
"path": "<Gamepad>/dpad/down",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraZoom",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "positive",
"id": "3ce859ed-6297-4bab-b40b-d6436bacd5ab",
"path": "<Gamepad>/dpad/up",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraZoom",
"isComposite": false,
"isPartOfComposite": true
}
]
},
{
"name": "SceneControls",
"id": "abb87e97-bffa-439c-a42d-7b1a9497c4cc",
"actions": [
{
"name": "ChangeVehicle",
"type": "Button",
"id": "a6ddd2a4-de73-4949-8b79-fef6d4b4bc3f",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "FPSMovement",
"type": "Value",
"id": "347a1c7d-d6ca-4838-9d67-ca3bece4074f",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "ToggleGUI",
"type": "Button",
"id": "420fdb48-6cea-444b-8cd6-256097129d3b",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "DragObjectModifier",
"type": "Button",
"id": "1fd9ef37-8fcf-43c4-9b96-ed432f843af4",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "ShowCursor",
"type": "Button",
"id": "4566d436-6301-4d31-bd9b-984b19b6cc9b",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "",
"id": "02e5b759-a74a-41e1-af72-80c6990f0d95",
"path": "<Keyboard>/v",
"interactions": "",
"processors": "",
"groups": "",
"action": "ChangeVehicle",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "01597fdb-29e0-4e77-a920-ba59240fe6d6",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "",
"action": "ChangeVehicle",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "Keyboard",
"id": "59431748-63e9-4210-8dd9-590e23bcdf0c",
"path": "2DVector(mode=1)",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "e0b8875d-06d4-467d-b8f0-61da2e804895",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "87e4ea7c-c07f-491e-8dc6-36f79dbf9805",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "9bba77a1-921c-493d-b881-6f14f1eb377b",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "cfa4cf6d-3fe9-4930-847f-b59a8277a8fc",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "Gamepad",
"id": "208efade-fdb9-49b9-a679-eb44b6ed6ac2",
"path": "2DVector(mode=2)",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "8087e701-d9e1-454b-8b70-50813a31516b",
"path": "<Gamepad>/leftStick/up",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "0b594ea6-b48c-4805-9cea-77058ade6d6a",
"path": "<Gamepad>/leftStick/down",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "e7548400-0520-4980-aded-b6d0ac753e4a",
"path": "<Gamepad>/leftStick/left",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "b46be990-1176-4948-8642-dddc1bf5ee6c",
"path": "<Gamepad>/leftStick/right",
"interactions": "",
"processors": "",
"groups": "",
"action": "FPSMovement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "9f9f8d86-cd0b-4953-8490-e72ab4b7d8f0",
"path": "<Keyboard>/tab",
"interactions": "",
"processors": "",
"groups": "",
"action": "ToggleGUI",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "2d06a9ed-570c-45df-ae1b-aec7652096fd",
"path": "<Mouse>/middleButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "DragObjectModifier",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "2685a4d7-beae-479c-a63b-f7cd494f9c8a",
"path": "<Keyboard>/leftCtrl",
"interactions": "",
"processors": "",
"groups": "",
"action": "ShowCursor",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": []
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: e6287ac585a812c479a27c6d0be9f915
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 1
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace: NWH.Common.Input

View File

@@ -0,0 +1,134 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
#endregion
namespace NWH.Common.Input
{
/// <summary>
/// Utility methods for safe input retrieval with automatic fallback to default keys.
/// Prevents errors when Input Manager bindings are missing.
/// </summary>
public class InputUtils
{
private static int _warningCount;
/// <summary>
/// Attempts to retrieve button state from Input Manager, falls back to KeyCode if binding is missing.
/// </summary>
/// <param name="buttonName">Input Manager button name to query.</param>
/// <param name="altKey">Fallback KeyCode to use if binding is missing.</param>
/// <param name="showWarning">Display warning message when falling back to default key.</param>
/// <returns>True if button is currently held down.</returns>
public static bool TryGetButton(string buttonName, KeyCode altKey, bool showWarning = true)
{
try
{
return UnityEngine.Input.GetButton(buttonName);
}
catch
{
// Make sure warning is not spammed as some users tend to ignore the warning and never set up the input,
// resulting in bad performance in editor.
if (_warningCount < 100 && showWarning)
{
Debug.LogWarning(buttonName +
" input binding missing, falling back to default. Check Input section in manual for more info.");
_warningCount++;
}
return UnityEngine.Input.GetKey(altKey);
}
}
/// <summary>
/// Attempts to retrieve button press from Input Manager, falls back to KeyCode if binding is missing.
/// </summary>
/// <param name="buttonName">Input Manager button name to query.</param>
/// <param name="altKey">Fallback KeyCode to use if binding is missing.</param>
/// <param name="showWarning">Display warning message when falling back to default key.</param>
/// <returns>True on the frame the button was pressed.</returns>
public static bool TryGetButtonDown(string buttonName, KeyCode altKey, bool showWarning = true)
{
try
{
return UnityEngine.Input.GetButtonDown(buttonName);
}
catch
{
if (_warningCount < 100 && showWarning)
{
Debug.LogWarning(buttonName +
" input binding missing, falling back to default. Check Input section in manual for more info.");
_warningCount++;
}
return UnityEngine.Input.GetKeyDown(altKey);
}
}
/// <summary>
/// Attempts to retrieve axis value from Input Manager, returns 0 if binding is missing.
/// </summary>
/// <param name="axisName">Input Manager axis name to query.</param>
/// <param name="showWarning">Display warning message when axis is missing.</param>
/// <returns>Axis value between -1 and 1, or 0 if binding is missing.</returns>
public static float TryGetAxis(string axisName, bool showWarning = true)
{
try
{
return UnityEngine.Input.GetAxis(axisName);
}
catch
{
if (_warningCount < 100 && showWarning)
{
Debug.LogWarning(axisName +
" input binding missing. Check Input section in manual for more info.");
_warningCount++;
}
}
return 0;
}
/// <summary>
/// Attempts to retrieve raw axis value from Input Manager, returns 0 if binding is missing.
/// Raw axes return only -1, 0, or 1 without smoothing.
/// </summary>
/// <param name="axisName">Input Manager axis name to query.</param>
/// <param name="showWarning">Display warning message when axis is missing.</param>
/// <returns>Raw axis value (-1, 0, or 1), or 0 if binding is missing.</returns>
public static float TryGetAxisRaw(string axisName, bool showWarning = true)
{
try
{
return UnityEngine.Input.GetAxisRaw(axisName);
}
catch
{
if (_warningCount < 100 && showWarning)
{
Debug.LogWarning(axisName +
" input binding missing. Check Input section in manual for more info.");
_warningCount++;
}
}
return 0;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e808b630f95a45838f09520152a38a93
timeCreated: 1593368933

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: deaa0d3d555c4273bde9ce8e169f76b6
timeCreated: 1593369326

View File

@@ -0,0 +1,51 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
#endregion
namespace NWH.Common.Input
{
/// <summary>
/// Extended Unity UI Button with state tracking for mobile input handling.
/// Provides hasBeenClicked and isPressed flags for easier input polling.
/// </summary>
[DefaultExecutionOrder(1000)]
public class MobileInputButton : Button
{
/// <summary>
/// True for one frame after the button is clicked. Automatically resets to false.
/// </summary>
public bool hasBeenClicked;
/// <summary>
/// True while the button is being held down. Updates every frame.
/// </summary>
public bool isPressed;
private void Update()
{
isPressed = IsPressed();
hasBeenClicked = false;
}
public override void OnPointerDown(PointerEventData eventData)
{
base.OnPointerDown(eventData);
hasBeenClicked = true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d2117e63fb06445ababc499401d5c062
timeCreated: 1593369326

View File

@@ -0,0 +1,126 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
#if UNITY_EDITOR
using NWH.NUI;
using UnityEditor;
#endif
#endregion
namespace NWH.Common.Input
{
/// <summary>
/// Scene input provider for mobile platforms using on-screen UI buttons.
/// Requires MobileInputButton components assigned to changeCameraButton and changeVehicleButton fields.
/// </summary>
public class MobileSceneInputProvider : SceneInputProviderBase
{
/// <summary>
/// UI button for changing camera. Should reference a MobileInputButton in the scene.
/// </summary>
public MobileInputButton changeCameraButton;
/// <summary>
/// UI button for changing vehicle. Should reference a MobileInputButton in the scene.
/// </summary>
public MobileInputButton changeVehicleButton;
public override bool ChangeCamera()
{
return changeCameraButton != null && changeCameraButton.hasBeenClicked;
}
public override bool ChangeVehicle()
{
return changeVehicleButton != null && changeVehicleButton.hasBeenClicked;
}
public override Vector2 CharacterMovement()
{
return Vector2.zero;
}
public override bool ToggleGUI()
{
return false;
}
public override Vector2 CameraRotation()
{
return Vector2.zero;
}
public override Vector2 CameraPanning()
{
return Vector2.zero;
}
public override bool CameraRotationModifier()
{
return false;
}
public override bool CameraPanningModifier()
{
return false;
}
public override float CameraZoom()
{
return 0;
}
}
}
#if UNITY_EDITOR
namespace NWH.Common.Input
{
/// <summary>
/// Editor for MobileInputProvider.
/// </summary>
[CustomEditor(typeof(MobileSceneInputProvider))]
public class MobileSceneInputProviderEditor : NUIEditor
{
public override bool OnInspectorNUI()
{
if (!base.OnInspectorNUI())
{
return false;
}
drawer.BeginSubsection("Scene Buttons");
drawer.Field("changeVehicleButton");
drawer.Field("changeCameraButton");
drawer.EndSubsection();
drawer.EndEditor(this);
return true;
}
public override bool UseDefaultMargins()
{
return false;
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 907294c7523f458dba9b3b3e8955d681
timeCreated: 1593369326

View File

@@ -0,0 +1,117 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
#endregion
namespace NWH.Common.Input
{
/// <summary>
/// InputProvider for scene and camera related behavior.
/// </summary>
public abstract class SceneInputProviderBase : InputProvider
{
/// <summary>
/// If true a button press will be required to unlock camera panning.
/// </summary>
[Tooltip(" If true a button press will be required to unlock camera panning.")]
public bool requireCameraPanningModifier = true;
/// <summary>
/// If true a button press will be required to unlock camera rotation.
/// </summary>
[Tooltip(" If true a button press will be required to unlock camera rotation.")]
public bool requireCameraRotationModifier = true;
/// <summary>
/// Returns true when the change camera button is pressed.
/// </summary>
public virtual bool ChangeCamera()
{
return false;
}
/// <summary>
/// Returns camera rotation input as a Vector2 (x = horizontal, y = vertical).
/// </summary>
public virtual Vector2 CameraRotation()
{
return Vector2.zero;
}
/// <summary>
/// Returns camera panning input as a Vector2 (x = horizontal, y = vertical).
/// </summary>
public virtual Vector2 CameraPanning()
{
return Vector2.zero;
}
/// <summary>
/// Returns true when the camera rotation modifier button is held.
/// If requireCameraRotationModifier is false, always returns true.
/// </summary>
public virtual bool CameraRotationModifier()
{
return !requireCameraRotationModifier;
}
/// <summary>
/// Returns true when the camera panning modifier button is held.
/// If requireCameraPanningModifier is false, always returns true.
/// </summary>
public virtual bool CameraPanningModifier()
{
return !requireCameraPanningModifier;
}
/// <summary>
/// Returns camera zoom input value. Positive = zoom in, negative = zoom out.
/// </summary>
public virtual float CameraZoom()
{
return 0;
}
/// <summary>
/// Returns true when the change vehicle button is pressed.
/// </summary>
public virtual bool ChangeVehicle()
{
return false;
}
/// <summary>
/// Returns character movement input as a Vector2 (x = horizontal, y = forward/back).
/// </summary>
public virtual Vector2 CharacterMovement()
{
return Vector2.zero;
}
/// <summary>
/// Returns true when the toggle GUI button is pressed.
/// </summary>
public virtual bool ToggleGUI()
{
return false;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9acc2544c2f24c428877837814870a58
timeCreated: 1593334735