Document undocumented IMGUI element classes
This commit is contained in:
parent
d954060a5a
commit
0ef875b6b2
3 changed files with 78 additions and 0 deletions
|
@ -12,12 +12,22 @@ using UnityEngine;
|
|||
|
||||
namespace GamecraftModdingAPI.Interface.IMGUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Keeps track of UIElement instances.
|
||||
/// This also handles displaying and processing them during the MonoBehaviour.OnGUI phase of screen updates.
|
||||
/// Most of this functionality is handled implicitly by the included UIElement implementations,
|
||||
/// but this is left as a public API so it can be expanded.
|
||||
/// </summary>
|
||||
public static class IMGUIManager
|
||||
{
|
||||
internal static OnGuiRunner ImguiScheduler = new OnGuiRunner("GamecraftModdingAPI_IMGUIScheduler");
|
||||
|
||||
private static FasterDictionary<string, UIElement> _activeElements = new FasterDictionary<string,UIElement>();
|
||||
|
||||
/// <summary>
|
||||
/// Add an UIElement instance to be managed by IMGUIManager.
|
||||
/// </summary>
|
||||
/// <param name="e">The UIElement instance.</param>
|
||||
public static void AddElement(UIElement e)
|
||||
{
|
||||
if (!ExistsElement(e))
|
||||
|
@ -26,16 +36,32 @@ namespace GamecraftModdingAPI.Interface.IMGUI
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the UIElement instance is already tracked by IMGUIManager.
|
||||
/// </summary>
|
||||
/// <param name="name">The UIElement's unique name.</param>
|
||||
/// <returns>Whether the UIElement instance is already tracked by IMGUIManager (true) or not (false).</returns>
|
||||
public static bool ExistsElement(string name)
|
||||
{
|
||||
return _activeElements.ContainsKey(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the UIElement instance is already tracked by IMGUIManager.
|
||||
/// </summary>
|
||||
/// <param name="element">The UIElement instance.</param>
|
||||
/// <returns>Whether the UIElement instance is already tracked by IMGUIManager (true) or not (false).</returns>
|
||||
public static bool ExistsElement(UIElement element)
|
||||
{
|
||||
return ExistsElement(element.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an UIElement instance from IMGUIManager.
|
||||
/// The UIElement will become invisible and stop generating events.
|
||||
/// </summary>
|
||||
/// <param name="name">The UIElement's unique name.</param>
|
||||
/// <returns>Whether the UIElement instance existed in IMGUIManager (true) or not (false).</returns>
|
||||
public static bool RemoveElement(string name)
|
||||
{
|
||||
if (ExistsElement(name))
|
||||
|
@ -46,6 +72,12 @@ namespace GamecraftModdingAPI.Interface.IMGUI
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an UIElement instance from IMGUIManager.
|
||||
/// The UIElement will become invisible and stop generating events.
|
||||
/// </summary>
|
||||
/// <param name="element">The UIElement instance.</param>
|
||||
/// <returns>Whether the UIElement instance existed in IMGUIManager (true) or not (false).</returns>
|
||||
public static bool RemoveElement(UIElement element)
|
||||
{
|
||||
return RemoveElement(element.Name);
|
||||
|
|
|
@ -2,12 +2,22 @@ using UnityEngine;
|
|||
|
||||
namespace GamecraftModdingAPI.Interface.IMGUI
|
||||
{
|
||||
/// <summary>
|
||||
/// An image.
|
||||
/// This wraps Unity's IMGUI Label.
|
||||
/// </summary>
|
||||
public class Image : UIElement
|
||||
{
|
||||
private bool automaticLayout = false;
|
||||
|
||||
/// <summary>
|
||||
/// The image texture to display
|
||||
/// </summary>
|
||||
public Texture Texture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The rectangular area in the window that the image can use
|
||||
/// </summary>
|
||||
public Rect Box { get; set; } = Rect.zero;
|
||||
|
||||
public void OnGUI()
|
||||
|
@ -23,9 +33,21 @@ namespace GamecraftModdingAPI.Interface.IMGUI
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The image element's unique name.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to display the image and everything in it.
|
||||
/// </summary>
|
||||
public bool Enabled { set; get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Image"/> class with automatic layout.
|
||||
/// </summary>
|
||||
/// <param name="texture">Image to display.</param>
|
||||
/// <param name="name">The element's name.</param>
|
||||
public Image(Texture texture = null, string name = null)
|
||||
{
|
||||
automaticLayout = true;
|
||||
|
@ -49,6 +71,12 @@ namespace GamecraftModdingAPI.Interface.IMGUI
|
|||
IMGUIManager.AddElement(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Image"/> class.
|
||||
/// </summary>
|
||||
/// <param name="box">Rectangular area for the image.</param>
|
||||
/// <param name="texture">Image to display.</param>
|
||||
/// <param name="name">The element's name.</param>
|
||||
public Image(Rect box, Texture texture = null, string name = null) : this(texture, name)
|
||||
{
|
||||
this.Box = box;
|
||||
|
|
|
@ -32,9 +32,21 @@ namespace GamecraftModdingAPI.Interface.IMGUI
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The label's unique name.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to display the label.
|
||||
/// </summary>
|
||||
public bool Enabled { set; get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Label"/> class with automatic layout.
|
||||
/// </summary>
|
||||
/// <param name="initialText">Initial string to display on the label.</param>
|
||||
/// <param name="name">The element's name.</param>
|
||||
public Label(string initialText = null, string name = null)
|
||||
{
|
||||
automaticLayout = true;
|
||||
|
@ -50,6 +62,12 @@ namespace GamecraftModdingAPI.Interface.IMGUI
|
|||
IMGUIManager.AddElement(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Label"/>.
|
||||
/// </summary>
|
||||
/// <param name="box">Rectangular area for the label.</param>
|
||||
/// <param name="initialText">Initial string to display on the label.</param>
|
||||
/// <param name="name">The element's name.</param>
|
||||
public Label(Rect box, string initialText = null, string name = null) : this(initialText, name)
|
||||
{
|
||||
this.Box = box;
|
||||
|
|
Loading…
Reference in a new issue