From 322f8d1986384994eebea86ddd52bee451f262ae Mon Sep 17 00:00:00 2001 From: Thibault Pouch Date: Fri, 6 Mar 2026 18:37:56 +0100 Subject: [PATCH] feat(DevRoom): add HUD prefab and DevRoomHUD script for controls display --- Assets/Code/Scripts/DevRoom.meta | 8 ++ Assets/Code/Scripts/DevRoom/DevRoomHUD.cs | 90 +++++++++++++++++++ .../Code/Scripts/DevRoom/DevRoomHUD.cs.meta | 2 + Assets/Level/Prefabs/Dev/HUD.prefab | 53 +++++++++++ Assets/Level/Prefabs/Dev/HUD.prefab.meta | 7 ++ 5 files changed, 160 insertions(+) create mode 100644 Assets/Code/Scripts/DevRoom.meta create mode 100644 Assets/Code/Scripts/DevRoom/DevRoomHUD.cs create mode 100644 Assets/Code/Scripts/DevRoom/DevRoomHUD.cs.meta create mode 100644 Assets/Level/Prefabs/Dev/HUD.prefab create mode 100644 Assets/Level/Prefabs/Dev/HUD.prefab.meta diff --git a/Assets/Code/Scripts/DevRoom.meta b/Assets/Code/Scripts/DevRoom.meta new file mode 100644 index 0000000..9d5375e --- /dev/null +++ b/Assets/Code/Scripts/DevRoom.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f4bfa7e49bca4e0439e2c2c04bd801fe +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Code/Scripts/DevRoom/DevRoomHUD.cs b/Assets/Code/Scripts/DevRoom/DevRoomHUD.cs new file mode 100644 index 0000000..d0a92b2 --- /dev/null +++ b/Assets/Code/Scripts/DevRoom/DevRoomHUD.cs @@ -0,0 +1,90 @@ +using UnityEngine; + +/// +/// Displays a controls legend in the top-left corner of the screen. +/// Attach to any active GameObject in the DevRoom scene. +/// +public class DevRoomHUD : MonoBehaviour +{ + [Header("Layout")] + [SerializeField] private float paddingX = 16f; + [SerializeField] private float paddingY = 16f; + [SerializeField] private float lineHeight = 22f; + [SerializeField] private int fontSize = 14; + + [Header("Style")] + [SerializeField] private Color backgroundColor = new Color(0f, 0f, 0f, 0.55f); + [SerializeField] private Color keyColor = new Color(1f, 0.85f, 0.2f); + [SerializeField] private Color labelColor = Color.white; + + private static readonly (string key, string action)[] k_Controls = + { + ("WASD / Arrows", "Move"), + ("Mouse", "Look"), + ("Space", "Jump"), + ("Left Shift", "Sprint"), + ("C", "Crouch"), + ("LMB", "Throw head"), + ("E (hold)", "Retrieve head"), + ("1 / 2", "Previous / Next"), + }; + + private GUIStyle m_keyStyle; + private GUIStyle m_labelStyle; + private GUIStyle m_boxStyle; + private Texture2D m_bgTexture; + + private void OnGUI() + { + EnsureStyles(); + + float keyColWidth = 110f; + float labelColWidth = 130f; + float totalWidth = paddingX * 2 + keyColWidth + 8f + labelColWidth; + float totalHeight = paddingY * 2 + k_Controls.Length * lineHeight; + + Rect bgRect = new Rect(8f, 8f, totalWidth, totalHeight); + GUI.DrawTexture(bgRect, m_bgTexture); + + float x = bgRect.x + paddingX; + float y = bgRect.y + paddingY; + + for (int i = 0; i < k_Controls.Length; i++) + { + float rowY = y + i * lineHeight; + + GUI.Label(new Rect(x, rowY, keyColWidth, lineHeight), k_Controls[i].key, m_keyStyle); + GUI.Label(new Rect(x + keyColWidth + 8f, rowY, labelColWidth, lineHeight), k_Controls[i].action, m_labelStyle); + } + } + + private void EnsureStyles() + { + if (m_keyStyle != null) + return; + + m_bgTexture = new Texture2D(1, 1); + m_bgTexture.SetPixel(0, 0, backgroundColor); + m_bgTexture.Apply(); + + m_keyStyle = new GUIStyle(GUI.skin.label) + { + fontSize = fontSize, + fontStyle = FontStyle.Bold, + }; + m_keyStyle.normal.textColor = keyColor; + + m_labelStyle = new GUIStyle(GUI.skin.label) + { + fontSize = fontSize, + fontStyle = FontStyle.Normal, + }; + m_labelStyle.normal.textColor = labelColor; + } + + private void OnDestroy() + { + if (m_bgTexture != null) + Destroy(m_bgTexture); + } +} diff --git a/Assets/Code/Scripts/DevRoom/DevRoomHUD.cs.meta b/Assets/Code/Scripts/DevRoom/DevRoomHUD.cs.meta new file mode 100644 index 0000000..92d4d8f --- /dev/null +++ b/Assets/Code/Scripts/DevRoom/DevRoomHUD.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: c34284eb72c0cc841b21e6425e27606a \ No newline at end of file diff --git a/Assets/Level/Prefabs/Dev/HUD.prefab b/Assets/Level/Prefabs/Dev/HUD.prefab new file mode 100644 index 0000000..bd9a219 --- /dev/null +++ b/Assets/Level/Prefabs/Dev/HUD.prefab @@ -0,0 +1,53 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4178108422795220641 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3591790312497930163} + - component: {fileID: 3550386926518610254} + m_Layer: 0 + m_Name: HUD + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3591790312497930163 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4178108422795220641} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 2.44109, y: 0.05, z: 2.28609} + 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!114 &3550386926518610254 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4178108422795220641} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c34284eb72c0cc841b21e6425e27606a, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::DevRoomHUD + paddingX: 16 + paddingY: 16 + lineHeight: 22 + fontSize: 14 + backgroundColor: {r: 0, g: 0, b: 0, a: 0.55} + keyColor: {r: 1, g: 0.85, b: 0.2, a: 1} + labelColor: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/Level/Prefabs/Dev/HUD.prefab.meta b/Assets/Level/Prefabs/Dev/HUD.prefab.meta new file mode 100644 index 0000000..136a04b --- /dev/null +++ b/Assets/Level/Prefabs/Dev/HUD.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d43f6e65b695a9e44a2e9207a7427e29 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: