RebuildAllDrawCalls() private method

private RebuildAllDrawCalls ( ) : void
return void
Esempio n. 1
0
    /// <summary>
    /// This callback is sent inside the editor notifying us that some property has changed.
    /// </summary>

    protected virtual void OnValidate()
    {
        mChanged = true;

        // Prior to NGUI 2.7.0 width and height was specified as transform's local scale
        if ((mWidth == 100 || mWidth == minWidth) &&
            (mHeight == 100 || mHeight == minHeight) && cachedTransform.localScale.magnitude > 8f)
        {
            UpgradeFrom265();
            cachedTransform.localScale = Vector3.one;
        }

        if (mWidth < minWidth)
        {
            mWidth = minWidth;
        }
        if (mHeight < minHeight)
        {
            mHeight = minHeight;
        }
        if (autoResizeBoxCollider)
        {
            ResizeCollider();
        }

        // If the texture is changing, we need to make sure to rebuild the draw calls
        if (mOldTex != mainTexture || mOldShader != shader)
        {
            mOldTex    = mainTexture;
            mOldShader = shader;
            UIPanel.RebuildAllDrawCalls(true);
        }
    }
Esempio n. 2
0
    public void AddChild(GameObject child)
    {
        if (child != null)
        {
            ElementInfo info = new ElementInfo();

            UIPanel panel         = child.GetComponent <UIPanel>();
            UIPanel previousPanel = null;
            if (panel == null)
            {
                previousPanel   = NGUITools.FindInParents <UIPanel>(child);
                panel           = child.AddComponent <UIPanel>();
                info.addedPanel = panel;
            }
            else
            {
                info.addedPanel    = null;
                info.previousDepth = panel.depth;
            }
            panel.depth           = ++currentDepth;
            _elementToInfo[child] = info;
            CheckParentInChildren(child);

            if (previousPanel)
            {
                previousPanel.RebuildAllDrawCalls();
            }
            else
            {
                panel.RebuildAllDrawCalls();
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Mark the widget as changed so that the geometry can be rebuilt.
    /// </summary>

    void SetDirty()
    {
        if (drawCall != null)
        {
            drawCall.isDirty = true;
        }
        else if (isVisible && hasVertices)
        {
            UIPanel.RebuildAllDrawCalls(true);
        }
    }
Esempio n. 4
0
 static public int RebuildAllDrawCalls(IntPtr l)
 {
     try {
         UIPanel self = (UIPanel)checkSelf(l);
         self.RebuildAllDrawCalls();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 5
0
 static int RebuildAllDrawCalls(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UIPanel obj = (UIPanel)ToLua.CheckObject <UIPanel>(L, 1);
         obj.RebuildAllDrawCalls();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 6
0
    /// <summary>
    /// Ensure we have a panel referencing this widget.
    /// </summary>

    public void CreatePanel()
    {
        if (mPanel == null && enabled && NGUITools.GetActive(gameObject))
        {
            mPanel = UIPanel.Find(cachedTransform, mStarted);

            if (mPanel != null)
            {
                CheckLayer();
                mChanged = true;
                if (material != null)
                {
                    UIPanel.RebuildAllDrawCalls(true);
                }
            }
        }
    }
Esempio n. 7
0
    protected void OnReload()
    {
        if (mhudDynamicPanel == null)
        {
            mhudDynamicPanel = hudDynamicContainer.GetComponent <UIPanel>();
        }
        if (mhudStaticPanel == null)
        {
            mhudStaticPanel = hudStaticContainer.GetComponent <UIPanel>();
        }
        mhudDynamicPanel.RebuildAllDrawCalls();
        mhudStaticPanel.RebuildAllDrawCalls();

        mhudDynamicPanel.alpha = 1.0f;
        mhudStaticPanel.alpha  = 1.0f;

        // the alpha of these panels, these values will be returned to after the HUD re-appears in the modal system
        _containersShown.Clear();
        _containersShown[eContainers.HUD_Dynamic] = true;
        _containersShown[eContainers.HUD_Static]  = true;

        SetHudShow();
    }
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }

                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0; i < UIPanel.list.size; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.baseClipRegion;

            // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable
            EditorGUI.BeginDisabledGroup(mPanel.GetComponent <UIScrollView>() != null);
            GUI.changed = false;
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset);
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipOffset = off;
                EditorUtility.SetDirty(mPanel);
            }
            EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.baseClipRegion != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.baseClipRegion = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        if (NGUIEditorTools.DrawHeader("Advanced Options"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();
            UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue);

            if (mPanel.renderQueue != rq)
            {
                mPanel.renderQueue = rq;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }

            if (rq != UIPanel.RenderQueue.Automatic)
            {
                int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f));

                if (mPanel.startingRenderQueue != sq)
                {
                    mPanel.startingRenderQueue = sq;
                    mPanel.RebuildAllDrawCalls();
                    EditorUtility.SetDirty(mPanel);
                    if (UIDrawCallViewer.instance != null)
                    {
                        UIDrawCallViewer.instance.Repaint();
                    }
                }
            }
            GUILayout.EndHorizontal();

#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
            if (rq == UIPanel.RenderQueue.Explicit)
            {
                GUI.changed = false;
                int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f));
                if (GUI.changed)
                {
                    mPanel.sortingOrder = so;
                }
            }
#endif
            GUILayout.BeginHorizontal();
            bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));
            GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.generateNormals != norms)
            {
                mPanel.generateNormals = norms;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));
            GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.cullWhileDragging != cull)
            {
                mPanel.cullWhileDragging = cull;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.alwaysOnScreen != alw)
            {
                mPanel.alwaysOnScreen = alw;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset, GUILayout.Width(100f));
            GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.anchorOffset != off)
            {
                mPanel.anchorOffset = off;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.widgetsAreStatic != stat)
            {
                mPanel.widgetsAreStatic = stat;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            if (stat)
            {
                EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
            }

            GUILayout.BeginHorizontal();
            bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f));
            GUILayout.Label("Show in panel tool");
            GUILayout.EndHorizontal();

            if (mPanel.showInPanelTool != tool)
            {
                mPanel.showInPanelTool = !mPanel.showInPanelTool;
                EditorUtility.SetDirty(mPanel);
                EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
            }
            NGUIEditorTools.EndContents();
        }
        return(true);
    }
Esempio n. 9
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }

                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0, imax = UIPanel.list.Count; i < imax; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        // Contributed by Benzino07: http://www.tasharen.com/forum/index.php?topic=6956.15
        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Sorting Layer");

            // Get the names of the Sorting layers
            System.Type  internalEditorUtilityType = typeof(InternalEditorUtility);
            PropertyInfo sortingLayersProperty     = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
            string[]     names = (string[])sortingLayersProperty.GetValue(null, new object[0]);

            int index = 0;
            if (!string.IsNullOrEmpty(mPanel.sortingLayerName))
            {
                for (int i = 0; i < names.Length; i++)
                {
                    if (mPanel.sortingLayerName == names[i])
                    {
                        index = i;
                        break;
                    }
                }
            }

            // Get the selected index and update the panel sorting layer if it has changed
            int selectedIndex = EditorGUILayout.Popup(index, names);

            if (index != selectedIndex)
            {
                mPanel.sortingLayerName = names[selectedIndex];
                EditorUtility.SetDirty(mPanel);
            }
        }
        GUILayout.EndHorizontal();

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.baseClipRegion;

            // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable
            //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null);
            GUI.changed = false;
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset, GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipOffset = off;
                EditorUtility.SetDirty(mPanel);
            }
            //EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y), GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w), GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.baseClipRegion != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.baseClipRegion = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness, GUILayout.MinWidth(20f));
                GUILayout.EndHorizontal();

                if (soft.x < 0f)
                {
                    soft.x = 0f;
                }
                if (soft.y < 0f)
                {
                    soft.y = 0f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }
            else if (mPanel.clipping == UIDrawCall.Clipping.TextureMask)
            {
                NGUIEditorTools.SetLabelWidth(0f);
                GUILayout.Space(-90f);
                Texture2D tex = (Texture2D)EditorGUILayout.ObjectField(mPanel.clipTexture,
                                                                       typeof(Texture2D), false, GUILayout.Width(70f), GUILayout.Height(70f));
                GUILayout.Space(20f);

                if (mPanel.clipTexture != tex)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipTexture = tex;
                    EditorUtility.SetDirty(mPanel);
                }
                NGUIEditorTools.SetLabelWidth(80f);
            }
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        if (NGUIEditorTools.DrawHeader("Advanced Options"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();
            UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue);

            if (mPanel.renderQueue != rq)
            {
                mPanel.renderQueue = rq;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }

            if (rq != UIPanel.RenderQueue.Automatic)
            {
                int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f));

                if (mPanel.startingRenderQueue != sq)
                {
                    mPanel.startingRenderQueue = sq;
                    mPanel.RebuildAllDrawCalls();
                    EditorUtility.SetDirty(mPanel);
                    if (UIDrawCallViewer.instance != null)
                    {
                        UIDrawCallViewer.instance.Repaint();
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUI.changed = false;
            int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f));
            if (GUI.changed)
            {
                mPanel.sortingOrder = so;
            }

            GUILayout.BeginHorizontal();
            bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));
            GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.generateNormals != norms)
            {
                mPanel.generateNormals = norms;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));
            GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.cullWhileDragging != cull)
            {
                mPanel.cullWhileDragging = cull;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.alwaysOnScreen != alw)
            {
                mPanel.alwaysOnScreen = alw;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Padding", serializedObject, "softBorderPadding", GUILayout.Width(100f));
            GUILayout.Label("Soft border pads content", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(mPanel.GetComponent <UIRoot>() != null);
            bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset && mPanel.GetComponent <UIRoot>() == null, GUILayout.Width(100f));
            GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f));
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            if (mPanel.anchorOffset != off)
            {
                mPanel.anchorOffset = off;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.widgetsAreStatic != stat)
            {
                mPanel.widgetsAreStatic = stat;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            if (stat)
            {
                EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
            }

            GUILayout.BeginHorizontal();
            bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f));
            GUILayout.Label("Show in panel tool");
            GUILayout.EndHorizontal();

            if (mPanel.showInPanelTool != tool)
            {
                mPanel.showInPanelTool = !mPanel.showInPanelTool;
                EditorUtility.SetDirty(mPanel);
                EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
            }
            NGUIEditorTools.EndContents();
        }
        return(true);
    }
Esempio n. 10
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0; i < UIPanel.list.size; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Info);
        }

        GUILayout.BeginHorizontal();
        bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));

        GUILayout.Label("Needed for lit shaders");
        GUILayout.EndHorizontal();

        if (mPanel.generateNormals != norms)
        {
            mPanel.generateNormals = norms;
            UIPanel.RebuildAllDrawCalls(true);
            EditorUtility.SetDirty(mPanel);
        }

        GUILayout.BeginHorizontal();
        bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));

        GUILayout.Label("Cull widgets while dragging them");
        GUILayout.EndHorizontal();

        if (mPanel.cullWhileDragging != cull)
        {
            mPanel.cullWhileDragging = cull;
            UIPanel.RebuildAllDrawCalls(true);
            EditorUtility.SetDirty(mPanel);
        }

        GUILayout.BeginHorizontal();
        bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));

        GUILayout.Label("Check if widgets won't move");
        GUILayout.EndHorizontal();

        if (mPanel.widgetsAreStatic != stat)
        {
            mPanel.widgetsAreStatic = stat;
            UIPanel.RebuildAllDrawCalls(true);
            EditorUtility.SetDirty(mPanel);
        }

        if (stat)
        {
            EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
        }

        GUILayout.BeginHorizontal();
        if (NGUISettings.showAllDCs != EditorGUILayout.Toggle("Show All", NGUISettings.showAllDCs, GUILayout.Width(100f)))
        {
            NGUISettings.showAllDCs = !NGUISettings.showAllDCs;
        }
        GUILayout.Label("Show all draw calls");
        GUILayout.EndHorizontal();

        if (mPanel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool))
        {
            mPanel.showInPanelTool = !mPanel.showInPanelTool;
            EditorUtility.SetDirty(mPanel);
            EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipRange = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }

#if !UNITY_3_5 && !UNITY_4_0 && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY)
            if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_1_x)
            {
                EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error);
            }
#endif
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        for (int i = 0; i < UIDrawCall.list.size; ++i)
        {
            UIDrawCall dc = UIDrawCall.list[i];

            if (dc.manager != mPanel)
            {
                if (!NGUISettings.showAllDCs)
                {
                    continue;
                }
                if (dc.showDetails)
                {
                    GUI.color = new Color(0.85f, 0.85f, 0.85f);
                }
                else
                {
                    GUI.contentColor = new Color(0.85f, 0.85f, 0.85f);
                }
            }
            else
            {
                GUI.contentColor = Color.white;
            }

            string key  = dc.keyName;
            string name = key + " of " + UIDrawCall.list.size;
            if (!dc.isActive)
            {
                name = name + " (HIDDEN)";
            }
            else if (dc.manager != mPanel)
            {
                name = name + " (" + dc.manager.name + ")";
            }

            if (NGUIEditorTools.DrawHeader(name, key))
            {
                GUI.color = (dc.manager == mPanel) ? Color.white : new Color(0.8f, 0.8f, 0.8f);

                NGUIEditorTools.BeginContents();
                EditorGUILayout.ObjectField("Material", dc.baseMaterial, typeof(Material), false);

                int count = 0;

                for (int b = 0; b < UIWidget.list.size; ++b)
                {
                    UIWidget w = UIWidget.list[b];
                    if (w.drawCall == dc)
                    {
                        ++count;
                    }
                }

                string   myPath = NGUITools.GetHierarchy(dc.manager.cachedGameObject);
                string   remove = myPath + "\\";
                string[] list   = new string[count + 1];
                list[0] = count.ToString();
                count   = 0;

                for (int b = 0; b < UIWidget.list.size; ++b)
                {
                    UIWidget w = UIWidget.list[b];

                    if (w.drawCall == dc)
                    {
                        string path = NGUITools.GetHierarchy(w.cachedGameObject);
                        list[++count] = count + ". " + (string.Equals(path, myPath) ? w.name : path.Replace(remove, ""));
                    }
                }

                GUILayout.BeginHorizontal();
                int sel = EditorGUILayout.Popup("Widgets", 0, list);
                GUILayout.Space(18f);
                GUILayout.EndHorizontal();

                if (sel != 0)
                {
                    count = 0;

                    for (int b = 0; b < UIWidget.list.size; ++b)
                    {
                        UIWidget w = UIWidget.list[b];

                        if (w.drawCall == dc && ++count == sel)
                        {
                            Selection.activeGameObject = w.gameObject;
                            break;
                        }
                    }
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Render Q", dc.finalRenderQueue.ToString(), GUILayout.Width(120f));
                bool draw = (Visibility)EditorGUILayout.EnumPopup(dc.isActive ? Visibility.Visible : Visibility.Hidden) == Visibility.Visible;
                GUILayout.Space(18f);
                GUILayout.EndHorizontal();

                if (dc.isActive != draw)
                {
                    dc.isActive = draw;
                    UnityEditor.EditorUtility.SetDirty(dc.manager);
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Triangles", dc.triangles.ToString(), GUILayout.Width(120f));

                if (dc.manager != mPanel)
                {
                    if (GUILayout.Button("Select the Panel"))
                    {
                        Selection.activeGameObject = dc.manager.gameObject;
                    }
                    GUILayout.Space(18f);
                }
                GUILayout.EndHorizontal();

                if (dc.manager.clipping != UIDrawCall.Clipping.None && !dc.isClipped)
                {
                    EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
                                            MessageType.Warning);
                }

                NGUIEditorTools.EndContents();
                GUI.color = Color.white;
            }
        }
    }
Esempio n. 11
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0; i < UIPanel.list.size; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipRange = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        if (NGUIEditorTools.DrawHeader("Advanced Options"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();
            bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));
            GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.generateNormals != norms)
            {
                mPanel.generateNormals = norms;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));
            GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.cullWhileDragging != cull)
            {
                mPanel.cullWhileDragging = cull;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.alwaysOnScreen != alw)
            {
                mPanel.alwaysOnScreen = alw;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.widgetsAreStatic != stat)
            {
                mPanel.widgetsAreStatic = stat;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            if (stat)
            {
                EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
            }

            GUILayout.BeginHorizontal();
            bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f));
            GUILayout.Label("Show in panel tool");
            GUILayout.EndHorizontal();

            if (mPanel.showInPanelTool != tool)
            {
                mPanel.showInPanelTool = !mPanel.showInPanelTool;
                EditorUtility.SetDirty(mPanel);
                EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
            }
            NGUIEditorTools.EndContents();
        }

        if (GUILayout.Button("Show Draw Calls"))
        {
            NGUISettings.showAllDCs = false;

            if (UIDrawCallViewer.instance != null)
            {
                UIDrawCallViewer.instance.Focus();
                UIDrawCallViewer.instance.Repaint();
            }
            else
            {
                EditorWindow.GetWindow <UIDrawCallViewer>(false, "Draw Call Tool", true);
            }
        }
    }