Пример #1
0
    public Material this[UIDrawCall.Clipping clipping]
    {
        get
        {
            UIMaterial.ClippingFlags clippingFlag = (UIMaterial.ClippingFlags)((int)UIDrawCall.Clipping.HardClip << (int)(clipping & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip)));
            if ((clippingFlag & this.madeMats) != clippingFlag)
            {
                return(this.MakeMaterial(clipping));
            }
            switch (clipping)
            {
            case UIDrawCall.Clipping.None:
            {
                return(this.matNone);
            }

            case UIDrawCall.Clipping.HardClip:
            {
                return(this.matHardClip);
            }

            case UIDrawCall.Clipping.AlphaClip:
            {
                return(this.matAlphaClip);
            }

            case UIDrawCall.Clipping.SoftClip:
            {
                return(this.matSoftClip);
            }
            }
            throw new NotImplementedException();
        }
    }
Пример #2
0
    public Material this[UIDrawCall.Clipping clipping]
    {
        get
        {
            ClippingFlags flags = (ClippingFlags)(((int)1) << clipping);
            if ((flags & this.madeMats) != flags)
            {
                return(this.MakeMaterial(clipping));
            }
            switch (clipping)
            {
            case UIDrawCall.Clipping.None:
                return(this.matNone);

            case UIDrawCall.Clipping.HardClip:
                return(this.matHardClip);

            case UIDrawCall.Clipping.AlphaClip:
                return(this.matAlphaClip);

            case UIDrawCall.Clipping.SoftClip:
                return(this.matSoftClip);
            }
            throw new NotImplementedException();
        }
    }
Пример #3
0
    private Material FastGet(UIDrawCall.Clipping clipping)
    {
        switch (clipping)
        {
        case UIDrawCall.Clipping.None:
        {
            return(this.matNone);
        }

        case UIDrawCall.Clipping.HardClip:
        {
            return(this.matHardClip);
        }

        case UIDrawCall.Clipping.AlphaClip:
        {
            return(this.matAlphaClip);
        }

        case UIDrawCall.Clipping.SoftClip:
        {
            return(this.matSoftClip);
        }
        }
        throw new NotImplementedException();
    }
Пример #4
0
    private Material MakeMaterial(UIDrawCall.Clipping clipping)
    {
        Material material;
        Material matNone;
        Shader   clippingShader;
        bool     flag = this.madeMats == ((ClippingFlags)0);

        switch (clipping)
        {
        case UIDrawCall.Clipping.None:
            clippingShader = this.key.shader;
            matNone        = this.matNone;
            material       = this.matNone = CreateMaterial(clippingShader);
            this.madeMats |= ClippingFlags.None;
            break;

        case UIDrawCall.Clipping.HardClip:
            clippingShader = GetClippingShader(this.key.shader, UIDrawCall.Clipping.HardClip);
            matNone        = this.matHardClip;
            material       = this.matHardClip = CreateMaterial(clippingShader);
            this.madeMats |= ClippingFlags.HardClip;
            break;

        case UIDrawCall.Clipping.AlphaClip:
            clippingShader = GetClippingShader(this.key.shader, UIDrawCall.Clipping.AlphaClip);
            matNone        = this.matAlphaClip;
            material       = this.matAlphaClip = CreateMaterial(clippingShader);
            this.madeMats |= ClippingFlags.AlphaClip;
            break;

        case UIDrawCall.Clipping.SoftClip:
            clippingShader = GetClippingShader(this.key.shader, UIDrawCall.Clipping.SoftClip);
            matNone        = this.matSoftClip;
            material       = this.matSoftClip = CreateMaterial(clippingShader);
            this.madeMats |= ClippingFlags.SoftClip;
            break;

        default:
            throw new NotImplementedException();
        }
        g.generatedMaterials.Add(material, this);
        if (flag)
        {
            this.matFirst = material;
            material.CopyPropertiesFromMaterial(this.key);
        }
        else
        {
            material.CopyPropertiesFromMaterial(this.matFirst);
        }
        if (matNone != null)
        {
            Object.DestroyImmediate(matNone);
        }
        return(material);
    }
Пример #5
0
    private static Shader GetClippingShader(Shader original, UIDrawCall.Clipping clipping)
    {
        if (original == null)
        {
            return(null);
        }
        string name = original.name;

        switch (clipping)
        {
        case UIDrawCall.Clipping.None:
        {
            string str2 = name.Replace(" (HardClip)", string.Empty).Replace(" (AlphaClip)", string.Empty).Replace(" (SoftClip)", string.Empty);
            if (!(str2 == name))
            {
                name = str2;
                break;
            }
            return(original);
        }

        case UIDrawCall.Clipping.HardClip:
            if (ShaderNameDecor(ref name, " (AlphaClip)", " (SoftClip)", " (HardClip)"))
            {
                break;
            }
            return(original);

        case UIDrawCall.Clipping.AlphaClip:
            if (ShaderNameDecor(ref name, " (SoftClip)", " (HardClip)", " (AlphaClip)"))
            {
                break;
            }
            return(original);

        case UIDrawCall.Clipping.SoftClip:
            if (ShaderNameDecor(ref name, " (HardClip)", " (AlphaClip)", " (SoftClip)"))
            {
                break;
            }
            return(original);

        default:
            throw new NotImplementedException();
        }
        Shader shader = Shader.Find(name);

        if (shader == null)
        {
            throw new MissingReferenceException("Theres no shader named " + name);
        }
        return(shader);
    }
Пример #6
0
 public UIPanelMessage(UIPanel uiPanel)
     : base(uiPanel)
 {
     Width        = uiPanel.width;
     Height       = uiPanel.height;
     Depth        = uiPanel.depth;
     SortingOrder = uiPanel.sortingOrder;
     Clipping     = uiPanel.clipping;
     ClipOffset   = uiPanel.clipOffset;
     ClipRegion   = uiPanel.baseClipRegion;
     ClipSoftness = uiPanel.clipSoftness;
 }
Пример #7
0
    public static UIMaterial Create(Material key, bool manageKeyDestruction, UIDrawCall.Clipping useAsClipping)
    {
        UIMaterial material;

        if (!manageKeyDestruction)
        {
            return(Create(key));
        }
        if (key == null)
        {
            return(null);
        }
        if (g.keyedMaterials.TryGetValue(key, out material))
        {
            throw new InvalidOperationException("That material is registered and cannot be used with manageKeyDestruction");
        }
        if (!g.generatedMaterials.TryGetValue(key, out material))
        {
            material          = ScriptableObject.CreateInstance <UIMaterial>();
            material.key      = key;
            material.hashCode = ++g.hashCodeIterator;
            if (material.hashCode == 0x7fffffff)
            {
                g.hashCodeIterator = -2147483648;
            }
            g.generatedMaterials.Add(key, material);
            material.matFirst = key;
            switch (useAsClipping)
            {
            case UIDrawCall.Clipping.None:
                material.matNone = key;
                break;

            case UIDrawCall.Clipping.HardClip:
                material.matHardClip = key;
                break;

            case UIDrawCall.Clipping.AlphaClip:
                material.matAlphaClip = key;
                break;

            case UIDrawCall.Clipping.SoftClip:
                material.matSoftClip = key;
                break;

            default:
                throw new NotImplementedException();
            }
            material.madeMats = (ClippingFlags)(((int)1) << useAsClipping);
        }
        return(material);
    }
Пример #8
0
        public override void Deserialize(BinaryReader br)
        {
            base.Deserialize(br);

            Width        = br.ReadInt32();
            Height       = br.ReadInt32();
            Depth        = br.ReadInt32();
            SortingOrder = br.ReadInt32();
            Clipping     = (UIDrawCall.Clipping)br.ReadInt32();
            ClipOffset   = br.ReadVector2();
            ClipRegion   = br.ReadVector4();
            ClipSoftness = br.ReadVector2();
        }
Пример #9
0
 public void SetPass(int pass)
 {
     if (this.madeMats == ((ClippingFlags)0))
     {
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping clipping = UIDrawCall.Clipping.None; clipping < ((UIDrawCall.Clipping) 4); clipping += 1)
     {
         if ((this.madeMats & (((int)1) << clipping)) != ((ClippingFlags)0))
         {
             this.FastGet(clipping).SetPass(pass);
         }
     }
 }
Пример #10
0
 public void SetTextureScale(string property, Vector2 scale)
 {
     if (this.madeMats == ((ClippingFlags)0))
     {
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping clipping = UIDrawCall.Clipping.None; clipping < ((UIDrawCall.Clipping) 4); clipping += 1)
     {
         if ((this.madeMats & (((int)1) << clipping)) != ((ClippingFlags)0))
         {
             this.FastGet(clipping).SetTextureScale(property, scale);
         }
     }
 }
Пример #11
0
 public void SetTextureScale(string property, Vector2 scale)
 {
     if ((int)this.madeMats == 0)
     {
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping i = UIDrawCall.Clipping.None; (int)i < 4; i = (UIDrawCall.Clipping)((int)i + (int)UIDrawCall.Clipping.HardClip))
     {
         if (((int)this.madeMats & (int)UIDrawCall.Clipping.HardClip << (int)(i & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip))) != (int)UIDrawCall.Clipping.None)
         {
             this.FastGet(i).SetTextureScale(property, scale);
         }
     }
 }
Пример #12
0
 public void SetPass(int pass)
 {
     if ((int)this.madeMats == 0)
     {
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping i = UIDrawCall.Clipping.None; (int)i < 4; i = (UIDrawCall.Clipping)((int)i + (int)UIDrawCall.Clipping.HardClip))
     {
         if (((int)this.madeMats & (int)UIDrawCall.Clipping.HardClip << (int)(i & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip))) != (int)UIDrawCall.Clipping.None)
         {
             this.FastGet(i).SetPass(pass);
         }
     }
 }
Пример #13
0
 public void Set(string property, Matrix4x4 mat)
 {
     if ((int)this.madeMats == 0)
     {
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping i = UIDrawCall.Clipping.None; (int)i < 4; i = (UIDrawCall.Clipping)((int)i + (int)UIDrawCall.Clipping.HardClip))
     {
         if (((int)this.madeMats & (int)UIDrawCall.Clipping.HardClip << (int)(i & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip))) != (int)UIDrawCall.Clipping.None)
         {
             this.FastGet(i).SetMatrix(property, mat);
         }
     }
 }
Пример #14
0
 public void Set(string property, Matrix4x4 mat)
 {
     if (this.madeMats == ((ClippingFlags)0))
     {
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping clipping = UIDrawCall.Clipping.None; clipping < ((UIDrawCall.Clipping) 4); clipping += 1)
     {
         if ((this.madeMats & (((int)1) << clipping)) != ((ClippingFlags)0))
         {
             this.FastGet(clipping).SetMatrix(property, mat);
         }
     }
 }
Пример #15
0
    private void CreateMaterial()
    {
        string text = (!(this.mShader != null)) ? ((!(this.mMaterial != null)) ? "Unlit/Transparent Colored" : this.mMaterial.shader.name) : this.mShader.name;

        text = text.Replace("GUI/Text Shader", "Unlit/Text");
        text = text.Replace(" (AlphaClip)", string.Empty);
        text = text.Replace(" (SoftClip)", string.Empty);
        Shader shader;

        if (this.mClipping == UIDrawCall.Clipping.SoftClip)
        {
            shader = Shader.Find(text + " (SoftClip)");
        }
        else if (this.mClipping == UIDrawCall.Clipping.AlphaClip)
        {
            shader = Shader.Find(text + " (AlphaClip)");
        }
        else
        {
            shader = Shader.Find(text);
        }
        if (this.mMaterial != null)
        {
            this.mDynamicMat           = new Material(this.mMaterial);
            this.mDynamicMat.hideFlags = (HideFlags.DontSave | HideFlags.NotEditable);
            this.mDynamicMat.CopyPropertiesFromMaterial(this.mMaterial);
        }
        else
        {
            this.mDynamicMat           = new Material(shader);
            this.mDynamicMat.hideFlags = (HideFlags.DontSave | HideFlags.NotEditable);
        }
        if (shader != null)
        {
            this.mDynamicMat.shader = shader;
        }
        else if (this.mClipping != UIDrawCall.Clipping.None)
        {
            LogSystem.LogWarning(new object[]
            {
                text,
                " doesn't have a clipped shader version for ",
                this.mClipping
            });
            this.mClipping = UIDrawCall.Clipping.None;
        }
    }
Пример #16
0
 private void OnDestroy()
 {
     if (this.madeMats != ((ClippingFlags)0))
     {
         for (UIDrawCall.Clipping clipping = UIDrawCall.Clipping.None; clipping < ((UIDrawCall.Clipping) 4); clipping += 1)
         {
             if ((this.madeMats & (((int)1) << clipping)) != ((ClippingFlags)0))
             {
                 Material key = this.FastGet(clipping);
                 g.generatedMaterials.Remove(key);
                 Object.DestroyImmediate(key);
             }
         }
     }
     g.keyedMaterials.Remove(this.key);
     this.matNone = this.matFirst = this.matHardClip = this.matSoftClip = this.matAlphaClip = (Material)(this.key = null);
 }
Пример #17
0
    static int get_clipping(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UIPanel             obj = (UIPanel)o;
            UIDrawCall.Clipping ret = obj.clipping;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index clipping on a nil value"));
        }
    }
Пример #18
0
    static int set_clipping(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UIPanel             obj  = (UIPanel)o;
            UIDrawCall.Clipping arg0 = (UIDrawCall.Clipping)ToLua.CheckObject(L, 2, typeof(UIDrawCall.Clipping));
            obj.clipping = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index clipping on a nil value"));
        }
    }
Пример #19
0
 public void CopyPropertiesFromMaterial(Material material)
 {
     if (this.madeMats == ((ClippingFlags)0))
     {
         if (material == this.key)
         {
             return;
         }
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping clipping = UIDrawCall.Clipping.None; clipping < ((UIDrawCall.Clipping) 4); clipping += 1)
     {
         if ((this.madeMats & (((int)1) << clipping)) != ((ClippingFlags)0))
         {
             this.FastGet(clipping).CopyPropertiesFromMaterial(material);
         }
     }
 }
Пример #20
0
 public void CopyPropertiesFromMaterial(Material material)
 {
     if ((int)this.madeMats == 0)
     {
         if (material == this.key)
         {
             return;
         }
         this.MakeDefaultMaterial();
     }
     for (UIDrawCall.Clipping i = UIDrawCall.Clipping.None; (int)i < 4; i = (UIDrawCall.Clipping)((int)i + (int)UIDrawCall.Clipping.HardClip))
     {
         if (((int)this.madeMats & (int)UIDrawCall.Clipping.HardClip << (int)(i & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip))) != (int)UIDrawCall.Clipping.None)
         {
             this.FastGet(i).CopyPropertiesFromMaterial(material);
         }
     }
 }
Пример #21
0
 private Material RebuildMaterial()
 {
     NGUITools.DestroyImmediate(this.mDynamicMat);
     this.CreateMaterial();
     this.mDynamicMat.renderQueue = this.mRenderQueue;
     this.mLastClip = this.mClipping;
     if (this.mTexture != null)
     {
         this.mDynamicMat.mainTexture = this.mTexture;
     }
     if (this.mRenderer != null)
     {
         this.mRenderer.sharedMaterials = new Material[]
         {
             this.mDynamicMat
         };
     }
     return(this.mDynamicMat);
 }
Пример #22
0
    public void Set(string property, Vector4 value)
    {
        Vector4 vector;

        if (this.madeMats == ((ClippingFlags)0))
        {
            this.MakeDefaultMaterial();
        }
        vector.x = value.x;
        vector.y = value.y;
        vector.z = vector.w = 0f;
        for (UIDrawCall.Clipping clipping = UIDrawCall.Clipping.None; clipping < ((UIDrawCall.Clipping) 4); clipping += 1)
        {
            if ((this.madeMats & (((int)1) << clipping)) != ((ClippingFlags)0))
            {
                this.FastGet(clipping).SetVector(property, vector);
            }
        }
    }
Пример #23
0
    public void Set(string property, Vector4 value)
    {
        Vector4 vector4 = new Vector4();

        if ((int)this.madeMats == 0)
        {
            this.MakeDefaultMaterial();
        }
        vector4.x = value.x;
        vector4.y = value.y;
        float single  = 0f;
        float single1 = single;

        vector4.w = single;
        vector4.z = single1;
        for (UIDrawCall.Clipping i = UIDrawCall.Clipping.None; (int)i < 4; i = (UIDrawCall.Clipping)((int)i + (int)UIDrawCall.Clipping.HardClip))
        {
            if (((int)this.madeMats & (int)UIDrawCall.Clipping.HardClip << (int)(i & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip))) != (int)UIDrawCall.Clipping.None)
            {
                this.FastGet(i).SetVector(property, vector4);
            }
        }
    }
Пример #24
0
    private void OnDestroy()
    {
        if ((int)this.madeMats != 0)
        {
            for (UIDrawCall.Clipping i = UIDrawCall.Clipping.None; (int)i < 4; i = (UIDrawCall.Clipping)((int)i + (int)UIDrawCall.Clipping.HardClip))
            {
                if (((int)this.madeMats & (int)UIDrawCall.Clipping.HardClip << (int)(i & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip))) != (int)UIDrawCall.Clipping.None)
                {
                    Material material = this.FastGet(i);
                    UIMaterial.g.generatedMaterials.Remove(material);
                    UnityEngine.Object.DestroyImmediate(material);
                }
            }
        }
        UIMaterial.g.keyedMaterials.Remove(this.key);
        object   obj       = null;
        Material material1 = (Material)obj;

        this.key = (Material)obj;
        Material material2 = material1;

        material1         = material2;
        this.matAlphaClip = material2;
        Material material3 = material1;

        material1        = material3;
        this.matSoftClip = material3;
        Material material4 = material1;

        material1        = material4;
        this.matHardClip = material4;
        Material material5 = material1;

        material1     = material5;
        this.matFirst = material5;
        this.matNone  = material1;
    }
Пример #25
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;
        BetterList <UIDrawCall> drawcalls = panel.drawCalls;

        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

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

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

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

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));

        GUILayout.Label("Extra draw call, saves fillrate");
        GUILayout.EndHorizontal();

        if (panel.depthPass != depth)
        {
            panel.depthPass = depth;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        EditorGUILayout.LabelField("Widgets", panel.widgets.size.ToString());
        EditorGUILayout.LabelField("Draw Calls", drawcalls.size.ToString());

        UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.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 (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

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

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

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

        foreach (UIDrawCall dc in drawcalls)
        {
            NGUIEditorTools.DrawSeparator();
            EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
            EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());
        }
    }
Пример #26
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;
        BetterList <UIDrawCall> drawcalls = panel.drawCalls;

        drawcalls.Sort(delegate(UIDrawCall w1, UIDrawCall w2) { return(w1.depth.CompareTo(w2.depth)); });
        //EditorGUIUtility.LookLikeControls(80f);
        EditorGUIUtility.labelWidth = 80;
        EditorGUIUtility.fieldWidth = 80;

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

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

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

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

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

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        // No one seems to know how to use this properly correctly. Solution? Removing it.
        // If you know wtf you're doing, you're welcome to uncomment it.

        //GUILayout.BeginHorizontal();
        //bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));
        //GUILayout.Label("Doubles draw calls, saves fillrate");
        //GUILayout.EndHorizontal();

        //if (panel.depthPass != depth)
        //{
        //    panel.depthPass = depth;
        //    panel.UpdateDrawcalls();
        //    EditorUtility.SetDirty(panel);
        //}

        //if (depth)
        //{
        //    UICamera cam = UICamera.FindCameraForLayer(panel.gameObject.layer);

        //    if (cam == null || cam.camera.isOrthoGraphic)
        //    {
        //        EditorGUILayout.HelpBox("Please note that depth pass will only save fillrate when used with 3D UIs, and only UIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning);
        //    }
        //}

        GUILayout.BeginHorizontal();
        bool sort = EditorGUILayout.Toggle("Depth Sort", panel.sortByDepth, GUILayout.Width(100f));

        GUILayout.Label("Sort widgets by depth (ignore Z)");
        GUILayout.EndHorizontal();

        if (panel.sortByDepth != sort)
        {
            panel.sortByDepth = sort;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        if (!sort)
        {
            EditorGUILayout.HelpBox("Keep the 'Depth Sort' flag turned on, unless you are working with a UI created prior to NGUI 2.7.0 and want to sort by Z in addition to Depth.", MessageType.Warning);
        }

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

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

        if (panel.cullWhileDragging != cull)
        {
            panel.cullWhileDragging = cull;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        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);
        }

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

        UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.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 (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

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

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

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

#if !UNITY_3_5 && !UNITY_4_0 && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY)
            if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_2_0)
            {
                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.HardClip)
        {
            EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.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(panel.gameObject);
            }
        }

        if (panel.drawCalls.size > 0 && NGUIEditorTools.DrawHeader(panel.drawCalls.size + " draw calls from " + panel.widgets.size + " widgets", "DrawCalls"))
        {
            NGUIEditorTools.BeginContents();

            foreach (UIDrawCall dc in drawcalls)
            {
                EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
                EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

                if (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();
        }
    }
Пример #27
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; 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);
    }
Пример #28
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;
        BetterList <UIDrawCall> drawcalls = panel.drawCalls;

        EditorGUIUtility.LookLikeControls(80f, 80f);

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

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

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

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

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

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

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));

        GUILayout.Label("Doubles draw calls, saves fillrate");
        GUILayout.EndHorizontal();

        if (panel.depthPass != depth)
        {
            panel.depthPass = depth;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        if (depth)
        {
            UICamera cam = UICamera.FindCameraForLayer(panel.gameObject.layer);

            if (cam == null || cam.camera.isOrthoGraphic)
            {
                EditorGUILayout.HelpBox("Please note that depth pass will only save fillrate when used with 3D UIs, and only UIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning);
            }
        }

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

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

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        EditorGUILayout.LabelField("Widgets", panel.widgets.size.ToString());
        EditorGUILayout.LabelField("Draw Calls", drawcalls.size.ToString());

        UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.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 (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

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

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

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

#if !UNITY_3_5 && (UNITY_ANDROID || UNITY_IPHONE)
            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.HardClip)
        {
            EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.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(panel.gameObject);
            }
        }

        foreach (UIDrawCall dc in drawcalls)
        {
            NGUIEditorTools.DrawSeparator();
            EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
            EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

            if (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);
            }
        }
    }
Пример #29
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;

        NGUIEditorTools.SetLabelWidth(80f);
        EditorGUILayout.Space();

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

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

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

            int depth = panel.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 (panel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", panel);
                panel.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 && panel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

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

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

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

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            UIPanel.SetDirty();
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.cullWhileDragging != cull)
        {
            panel.cullWhileDragging = cull;
            UIPanel.SetDirty();
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            UIPanel.SetDirty();
            EditorUtility.SetDirty(panel);
        }

        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 (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool))
        {
            panel.showInPanelTool = !panel.showInPanelTool;
            EditorUtility.SetDirty(panel);
            EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
        }

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

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

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.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 (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

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

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

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

#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(panel.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(panel.gameObject);
            }
        }

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

            if (dc.panel != panel)
            {
                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.panel != panel)
            {
                name = name + " (" + dc.panel.name + ")";
            }

            if (NGUIEditorTools.DrawHeader(name, key))
            {
                GUI.color = (dc.panel == panel) ? 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.panel.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.panel);
                }

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

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

                if (dc.panel.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;
            }
        }
    }
Пример #30
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;
        BetterList <UIDrawCall> drawcalls = panel.drawCalls;

        EditorGUIUtility.LookLikeControls(80f);

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

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

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

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

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

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

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));

        GUILayout.Label("Extra draw call, saves fillrate");
        GUILayout.EndHorizontal();

        if (panel.depthPass != depth)
        {
            panel.depthPass = depth;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        EditorGUILayout.LabelField("Widgets", panel.widgets.size.ToString());
        EditorGUILayout.LabelField("Draw Calls", drawcalls.size.ToString());

        UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

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

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

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.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 (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

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

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

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

        if (clipping == UIDrawCall.Clipping.HardClip)
        {
            EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.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(panel.gameObject);
            }
        }

        foreach (UIDrawCall dc in drawcalls)
        {
            NGUIEditorTools.DrawSeparator();
            EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
            EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

            if (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);
            }
        }
    }