This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
168 additions
and
60 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,28 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace RogueLibsCore | ||
{ | ||
public abstract class CustomUiBase : CustomUiElement, IHook<MainGUI> | ||
{ | ||
public MainGUI MainGUI { get; private set; } = null!; | ||
protected Canvas canvas { get; private set; } = null!; | ||
protected GraphicRaycaster graphicRaycaster { get; private set; } = null!; | ||
protected CanvasGroup canvasGroup { get; private set; } = null!; | ||
|
||
object IHook.Instance => MainGUI; | ||
MainGUI IHook<MainGUI>.Instance => MainGUI; | ||
void IHook.Initialize(object _) { } | ||
|
||
public override void Awake() | ||
{ | ||
MainGUI = gameObject.GetComponentInParent<MainGUI>(); | ||
SetCenterPosition(gameObject, transform.parent, new Rect(960f, 540f, 1920f, 1080f)); | ||
|
||
canvas = gameObject.AddComponent<Canvas>(); | ||
graphicRaycaster = gameObject.AddComponent<GraphicRaycaster>(); | ||
canvasGroup = gameObject.AddComponent<CanvasGroup>(); | ||
} | ||
|
||
} | ||
} |
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,67 @@ | ||
using UnityEngine; | ||
|
||
namespace RogueLibsCore | ||
{ | ||
public abstract class CustomUiElement : MonoBehaviour | ||
{ | ||
private RectTransform? _rect; | ||
public RectTransform rect => _rect ??= GetComponent<RectTransform>(); | ||
|
||
public abstract void Awake(); | ||
|
||
/// <summary> | ||
/// <para>Gets the currently used instance of <see cref="GameController"/>.</para> | ||
/// </summary> | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Usage of gc fields in SoR")] | ||
// ReSharper disable once InconsistentNaming | ||
public static GameController gc => GameController.gameController; | ||
|
||
public GameObject CreateElement(string gameObjectName, Vector2 position) | ||
=> CreateElement(transform, gameObjectName, position); | ||
public GameObject CreateElement(string gameObjectName, Rect rectangle) | ||
=> CreateElement(transform, gameObjectName, rectangle); | ||
public static GameObject CreateElement(Transform parent, string gameObjectName, Vector2 position) | ||
=> CreateElement(parent, gameObjectName, new Rect(position, new Vector2(100f, 100f))); | ||
public static GameObject CreateElement(Transform parent, string gameObjectName, Rect rectangle) | ||
{ | ||
GameObject go = new GameObject(gameObjectName, typeof(RectTransform)); | ||
SetTopLeftCornerPosition(go, parent, rectangle); | ||
return go; | ||
} | ||
|
||
public TElement CreateElement<TElement>(string gameObjectName, Vector2 position) where TElement : Component | ||
=> CreateElement<TElement>(transform, gameObjectName, position); | ||
public TElement CreateElement<TElement>(string gameObjectName, Rect rectangle) where TElement : Component | ||
=> CreateElement<TElement>(transform, gameObjectName, rectangle); | ||
public static TElement CreateElement<TElement>(Transform parent, string gameObjectName, Vector2 position) where TElement : Component | ||
=> CreateElement<TElement>(parent, gameObjectName, new Rect(position, new Vector2(100f, 100f))); | ||
public static TElement CreateElement<TElement>(Transform parent, string gameObjectName, Rect rectangle) where TElement : Component | ||
=> CreateElement(parent, gameObjectName, rectangle).AddComponent<TElement>(); | ||
|
||
protected static void SetTopLeftCornerPosition(GameObject go, Transform parent, Rect rectangle) | ||
{ | ||
RectTransform rect = go.GetComponent<RectTransform>(); | ||
rect.SetParent(parent); | ||
|
||
rect.localScale = Vector3.one; | ||
rect.anchorMin = new Vector2(0f, 1f); | ||
rect.anchorMax = new Vector2(0f, 1f); | ||
rect.pivot = new Vector2(0f, 1f); | ||
rect.anchoredPosition = new Vector2(rectangle.x, -rectangle.y); | ||
rect.sizeDelta = rectangle.size; | ||
} | ||
protected static void SetCenterPosition(GameObject go, Transform parent, Rect rectangle) | ||
{ | ||
RectTransform rect = go.GetComponent<RectTransform>(); | ||
rect.SetParent(parent); | ||
|
||
rect.localScale = Vector3.one; | ||
rect.anchorMin = new Vector2(0f, 1f); | ||
rect.anchorMax = new Vector2(0f, 1f); | ||
rect.pivot = new Vector2(0.5f, 0.5f); | ||
rect.anchoredPosition = new Vector2(rectangle.x, -rectangle.y); | ||
rect.sizeDelta = rectangle.size; | ||
} | ||
|
||
} | ||
} |
110 changes: 53 additions & 57 deletions
110
RogueLibsCore/Hooks/UserInterfaces/CustomUserInterface.cs
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,16 @@ | ||
namespace RogueLibsCore | ||
{ | ||
public abstract class CustomUserOverlay : CustomUiBase | ||
{ | ||
public sealed override void Awake() | ||
{ | ||
base.Awake(); | ||
canvas.enabled = true; | ||
graphicRaycaster.enabled = true; | ||
canvasGroup.alpha = 1f; | ||
Setup(); | ||
} | ||
public abstract void Setup(); | ||
|
||
} | ||
} |
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