NGUI: Next-Gen UI kit  3.7.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
NGUITools Class Reference

Helper class containing generic functions used throughout the UI library. More...

Static Public Member Functions

static AudioSource PlaySound (AudioClip clip)
 Play the specified audio clip. More...
 
static AudioSource PlaySound (AudioClip clip, float volume)
 Play the specified audio clip with the specified volume. More...
 
static AudioSource PlaySound (AudioClip clip, float volume, float pitch)
 Play the specified audio clip with the specified volume and pitch. More...
 
static int RandomRange (int min, int max)
 New WWW call can fail if the crossdomain policy doesn't check out. Exceptions suck. It's much more elegant to check for null instead. More...
 
static string GetHierarchy (GameObject obj)
 Returns the hierarchy of the object in a human-readable format. More...
 
static T[] FindActive< T > ()
 Find all active objects of specified type. More...
 
static Camera FindCameraForLayer (int layer)
 Find the camera responsible for drawing the objects on the specified layer. More...
 
static void AddWidgetCollider (GameObject go)
 Add a collider to the game object containing one or more widgets. More...
 
static void AddWidgetCollider (GameObject go, bool considerInactive)
 Add a collider to the game object containing one or more widgets. More...
 
static void UpdateWidgetCollider (GameObject go)
 Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions. More...
 
static void UpdateWidgetCollider (GameObject go, bool considerInactive)
 Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions. More...
 
static void UpdateWidgetCollider (BoxCollider box, bool considerInactive)
 Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions. More...
 
static void UpdateWidgetCollider (BoxCollider2D box, bool considerInactive)
 Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions. More...
 
static string GetTypeName< T > ()
 Helper function that returns the string name of the type. More...
 
static string GetTypeName (UnityEngine.Object obj)
 Helper function that returns the string name of the type. More...
 
static void RegisterUndo (UnityEngine.Object obj, string name)
 Convenience method that works without warnings in both Unity 3 and 4. More...
 
static void SetDirty (UnityEngine.Object obj)
 Convenience function that marks the specified object as dirty in the Unity Editor. More...
 
static GameObject AddChild (GameObject parent)
 Add a new child game object. More...
 
static GameObject AddChild (GameObject parent, bool undo)
 Add a new child game object. More...
 
static GameObject AddChild (GameObject parent, GameObject prefab)
 Instantiate an object and add it to the specified parent. More...
 
static int CalculateRaycastDepth (GameObject go)
 Calculate the game object's depth based on the widgets within, and also taking panel depth into consideration. More...
 
static int CalculateNextDepth (GameObject go)
 Gathers all widgets and calculates the depth for the next widget. More...
 
static int CalculateNextDepth (GameObject go, bool ignoreChildrenWithColliders)
 Gathers all widgets and calculates the depth for the next widget. More...
 
static int AdjustDepth (GameObject go, int adjustment)
 Adjust the widgets' depth by the specified value. Returns '0' if nothing was adjusted, '1' if panels were adjusted, and '2' if widgets were adjusted. More...
 
static void BringForward (GameObject go)
 Bring all of the widgets on the specified object forward. More...
 
static void PushBack (GameObject go)
 Push all of the widgets on the specified object back, making them appear behind everything else. More...
 
static void NormalizeDepths ()
 Normalize the depths of all the widgets and panels in the scene, making them start from 0 and remain in order. More...
 
static void NormalizeWidgetDepths ()
 Normalize the depths of all the widgets in the scene, making them start from 0 and remain in order. More...
 
static void NormalizeWidgetDepths (GameObject go)
 Normalize the depths of all the widgets in the scene, making them start from 0 and remain in order. More...
 
static void NormalizeWidgetDepths (UIWidget[] list)
 Normalize the depths of all the widgets in the scene, making them start from 0 and remain in order. More...
 
static void NormalizePanelDepths ()
 Normalize the depths of all the panels in the scene, making them start from 0 and remain in order. More...
 
static UIPanel CreateUI (bool advanced3D)
 Create a new UI. More...
 
static UIPanel CreateUI (bool advanced3D, int layer)
 Create a new UI. More...
 
static UIPanel CreateUI (Transform trans, bool advanced3D, int layer)
 Create a new UI. More...
 
static void SetChildLayer (Transform t, int layer)
 Helper function that recursively sets all children with widgets' game objects layers to the specified value. More...
 
static T AddChild< T > (GameObject parent)
 Add a child object to the specified parent and attaches the specified script to it. More...
 
static T AddChild< T > (GameObject parent, bool undo)
 Add a child object to the specified parent and attaches the specified script to it. More...
 
static T AddWidget< T > (GameObject go)
 Add a new widget of specified type. More...
 
static UISprite AddSprite (GameObject go, UIAtlas atlas, string spriteName)
 Add a sprite appropriate for the specified atlas sprite. It will be sliced if the sprite has an inner rect, and a regular sprite otherwise. More...
 
static GameObject GetRoot (GameObject go)
 Get the rootmost object of the specified game object. More...
 
static T FindInParents< T > (GameObject go)
 Finds the specified component on the game object or one of its parents. More...
 
static T FindInParents< T > (Transform trans)
 Finds the specified component on the game object or one of its parents. More...
 
static void Destroy (UnityEngine.Object obj)
 Destroy the specified object, immediately if in edit mode. More...
 
static void DestroyImmediate (UnityEngine.Object obj)
 Destroy the specified object immediately, unless not in the editor, in which case the regular Destroy is used instead. More...
 
static void Broadcast (string funcName)
 Call the specified function on all objects in the scene. More...
 
static void Broadcast (string funcName, object param)
 Call the specified function on all objects in the scene. More...
 
static bool IsChild (Transform parent, Transform child)
 Determines whether the 'parent' contains a 'child' in its hierarchy. More...
 
static void SetActive (GameObject go, bool state)
 SetActiveRecursively enables children before parents. This is a problem when a widget gets re-enabled and it tries to find a panel on its parent. More...
 
static void SetActive (GameObject go, bool state, bool compatibilityMode)
 SetActiveRecursively enables children before parents. This is a problem when a widget gets re-enabled and it tries to find a panel on its parent. More...
 
static void SetActiveChildren (GameObject go, bool state)
 Activate or deactivate children of the specified game object without changing the active state of the object itself. More...
 
static bool IsActive (Behaviour mb)
 Helper function that returns whether the specified MonoBehaviour is active. More...
 
static bool GetActive (Behaviour mb)
 Helper function that returns whether the specified MonoBehaviour is active. More...
 
static bool GetActive (GameObject go)
 Unity4 has changed GameObject.active to GameObject.activeself. More...
 
static void SetActiveSelf (GameObject go, bool state)
 Unity4 has changed GameObject.active to GameObject.SetActive. More...
 
static void SetLayer (GameObject go, int layer)
 Recursively set the game object's layer. More...
 
static Vector3 Round (Vector3 v)
 Helper function used to make the vector use integer numbers. More...
 
static void MakePixelPerfect (Transform t)
 Make the specified selection pixel-perfect. More...
 
static bool Save (string fileName, byte[] bytes)
 Save the specified binary data into the specified file. More...
 
static byte[] Load (string fileName)
 Load all binary data from the specified file. More...
 
static Color ApplyPMA (Color c)
 Pre-multiply shaders result in a black outline if this operation is done in the shader. It's better to do it outside. More...
 
static void MarkParentAsChanged (GameObject go)
 Inform all widgets underneath the specified object that the parent has changed. More...
 
static string EncodeColor (Color c)
 
static Color ParseColor (string text, int offset)
 
static string StripSymbols (string text)
 
static T AddMissingComponent< T > (this GameObject go)
 Extension for the game object that checks to see if the component already exists before adding a new one. If the component is already present it will be returned instead. More...
 
static Vector3[] GetSides (this Camera cam)
 Get sides relative to the specified camera. The order is left, top, right, bottom. More...
 
static Vector3[] GetSides (this Camera cam, float depth)
 Get sides relative to the specified camera. The order is left, top, right, bottom. More...
 
static Vector3[] GetSides (this Camera cam, Transform relativeTo)
 Get sides relative to the specified camera. The order is left, top, right, bottom. More...
 
static Vector3[] GetSides (this Camera cam, float depth, Transform relativeTo)
 Get sides relative to the specified camera. The order is left, top, right, bottom. More...
 
static Vector3[] GetWorldCorners (this Camera cam)
 Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right. More...
 
static Vector3[] GetWorldCorners (this Camera cam, float depth)
 Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right. More...
 
static Vector3[] GetWorldCorners (this Camera cam, Transform relativeTo)
 Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right. More...
 
static Vector3[] GetWorldCorners (this Camera cam, float depth, Transform relativeTo)
 Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right. More...
 
static string GetFuncName (object obj, string method)
 Convenience function that converts Class + Function combo into Class.Function representation. More...
 
static void Execute< T > (GameObject go, string funcName)
 Execute the specified function on the target game object. More...
 
static void ExecuteAll< T > (GameObject root, string funcName)
 Execute the specified function on the target game object and all of its children. More...
 
static void ImmediatelyCreateDrawCalls (GameObject root)
 Immediately start, update, and create all the draw calls from newly instantiated UI. This is useful if you plan on doing something like immediately taking a screenshot then destroying the UI. More...
 

Properties

static float soundVolume [get, set]
 Globally accessible volume affecting all sounds played via NGUITools.PlaySound(). More...
 
static bool fileAccess [get]
 Helper function – whether the disk access is allowed. More...
 
static string clipboard [get, set]
 Access to the clipboard via undocumented APIs. More...
 
static Vector2 screenSize [get]
 Size of the game view cannot be retrieved from Screen.width and Screen.height when the game view is hidden. More...
 

Detailed Description

Helper class containing generic functions used throughout the UI library.

Member Function Documentation

static GameObject NGUITools.AddChild ( GameObject  parent)
static

Add a new child game object.

static GameObject NGUITools.AddChild ( GameObject  parent,
bool  undo 
)
static

Add a new child game object.

static GameObject NGUITools.AddChild ( GameObject  parent,
GameObject  prefab 
)
static

Instantiate an object and add it to the specified parent.

static T NGUITools.AddChild< T > ( GameObject  parent)
static

Add a child object to the specified parent and attaches the specified script to it.

Type Constraints
T :Component 
static T NGUITools.AddChild< T > ( GameObject  parent,
bool  undo 
)
static

Add a child object to the specified parent and attaches the specified script to it.

Type Constraints
T :Component 
static T NGUITools.AddMissingComponent< T > ( this GameObject  go)
static

Extension for the game object that checks to see if the component already exists before adding a new one. If the component is already present it will be returned instead.

Type Constraints
T :Component 
static UISprite NGUITools.AddSprite ( GameObject  go,
UIAtlas  atlas,
string  spriteName 
)
static

Add a sprite appropriate for the specified atlas sprite. It will be sliced if the sprite has an inner rect, and a regular sprite otherwise.

static T NGUITools.AddWidget< T > ( GameObject  go)
static

Add a new widget of specified type.

Type Constraints
T :UIWidget 
static void NGUITools.AddWidgetCollider ( GameObject  go)
static

Add a collider to the game object containing one or more widgets.

static void NGUITools.AddWidgetCollider ( GameObject  go,
bool  considerInactive 
)
static

Add a collider to the game object containing one or more widgets.

static int NGUITools.AdjustDepth ( GameObject  go,
int  adjustment 
)
static

Adjust the widgets' depth by the specified value. Returns '0' if nothing was adjusted, '1' if panels were adjusted, and '2' if widgets were adjusted.

static Color NGUITools.ApplyPMA ( Color  c)
static

Pre-multiply shaders result in a black outline if this operation is done in the shader. It's better to do it outside.

static void NGUITools.BringForward ( GameObject  go)
static

Bring all of the widgets on the specified object forward.

static void NGUITools.Broadcast ( string  funcName)
static

Call the specified function on all objects in the scene.

static void NGUITools.Broadcast ( string  funcName,
object  param 
)
static

Call the specified function on all objects in the scene.

static int NGUITools.CalculateNextDepth ( GameObject  go)
static

Gathers all widgets and calculates the depth for the next widget.

static int NGUITools.CalculateNextDepth ( GameObject  go,
bool  ignoreChildrenWithColliders 
)
static

Gathers all widgets and calculates the depth for the next widget.

static int NGUITools.CalculateRaycastDepth ( GameObject  go)
static

Calculate the game object's depth based on the widgets within, and also taking panel depth into consideration.

static UIPanel NGUITools.CreateUI ( bool  advanced3D)
static

Create a new UI.

static UIPanel NGUITools.CreateUI ( bool  advanced3D,
int  layer 
)
static

Create a new UI.

static UIPanel NGUITools.CreateUI ( Transform  trans,
bool  advanced3D,
int  layer 
)
static

Create a new UI.

static void NGUITools.Destroy ( UnityEngine.Object  obj)
static

Destroy the specified object, immediately if in edit mode.

static void NGUITools.DestroyImmediate ( UnityEngine.Object  obj)
static

Destroy the specified object immediately, unless not in the editor, in which case the regular Destroy is used instead.

static string NGUITools.EncodeColor ( Color  c)
static
static void NGUITools.Execute< T > ( GameObject  go,
string  funcName 
)
static

Execute the specified function on the target game object.

Type Constraints
T :Component 
static void NGUITools.ExecuteAll< T > ( GameObject  root,
string  funcName 
)
static

Execute the specified function on the target game object and all of its children.

Type Constraints
T :Component 
static T [] NGUITools.FindActive< T > ( )
static

Find all active objects of specified type.

Type Constraints
T :Component 
static Camera NGUITools.FindCameraForLayer ( int  layer)
static

Find the camera responsible for drawing the objects on the specified layer.

static T NGUITools.FindInParents< T > ( GameObject  go)
static

Finds the specified component on the game object or one of its parents.

Type Constraints
T :Component 
static T NGUITools.FindInParents< T > ( Transform  trans)
static

Finds the specified component on the game object or one of its parents.

Type Constraints
T :Component 
static bool NGUITools.GetActive ( Behaviour  mb)
static

Helper function that returns whether the specified MonoBehaviour is active.

static bool NGUITools.GetActive ( GameObject  go)
static

Unity4 has changed GameObject.active to GameObject.activeself.

static string NGUITools.GetFuncName ( object  obj,
string  method 
)
static

Convenience function that converts Class + Function combo into Class.Function representation.

static string NGUITools.GetHierarchy ( GameObject  obj)
static

Returns the hierarchy of the object in a human-readable format.

static GameObject NGUITools.GetRoot ( GameObject  go)
static

Get the rootmost object of the specified game object.

static Vector3 [] NGUITools.GetSides ( this Camera  cam)
static

Get sides relative to the specified camera. The order is left, top, right, bottom.

static Vector3 [] NGUITools.GetSides ( this Camera  cam,
float  depth 
)
static

Get sides relative to the specified camera. The order is left, top, right, bottom.

static Vector3 [] NGUITools.GetSides ( this Camera  cam,
Transform  relativeTo 
)
static

Get sides relative to the specified camera. The order is left, top, right, bottom.

static Vector3 [] NGUITools.GetSides ( this Camera  cam,
float  depth,
Transform  relativeTo 
)
static

Get sides relative to the specified camera. The order is left, top, right, bottom.

static string NGUITools.GetTypeName ( UnityEngine.Object  obj)
static

Helper function that returns the string name of the type.

static string NGUITools.GetTypeName< T > ( )
static

Helper function that returns the string name of the type.

static Vector3 [] NGUITools.GetWorldCorners ( this Camera  cam)
static

Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right.

static Vector3 [] NGUITools.GetWorldCorners ( this Camera  cam,
float  depth 
)
static

Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right.

static Vector3 [] NGUITools.GetWorldCorners ( this Camera  cam,
Transform  relativeTo 
)
static

Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right.

static Vector3 [] NGUITools.GetWorldCorners ( this Camera  cam,
float  depth,
Transform  relativeTo 
)
static

Get the camera's world-space corners. The order is bottom-left, top-left, top-right, bottom-right.

static void NGUITools.ImmediatelyCreateDrawCalls ( GameObject  root)
static

Immediately start, update, and create all the draw calls from newly instantiated UI. This is useful if you plan on doing something like immediately taking a screenshot then destroying the UI.

static bool NGUITools.IsActive ( Behaviour  mb)
static

Helper function that returns whether the specified MonoBehaviour is active.

static bool NGUITools.IsChild ( Transform  parent,
Transform  child 
)
static

Determines whether the 'parent' contains a 'child' in its hierarchy.

static byte [] NGUITools.Load ( string  fileName)
static

Load all binary data from the specified file.

static void NGUITools.MakePixelPerfect ( Transform  t)
static

Make the specified selection pixel-perfect.

static void NGUITools.MarkParentAsChanged ( GameObject  go)
static

Inform all widgets underneath the specified object that the parent has changed.

static void NGUITools.NormalizeDepths ( )
static

Normalize the depths of all the widgets and panels in the scene, making them start from 0 and remain in order.

static void NGUITools.NormalizePanelDepths ( )
static

Normalize the depths of all the panels in the scene, making them start from 0 and remain in order.

static void NGUITools.NormalizeWidgetDepths ( )
static

Normalize the depths of all the widgets in the scene, making them start from 0 and remain in order.

static void NGUITools.NormalizeWidgetDepths ( GameObject  go)
static

Normalize the depths of all the widgets in the scene, making them start from 0 and remain in order.

static void NGUITools.NormalizeWidgetDepths ( UIWidget[]  list)
static

Normalize the depths of all the widgets in the scene, making them start from 0 and remain in order.

static Color NGUITools.ParseColor ( string  text,
int  offset 
)
static
static AudioSource NGUITools.PlaySound ( AudioClip  clip)
static

Play the specified audio clip.

static AudioSource NGUITools.PlaySound ( AudioClip  clip,
float  volume 
)
static

Play the specified audio clip with the specified volume.

static AudioSource NGUITools.PlaySound ( AudioClip  clip,
float  volume,
float  pitch 
)
static

Play the specified audio clip with the specified volume and pitch.

static void NGUITools.PushBack ( GameObject  go)
static

Push all of the widgets on the specified object back, making them appear behind everything else.

static int NGUITools.RandomRange ( int  min,
int  max 
)
static

New WWW call can fail if the crossdomain policy doesn't check out. Exceptions suck. It's much more elegant to check for null instead.

Same as Random.Range, but the returned value is between min and max, inclusive. Unity's Random.Range is less than max instead, unless min == max. This means Range(0,1) produces 0 instead of 0 or 1. That's unacceptable.

static void NGUITools.RegisterUndo ( UnityEngine.Object  obj,
string  name 
)
static

Convenience method that works without warnings in both Unity 3 and 4.

static Vector3 NGUITools.Round ( Vector3  v)
static

Helper function used to make the vector use integer numbers.

static bool NGUITools.Save ( string  fileName,
byte[]  bytes 
)
static

Save the specified binary data into the specified file.

static void NGUITools.SetActive ( GameObject  go,
bool  state 
)
static

SetActiveRecursively enables children before parents. This is a problem when a widget gets re-enabled and it tries to find a panel on its parent.

static void NGUITools.SetActive ( GameObject  go,
bool  state,
bool  compatibilityMode 
)
static

SetActiveRecursively enables children before parents. This is a problem when a widget gets re-enabled and it tries to find a panel on its parent.

static void NGUITools.SetActiveChildren ( GameObject  go,
bool  state 
)
static

Activate or deactivate children of the specified game object without changing the active state of the object itself.

static void NGUITools.SetActiveSelf ( GameObject  go,
bool  state 
)
static

Unity4 has changed GameObject.active to GameObject.SetActive.

static void NGUITools.SetChildLayer ( Transform  t,
int  layer 
)
static

Helper function that recursively sets all children with widgets' game objects layers to the specified value.

static void NGUITools.SetDirty ( UnityEngine.Object  obj)
static

Convenience function that marks the specified object as dirty in the Unity Editor.

static void NGUITools.SetLayer ( GameObject  go,
int  layer 
)
static

Recursively set the game object's layer.

static string NGUITools.StripSymbols ( string  text)
static
static void NGUITools.UpdateWidgetCollider ( GameObject  go)
static

Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions.

static void NGUITools.UpdateWidgetCollider ( GameObject  go,
bool  considerInactive 
)
static

Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions.

static void NGUITools.UpdateWidgetCollider ( BoxCollider  box,
bool  considerInactive 
)
static

Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions.

static void NGUITools.UpdateWidgetCollider ( BoxCollider2D  box,
bool  considerInactive 
)
static

Adjust the widget's collider based on the depth of the widgets, as well as the widget's dimensions.

Property Documentation

string NGUITools.clipboard
staticgetset

Access to the clipboard via undocumented APIs.

bool NGUITools.fileAccess
staticget

Helper function – whether the disk access is allowed.

Vector2 NGUITools.screenSize
staticget

Size of the game view cannot be retrieved from Screen.width and Screen.height when the game view is hidden.

float NGUITools.soundVolume
staticgetset

Globally accessible volume affecting all sounds played via NGUITools.PlaySound().


The documentation for this class was generated from the following file: