13using System.Collections.Generic;
14using System.Text.RegularExpressions;
22 private static Regex _graphicMaxRegex =
new Regex(
@"^#define\s+GRAPHIC_MAX\s+(\d+)\s*$");
28 private static int _cachedGraphicMax = -1;
31 if (_cachedGraphicMax == -1) {
37 tryCalculateGraphicMax(out _cachedGraphicMax, out errorMesage, out path, out lines, out lineIndex);
39 if (errorMesage !=
null) {
40 _cachedGraphicMax =
int.MaxValue;
44 return _cachedGraphicMax;
67 private static void preferencesGUI() {
68 drawGraphicMaxField();
70 GUIContent groupChangedContent =
new GUIContent(
"Prompt When Group Changed",
"Should the system prompt the user when they change the group of a graphic to a group with different features.");
76 GUIContent addChannelContent =
new GUIContent(
"Prompt For Custom Channel",
"Should the system warn the user about writing custom shaders when they try to add a Custom Channel feature?");
82 EditorGUILayout.Space();
83 GUILayout.Label(
"Surface-shader variant options", EditorStyles.boldLabel);
85 EditorGUILayout.HelpBox(
"Using surface-shader variants can drastically increase import time! Only enable variants if you are using surface shaders with the graphic renderer.", MessageType.Info);
87 using (
new EditorGUILayout.HorizontalScope()) {
88 if (GUILayout.Button(
"Enable all variants")) {
89 setVariantsEnabledForSurfaceShaders(enable:
true);
92 if (GUILayout.Button(
"Disable all variants")) {
93 setVariantsEnabledForSurfaceShaders(enable:
false);
98 private static void setVariantsEnabledForSurfaceShaders(
bool enable) {
100 var shader = AssetDatabase.LoadAssetAtPath<Shader>(path);
101 if (shader ==
null)
continue;
103 if (VariantEnabler.IsSurfaceShader(shader)) {
104 VariantEnabler.SetShaderVariantsEnabled(shader, enable);
107 AssetDatabase.Refresh();
110 private static void drawGraphicMaxField() {
117 _cachedGraphicMax = -1;
118 if (!tryCalculateGraphicMax(out
graphicMax, out errorMessage, out path, out lines, out lineIndex)) {
119 EditorGUILayout.HelpBox(errorMessage +
120 "\n\nRe-installing the Leap Gui package can help fix this problem.",
121 MessageType.Warning);
125 int newGraphicMax = EditorGUILayout.DelayedIntField(
"Max Graphics Per-Group",
graphicMax);
126 newGraphicMax = Mathf.Min(newGraphicMax, 1023);
129 if (!EditorUtility.DisplayDialog(
"Large Graphic Count",
130 "Setting the graphic count larger than 144 can cause incorrect rendering " +
131 "or shader compilation failure on certain systems, are you sure you want " +
132 "to continue?",
"Yes",
"Cancel")) {
141 lines[lineIndex] = lines[lineIndex].Replace(
graphicMax.ToString(), newGraphicMax.ToString());
144 File.WriteAllLines(path, lines.ToArray());
150 private static bool tryCalculateGraphicMax(out
int elementMax,
151 out
string errorMessage,
153 out List<string> lines,
161 if (!
File.Exists(path)) {
162 errorMessage =
"Could not locate the Leap cginclude file, was it renamed or deleted?";
166 lines =
new List<string>();
168 StreamReader reader =
null;
170 reader =
File.OpenText(path);
173 string line = reader.ReadLine();
179 }
catch (Exception e) {
180 errorMessage =
"Exception caught when trying to read file.";
184 if (reader !=
null) {
189 Match successMatch =
null;
190 for (
int i = 0; i < lines.Count; i++) {
191 string line = lines[i];
192 var match = _graphicMaxRegex.Match(line);
194 successMatch = match;
200 if (successMatch ==
null) {
201 errorMessage =
"Could not parse the file correctly, it might have been modified!";
205 if (!
int.TryParse(successMatch.Groups[1].Value, out elementMax)) {
206 errorMessage =
"The maximum graphic value must always be an integer value!";
const string LEAP_GRAPHIC_CGINC_PATH
const string PROMPT_WHEN_GROUP_CHANGE_KEY
const int GRAPHIC_COUNT_SOFT_CEILING
static bool promptWhenGroupChange
const string LEAP_GRAPHIC_SHADER_FOLDER
const string PROMP_WHEN_ADD_CUSTOM_CHANNEL_LEY
static bool promptWhenAddCustomChannel
This attribute is used to add items to the Leap Motion preferences window. This allows each module to...