summaryrefslogtreecommitdiff
path: root/Assets/BOXOPHOBIC/Utils/Editor/StyledMaterial/StyledButtonDrawer.cs
blob: 4c1a46aec9fd3db8e4b08104a434cb4ce346bcde (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
// Cristian Pop - https://boxophobic.com/

using UnityEngine;
using UnityEditor;
using System;

namespace Boxophobic.StyledGUI
{
    public class StyledButtonDrawer : MaterialPropertyDrawer
    {
        public string text;
        public string target = "";
        public float value = 1;
        public float top;
        public float down;

        public StyledButtonDrawer(string text)
        {
            this.text = text;
            this.value = 1;
            this.top = 0;
            this.down = 0;
        }

        public StyledButtonDrawer(string text, float value, float top, float down)
        {
            this.text = text;
            this.value = value;
            this.top = top;
            this.down = down;
        }

        public StyledButtonDrawer(string text, string target, float value, float top, float down)
        {
            this.text = text;
            this.target = target;
            this.value = value;
            this.top = top;
            this.down = down;
        }

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

            GUILayout.Space(top);

            if (GUILayout.Button(text))
            {
                if (target == "")
                {
                    prop.floatValue = value;
                }
                else
                {
                    if (material.HasProperty(target))
                    {
                        material.SetFloat(target, value);
                    }
                }
            }

            GUILayout.Space(down);
        }

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