From adcabae56640981b305cdd8c9600cea870cb4fcc Mon Sep 17 00:00:00 2001 From: Adrian Babilinski Date: Tue, 19 Dec 2023 21:44:22 -0500 Subject: [PATCH] correct naming --- .../Scripts/Keyboard/KeyboardBuilder.cs | 30 +++++++++++-------- .../KeyboardComponents/KeyboardKey.cs | 4 +-- .../Panels/KeyboardLayout.cs | 25 +++++++++------- .../KeyboardComponents/Panels/PopupPanel.cs | 6 ++-- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardBuilder.cs b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardBuilder.cs index 5a32f49..ff7822b 100644 --- a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardBuilder.cs +++ b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardBuilder.cs @@ -7,6 +7,7 @@ using UnityEngine.UI; using MagicLeap.XRKeyboard.Extensions; using MagicLeap.XRKeyboard.Model; +using UnityEngine.Serialization; namespace MagicLeap.XRKeyboard { @@ -17,13 +18,16 @@ public class KeyboardBuilder : MonoBehaviour { + [FormerlySerializedAs("keyPrefab")] [Header("Prefabs")] - public KeyboardKey keyPrefab; + public KeyboardKey KeyPrefab; - public KeyboardRow keyboardRowPrefab; + [FormerlySerializedAs("keyboardRowPrefab")] + public KeyboardRow KeyboardRowPrefab; + [FormerlySerializedAs("keyboardContainer")] [Header("Grouped Layout Settings")] - public RectTransform keyboardContainer; + public RectTransform KeyboardContainer; [Header("Data")] public KeyboardLayoutData keyboardLayoutData; @@ -89,9 +93,9 @@ public RectTransform AddHorizontalGap(Transform parent, Vector2 sizeDelta, Vecto public void RegenerateKeyboard() { - while (keyboardContainer.childCount > 0) + while (KeyboardContainer.childCount > 0) { - DestroyImmediate(keyboardContainer.transform.GetChild(0).gameObject); + DestroyImmediate(KeyboardContainer.transform.GetChild(0).gameObject); } Keys.Clear(); @@ -101,10 +105,10 @@ public void RegenerateKeyboard() var rows = keyboardLayoutData.GetKeyboardRows(); - var rect = keyboardContainer.rect; + var rect = KeyboardContainer.rect; Vector2 rowSize = new Vector2(rect.size.x, rect.size.y / rows.Count); - float rowCenterX = keyboardContainer.anchoredPosition.x / 2; - float rowTopY = keyboardContainer.rect.size.y/2; + float rowCenterX = KeyboardContainer.anchoredPosition.x / 2; + float rowTopY = KeyboardContainer.rect.size.y/2; for (var i = 0; i < rows.Count; i++) { @@ -112,8 +116,8 @@ public void RegenerateKeyboard() var anchoredPosition = new Vector2(rowCenterX, rowTopY - (rowSize.y * i)); - var keyRow = Instantiate(keyboardRowPrefab, keyboardContainer.transform); - keyRow.Initialize($"Row {i}", keyboardContainer, rowSize, anchoredPosition, row.Size, row.Spacing,row.VerticalGap); + var keyRow = Instantiate(KeyboardRowPrefab, KeyboardContainer.transform); + keyRow.Initialize($"Row {i}", KeyboardContainer, rowSize, anchoredPosition, row.Size, row.Spacing,row.VerticalGap); Vector2 keySize = new Vector2(rowSize.x / row.Keys.Count, rowSize.y); @@ -128,7 +132,7 @@ public void RegenerateKeyboard() { var sizeDelta = new Vector2(keySize.x * key.WidthScale, keySize.y); var anchorPosition = new Vector2(keySize.x * j, 0); - var newKey = Instantiate(keyPrefab, keyRow.transform); + var newKey = Instantiate(KeyPrefab, keyRow.transform); newKey.Initialize(key, sizeDelta, anchorPosition, new Vector2(row.PreferredKeySize.x * key.WidthScale, row.PreferredKeySize.y) , row.ShowAccentHint); Keys.Add(newKey); keyRow.Keys.Add(newKey); @@ -143,8 +147,8 @@ public void RegenerateKeyboard() Canvas.ForceUpdateCanvases(); } - keyboardContainer.MarkAsDirty($"Created Keyboard: {keyboardContainer.name}"); - LayoutRebuilder.ForceRebuildLayoutImmediate(keyboardContainer); + KeyboardContainer.MarkAsDirty($"Created Keyboard: {KeyboardContainer.name}"); + LayoutRebuilder.ForceRebuildLayoutImmediate(KeyboardContainer); Canvas.ForceUpdateCanvases(); } diff --git a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/KeyboardKey.cs b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/KeyboardKey.cs index 2c14253..adfecdc 100644 --- a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/KeyboardKey.cs +++ b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/KeyboardKey.cs @@ -246,10 +246,10 @@ private void LongPressStart(PointerEventData eventData) private IEnumerator LongPressDetection(PointerEventData eventData) { - float longpressThreshold = Time.time + _longPressedThreshold; + float longPressedThreshold = Time.time + _longPressedThreshold; while (_isPressed && !_longPressed) { - if (Time.time > longpressThreshold) + if (Time.time > longPressedThreshold) { _longPressed = true; InvokeLongPress(eventData); diff --git a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/KeyboardLayout.cs b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/KeyboardLayout.cs index 4953bbf..d0664f7 100644 --- a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/KeyboardLayout.cs +++ b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/KeyboardLayout.cs @@ -4,21 +4,24 @@ using MagicLeap.XRKeyboard.Component; using UnityEngine; using MagicLeap.XRKeyboard.Extensions; +using UnityEngine.Serialization; namespace MagicLeap.XRKeyboard { /// - /// Groups the s and s and communicates to the to generate a new layout if needed. + /// Groups the s and s and communicates to the to generate a new layout if needed. /// [RequireComponent(typeof(KeyboardBuilder))] public class KeyboardLayout : MonoBehaviour { - public KeyboardBuilder keyboardBuilder; + [FormerlySerializedAs("keyboardBuilder")] + public KeyboardBuilder KeyboardBuilder; public string LayoutId; + [FormerlySerializedAs("regenKeyboardOnStart")] [Tooltip("When enabled, the keyboard will regenerate from the key map on start")] - public bool regenKeyboardOnStart; + public bool RegenKeyboardOnStart; private RectTransform _rectTransform; @@ -27,27 +30,27 @@ public class KeyboardLayout : MonoBehaviour void Start() { _rectTransform = gameObject.GetCachedComponent(ref _rectTransform); - keyboardBuilder = GetComponent(); + KeyboardBuilder = GetComponent(); - if (regenKeyboardOnStart) keyboardBuilder.RegenerateKeyboard(); + if (RegenKeyboardOnStart) KeyboardBuilder.RegenerateKeyboard(); } private void Reset() { - keyboardBuilder = GetComponent(); + KeyboardBuilder = GetComponent(); } public Transform KeyboardContainer() { - return keyboardBuilder.keyboardContainer; + return KeyboardBuilder.KeyboardContainer; } private void OnDrawGizmosSelected() { - keyboardBuilder = gameObject.GetCachedComponent(ref keyboardBuilder); - if (keyboardBuilder) + KeyboardBuilder = gameObject.GetCachedComponent(ref KeyboardBuilder); + if (KeyboardBuilder) { - LayoutId = keyboardBuilder.LayoutId; + LayoutId = KeyboardBuilder.LayoutId; } } @@ -59,7 +62,7 @@ public IReadOnlyCollection GetKeys() public IReadOnlyCollection GetRows() { - return keyboardBuilder.KeyRows; + return KeyboardBuilder.KeyRows; } diff --git a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/PopupPanel.cs b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/PopupPanel.cs index 859c987..016a870 100644 --- a/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/PopupPanel.cs +++ b/Packages/MagicLeapXRKeyboard/Runtime/Scripts/Keyboard/KeyboardComponents/Panels/PopupPanel.cs @@ -7,6 +7,7 @@ using MagicLeap.XRKeyboard.Component; using UnityEngine.Events; using MagicLeap.XRKeyboard.Extensions; +using UnityEngine.Serialization; namespace MagicLeap.XRKeyboard { @@ -17,8 +18,9 @@ public class PopupPanel : MonoBehaviour { public UnityEvent OnKeysCreated; + [FormerlySerializedAs("keyPrefab")] [Header("Prefabs")] - [SerializeField] private KeyboardKey keyPrefab; + [SerializeField] private KeyboardKey _keyPrefab; [Header("Components")] [SerializeField] private LayoutGroup _container; @@ -127,7 +129,7 @@ public void GeneratePanel(Keyboard.Modifier modifier) for (var i = 0; i < _keyCodes.Count; i++) { var special = _keyCodes[i]; - var newKey = Instantiate(keyPrefab, _container.transform); + var newKey = Instantiate(_keyPrefab, _container.transform); newKey.Initialize(_keySize, new Vector2(_keySize.x * i, 0), special, special, KeyboardKey.KeyGroup.Accent, modifier);