예제 #1
0
    /// <summary>
    /// All widgets have depth, color and make pixel-perfect options
    /// </summary>

    protected void DrawCommonProperties()
    {
#if UNITY_3_4
        PrefabType type = EditorUtility.GetPrefabType(mWidget.gameObject);
#else
        PrefabType type = PrefabUtility.GetPrefabType(mWidget.gameObject);
#endif

        NGUIEditorTools.DrawSeparator();

        // Depth navigation
        if (type != PrefabType.Prefab)
        {
            GUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Depth");

                int depth = mWidget.depth;
                if (GUILayout.Button("Back"))
                {
                    --depth;
                }
                depth = EditorGUILayout.IntField(depth, GUILayout.Width(40f));
                if (GUILayout.Button("Forward"))
                {
                    ++depth;
                }

                if (mWidget.depth != depth)
                {
                    NGUIEditorTools.RegisterUndo("Depth Change", mWidget);
                    mWidget.depth = depth;
                }
            }
            GUILayout.EndHorizontal();
        }

        Color color = EditorGUILayout.ColorField("Color Tint", mWidget.color);

        if (mWidget.color != color)
        {
            NGUIEditorTools.RegisterUndo("Color Change", mWidget);
            mWidget.color = color;
        }
        // Depth navigation
        if (type != PrefabType.Prefab)
        {
            GUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Normalize");
                if (GUILayout.Button("Normalize from old version"))
                {
                    mWidget.FixOldVersion();
                }
            }
            GUILayout.EndHorizontal();

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

                if (GUILayout.Button("Make Pixel-Perfect"))
                {
                    NGUIEditorTools.RegisterUndo("Make Pixel-Perfect", mWidget.transform);
                    mWidget.MakePixelPerfect();
                }
            }
            GUILayout.EndHorizontal();

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

                if (GUILayout.Button("Mark As Changed"))
                {
                    if (mWidget is UISprite)
                    {
                        (mWidget as UISprite).UpdateUVs();
                    }
                    mWidget.MarkAsChanged();
                }
            }
            GUILayout.EndHorizontal();
        }

        UIWidget.Pivot pivot = (UIWidget.Pivot)EditorGUILayout.EnumPopup("Pivot", mWidget.pivot);

        if (mWidget.pivot != pivot)
        {
            NGUIEditorTools.RegisterUndo("Pivot Change", mWidget);
            mWidget.pivot = pivot;
        }

        DrawDimensions();

        if (mAllowPreview && mWidget.mainTexture != null)
        {
            GUILayout.BeginHorizontal();
            {
                UISettings.texturePreview = EditorGUILayout.Toggle("Preview", UISettings.texturePreview, GUILayout.Width(100f));

                /*if (UISettings.texturePreview)
                 * {
                 *      if (mUseShader != EditorGUILayout.Toggle("Use Shader", mUseShader))
                 *      {
                 *              mUseShader = !mUseShader;
                 *
                 *              if (mUseShader)
                 *              {
                 *                      // TODO: Remove this when Unity fixes the bug with DrawPreviewTexture not being affected by BeginGroup
                 *                      Debug.LogWarning("There is a bug in Unity that prevents the texture from getting clipped properly.\n" +
                 *                              "Until it's fixed by Unity, your texture may spill onto the rest of the Unity's GUI while using this mode.");
                 *              }
                 *      }
                 * }*/
            }
            GUILayout.EndHorizontal();



            // Draw the texture last
            if (UISettings.texturePreview)
            {
                OnDrawTexture();
            }
        }
    }