-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ScriptingSymbols class and added it to Weaver Settings
This allows you to only run Weaver when a set of symbols is defined.
- Loading branch information
1 parent
48a7f09
commit 878a63e
Showing
8 changed files
with
402 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Weaver | ||
{ | ||
[CustomPropertyDrawer(typeof(ScriptingSymbols))] | ||
public class ScriptingSymbolsEditor : PropertyDrawer | ||
{ | ||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) | ||
{ | ||
return EditorGUIUtility.singleLineHeight * 2f; | ||
} | ||
|
||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
position.height = EditorGUIUtility.singleLineHeight; | ||
|
||
GUI.Label(position, label); | ||
|
||
position.y += EditorGUIUtility.singleLineHeight; | ||
|
||
// Get the value field | ||
property = property.FindPropertyRelative("value"); | ||
|
||
EditorGUI.BeginChangeCheck(); | ||
{ | ||
EditorGUI.DelayedTextField(position, property, GUIContent.none); | ||
} | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
// Filter out input | ||
string value = property.stringValue; | ||
if (!string.IsNullOrEmpty(value)) | ||
{ | ||
char[] result = new char[value.Length]; | ||
int length = 0; | ||
for (int i = 0; i < value.Length; i++) | ||
{ | ||
char letter = value[i]; | ||
|
||
if ((letter >= 'a' && letter <= 'z') || | ||
(letter >= 'A' && letter <= 'Z')) | ||
{ | ||
result[length] = letter; | ||
length++; | ||
continue; | ||
} | ||
|
||
if (letter == '!' && (i == 0 || value[i - 1] == ';')) | ||
{ | ||
result[length] = letter; | ||
length++; | ||
} | ||
|
||
switch (letter) | ||
{ | ||
case '_': | ||
result[length] = letter; | ||
length++; | ||
break; | ||
case ';': | ||
// Don't allow double semi colons. | ||
if (length > 0 && result[length - 1] != ';') | ||
{ | ||
result[length] = letter; | ||
length++; | ||
} | ||
break; | ||
case ' ': | ||
result[length] = ';'; | ||
length++; | ||
break; | ||
} | ||
} | ||
property.stringValue = new string(result, 0, length); | ||
} | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Weaver/Editor/Inspectors/ScriptingSymbolsDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.