//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Method")){ System.Action<MethodInfo> MethodSelected = (method) => { functionWrapper = ReflectedWrapper.Create(method, blackboard); }; if (agent != null){ EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 3, false, false); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true)) menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 3, false, false, menu); menu.ShowAsContext(); Event.current.Use(); } } if (targetMethod != null){ GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name); UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName()); if (targetMethod.ReturnType == typeof(IEnumerator)) GUILayout.Label("<b>This will execute as a Coroutine</b>"); GUILayout.EndVertical(); var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase() ).ToArray(); var variables = functionWrapper.GetVariables(); if (targetMethod.ReturnType == typeof(void)){ for (var i = 0; i < paramNames.Length; i++){ EditorUtils.BBParameterField(paramNames[i], variables[i]); } } else { for (var i = 0; i < paramNames.Length; i++){ EditorUtils.BBParameterField(paramNames[i], variables[i+1]); } if (targetMethod.ReturnType != typeof(IEnumerator)){ EditorUtils.BBParameterField("Save Return Value", variables[0], true); } } } }
void SetMethod(MethodInfo method) { if (method != null){ functionWrapper = ReflectedWrapper.Create(method, blackboard); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Static Method")){ UnityEditor.GenericMenu.MenuFunction2 MethodSelected = (m) => { functionWrapper = ReflectedWrapper.Create((MethodInfo)m, blackboard); }; var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(object), true)){ foreach(var m in t.GetMethods(BindingFlags.Static | BindingFlags.Public).OrderBy(m => !m.IsSpecialName) ){ if (m.IsGenericMethod) continue; var parameters = m.GetParameters(); if (parameters.Length > 3) continue; menu.AddItem(new GUIContent(t.FriendlyName() + "/" + m.SignatureName()), false, MethodSelected, m); } } menu.ShowAsContext(); Event.current.Use(); } if (targetMethod != null){ GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.DeclaringType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name); UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName()); if (targetMethod.ReturnType == typeof(IEnumerator)) GUILayout.Label("<b>This will execute as a Coroutine</b>"); GUILayout.EndVertical(); var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase() ).ToArray(); var variables = functionWrapper.GetVariables(); if (targetMethod.ReturnType == typeof(void)){ for (var i = 0; i < paramNames.Length; i++){ EditorUtils.BBParameterField(paramNames[i], variables[i]); } } else { for (var i = 0; i < paramNames.Length; i++){ EditorUtils.BBParameterField(paramNames[i], variables[i+1]); } EditorUtils.BBParameterField("Save Return Value", variables[0], true); } } }