Skip to content

Commit

Permalink
Implemented Feature #9
Browse files Browse the repository at this point in the history
  • Loading branch information
saschaledermann committed Mar 18, 2024
1 parent 9cca05a commit 72b1039
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 23 deletions.
188 changes: 178 additions & 10 deletions Prefabs/handMenuButtonPrefab.prefab
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2827295834620005008
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6172332255966151713}
- component: {fileID: 5512862471390106759}
- component: {fileID: 7289734377001799295}
m_Layer: 5
m_Name: Sprite
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6172332255966151713
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2827295834620005008}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2152916731631440467}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 30, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5512862471390106759
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2827295834620005008}
m_CullTransparentMesh: 1
--- !u!114 &7289734377001799295
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2827295834620005008}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 01c9a8bf23c12eb4f9de8510786d3b52, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &5044333991272172211
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -32,10 +107,10 @@ RectTransform:
m_Children: []
m_Father: {fileID: 3214908287399388135}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: 22.5, y: 0}
m_SizeDelta: {x: -45, y: 40}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &721533012943717586
CanvasRenderer:
Expand Down Expand Up @@ -99,7 +174,7 @@ MonoBehaviour:
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 2
m_HorizontalAlignment: 1
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
Expand All @@ -110,7 +185,7 @@ MonoBehaviour:
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_overflowMode: 2
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
Expand All @@ -134,6 +209,82 @@ MonoBehaviour:
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &6159024145498940321
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2152916731631440467}
- component: {fileID: 7044291855128376003}
- component: {fileID: 5089933871113702611}
m_Layer: 5
m_Name: Graphic
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2152916731631440467
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6159024145498940321}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6172332255966151713}
m_Father: {fileID: 3214908287399388135}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 40, y: 40}
m_Pivot: {x: 0, y: 0.5}
--- !u!222 &7044291855128376003
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6159024145498940321}
m_CullTransparentMesh: 1
--- !u!114 &5089933871113702611
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6159024145498940321}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &6268896315730717319
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -144,7 +295,8 @@ GameObject:
m_Component:
- component: {fileID: 3214908287399388135}
- component: {fileID: 9010663336430904804}
- component: {fileID: 2302973234404424886}
- component: {fileID: 3826983172897042623}
- component: {fileID: 6145718140741343571}
- component: {fileID: 7246227573358393957}
m_Layer: 5
m_Name: handMenuButtonPrefab
Expand All @@ -166,6 +318,7 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7245477669059734699}
- {fileID: 2152916731631440467}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
Expand All @@ -181,7 +334,22 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6268896315730717319}
m_CullTransparentMesh: 1
--- !u!114 &2302973234404424886
--- !u!114 &3826983172897042623
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6268896315730717319}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bb258bdb3efb0a54e8abb3f678f01d37, type: 3}
m_Name:
m_EditorClassIdentifier:
m_spriteImage: {fileID: 7289734377001799295}
m_text: {fileID: 6838571361396830952}
m_button: {fileID: 7246227573358393957}
--- !u!114 &6145718140741343571
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -194,7 +362,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 1, g: 1, b: 1, a: 0.29803923}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
Expand Down Expand Up @@ -251,7 +419,7 @@ MonoBehaviour:
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 2302973234404424886}
m_TargetGraphic: {fileID: 5089933871113702611}
m_OnClick:
m_PersistentCalls:
m_Calls: []
35 changes: 35 additions & 0 deletions Scripts/UI/HandMenu/HandMenuButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class HandMenuButton : MonoBehaviour
{
[SerializeField] Image m_spriteImage;
public Sprite Sprite
{
get => m_spriteImage != null ? m_spriteImage.sprite : null;
set
{
if (m_spriteImage == null) return;

m_spriteImage.sprite = value;
m_spriteImage.gameObject.SetActive(value != null);
}
}
[SerializeField] TMP_Text m_text;
public string Text
{
get => m_text != null ? m_text.text : string.Empty;
set
{
if (m_text != null)
m_text.text = value;
}
}
[SerializeField] Button m_button;
public Button Button
{
get => m_button;
private set => m_button = value;
}
}
11 changes: 11 additions & 0 deletions Scripts/UI/HandMenu/HandMenuButton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Scripts/UI/HandMenu/MainPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ public void AddPanelButton(MenuPanel panel)
}


var button = Instantiate(m_buttonPrefab, m_scrollviewContent).GetComponent<Button>();
var handButton = Instantiate(m_buttonPrefab, m_scrollviewContent).GetComponent<HandMenuButton>();

if (button.transform.GetChild(0).TryGetComponent<TMP_Text>(out var text))
text.text = "Toggle Scene Objects";
if (!string.IsNullOrEmpty(panel.PanelName))
handButton.Text = panel.PanelName;
if (panel.Sprite != null)
handButton.Sprite = panel.Sprite;

button.onClick.AddListener(() => handMenuController.OpenPanel(panel));
handMenuController.AddButtonSoundFeedback(button);
m_menuButtonDictionary.Add(panel, button);
handButton.Button.onClick.AddListener(() => handMenuController.OpenPanel(panel));
handMenuController.AddButtonSoundFeedback(handButton.Button);
m_menuButtonDictionary.Add(panel, handButton.Button);
}

public void RemovePanelButton(MenuPanel panel)
Expand Down
3 changes: 2 additions & 1 deletion Scripts/UI/HandMenu/MenuPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public abstract class MenuPanel : MonoBehaviour
protected HandMenuController handMenuController;
[SerializeField] PanelType m_panelType = PanelType.Static;
[SerializeField] Sprite m_sprite;

public Sprite Sprite { get => m_sprite; private set => m_sprite = value; }
[SerializeField] string m_panelName;
public string PanelName { get => m_panelName; private set => m_panelName = value; }
public PanelType PanelType { get => m_panelType; private set => m_panelType = value; }

protected virtual void Start()
Expand Down
13 changes: 7 additions & 6 deletions Scripts/UI/HandMenu/SceneSelectionPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ protected override void Start()
public Button CreateSceneButton<T>(string label, Action<T> callback, T argument)
{
var buttonObject = Instantiate(m_buttonPrefab, m_scrollviewContent);
buttonObject.GetComponentInChildren<TextMeshProUGUI>().text = label;
var button = buttonObject.GetComponent<Button>();
button.onClick.AddListener(() => callback.Invoke(argument));
m_sceneButtons.Add(button);
handMenuController.AddButtonSoundFeedback(button);
return button;
var handButton = buttonObject.GetComponent<HandMenuButton>();
handButton.Text = label;
handButton.Sprite = null;
handButton.Button.onClick.AddListener(() => callback.Invoke(argument));
m_sceneButtons.Add(handButton.Button);
handMenuController.AddButtonSoundFeedback(handButton.Button);
return handButton.Button;
}

public void RemoveDynamicPanels() => handMenuController.UnregisterDynamicPanels();
Expand Down

0 comments on commit 72b1039

Please sign in to comment.