summaryrefslogtreecommitdiff
path: root/Assets/BOXOPHOBIC/Utils/Editor/StyledMaterial/StyledTextDrawer.cs
blob: 88e07a48e02a0948f5051994490fc27798980f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Cristian Pop - https://boxophobic.com/

using UnityEngine;
using UnityEditor;
using System;

namespace Boxophobic.StyledGUI
{
    public class StyledTextDrawer : MaterialPropertyDrawer
    {
        public string text = "";
        public string alignment = "Center";
        public string font = "Normal";
        public string disabled = "";
        public float size = 11;
        public float top = 0;
        public float down = 0;

        public StyledTextDrawer(string text)
        {
            this.text = text;
        }

        public StyledTextDrawer(string text, string alignment, string font, string disabled, float size)
        {
            this.text = text;
            this.alignment = alignment;
            this.font = font;
            this.disabled = disabled;
            this.size = size;
        }

        public StyledTextDrawer(string text, string alignment, string font, string disabled, float size, float top, float down)
        {
            this.text = text;
            this.alignment = alignment;
            this.font = font;
            this.disabled = disabled;
            this.size = size;
            this.top = top;
            this.down = down;
        }

        public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor materialEditor)
        {
            //Material material = materialEditor.target as Material;

            GUIStyle styleLabel = new GUIStyle(EditorStyles.label)
            {
                richText = true,
                alignment = TextAnchor.MiddleCenter,
                wordWrap = true
            };

            GUILayout.Space(top);

            if (alignment == "Center")
            {
                styleLabel.alignment = TextAnchor.MiddleCenter;

            }
            else if (alignment == "Left")
            {
                styleLabel.alignment = TextAnchor.MiddleCenter;
            }
            else if (alignment == "Left")
            {
                styleLabel.alignment = TextAnchor.MiddleCenter;
            }

            if (font == "Bold")
            {
                styleLabel.fontStyle = FontStyle.Bold;
            }
            else
            {
                styleLabel.fontStyle = FontStyle.Normal;
            }

            styleLabel.fontSize = (int)size;

            if (disabled == "Disabled")
            {
                GUI.enabled = false;
            }

            GUILayout.Label(text, styleLabel);

            GUI.enabled = true;

            GUILayout.Space(down);
        }

        public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
        {
            return -2;
        }
    }
}