Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Add top level SendCustomEvent to event editor
Browse files Browse the repository at this point in the history
- Add SendCustomEvent to the top level of the event editor right under the behaviour for easier access. Requested by orels
  • Loading branch information
MerlinVR committed Feb 23, 2021
1 parent 33de2e6 commit 6a03155
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Assets/UdonSharp/Editor/Editors/EasyEventEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,11 +1230,14 @@ void AddFunctionToMenu(string contentPath, SerializedProperty elementProperty, F

void BuildMenuForObject(Object targetObject, SerializedProperty elementProperty, GenericMenu menu, int componentCount = 0)
{
#if UDONSHARP
bool isUdonSharpBehaviour = targetObject is UdonBehaviour udonBehaviour && UdonSharpEditorUtility.IsUdonSharpBehaviour(udonBehaviour);
#endif

List<FunctionData> methodInfos = new List<FunctionData>();
string contentPath = targetObject.GetType().Name + (componentCount > 0 ? string.Format("({0})", componentCount) : "")
#if UDONSHARP
//+ ((targetObject is UdonSharpBehaviour udonSharpBehaviour && UdonSharpEditorUtility.IsProxyBehaviour(udonSharpBehaviour)) ? " <proxy>" : "")
+ ((targetObject is UdonBehaviour udonBehaviour && UdonSharpEditorUtility.IsUdonSharpBehaviour(udonBehaviour)) ? $" ({UdonSharpEditorUtility.GetUdonSharpBehaviourType(udonBehaviour)})" : "")
+ (isUdonSharpBehaviour ? $" ({UdonSharpEditorUtility.GetUdonSharpBehaviourType((UdonBehaviour)targetObject)})" : "")
#endif
+ "/";

Expand All @@ -1251,6 +1254,11 @@ void BuildMenuForObject(Object targetObject, SerializedProperty elementProperty,
System.Type[] eventArgs = dummyEvent.GetType().GetMethod("Invoke").GetParameters().Select(p => p.ParameterType).ToArray();

bool dynamicBinding = false;

#if UDONSHARP
if (isUdonSharpBehaviour)
menu.AddSeparator("");
#endif

if (eventArgs.Length > 0)
{
Expand Down Expand Up @@ -1285,6 +1293,15 @@ void BuildMenuForObject(Object targetObject, SerializedProperty elementProperty,
{
AddFunctionToMenu(contentPath, elementProperty, method, menu, componentCount);
}

#if UDONSHARP
// Push SendCustomEvent up to the top level menu and create a separator since it is a very commonly used method on UdonBehaviours
if (isUdonSharpBehaviour)
{
FunctionData sendCustomEventMethod = methodInfos.First(e => e.targetMethod.Name == "SendCustomEvent");
AddFunctionToMenu($"UdonBehaviour{(componentCount > 0 ? string.Format("({0}) ", componentCount) : " ")}", elementProperty, sendCustomEventMethod, menu, componentCount);
}
#endif
}

class ComponentTypeCount
Expand Down

0 comments on commit 6a03155

Please sign in to comment.