forked from karlsonmodding/KarlsonMapEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIex.cs
62 lines (60 loc) · 2.17 KB
/
GUIex.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace KarlsonMapEditor
{
internal class GUIex
{
public static bool Toggle(Rect pos, ref bool toggle, string onText="On", string offText="Off")
{
if (GUI.Button(pos, toggle ? onText : offText))
{
toggle = !toggle;
return true;
}
return false;
}
public class Dropdown
{
public Dropdown(string[] options, int defaultIdx)
{
Options = options;
Index = defaultIdx;
buttonText = new GUIStyle();
buttonText.normal.background = Texture2D.blackTexture;
buttonText.alignment = TextAnchor.MiddleCenter;
}
public string[] Options;
public int Index;
private bool dropped = false;
GUIStyle buttonText;
public void Draw(Rect pos)
{
if(!dropped)
{
if (GUI.Button(pos, Options[Index])) dropped = true;
GUI.Label(new Rect(pos.x + pos.width - pos.height, pos.y, pos.height, pos.height), "▼");
}
else
{
if (GUI.Button(pos, Options[Index])) dropped = false;
GUI.Label(new Rect(pos.x + pos.width - pos.height, pos.y, pos.height, pos.height), "▲");
GUI.Box(new Rect(pos.x, pos.y + pos.height, pos.width, pos.height * Options.Length), "");
for (int i = 0; i < Options.Length; i++)
{
string color = "<color=white>";
if (i == Index) color = "<color=green>";
if (GUI.Button(new Rect(pos.x, pos.y + pos.height * (i + 1), pos.width, pos.height), color + Options[i] + "</color>", buttonText))
{
Index = i;
dropped = false;
}
}
}
}
}
}
}