-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will serve as the base class for any component that wants to draw UI. Still works as a normal component
- Loading branch information
1 parent
ac91489
commit de7f029
Showing
3 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Basalt.Common.Entities; | ||
using Basalt.Common.Utils; | ||
using Basalt.Core.Common.Abstractions.Engine; | ||
using Basalt.Types; | ||
using System.Numerics; | ||
|
||
namespace Basalt.Common.Components | ||
{ | ||
public abstract class UIComponent : Component | ||
{ | ||
public UIPivot Pivot { get; set; } | ||
public Vector3 Offset { get; set; } | ||
public Vector3 Scale { get; set; } | ||
protected UIComponent(Entity entity) : base(entity) | ||
{ | ||
} | ||
|
||
public virtual void OnUIRender() | ||
{ | ||
} | ||
|
||
private void OnUIRenderEvent(object? sender, EventArgs args) | ||
{ | ||
if (Entity.Enabled && Enabled) | ||
OnUIRender(); | ||
} | ||
|
||
private protected override void SubscribeToEvents() | ||
{ | ||
base.SubscribeToEvents(); | ||
Engine.Instance.GetEngineComponent<IEventBus>()!.Subscribe(BasaltConstants.UiRenderEventKey, OnUIRenderEvent); | ||
} | ||
|
||
private protected override void UnsubscribeFromEvents() | ||
{ | ||
base.UnsubscribeFromEvents(); | ||
Engine.Instance.GetEngineComponent<IEventBus>()!.Unsubscribe(BasaltConstants.UiRenderEventKey, OnUIRenderEvent); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Basalt.Types | ||
{ | ||
public enum UIPivot | ||
{ | ||
TopLeft, | ||
TopCenter, | ||
TopRight, | ||
MiddleLeft, | ||
MiddleCenter, | ||
MiddleRight, | ||
BottomLeft, | ||
BottomCenter, | ||
BottomRight | ||
} | ||
} |