feat(DevRoom): add HUD prefab and DevRoomHUD script for controls display
This commit is contained in:
8
Assets/Code/Scripts/DevRoom.meta
Normal file
8
Assets/Code/Scripts/DevRoom.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4bfa7e49bca4e0439e2c2c04bd801fe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
90
Assets/Code/Scripts/DevRoom/DevRoomHUD.cs
Normal file
90
Assets/Code/Scripts/DevRoom/DevRoomHUD.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Displays a controls legend in the top-left corner of the screen.
|
||||
/// Attach to any active GameObject in the DevRoom scene.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
2
Assets/Code/Scripts/DevRoom/DevRoomHUD.cs.meta
Normal file
2
Assets/Code/Scripts/DevRoom/DevRoomHUD.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c34284eb72c0cc841b21e6425e27606a
|
||||
53
Assets/Level/Prefabs/Dev/HUD.prefab
Normal file
53
Assets/Level/Prefabs/Dev/HUD.prefab
Normal file
@@ -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}
|
||||
7
Assets/Level/Prefabs/Dev/HUD.prefab.meta
Normal file
7
Assets/Level/Prefabs/Dev/HUD.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d43f6e65b695a9e44a2e9207a7427e29
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user