Example #1
0
    /// <summary>
    /// Helper function that returns the selected root object.
    /// </summary>

    static public GameObject SelectedRoot(bool createIfMissing)
    {
        GameObject go = Selection.activeGameObject;

        // Only use active objects
        if (go != null && !NGUITools.GetActive(go))
        {
            go = null;
        }

        // Try to find a panel
        UIPanel p = (go != null) ? NGUITools.FindInParents <UIPanel>(go) : null;

        // No selection? Try to find the root automatically
        if (p == null)
        {
            UIPanel[] panels = GameObject.FindSceneObjectsOfType(typeof(UIPanel)) as UIPanel[];
            if (panels.Length > 0)
            {
                go = panels[0].gameObject;
            }
        }

        // Now find the first uniformly scaled object
        if (go != null)
        {
            Transform t = go.transform;

            // Find the first uniformly scaled object
            while (!Mathf.Approximately(t.localScale.x, t.localScale.y) ||
                   !Mathf.Approximately(t.localScale.x, t.localScale.z))
            {
                t = t.parent;
                if (t == null)
                {
                    return((p != null) ? p.gameObject : null);
                }
                else
                {
                    go = t.gameObject;
                }
            }
        }

        if (createIfMissing && go == null)
        {
            // No object specified -- find the first panel
            if (go == null)
            {
                UIPanel panel = GameObject.FindObjectOfType(typeof(UIPanel)) as UIPanel;
                if (panel != null)
                {
                    go = panel.gameObject;
                }
            }

            // No UI present -- create a new one
            if (go == null)
            {
                go = UICreateNewUIWizard.CreateNewUI();
            }
        }
        return(go);
    }
Example #2
0
 static void Create2D()
 {
     UICreateNewUIWizard.CreateNewUI(UICreateNewUIWizard.CameraType.Simple2D);
 }
Example #3
0
 static void Create3D()
 {
     UICreateNewUIWizard.CreateNewUI(UICreateNewUIWizard.CameraType.Advanced3D);
 }
Example #4
0
 public static GameObject CreateNewUI()
 {
     return(UICreateNewUIWizard.CreateNewUI(UICreateNewUIWizard.camType));
 }