Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added separate MonoBehaviour Methods #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions EasyEventEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class EasyEventEditorHandler
private const string eeeDisplayArgumentTypeKey = "EEE.displayArgumentType";
private const string eeeGroupSameComponentTypeKey = "EEE.groupSameComponentType";
private const string eeeUseHotkeys = "EEE.usehotkeys";
private const string eeeSeparateMonoBehaviourMethods = "EEE.separateMonoBehaviourMetods";

private static bool patchApplied = false;
private static FieldInfo internalDrawerTypeMap = null;
Expand All @@ -71,6 +72,7 @@ public class EEESettings
public bool displayArgumentType;
public bool groupSameComponentType;
public bool useHotkeys;
public bool separateMonoBehaviourMethods;
}

// https://stackoverflow.com/questions/12898282/type-gettype-not-working
Expand Down Expand Up @@ -354,6 +356,7 @@ public static EEESettings GetEditorSettings()
displayArgumentType = EditorPrefs.GetBool(eeeDisplayArgumentTypeKey, true),
groupSameComponentType = EditorPrefs.GetBool(eeeGroupSameComponentTypeKey, false),
useHotkeys = EditorPrefs.GetBool(eeeUseHotkeys, true),
separateMonoBehaviourMethods = EditorPrefs.GetBool(eeeSeparateMonoBehaviourMethods, true),
};

return settings;
Expand All @@ -367,6 +370,7 @@ public static void SetEditorSettings(EEESettings settings)
EditorPrefs.SetBool(eeeDisplayArgumentTypeKey, settings.displayArgumentType);
EditorPrefs.SetBool(eeeGroupSameComponentTypeKey, settings.groupSameComponentType);
EditorPrefs.SetBool(eeeUseHotkeys, settings.useHotkeys);
EditorPrefs.SetBool(eeeSeparateMonoBehaviourMethods, settings.separateMonoBehaviourMethods);
}
}

Expand All @@ -378,6 +382,7 @@ internal class SettingsGUIContent
private static GUIContent displayArgumentTypeContent = new GUIContent("Display argument type on function name", "Shows the argument that a function takes on the function header");
private static GUIContent groupSameComponentTypeContent = new GUIContent("Do not group components of the same type", "If you have multiple components of the same type on one object, show all components. Unity hides duplicate components by default.");
private static GUIContent useHotkeys = new GUIContent("Use hotkeys", "Adds common Unity hotkeys to event editor that operate on the currently selected event. The commands are Add (CTRL+A), Copy, Paste, Cut, Delete, and Duplicate");
private static GUIContent separateMonoBehaviourMethods = new GUIContent("Separate MonoBehaviour Methods", "Separate MonoBehaviour Methods");

public static void DrawSettingsButtons(EasyEventEditorHandler.EEESettings settings)
{
Expand All @@ -392,6 +397,7 @@ public static void DrawSettingsButtons(EasyEventEditorHandler.EEESettings settin
settings.displayArgumentType = EditorGUILayout.ToggleLeft(displayArgumentTypeContent, settings.displayArgumentType);
settings.groupSameComponentType = !EditorGUILayout.ToggleLeft(groupSameComponentTypeContent, !settings.groupSameComponentType);
settings.useHotkeys = EditorGUILayout.ToggleLeft(useHotkeys, settings.useHotkeys);
settings.separateMonoBehaviourMethods = EditorGUILayout.ToggleLeft(separateMonoBehaviourMethods, settings.separateMonoBehaviourMethods);

EditorGUI.EndDisabledGroup();
EditorGUI.indentLevel -= 1;
Expand Down Expand Up @@ -1246,8 +1252,41 @@ void BuildMenuForObject(Object targetObject, SerializedProperty elementProperty,
}
}

// Add static header if we have dynamic bindings
if (dynamicBinding)
if (cachedSettings.separateMonoBehaviourMethods)
{
// Add MonoBehaviour Methods header
{
menu.AddDisabledItem(new GUIContent(contentPath + "MonoBehaviour Methods"));
menu.AddSeparator(contentPath);
}

foreach (FunctionData method in methodInfos)
{
if (method.targetMethod.Name == "StopCoroutine" ||
method.targetMethod.Name == "Invoke" ||
method.targetMethod.Name == "CancelInvoke" ||
method.targetMethod.Name == "StartCoroutine" ||
method.targetMethod.Name == "StopAllCoroutines" ||
method.targetMethod.Name == "set_useGUILayout" ||
method.targetMethod.Name == "set_runInEditMode" ||
method.targetMethod.Name == "set_enabled" ||
method.targetMethod.Name == "set_name" ||
method.targetMethod.Name == "set_tag" ||
method.targetMethod.Name == "BroadcastMessage" ||
method.targetMethod.Name == "Finalize" ||
method.targetMethod.Name == "OnDestroy" ||
method.targetMethod.Name == "Start" ||
method.targetMethod.Name == "SendMessage" ||
method.targetMethod.Name == "SendMessageUpwards" ||
method.targetMethod.Name == "EnsureRunningOnMainThread")
{
AddFunctionToMenu(contentPath, elementProperty, method, menu, componentCount);
}
}
}

// Add static header
if (dynamicBinding || cachedSettings.separateMonoBehaviourMethods)
{
menu.AddDisabledItem(new GUIContent(contentPath + "Static Parameters"));
menu.AddSeparator(contentPath);
Expand All @@ -1257,7 +1296,7 @@ void BuildMenuForObject(Object targetObject, SerializedProperty elementProperty,
{
AddFunctionToMenu(contentPath, elementProperty, method, menu, componentCount);
}
}
}

class ComponentTypeCount
{
Expand Down