//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Event")) { Action <EventInfo> Selected = (e) => { targetType = e.DeclaringType; eventName = e.Name; }; var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetInstanceEventSelectionMenu(comp.GetType(), null, Selected, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetInstanceEventSelectionMenu(t, null, Selected, menu); } menu.ShowAsBrowser("Select Event", this.GetType()); Event.current.Use(); } if (targetType != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Selected Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Event", eventName); GUILayout.EndVertical(); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI(){ if (!Application.isPlaying && GUILayout.Button("Select Field")){ System.Action<FieldInfo> FieldSelected = (field)=> { targetType = field.DeclaringType; fieldName = field.Name; saveAs.SetType(field.FieldType); }; var menu = new UnityEditor.GenericMenu(); if (agent != null){ foreach(var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector) ){ menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(object), FieldSelected, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))){ menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(object), FieldSelected, menu); } menu.ShowAsBrowser("Select Field", this.GetType()); Event.current.Use(); } if (agentType != null && !string.IsNullOrEmpty(fieldName)){ GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.Name); UnityEditor.EditorGUILayout.LabelField("Field", fieldName); UnityEditor.EditorGUILayout.LabelField("Field Type", saveAs.varType.FriendlyName() ); GUILayout.EndVertical(); NodeCanvas.Editor.BBParameterEditor.ParameterField("Save As", saveAs, true); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Action Method")) { if (agent != null) { EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(Status), typeof(object), SetMethod, 1, false, true); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true)) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(Status), typeof(object), SetMethod, 1, false, true, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Action Method:", targetMethod.Name); GUILayout.EndVertical(); if (targetMethod.GetParameters().Length == 1) { var paramName = targetMethod.GetParameters()[0].Name.SplitCamelCase(); EditorUtils.BBParameterField(paramName, parameters[0]); } } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Event")) { Action <EventInfo> Selected = (e) => { targetType = e.DeclaringType; eventName = e.Name; }; if (agent != null) { EditorUtils.ShowGameObjectEventSelectionMenu(agent.gameObject, Selected); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetEventSelectionMenu(t, Selected, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (agentType != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Selected Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Event", eventName); GUILayout.EndVertical(); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Event")) { Action <EventInfo> Selected = (e) => { targetType = e.DeclaringType; eventName = e.Name; }; var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(object))) { menu = EditorUtils.GetStaticEventSelectionMenu(t, null, Selected, menu); } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select System.Action Event", this.GetType()); } else { menu.ShowAsContext(); } Event.current.Use(); } if (targetType != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Selected Type", targetType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Event", eventName); GUILayout.EndVertical(); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Property")) { System.Action <MethodInfo> MethodSelected = (method) => { functionWrapper = ReflectedFunctionWrapper.Create(method, blackboard); }; if (agent != null) { EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 0, true, true); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true)) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 0, true, true, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name); UnityEditor.EditorGUILayout.LabelField("Property Type", targetMethod.ReturnType.FriendlyName()); GUILayout.EndVertical(); EditorUtils.BBParameterField("Save As", functionWrapper.GetVariables()[0], true); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Property")) { var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetMethodSelectionMenu(comp.GetType(), typeof(void), typeof(object), SetMethod, 1, true, false, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true)) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(void), typeof(object), SetMethod, 1, true, false, menu); } menu.ShowAsContext(); Event.current.Use(); } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name); UnityEditor.EditorGUILayout.LabelField("Set Type", functionWrapper.GetVariables()[0].varType.FriendlyName()); GUILayout.EndVertical(); EditorUtils.BBParameterField("Set Value", functionWrapper.GetVariables()[0]); } }
///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Property")) { var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(void), typeof(object), SetMethod, 1, true, false, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(object))) { menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(void), typeof(object), SetMethod, 1, true, false, menu); if (typeof(UnityEngine.Component).IsAssignableFrom(t)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(void), typeof(object), SetMethod, 1, true, false, menu); } } menu.ShowAsBrowser("Select Property", this.GetType()); Event.current.Use(); } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedType().FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name); UnityEditor.EditorGUILayout.LabelField("Set Type", parameter.varType.FriendlyName()); GUILayout.EndVertical(); NodeCanvas.Editor.BBParameterEditor.ParameterField("Set Value", parameter); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Property")) { var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 0, true, true, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu); } menu.ShowAsContext(); Event.current.Use(); } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name); GUILayout.EndVertical(); GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int); comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison); GUI.enabled = true; EditorUtils.BBParameterField("Value", checkValue); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Property")) { System.Action <MethodInfo> MethodSelected = (method) => { this.method = new SerializedMethodInfo(method); this.parameter.SetType(method.GetParameters()[0].ParameterType); }; if (agent != null) { EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(void), typeof(object), MethodSelected, 1, true, false); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true)) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(void), typeof(object), MethodSelected, 1, true, false, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name); UnityEditor.EditorGUILayout.LabelField("Set Type", parameter.varType.FriendlyName()); GUILayout.EndVertical(); EditorUtils.BBParameterField("Set Value", parameter); } }
///All reflection type nodes public static UnityEditor.GenericMenu AppendAllReflectionNodesMenu(this FlowGraph graph, UnityEditor.GenericMenu menu, string baseCategory, Vector2 pos, Port sourcePort, object dropInstance) { foreach (var type in UserTypePrefs.GetPreferedTypesList()) { menu = graph.AppendTypeReflectionNodesMenu(menu, type, baseCategory, pos, sourcePort, dropInstance); } return(menu); }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR 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))) { 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]); } EditorUtils.BBParameterField("Save Return Value", variables[0], true); } } }
///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Method")) { var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 10, false, false, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, false, menu); menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, false, menu); } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select Method", this.GetType()); } else { menu.ShowAsContext(); } Event.current.Use(); } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedType().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(); for (var i = 0; i < paramNames.Length; i++) { NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], parameters[i]); } if (targetMethod.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator)) { NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Return Value", returnValue, true); } } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Method")){ System.Action<MethodInfo> MethodSelected = (method) => { this.method = new SerializedMethodInfo(method); this.parameters.Clear(); foreach(var p in method.GetParameters()){ var newParam = new BBObjectParameter{bb = blackboard}; newParam.SetType(p.ParameterType); if (p.IsOptional){ newParam.value = p.DefaultValue; } parameters.Add(newParam); } if (method.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator)){ this.returnValue = new BBObjectParameter{bb = blackboard}; this.returnValue.SetType(method.ReturnType); } }; 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(); for (var i = 0; i < paramNames.Length; i++){ EditorUtils.BBParameterField(paramNames[i], parameters[i]); } if (targetMethod.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator)){ EditorUtils.BBParameterField("Save Return Value", returnValue, true); } } }
void OnEnable() { #if UNITY_5_1 titleContent = new GUIContent("Preferred Types"); #else title = "Preferred Types"; #endif typeList = UserTypePrefs.GetPreferedTypesList(typeof(object), true); }
///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { base.OnTaskInspectorGUI(); if (!Application.isPlaying && GUILayout.Button("Select Method")) { var menu = new UnityEditor.GenericMenu(); menu = EditorUtils.GetInstanceMethodSelectionMenu(_agentType, typeof(object), typeof(object), SetMethod, 6, false, true, menu); menu.AddSeparator("/"); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 6, false, true, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, true, menu); menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, true, menu); } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select Method", this.GetType()); } else { menu.ShowAsContext(); } Event.current.Use(); } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedType().FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name); GUILayout.EndVertical(); var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray(); var variables = functionWrapper.GetVariables(); for (var i = 0; i < paramNames.Length; i++) { NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i + 1]); } GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int); comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison); GUI.enabled = true; NodeCanvas.Editor.BBParameterEditor.ParameterField("Check Value", checkValue); } }
///Get a generic menu per variable static GenericMenu GetVariableMenu(Variable data, IBlackboard bb) { var menu = new GenericMenu(); if (data.varType == typeof(VariableSeperator)) { menu.AddItem(new GUIContent("Rename"), false, () => { (data.value as VariableSeperator).isEditingName = true; }); menu.AddItem(new GUIContent("Remove"), false, () => { bb.RemoveVariable(data.name); }); return(menu); } System.Action <PropertyInfo> SelectProp = (p) => { data.BindProperty(p); }; System.Action <FieldInfo> SelectField = (f) => { data.BindProperty(f); }; menu.AddDisabledItem(new GUIContent(string.Format("Type: {0}", data.varType.FriendlyName()))); if (bb.propertiesBindTarget != null) { foreach (var comp in bb.propertiesBindTarget.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector)) { menu = EditorUtils.GetInstancePropertySelectionMenu(comp.GetType(), data.varType, SelectProp, false, false, menu, "Bind (Self)/Property"); menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), data.varType, SelectField, menu, "Bind (Self)/Field"); } } foreach (var type in UserTypePrefs.GetPreferedTypesList()) { menu = EditorUtils.GetStaticPropertySelectionMenu(type, data.varType, SelectProp, false, false, menu, "Bind (Static)/Property"); menu = EditorUtils.GetStaticFieldSelectionMenu(type, data.varType, SelectField, menu, "Bind (Static)/Field"); } menu.AddItem(new GUIContent("Protected"), data.isProtected, () => { data.isProtected = !data.isProtected; }); menu.AddSeparator("/"); if (data.hasBinding) { menu.AddItem(new GUIContent("UnBind"), false, () => { data.UnBindProperty(); }); } else { menu.AddDisabledItem(new GUIContent("UnBind")); } menu.AddItem(new GUIContent("Delete Variable"), false, () => { if (EditorUtility.DisplayDialog("Delete Variable '" + data.name + "'", "Are you sure?", "Yes", "No")) { bb.RemoveVariable(data.name); GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } }); return(menu); }
///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override UnityEditor.GenericMenu OnContextMenu(UnityEditor.GenericMenu menu) { menu = base.OnContextMenu(menu); if (method != null) { var overloads = new List <MethodBase>(); if (method is MethodInfo) { foreach (var m in method.DeclaringType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)) { if (m.Name == method.Name) { overloads.Add(m); } } } if (method is ConstructorInfo) { foreach (var m in method.DeclaringType.GetConstructors(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)) { if (m.Name == method.Name) { overloads.Add(m); } } } if (overloads.Count > 1) { foreach (var _m in overloads) { var m = _m; var isSame = m.SignatureName() == method.SignatureName(); menu.AddItem(new GUIContent("Change Method Overload/" + m.SignatureName()), isSame, () => { SetMethodBase(m); }); } } if (method.IsGenericMethod && method is MethodInfo) { var methodInfo = (MethodInfo)method; var arg1 = methodInfo.GetGenericArguments().FirstOrDefault(); foreach (var _type in UserTypePrefs.GetPreferedTypesList(true)) { var type = _type; var isSame = arg1 == type; if (methodInfo.CanBeMadeGenericWith(type)) { menu.AddItem(new GUIContent("Change Generic Type/" + type.FriendlyName()), isSame, () => { SetMethodBase(methodInfo.MakeGenericMethod(type)); }); } } } } return(menu); }
//Add variable button static void DoAddVariableButton(IBlackboard bb, Event e) { GUI.backgroundColor = EditorUtils.lightBlue; if (GUILayout.Button("Add Variable")) { System.Action <System.Type> AddNewVariable = (t) => { var name = "my" + t.FriendlyName(); while (bb.GetVariable(name) != null) { name += "."; } bb.AddVariable(name, t); }; System.Action <PropertyInfo> AddBoundProp = (p) => { var newVar = bb.AddVariable(p.Name, p.PropertyType); newVar.BindProperty(p); }; System.Action <FieldInfo> AddBoundField = (f) => { var newVar = bb.AddVariable(f.Name, f.FieldType); newVar.BindProperty(f); }; var menu = new GenericMenu(); menu = EditorUtils.GetPreferedTypesSelectionMenu(typeof(object), AddNewVariable, menu, "New", true); if (bb.propertiesBindTarget != null) { foreach (var comp in bb.propertiesBindTarget.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetPropertySelectionMenu(comp.GetType(), typeof(object), AddBoundProp, false, false, menu, "Bound (Self)/Property"); menu = EditorUtils.GetFieldSelectionMenu(comp.GetType(), typeof(object), AddBoundField, menu, "Bound (Self)/Field"); } } foreach (var type in UserTypePrefs.GetPreferedTypesList(typeof(object))) { menu = EditorUtils.GetStaticPropertySelectionMenu(type, typeof(object), AddBoundProp, false, false, menu, "Bound (Static)/Property"); menu = EditorUtils.GetStaticFieldSelectionMenu(type, typeof(object), AddBoundField, menu, "Bound (Static)/Field"); } menu.AddSeparator("/"); menu.AddItem(new GUIContent("Add Header Separator"), false, () => { bb.AddVariable("Separator (Double Click To Rename)", new VariableSeperator()); }); menu.ShowAsContext(); e.Use(); } GUI.backgroundColor = Color.white; }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Static Method")) { UnityEditor.GenericMenu.MenuFunction2 MethodSelected = (m) => { SetMethod((MethodInfo)m); }; var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(object))) { foreach (var m in t.GetMethods(BindingFlags.Static | BindingFlags.Public).OrderBy(m => !m.IsSpecialName)) { if (m.IsGenericMethod) { continue; } menu.AddItem(new GUIContent(t.FriendlyName() + "/" + m.SignatureName()), false, MethodSelected, m); } } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select Static Method", this.GetType()); } else { 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()); GUILayout.EndVertical(); var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray(); for (var i = 0; i < paramNames.Length; i++) { NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], parameters[i]); } if (targetMethod.ReturnType != typeof(void)) { NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Return Value", returnValue, true); } } }
///Return get add variable menu static GenericMenu GetAddVariableMenu(IBlackboard bb, UnityEngine.Object contextParent) { System.Action <System.Type> AddNewVariable = (t) => { Undo.RecordObject(contextParent, "Variable Added"); var name = "my" + t.FriendlyName(); while (bb.GetVariable(name) != null) { name += "."; } bb.AddVariable(name, t); }; System.Action <PropertyInfo> AddBoundProp = (p) => { Undo.RecordObject(contextParent, "Variable Added"); var newVar = bb.AddVariable(p.Name, p.PropertyType); newVar.BindProperty(p); }; System.Action <FieldInfo> AddBoundField = (f) => { Undo.RecordObject(contextParent, "Variable Added"); var newVar = bb.AddVariable(f.Name, f.FieldType); newVar.BindProperty(f); }; var menu = new GenericMenu(); menu = EditorUtils.GetPreferedTypesSelectionMenu(typeof(object), AddNewVariable, menu, "New", true); if (bb.propertiesBindTarget != null) { foreach (var comp in bb.propertiesBindTarget.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(object), AddBoundField, menu, "Bound (Self)"); menu = EditorUtils.GetInstancePropertySelectionMenu(comp.GetType(), typeof(object), AddBoundProp, false, false, menu, "Bound (Self)"); } } foreach (var type in UserTypePrefs.GetPreferedTypesList(typeof(object))) { menu = EditorUtils.GetStaticFieldSelectionMenu(type, typeof(object), AddBoundField, menu, "Bound (Static)"); menu = EditorUtils.GetStaticPropertySelectionMenu(type, typeof(object), AddBoundProp, false, false, menu, "Bound (Static)"); } menu.AddSeparator("/"); menu.AddItem(new GUIContent("Add Header Separator"), false, () => { bb.AddVariable("Separator (Double Click To Rename)", new VariableSeperator()); }); return(menu); }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Field")) { System.Action <FieldInfo> FieldSelected = (field) => { targetType = field.DeclaringType; fieldName = field.Name; checkValue = BBParameter.CreateInstance(field.FieldType, blackboard); comparison = CompareMethod.EqualTo; }; var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(object), FieldSelected, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(object), FieldSelected, menu); } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select Field", this.GetType()); } else { menu.ShowAsContext(); } Event.current.Use(); } if (agentType != null && !string.IsNullOrEmpty(fieldName)) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Field", fieldName); GUILayout.EndVertical(); GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int); comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison); GUI.enabled = true; NodeCanvas.Editor.BBParameterEditor.ParameterField("Value", checkValue); } }
///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { base.OnTaskInspectorGUI(); if (!Application.isPlaying && GUILayout.Button("Select Action Method")) { var menu = new UnityEditor.GenericMenu(); menu = EditorUtils.GetInstanceMethodSelectionMenu(_agentType, typeof(object), typeof(object), SetMethod, 1, false, true, menu); menu.AddSeparator("/"); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(Status), typeof(object), SetMethod, 1, false, true, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(Status), typeof(object), SetMethod, 1, false, true, menu); menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(Status), typeof(object), SetMethod, 1, false, true, menu); } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select Action Method", this.GetType()); } else { menu.ShowAsContext(); } Event.current.Use(); } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedType().FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Action Method:", targetMethod.Name); GUILayout.EndVertical(); if (targetMethod.GetParameters().Length == 1) { var paramName = targetMethod.GetParameters()[0].Name.SplitCamelCase(); NodeCanvas.Editor.BBParameterEditor.ParameterField(paramName, functionWrapper.GetVariables()[1]); } } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Action Method")) { System.Action <MethodInfo> MethodSelected = (method) => { this.method = new SerializedMethodInfo(method); this.parameters.Clear(); foreach (var p in method.GetParameters()) { var newParam = new BBObjectParameter { bb = blackboard }; newParam.SetType(p.ParameterType); parameters.Add(newParam); } }; if (agent != null) { EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(Status), typeof(object), MethodSelected, 1, false, true); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true)) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(Status), typeof(object), MethodSelected, 1, false, true, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Action Method:", targetMethod.Name); GUILayout.EndVertical(); if (targetMethod.GetParameters().Length == 1) { var paramName = targetMethod.GetParameters()[0].Name.SplitCamelCase(); EditorUtils.BBParameterField(paramName, parameters[0]); } } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Method")) { System.Action <MethodInfo> MethodSelected = (method) => { functionWrapper = ReflectedFunctionWrapper.Create(method, blackboard); checkValue = BBParameter.CreateInstance(method.ReturnType, blackboard); comparison = CompareMethod.EqualTo; }; if (agent != null) { EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 3, false, true); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 3, false, true, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name); GUILayout.EndVertical(); var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray(); var variables = functionWrapper.GetVariables(); for (var i = 0; i < paramNames.Length; i++) { EditorUtils.BBParameterField(paramNames[i], variables[i + 1]); } GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int); comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison); GUI.enabled = true; EditorUtils.BBParameterField("Check Value", checkValue); } }
///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { base.OnTaskInspectorGUI(); if (!Application.isPlaying && GUILayout.Button("Select Property")) { var menu = new UnityEditor.GenericMenu(); menu = EditorUtils.GetInstanceMethodSelectionMenu(_agentType, typeof(object), typeof(object), SetMethod, 0, true, true, menu); menu.AddSeparator("/"); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 0, true, true, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu); menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu); } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select Property", this.GetType()); } else { menu.ShowAsContext(); } Event.current.Use(); } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedType().FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name); UnityEditor.EditorGUILayout.LabelField("Property Type", targetMethod.ReturnType.FriendlyName()); GUILayout.EndVertical(); NodeCanvas.Editor.BBParameterEditor.ParameterField("Save As", returnValue, true); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Event")) { Action <FieldInfo> Selected = (f) => { targetType = f.DeclaringType; eventName = f.Name; }; var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0)) { menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(UnityEvent <T>), Selected, menu); } menu.AddSeparator("/"); } foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(UnityEvent <T>), Selected, menu); } if (NodeCanvas.Editor.NCPrefs.useBrowser) { menu.ShowAsBrowser("Select Event", this.GetType()); } else { menu.ShowAsContext(); } Event.current.Use(); } if (targetType != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Selected Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Event", eventName); GUILayout.EndVertical(); NodeCanvas.Editor.BBParameterEditor.ParameterField("Check Value", checkValue); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Property")) { System.Action <MethodInfo> MethodSelected = (method) => { this.method = new SerializedMethodInfo(method); this.checkValue.SetType(method.ReturnType); comparison = CompareMethod.EqualTo; }; if (agent != null) { EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 0, true, true); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true)) { menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 0, true, true, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (targetMethod != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name); GUILayout.EndVertical(); GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int); comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison); GUI.enabled = true; EditorUtils.BBParameterField("Value", checkValue); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnNodeInspectorGUI() { base.OnNodeInspectorGUI(); if (eventName == null && !Application.isPlaying && GUILayout.Button("Select Event")) { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(object))) { menu = EditorUtils.GetStaticEventSelectionMenu(t, null, SetEvent, menu); } menu.ShowAsContext(); Event.current.Use(); } if (eventName != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Selected Type", targetType.FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Selected Event", eventName); GUILayout.EndVertical(); } }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Field")) { System.Action <FieldInfo> FieldSelected = (field) => { targetType = field.DeclaringType; fieldName = field.Name; setValue = BBParameter.CreateInstance(field.FieldType, blackboard); }; if (agent != null) { EditorUtils.ShowGameObjectFieldSelectionMenu(agent.gameObject, typeof(object), FieldSelected); } else { var menu = new UnityEditor.GenericMenu(); foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component))) { menu = EditorUtils.GetFieldSelectionMenu(t, typeof(object), FieldSelected, menu); } menu.ShowAsContext(); Event.current.Use(); } } if (agentType != null && !string.IsNullOrEmpty(fieldName)) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", agentType.Name); UnityEditor.EditorGUILayout.LabelField("Field", fieldName); UnityEditor.EditorGUILayout.LabelField("Field Type", setValue.varType.FriendlyName()); GUILayout.EndVertical(); EditorUtils.BBParameterField("Set Value", setValue); } }