/// <summary> /// Create an undo point for the specified objects. /// </summary> static public void RegisterUndo(string name, params Object[] objects) { if (objects != null && objects.Length > 0) { foreach (Object obj in objects) { if (obj == null) { continue; } RebasedUndo.RegisterUndo(obj, name); EditorUtility.SetDirty(obj); } } }
/// <summary> /// Fix uniform scaling of the specified object. /// </summary> static public void FixUniform(GameObject go) { Transform t = go.transform; while (t != null && t.gameObject.GetComponent <UIRoot>() == null) { if (!NGUIEditorTools.IsUniform(t.localScale)) { RebasedUndo.RegisterUndo(t, "Uniform scaling fix"); t.localScale = Vector3.one; EditorUtility.SetDirty(t); } t = t.parent; } }
static public void AddTexture() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { UITexture tex = NGUITools.AddWidget <UITexture>(go); tex.name = "Texture"; tex.pivot = NGUISettings.pivot; tex.cachedTransform.localScale = new Vector3(100f, 100f, 1f); Selection.activeGameObject = tex.gameObject; // Fixing deprecated Undo.RegisterSceneUndo("Add a Texture"); RebasedUndo.RegisterUndo(tex.gameObject, "Add a Texture"); } else { Debug.Log("You must select a game object first."); } }
static public void AddLabel() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.name = "Label"; lbl.font = NGUISettings.font; lbl.text = "New Label"; lbl.pivot = NGUISettings.pivot; lbl.cachedTransform.localScale = new Vector3(100f, 100f, 1f); lbl.MakePixelPerfect(); Selection.activeGameObject = lbl.gameObject; RebasedUndo.RegisterUndo(lbl.gameObject, "Add a Label"); } else { Debug.Log("You must select a game object first."); } }
static public void AddSprite() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { UISprite sprite = NGUITools.AddWidget <UISprite>(go); sprite.name = "Sprite"; sprite.atlas = NGUISettings.atlas; if (sprite.atlas != null) { string sn = EditorPrefs.GetString("NGUI Sprite", ""); UIAtlas.Sprite sp = sprite.atlas.GetSprite(sn); if (sp != null) { sprite.spriteName = sn; if (sp.inner != sp.outer) { sprite.type = UISprite.Type.Sliced; } } } sprite.pivot = NGUISettings.pivot; sprite.cachedTransform.localScale = new Vector3(100f, 100f, 1f); sprite.MakePixelPerfect(); Selection.activeGameObject = sprite.gameObject; // Fixing deprecated Undo.RegisterSceneUndo("Add a Sprite"); RebasedUndo.RegisterUndo(sprite.gameObject, "Add a Sprite"); } else { Debug.Log("You must select a game object first."); } }