From ade3c15834ec0a6e631ad1eb8dd5ce07d02ec3e2 Mon Sep 17 00:00:00 2001 From: Vladimir Sigalkin Date: Wed, 17 Nov 2021 15:57:20 +0300 Subject: [PATCH] feat(UGUI): renamed DMUGUIRender, DNUGUIRender, DNUGUIItem, DNUGUIAnimation --- .../Examples/UGUI.Menu/Example_UGUI_Text.cs | 2 +- .../UGUI.Menu/Example_UGUI_TextMeshPro.cs | 2 +- .../UGUI.Notifications/Example_UGUI.cs | 9 ++++-- .../Menu/{DMUGUIRender.cs => MenuRender.cs} | 9 +++--- ...MUGUIRender.cs.meta => MenuRender.cs.meta} | 0 .../{DNUGUIItem.cs => NoticeItem.cs} | 3 +- ...{DNUGUIItem.cs.meta => NoticeItem.cs.meta} | 0 .../{DNUGUIRender.cs => NoticeRender.cs} | 28 +++++++++---------- ...GUIRender.cs.meta => NoticeRender.cs.meta} | 0 README.md | 8 +++--- 10 files changed, 30 insertions(+), 31 deletions(-) rename Assets/extDebug.UGUI/Scripts/Menu/{DMUGUIRender.cs => MenuRender.cs} (89%) rename Assets/extDebug.UGUI/Scripts/Menu/{DMUGUIRender.cs.meta => MenuRender.cs.meta} (100%) rename Assets/extDebug.UGUI/Scripts/Notifications/{DNUGUIItem.cs => NoticeItem.cs} (94%) rename Assets/extDebug.UGUI/Scripts/Notifications/{DNUGUIItem.cs.meta => NoticeItem.cs.meta} (100%) rename Assets/extDebug.UGUI/Scripts/Notifications/{DNUGUIRender.cs => NoticeRender.cs} (76%) rename Assets/extDebug.UGUI/Scripts/Notifications/{DNUGUIRender.cs.meta => NoticeRender.cs.meta} (100%) diff --git a/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_Text.cs b/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_Text.cs index f14a73a..f46b5ad 100644 --- a/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_Text.cs +++ b/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_Text.cs @@ -79,7 +79,7 @@ private void Start() void ExampleAction(DMAction action) => Debug.Log(action.Data); // Initialize UGUI render - DM.Render = new DMUGUIRender(MenuObject, MenuText); + DM.Render = new MenuRender(MenuObject, MenuText); // Simple Menus DM.Add("Simple Menus/Action", action => Debug.Log("Hello/Action"), order: 0); diff --git a/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_TextMeshPro.cs b/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_TextMeshPro.cs index 8b43f88..1114a2c 100644 --- a/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_TextMeshPro.cs +++ b/Assets/extDebug.UGUI/Examples/UGUI.Menu/Example_UGUI_TextMeshPro.cs @@ -78,7 +78,7 @@ private void Start() void ExampleAction(DMAction action) => Debug.Log(action.Data); // Initialize TextMeshPro render - DM.Render = new DMUGUIRender(MenuObject, MenuText); + DM.Render = new MenuRender(MenuObject, MenuText); // Simple Menus DM.Add("Simple Menus/Action", action => Debug.Log("Hello/Action"), order: 0); diff --git a/Assets/extDebug.UGUI/Examples/UGUI.Notifications/Example_UGUI.cs b/Assets/extDebug.UGUI/Examples/UGUI.Notifications/Example_UGUI.cs index d05c2a0..814ee7c 100644 --- a/Assets/extDebug.UGUI/Examples/UGUI.Notifications/Example_UGUI.cs +++ b/Assets/extDebug.UGUI/Examples/UGUI.Notifications/Example_UGUI.cs @@ -1,6 +1,7 @@ /* Copyright (c) 2021 dr. ext (Vladimir Sigalkin) */ using UnityEngine; +using UnityEngine.Serialization; using extDebug.Menu; using extDebug.Notifications; @@ -12,11 +13,13 @@ public class Example_UGUI : MonoBehaviour { #region Public Vars - public DNUGUIAnimation NotifyAnimation; + [FormerlySerializedAs("NotifyAnimation")] + public RenderType RenderType; public RectTransform NotifyAnchor; - public DNUGUIItem NotifyPrefab; + [FormerlySerializedAs("NotifyPrefab")] + public NoticeItem NoticePrefab; #endregion @@ -32,7 +35,7 @@ public class Example_UGUI : MonoBehaviour private void Start() { - DN.Render = new DNUGUIRender(NotifyAnchor, NotifyPrefab, NotifyAnimation); + DN.Render = new NoticeRender(NotifyAnchor, NoticePrefab, RenderType); DM.Add("Simple Notice", action => DN.Notify("Simple notification"), order: 0); diff --git a/Assets/extDebug.UGUI/Scripts/Menu/DMUGUIRender.cs b/Assets/extDebug.UGUI/Scripts/Menu/MenuRender.cs similarity index 89% rename from Assets/extDebug.UGUI/Scripts/Menu/DMUGUIRender.cs rename to Assets/extDebug.UGUI/Scripts/Menu/MenuRender.cs index beae9b0..6087fcb 100644 --- a/Assets/extDebug.UGUI/Scripts/Menu/DMUGUIRender.cs +++ b/Assets/extDebug.UGUI/Scripts/Menu/MenuRender.cs @@ -11,8 +11,7 @@ namespace extDebug.Menu.UGUI { - // TODO: Move to extDebug.UGUI repo - public class DMUGUIRender : IDMRender, IDMRender_Update + public class MenuRender : IDMRender, IDMRender_Update { #region Private Vars @@ -30,9 +29,9 @@ public class DMUGUIRender : IDMRender, IDMRender_Update #region Constructor - public DMUGUIRender(GameObject menuObject, Text menuLabel) : this(menuObject) => _label_Text = menuLabel; + public MenuRender(GameObject menuObject, Text menuLabel) : this(menuObject) => _label_Text = menuLabel; - public DMUGUIRender(GameObject menuObject, TextMeshPro menuLabel) : this(menuObject) => _label_TextMeshPro = menuLabel; + public MenuRender(GameObject menuObject, TextMeshPro menuLabel) : this(menuObject) => _label_TextMeshPro = menuLabel; #endregion @@ -105,7 +104,7 @@ void IDMRender_Update.Update() #region Private Methods - private DMUGUIRender(GameObject menuObject) => _menuObject = menuObject; + private MenuRender(GameObject menuObject) => _menuObject = menuObject; private void CalculateLengths(DMBranch branch, IReadOnlyList items, int space, out int fullLength, out int maxNameLength, out int maxValueLength) { diff --git a/Assets/extDebug.UGUI/Scripts/Menu/DMUGUIRender.cs.meta b/Assets/extDebug.UGUI/Scripts/Menu/MenuRender.cs.meta similarity index 100% rename from Assets/extDebug.UGUI/Scripts/Menu/DMUGUIRender.cs.meta rename to Assets/extDebug.UGUI/Scripts/Menu/MenuRender.cs.meta diff --git a/Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIItem.cs b/Assets/extDebug.UGUI/Scripts/Notifications/NoticeItem.cs similarity index 94% rename from Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIItem.cs rename to Assets/extDebug.UGUI/Scripts/Notifications/NoticeItem.cs index 56fbf2a..8ce3e32 100644 --- a/Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIItem.cs +++ b/Assets/extDebug.UGUI/Scripts/Notifications/NoticeItem.cs @@ -10,8 +10,7 @@ namespace extDebug.Notifications.UGUI { - // TODO: Move to extDebug.UGUI repo - public class DNUGUIItem : MonoBehaviour + public class NoticeItem : MonoBehaviour { #region Public Vars diff --git a/Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIItem.cs.meta b/Assets/extDebug.UGUI/Scripts/Notifications/NoticeItem.cs.meta similarity index 100% rename from Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIItem.cs.meta rename to Assets/extDebug.UGUI/Scripts/Notifications/NoticeItem.cs.meta diff --git a/Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIRender.cs b/Assets/extDebug.UGUI/Scripts/Notifications/NoticeRender.cs similarity index 76% rename from Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIRender.cs rename to Assets/extDebug.UGUI/Scripts/Notifications/NoticeRender.cs index 24fb1aa..7178baf 100644 --- a/Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIRender.cs +++ b/Assets/extDebug.UGUI/Scripts/Notifications/NoticeRender.cs @@ -4,15 +4,13 @@ namespace extDebug.Notifications.UGUI { - // TODO: Rename - public enum DNUGUIAnimation + public enum RenderType { Default, VR } - // TODO: Move to extDebug.UGUI repo - public class DNUGUIRender : IDNRender + public class NoticeRender : IDNRender { #region Public Vars @@ -26,9 +24,9 @@ public class DNUGUIRender : IDNRender private readonly RectTransform _noticeAnchor; - private readonly DNUGUIItem _noticePrefab; + private readonly NoticeItem _noticePrefab; - private readonly DNUGUIAnimation _animation; + private readonly RenderType _type; private Vector2 _previousSize; @@ -36,11 +34,11 @@ public class DNUGUIRender : IDNRender #region Public Methods - public DNUGUIRender(RectTransform noticeAnchor, DNUGUIItem noticePrefab, DNUGUIAnimation animation = DNUGUIAnimation.Default) + public NoticeRender(RectTransform noticeAnchor, NoticeItem noticePrefab, RenderType type = RenderType.Default) { _noticeAnchor = noticeAnchor; _noticePrefab = noticePrefab; - _animation = animation; + _type = type; } #endregion @@ -52,12 +50,12 @@ void IDNRender.SetupNotice(DNNotice notice, float currentHeight) var noticeData = Object.Instantiate(_noticePrefab, _noticeAnchor); noticeData.Text = notice.Text; - if (_animation == DNUGUIAnimation.Default) + if (_type == RenderType.Default) { noticeData.Position = new Vector2(noticeData.Width, -ItemsOffset.y - currentHeight - (_previousSize.y + ItemSpace)); noticeData.Alpha = 1f; } - else if (_animation == DNUGUIAnimation.VR) + else if (_type == RenderType.VR) { noticeData.Position = new Vector2(-noticeData.Width * 2, currentHeight + _previousSize.y + ItemSpace); noticeData.Alpha = 0f; @@ -68,13 +66,13 @@ void IDNRender.SetupNotice(DNNotice notice, float currentHeight) void IDNRender.RemoveNotice(DNNotice notice) { - if (notice.Data is DNUGUIItem noticeData) + if (notice.Data is NoticeItem noticeData) Object.Destroy(noticeData.gameObject); } void IDNRender.Repaint(DNNotice notice, float timeLeft, ref float currentHeight) { - if (!(notice.Data is DNUGUIItem noticeData)) + if (notice.Data is not NoticeItem noticeData) return; var size = noticeData.Size; @@ -88,14 +86,14 @@ void IDNRender.Repaint(DNNotice notice, float timeLeft, ref float currentHeight) var targetX = 0f; var targetY = 0f; - targetX = _animation == DNUGUIAnimation.Default ? -ItemsOffset.x : 0; - targetY = _animation == DNUGUIAnimation.Default ? height - currentHeight - ItemsOffset.y : height + currentHeight; + targetX = _type == RenderType.Default ? -ItemsOffset.x : 0; + targetY = _type == RenderType.Default ? height - currentHeight - ItemsOffset.y : height + currentHeight; // Calculate targets if (timeLeft < 0.2f) targetX += width * 2; else if (timeLeft < 0.7f) targetX -= 50; - if (_animation == DNUGUIAnimation.VR) + if (_type == RenderType.VR) { if (timeLeft > 0.2f) { diff --git a/Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIRender.cs.meta b/Assets/extDebug.UGUI/Scripts/Notifications/NoticeRender.cs.meta similarity index 100% rename from Assets/extDebug.UGUI/Scripts/Notifications/DNUGUIRender.cs.meta rename to Assets/extDebug.UGUI/Scripts/Notifications/NoticeRender.cs.meta diff --git a/README.md b/README.md index 839a46b..0df0e1f 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ GameObject MenuObject; // extDebug Unity UI Root instance. The object to hide wh Text MenuText; // Unity UI Text instance. The object in which the menu text will be displayed. // Initialize Unity UI render -DM.Render = new DMUGUIRender(MenuObject, MenuText); +DM.Render = new MenuRender(MenuObject, MenuText); ``` **Unity UI and TextMeshPro**
@@ -82,7 +82,7 @@ GameObject MenuObject; // extDebug Unity UI Root instance. The object to hide wh TextMeshProUGUI MenuText; // TextMeshPro UI Text instance. The object in which the menu text will be displayed. // Initialize Unity UI render -DM.Render = new DMUGUIRender(MenuObject, MenuText); +DM.Render = new MenuRender(MenuObject, MenuText); ``` ## extDebug.Notifications.UGUI - Debug Notifications UGUI Render @@ -95,10 +95,10 @@ Full examples you can find in [Examples/UGUI.Notifications](Assets/extDebug.UGUI **Unity UI or TextMeshPro**
```C# RectTransform NotifyAnchor; // Ref to the transform of the component on which the notification will be instantiated. -DNUGUIItem NotifyPrefab; // Notification prefab. Inside this prefab, you can choose between Unity UI and TextMeshPro +NoticeItem NotifyPrefab; // Notification prefab. Inside this prefab, you can choose between Unity UI and TextMeshPro // Initialize Unity UI render -DN.Render = new DNUGUIRender(NotifyAnchor, NotifyPrefab); +DN.Render = new NoticeRender(NotifyAnchor, NotifyPrefab); ``` ## Author Contacts: