Introduce input modes and Pause Menu (#8)

- Add input mode switching to the Input Manager
- Automatically set input mode on scene load - UI for MainMenu and GameAndUI for other scenes
- Add PauseMenu prefab, auto-loaded via the boostrap system
- Automatically control PauseMenu visibility based on current scene

Co-authored-by: AlexanderT <alexander@foolhardyhorizons.com>
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com>
Reviewed-on: #8
This commit is contained in:
2025-09-25 10:06:51 +00:00
parent 63cb3f1a8c
commit e878a32263
16 changed files with 3950 additions and 203 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@@ -0,0 +1,195 @@
fileFormatVersion: 2
guid: 0a391f68acfee1041a26723b1dafb73b
TextureImporter:
internalIDToNameTable:
- first:
213: 1108211999407853544
second: MenuIcon_PLACEHOLDER_0
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: iOS
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: WindowsStoreApps
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: MenuIcon_PLACEHOLDER_0
rect:
serializedVersion: 2
x: 9
y: 8
width: 239
height: 240
alignment: 0
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
customData:
outline: []
physicsShape: []
tessellationDetail: -1
bones: []
spriteID: 8efc78021f8216f00800000000000000
internalID: 1108211999407853544
vertices: []
indices:
edges: []
weights: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable:
MenuIcon_PLACEHOLDER_0: 1108211999407853544
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -18,3 +18,4 @@ MonoBehaviour:
- {fileID: 458265635552197097, guid: a77d1e8b2fa8aa945a6f39b312536e0d, type: 3}
- {fileID: 552225285624929822, guid: e39992796d5459442be9967c77e27066, type: 3}
- {fileID: 7644433920135100480, guid: 12d242e44fe80ab44af852254b7cab0f, type: 3}
- {fileID: 1794231825201849485, guid: 6fb0d7fc6faad154b8c3e3cb7abb7c15, type: 3}

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,7 @@
"name": "PlayerTouchActions",
"maps": [
{
"name": "DefaultActionMap",
"name": "PlayerTouch",
"id": "53d55b3c-f7c2-4706-a857-c615ecb16ff7",
"actions": [
{
@@ -69,6 +69,522 @@
"isPartOfComposite": false
}
]
},
{
"name": "UI",
"id": "12cf45dc-5cb9-4cc1-b345-1169f531df44",
"actions": [
{
"name": "Navigate",
"type": "PassThrough",
"id": "cef0a4a7-0193-44a6-bad9-f46ca2845c43",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Submit",
"type": "Button",
"id": "843a4564-118d-44ea-8bd3-edcdc48f98c3",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Cancel",
"type": "Button",
"id": "4a050dc0-bc3d-4941-aec6-d8d539f3e4b3",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Point",
"type": "PassThrough",
"id": "a03cf960-cfac-495c-9344-de5f5ef44bba",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "Click",
"type": "PassThrough",
"id": "7e486236-0e6f-4f21-ade8-0ab696112f8e",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "RightClick",
"type": "PassThrough",
"id": "09458b52-8a45-4617-a412-000ed647d359",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "MiddleClick",
"type": "PassThrough",
"id": "7c721d8a-977d-4ff7-87b2-19dbd4eb5ea6",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "ScrollWheel",
"type": "PassThrough",
"id": "e6a073b0-0030-42c2-88ef-85d828760630",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "TrackedDevicePosition",
"type": "PassThrough",
"id": "efcff6db-3f65-4107-8658-7e56305f2c8a",
"expectedControlType": "Vector3",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "TrackedDeviceOrientation",
"type": "PassThrough",
"id": "2c7ed826-65c6-4dc4-81c7-536d62bbede1",
"expectedControlType": "Quaternion",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "Gamepad",
"id": "499b8c05-0325-4b99-9be0-9c8aa41ec39d",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Navigate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "e5794321-3fc2-4ca8-a7a9-e35446b102ef",
"path": "<Gamepad>/leftStick/up",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "up",
"id": "72f978c8-23be-4e97-8609-0b1426355553",
"path": "<Gamepad>/rightStick/up",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "6009f3e0-d95b-4440-a827-617812265049",
"path": "<Gamepad>/leftStick/down",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "590f0119-784f-45f3-97b6-5ffbfad9941f",
"path": "<Gamepad>/rightStick/down",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "e3588172-d7ee-4395-bc1a-3fc013f42400",
"path": "<Gamepad>/leftStick/left",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "4da29037-9c91-4140-8068-68a7375cdc4e",
"path": "<Gamepad>/rightStick/left",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "4620550c-3f8f-437c-a426-ad3e52b2764c",
"path": "<Gamepad>/leftStick/right",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "c74b9635-b880-45f5-a469-5cb8c2b83909",
"path": "<Gamepad>/rightStick/right",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "7a2feef9-0779-498f-a6ae-08484b606d07",
"path": "<Gamepad>/dpad",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "Joystick",
"id": "cd58a9a8-6605-4b26-8fb3-466b928fad60",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Navigate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "be8cdff0-47f9-4546-a919-405e54580ea5",
"path": "<Joystick>/stick/up",
"interactions": "",
"processors": "",
"groups": "Joystick",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "04487afd-6a42-471a-ae70-49d7583ad93b",
"path": "<Joystick>/stick/down",
"interactions": "",
"processors": "",
"groups": "Joystick",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "d327788e-3a9a-4c14-97c8-b46bff05cf16",
"path": "<Joystick>/stick/left",
"interactions": "",
"processors": "",
"groups": "Joystick",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "4c760fb6-00fc-46bc-8a0f-e1be2a3a91cd",
"path": "<Joystick>/stick/right",
"interactions": "",
"processors": "",
"groups": "Joystick",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "Keyboard",
"id": "21afa4c3-8c86-4939-bafc-c75c37368f04",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Navigate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "1d6ea17c-5d6b-4ae5-9881-cf787fd492ed",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "up",
"id": "6e90418f-6f67-4248-bbb4-90243304f39a",
"path": "<Keyboard>/upArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "6be3eb21-d6ea-458d-a66f-f82487ec9139",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "3188c496-3978-454b-be6f-944521aabea4",
"path": "<Keyboard>/downArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "00de0415-2218-4887-9ad6-e4a6c1dacc5b",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "f723bc7b-263d-4619-93aa-0afdc40f3bc3",
"path": "<Keyboard>/leftArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "f3530c12-f67f-437a-979e-2271af5b2d2d",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "d760d39b-f0b3-4823-a705-c20b641b5720",
"path": "<Keyboard>/rightArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "2cc2aec1-4255-4cab-bb40-0a894a0d87d3",
"path": "*/{Submit}",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse;Gamepad;Touch;Joystick;XR",
"action": "Submit",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "fbe038e0-74cf-48bc-b013-4d6f9e817833",
"path": "*/{Cancel}",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse;Gamepad;Touch;Joystick;XR",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "21be382d-dc2e-4360-bdb6-a3cc412a0abe",
"path": "<Mouse>/position",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Point",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "38f39dfe-e703-4be0-8fcf-6de2167518c1",
"path": "<Pen>/position",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Point",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "5bbcf2f7-aea0-4067-ae32-aaf383287fb3",
"path": "<Touchscreen>/touch*/position",
"interactions": "",
"processors": "",
"groups": "Touch",
"action": "Point",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "32dde7e0-9557-4429-a882-7c87540c7e53",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "Click",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f22741eb-66dd-4e3e-aaca-94d92991235c",
"path": "<Pen>/tip",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "Click",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "1bec0af0-b75f-43da-a4a7-7de7f952df13",
"path": "<Touchscreen>/touch*/press",
"interactions": "",
"processors": "",
"groups": "Touch",
"action": "Click",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "d281b478-404c-47ec-95d3-ddcdcc19369a",
"path": "<XRController>/trigger",
"interactions": "",
"processors": "",
"groups": "XR",
"action": "Click",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "ea2e7ff3-1a42-4202-8c53-abcae2467bb2",
"path": "<Mouse>/scroll",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "ScrollWheel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b0b7ca17-b763-4af6-a02a-0fcfbf043c37",
"path": "<Mouse>/rightButton",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "RightClick",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "c3146994-3749-4211-a80a-5766edd782e3",
"path": "<Mouse>/middleButton",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "MiddleClick",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "35aad27d-6a71-481b-b308-7763de690931",
"path": "<XRController>/devicePosition",
"interactions": "",
"processors": "",
"groups": "XR",
"action": "TrackedDevicePosition",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "d116b82b-e40f-4ab3-b7b8-eec40f53e88a",
"path": "<XRController>/deviceRotation",
"interactions": "",
"processors": "",
"groups": "XR",
"action": "TrackedDeviceOrientation",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": []

View File

@@ -72,6 +72,6 @@ MonoBehaviour:
m_ActionEvents: []
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: DefaultActionMap
m_DefaultActionMap: 53d55b3c-f7c2-4706-a857-c615ecb16ff7
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6fb0d7fc6faad154b8c3e3cb7abb7c15
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1633,6 +1633,37 @@ SpriteRenderer:
m_CorrespondingSourceObject: {fileID: 7494677664706785084, guid: bf4b9d7045397f946b2125b1ad4a3fbd, type: 3}
m_PrefabInstance: {fileID: 1336824707}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1668240410
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1668240411}
m_Layer: 0
m_Name: Buttons
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1668240411
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1668240410}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 898.1756, y: 720.9647, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1741016587
GameObject:
m_ObjectHideFlags: 0
@@ -2062,3 +2093,4 @@ SceneRoots:
- {fileID: 1234715653}
- {fileID: 1336824707}
- {fileID: 384576747}
- {fileID: 1668240411}

View File

@@ -1,12 +1,28 @@
using UnityEngine;
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
/// <summary>
/// Handles input events and dispatches them to the appropriate ITouchInputConsumer.
/// Supports tap and hold/drag logic, with interactable delegation and debug logging.
/// </summary>
public class InputManager : MonoBehaviour
namespace Input
{
public enum InputMode
{
Game,
UI,
GameAndUI,
InputDisabled
}
/// <summary>
/// Handles input events and dispatches them to the appropriate ITouchInputConsumer.
/// Supports tap and hold/drag logic, with interactable delegation and debug logging.
/// </summary>
public class InputManager : MonoBehaviour
{
private const string UiActions = "UI";
private const string GameActions = "PlayerTouch";
private static InputManager _instance;
private static bool _isQuitting = false;
@@ -50,6 +66,49 @@ public class InputManager : MonoBehaviour
positionAction = playerInput.actions.FindAction("TouchPosition", false);
}
private void Start()
{
SceneManagerService.Instance.SceneLoadCompleted += SwitchInputOnSceneLoaded;
SwitchInputOnSceneLoaded(SceneManager.GetActiveScene().name);
}
private void SwitchInputOnSceneLoaded(string sceneName)
{
if (sceneName.ToLower().Contains("mainmenu"))
{
Debug.Log("[InputManager] SwitchInputOnSceneLoaded - Setting InputMode to UI for MainMenu");
SetInputMode(InputMode.UI);
}
else
{
Debug.Log("[InputManager] SwitchInputOnSceneLoaded - Setting InputMode to PlayerTouch");
SetInputMode(InputMode.GameAndUI);
}
}
public void SetInputMode(InputMode inputMode)
{
switch (inputMode)
{
case InputMode.UI:
playerInput.actions.FindActionMap(UiActions).Enable();
playerInput.actions.FindActionMap(GameActions).Disable();
break;
case InputMode.Game:
playerInput.actions.FindActionMap(UiActions).Disable();
playerInput.actions.FindActionMap(GameActions).Enable();
break;
case InputMode.GameAndUI:
playerInput.actions.FindActionMap(UiActions).Enable();
playerInput.actions.FindActionMap(GameActions).Enable();
break;
case InputMode.InputDisabled:
playerInput.actions.FindActionMap(UiActions).Disable();
playerInput.actions.FindActionMap(GameActions).Disable();
break;
}
}
void OnEnable()
{
if (tapMoveAction != null)
@@ -90,6 +149,11 @@ public class InputManager : MonoBehaviour
/// </summary>
private void OnTapMovePerformed(InputAction.CallbackContext ctx)
{
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
Vector2 screenPos = positionAction.ReadValue<Vector2>();
Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);
Vector2 worldPos2D = new Vector2(worldPos.x, worldPos.y);
@@ -172,4 +236,5 @@ public class InputManager : MonoBehaviour
}
return false;
}
}
}

View File

@@ -96,6 +96,9 @@ public class LevelSwitch : MonoBehaviour
// Setup menu with data and callbacks
menu.Setup(switchData, OnMenuConfirm, OnMenuCancel);
_isActive = false; // Prevent re-triggering until menu is closed
// Switch input mode to UI only
InputManager.Instance.SetInputMode(InputMode.UI);
}
private async void OnMenuConfirm()

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using AppleHills.Core.Settings;
using Input;
namespace Minigames.DivingForPictures
{

8
Assets/Scripts/Test.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 23fdb60880dd05846a6e0d3681a02242
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,142 @@
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using Input;
namespace UI
{
public class PauseMenu : MonoBehaviour
{
[Header("UI References")]
[SerializeField] private GameObject pauseMenuPanel;
[SerializeField] private GameObject pauseButton;
private void Start()
{
// Subscribe to scene loaded events
SceneManagerService.Instance.SceneLoadCompleted += SetPauseMenuByLevel;
// Set initial state based on current scene
SetPauseMenuByLevel(SceneManager.GetActiveScene().name);
// Initialize pause menu state
HidePauseMenu();
}
private void OnDestroy()
{
// Unsubscribe when destroyed
if (SceneManagerService.Instance != null)
{
SceneManagerService.Instance.SceneLoadCompleted -= SetPauseMenuByLevel;
}
}
/// <summary>
/// Sets the pause menu game object active or inactive based on the current level
/// </summary>
/// <param name="levelName">The name of the level/scene</param>
public void SetPauseMenuByLevel(string levelName)
{
if (string.IsNullOrEmpty(levelName))
return;
bool isMainMenu = levelName.ToLower().Contains("mainmenu");
gameObject.SetActive(!isMainMenu);
if(!isMainMenu)
HidePauseMenu(); // Ensure menu is hidden when switching to a game level
Debug.Log($"[PauseMenu] Setting pause menu active: {!isMainMenu} for scene: {levelName}");
}
/// <summary>
/// Shows the pause menu and hides the pause button. Sets input mode to UI.
/// </summary>
public void ShowPauseMenu()
{
if (pauseMenuPanel != null)
pauseMenuPanel.SetActive(true);
if (pauseButton != null)
pauseButton.SetActive(false);
// Change input mode to UI when menu is open
InputManager.Instance.SetInputMode(InputMode.UI);
}
/// <summary>
/// Hides the pause menu and shows the pause button. Sets input mode to Game.
/// </summary>
public void HidePauseMenu()
{
if (pauseMenuPanel != null)
pauseMenuPanel.SetActive(false);
if (pauseButton != null)
pauseButton.SetActive(true);
// Change input mode back to Game when menu is closed
InputManager.Instance.SetInputMode(InputMode.Game);
}
/// <summary>
/// Resumes the game by hiding the pause menu.
/// </summary>
public void ResumeGame()
{
HidePauseMenu();
}
/// <summary>
/// Exits to the main menu scene.
/// </summary>
public async void ExitToMainMenu()
{
// Replace with the actual scene name as set in Build Settings
var progress = new Progress<float>(p => Debug.Log($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync("MainMenu", progress);
}
/// <summary>
/// Exits the application.
/// </summary>
public void ExitGame()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
/// <summary>
/// Loads a level based on the selection from a dropdown menu.
/// Connect this to a Dropdown's onValueChanged event and pass the selected option text.
/// </summary>
/// <param name="levelSelection">The selected level name or identifier from the dropdown</param>
public async void LoadLevel(int levelSelection)
{
// Hide the pause menu before loading a new level
HidePauseMenu();
// Replace with the actual scene name as set in Build Settings
var progress = new Progress<float>(p => Debug.Log($"Loading progress: {p * 100:F0}%"));
switch (levelSelection)
{
case 0:
await SceneManagerService.Instance.SwitchSceneAsync("MainMenu", progress);
break;
case 1:
await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress);
break;
case 2:
await SceneManagerService.Instance.SwitchSceneAsync("Quarry", progress);
break;
case 3:
await SceneManagerService.Instance.SwitchSceneAsync("DivingForPictures", progress);
break;
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: cb36c2845dc855a4c980ef9dec6ca127

View File

@@ -31,7 +31,7 @@ MonoBehaviour:
surfacingSpawnDelay: 5
initialTileCount: 3
tileSpawnBuffer: 1
moveSpeed: 2
moveSpeed: 1
speedUpFactor: 0
speedUpInterval: 10
maxMoveSpeed: 12