Skip to content

Commit

Permalink
feat(UGUI): renamed DMUGUIRender, DNUGUIRender, DNUGUIItem, DNUGUIAni…
Browse files Browse the repository at this point in the history
…mation
  • Loading branch information
Iam1337 committed Nov 17, 2021
1 parent 72c63d1 commit ade3c15
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Copyright (c) 2021 dr. ext (Vladimir Sigalkin) */

using UnityEngine;
using UnityEngine.Serialization;

using extDebug.Menu;
using extDebug.Notifications;
Expand All @@ -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

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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<DMItem> items, int space, out int fullLength, out int maxNameLength, out int maxValueLength)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,21 +24,21 @@ 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;

#endregion

#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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**<br>
Expand All @@ -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
Expand All @@ -95,10 +95,10 @@ Full examples you can find in [Examples/UGUI.Notifications](Assets/extDebug.UGUI
**Unity UI or TextMeshPro**<br>
```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:
Expand Down

0 comments on commit ade3c15

Please sign in to comment.