-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVT0InfoEditor.cs
More file actions
134 lines (117 loc) · 4.85 KB
/
VT0InfoEditor.cs
File metadata and controls
134 lines (117 loc) · 4.85 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using UnityEngine;
using UnityEditor;
using static UnityEngine.GUILayout;
using E = UnityEditor.EditorGUILayout;
namespace VT0
{
[CustomEditor(typeof(VT0Info))]
public class VT0InfoEditor : Editor
{
[MenuItem("VT0/Settings")]
public static void Show()
{
Selection.activeObject = VT0Info.Current;
}
public static void UpdateChannelFile()
{
VT0Info.Current.UpdateChannelFile(System.IO.File.Create("Assets/VT0/VT0_channels.cginc"));
AssetDatabase.Refresh();
}
public override void OnInspectorGUI()
{
serializedObject.UpdateIfRequiredOrScript();
Label("General", EditorStyles.boldLabel);
E.PropertyField(serializedObject.FindProperty(nameof(VT0Info.ThumbSize)));
E.PropertyField(serializedObject.FindProperty(nameof(VT0Info.MemoryCompression)));
var vramBytes = ((VT0Info)target).EstimateVRAM(100);
string specifier = "B";
if (vramBytes > (1 << 30)) {
vramBytes /= (1 << 30);
specifier = "GiB";
} else if (vramBytes > (1 << 20)) {
vramBytes /= (1 << 20);
specifier = "MiB";
} else if (vramBytes > (1 << 10)) {
vramBytes /= (1 << 10);
specifier = "KiB";
}
E.HelpBox(
$"This configuration uses approximately {vramBytes:F1} {specifier} of VRAM",
MessageType.Info);
BeginHorizontal();
if (serializedObject.FindProperty(nameof(VT0Info.Modified)).boolValue)
{
GUI.color = Color.red;
E.HelpBox("Settings were modified; apply changes before running", MessageType.None);
GUI.color = Color.white;
} else {
E.HelpBox("No modifications", MessageType.None);
}
if (Button("Apply", ExpandWidth(false))) {
UpdateChannelFile();
serializedObject.FindProperty(nameof(VT0Info.Modified)).boolValue = false;
serializedObject.ApplyModifiedPropertiesWithoutUndo();
}
EndHorizontal();
var channels = serializedObject.FindProperty(nameof(VT0Info.Channels));
for (int j = 0; j < channels.arraySize; j++)
{
var channel = channels.GetArrayElementAtIndex(j);
BeginVertical("HelpBox");
BeginHorizontal();
Label("Channel", EditorStyles.boldLabel);
var removeChannel = Button("x", Width(20f));
EndHorizontal();
E.PropertyField(channel.FindPropertyRelative(nameof(VT0Channel.Count)));
BeginHorizontal();
Label("Format");
var format = channel.FindPropertyRelative(nameof(VT0Channel.Format));
E.PropertyField(format, GUIContent.none, MaxWidth(120f));
// TODO: Platform-specific formats
if (Button("Opaque")) {
format.intValue = (int)TextureFormat.DXT1;
}
if (Button("Transparent")) {
format.intValue = (int)TextureFormat.DXT5;
}
if (Button("Alpha")) {
format.intValue = (int)TextureFormat.Alpha8;
}
EndHorizontal();
var textureNames = channel.FindPropertyRelative(nameof(VT0Channel.TextureNames));
BeginHorizontal();
if (Button("+", Width(20f))) {
textureNames.arraySize++;
}
Label("Property names:", EditorStyles.miniLabel);
EndHorizontal();
for (int i = 0; i < textureNames.arraySize; i++)
{
BeginHorizontal();
var removeMe = Button("x", Width(20f));
E.PropertyField(textureNames.GetArrayElementAtIndex(i), GUIContent.none);
EndHorizontal();
if (removeMe) {
textureNames.DeleteArrayElementAtIndex(i--);
}
}
E.Space();
EndVertical();
if (removeChannel) {
channels.DeleteArrayElementAtIndex(j--);
}
}
BeginHorizontal();
FlexibleSpace();
if (Button("New channel")) {
channels.arraySize++;
}
FlexibleSpace();
EndHorizontal();
if (serializedObject.ApplyModifiedProperties()) {
serializedObject.FindProperty(nameof(VT0Info.Modified)).boolValue = true;
serializedObject.ApplyModifiedPropertiesWithoutUndo();
}
}
}
}