Skip to content

Commit

Permalink
Added ScriptingSymbols class and added it to Weaver Settings
Browse files Browse the repository at this point in the history
This allows you to only run Weaver when a set of symbols is defined.
  • Loading branch information
ByronMayne committed Jan 21, 2018
1 parent 48a7f09 commit 878a63e
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 196 deletions.
5 changes: 5 additions & 0 deletions Assembly-CSharp-Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Editor\CaptureGroups\CaptureGroup.cs" />
<Compile Include="Assets\Weaver\Editor\Analytics\AnalyticConstants.cs" />
<Compile Include="Assets\Weaver\Editor\Analytics\AnalyticState.cs" />
<Compile Include="Assets\Weaver\Editor\Analytics\WeaverAnalytics.cs" />
<Compile Include="Assets\Weaver\Editor\AssemblyPosprocessor.cs" />
<Compile Include="Assets\Weaver\Editor\AssemblyUtility.cs" />
<Compile Include="Assets\Weaver\Editor\Inspectors\ComponentControllerEditor.cs" />
<Compile Include="Assets\Weaver\Editor\Inspectors\ScriptingSymbolsDrawer.cs" />
<Compile Include="Assets\Weaver\Editor\Inspectors\WeavedAssemblyDrawer.cs" />
<Compile Include="Assets\Weaver\Editor\Inspectors\WeaverSettingsEditor.cs" />
<Compile Include="Assets\Weaver\Editor\Resolver\WeaverAssemblyResolver.cs" />
<Compile Include="Assets\Weaver\Editor\Settings\ComponentController.cs" />
<Compile Include="Assets\Weaver\Editor\Settings\ScriptingSymbols.cs" />
<Compile Include="Assets\Weaver\Editor\Settings\SerializedWeaver.cs" />
<Compile Include="Assets\Weaver\Editor\Settings\WeavedAssembly.cs" />
<Compile Include="Assets\Weaver\Editor\Settings\WeaverSettings.cs" />
Expand Down
80 changes: 80 additions & 0 deletions Assets/Weaver/Editor/Inspectors/ScriptingSymbolsDrawer.cs
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 Assets/Weaver/Editor/Inspectors/ScriptingSymbolsDrawer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 878a63e

Please sign in to comment.