using UnityEngine;
namespace PixelCrushers.DialogueSystem.UnityGUI
{
///
/// The root of a GUI layout. Place all child controls under the root's hierarchy. The root
/// applies a GUI skin to the layout, and refreshes the entire layout as necessary.
///
/// Only the root has an OnGUI method. All child controls are drawn from the root's OnGUI.
/// This is much more efficient than giving each child its own OnGUI, since each OnGUI call
/// requires substantial internal overhead to set up in Unity. To hide a GUI layout, you
/// only need to disable the GUIRoot component or deactivate its game object.
///
///
/// GUIRoot updates in editor mode. This allows you to view changes on the fly (WYSIWYG
/// editing).
///
[ExecuteInEditMode]
[AddComponentMenu("")] // Deprecated
public class GUIRoot : GUIControl
{
///
/// The GUI skin to apply to all of the child controls.
///
public GUISkin guiSkin;
///
/// Draws the GUI layout.
///
public void OnGUI()
{
UseGUISkin();
if (!Application.isPlaying) ManualRefresh();
Vector2 screenMousePosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
Draw(screenMousePosition);
}
///
/// Tells the root to recalculate the sizes, positions, and appearance of all of its
/// children.
///
public void ManualRefresh()
{
Refresh(new Vector2(Screen.width, Screen.height));
}
private void UseGUISkin()
{
if (guiSkin != null) GUI.skin = guiSkin;
}
}
}