public BBObjectParameter(BBParameter source) { if (source != null) { type = source.varType; _value = source.value; name = source.name; targetVariableID = source.targetVariableID; } }
protected override string OnInit() { leftChecker = agent.transform.Find("LeftChecker"); rightChecker = agent.transform.Find("RightChecker"); frontChecker = agent.transform.Find("FrontChecker"); backChecker = agent.transform.Find("BackChecker"); checkers.Add("left", leftChecker.value.GetComponent <SenseChecker>()); checkers.Add("right", rightChecker.value.GetComponent <SenseChecker>()); checkers.Add("forward", frontChecker.value.GetComponent <SenseChecker>()); checkers.Add("backward", backChecker.value.GetComponent <SenseChecker>()); return(null); }
protected override void OnExecute() { if (secondary.value) { attackRange = (agent.GetComponent <Inventory>().activeItem as WeaponItem).secondaryAttack.range; } else { attackRange = (agent.GetComponent <Inventory>().activeItem as WeaponItem).primaryAttack.range; } EndAction(true); }
protected override void OnNodeInspectorGUI() { repeaterMode = (RepeaterMode)UnityEditor.EditorGUILayout.EnumPopup("Repeat Type", repeaterMode); if (repeaterMode == RepeaterMode.RepeatTimes) { repeatTimes = (BBParameter <int>)EditorUtils.BBParameterField("Repeat Times", repeatTimes); } else if (repeaterMode == RepeaterMode.RepeatUntil) { repeatUntilStatus = (RepeatUntilStatus)UnityEditor.EditorGUILayout.EnumPopup("Repeat Until", repeatUntilStatus); } }
//////////////////////////////////////// ///////////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); } }
///Get a list of variable names used by the current selection of the current graph in the NC Editor window. static List <string> GetUsedVariablesBySelectionParameters() { var result = new List <string>(); if (Graph.currentSelection == null) { return(result); } result.AddRange(BBParameter.GetObjectBBParameters(Graph.currentSelection).Select(p => p.name)); var assignable = Graph.currentSelection as ITaskAssignable; if (assignable != null && assignable.task != null) { result.AddRange(BBParameter.GetObjectBBParameters(assignable.task).Select(p => p.name)); if (assignable.task.agentIsOverride && !string.IsNullOrEmpty(assignable.task.overrideAgentParameterName)) { result.Add(assignable.task.overrideAgentParameterName); } var taskActionList = assignable.task as ActionList; if (taskActionList != null) { foreach (var t in taskActionList.actions) { result.AddRange(BBParameter.GetObjectBBParameters(t).Select(p => p.name)); if (!string.IsNullOrEmpty(t.overrideAgentParameterName)) { result.Add(t.overrideAgentParameterName); } } } var taskConditionList = assignable.task as ConditionList; if (taskConditionList != null) { foreach (var t in taskConditionList.conditions) { result.AddRange(BBParameter.GetObjectBBParameters(t).Select(p => p.name)); if (!string.IsNullOrEmpty(t.overrideAgentParameterName)) { result.Add(t.overrideAgentParameterName); } } } } return(result); }
new public static ReflectedFunctionWrapper Create(MethodInfo method, IBlackboard bb) { if (method == null) { return(null); } Type type = null; var argTypes = new List <Type> { method.ReturnType }; var parameters = method.GetParameters(); if (parameters.Length == 0) { type = typeof(ReflectedFunction <>); } if (parameters.Length == 1) { type = typeof(ReflectedFunction <,>); } if (parameters.Length == 2) { type = typeof(ReflectedFunction <, ,>); } if (parameters.Length == 3) { type = typeof(ReflectedFunction <, , ,>); } argTypes.AddRange(parameters.Select(p => p.ParameterType)); var o = (ReflectedFunctionWrapper)Activator.CreateInstance(type.RTMakeGenericType(argTypes.ToArray())); o._targetMethod = new SerializedMethodInfo(method); BBParameter.SetBBFields(o, bb); var bbParams = o.GetVariables(); for (int i = 0; i < parameters.Length; i++) { var p = parameters[i]; if (p.IsOptional) { bbParams[i + 1].value = p.DefaultValue; //index 0 is return value } } return(o); }
protected override void OnNodeInspectorGUI() { filterMode = (FilterMode)UnityEditor.EditorGUILayout.EnumPopup("Mode", filterMode); if (filterMode == FilterMode.CoolDown) { coolDownTime = (BBParameter <float>)EditorUtils.BBParameterField("CoolDown Time", coolDownTime); } else if (filterMode == FilterMode.LimitNumberOfTimes) { maxCount = (BBParameter <int>)EditorUtils.BBParameterField("Max Times", maxCount); } inactiveWhenLimited = UnityEditor.EditorGUILayout.Toggle("Inactive When Limited", inactiveWhenLimited); }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { languageSource = EditorUtils.BBParameterField("Language Source", languageSource) as BBParameter <LanguageSource>; selectionMode = EditorUtils.BBParameterField("Selection Mode", selectionMode) as BBParameter <bool>; if (selectionMode.value) { EditTermSelection(); } else { term = EditorUtils.BBParameterField("Term", term) as BBParameter <string>; } translation = EditorUtils.BBParameterField("Translation", translation) as BBParameter <string>; }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { localizeObject = EditorUtils.BBParameterField("Localize Object", localizeObject) as BBParameter <Localize>; var terms = (!localizeObject.isNull && localizeObject.value.Source != null) ? localizeObject.value.Source.GetTermsList() : LocalizationManager.GetTermsList(); terms.Sort(System.StringComparer.OrdinalIgnoreCase); terms.Add(""); terms.Add("<inferred from text>"); terms.Add("<none>"); var aTerms = terms.ToArray(); DoTermPopup("Primary Term", primaryTerm, aTerms); DoTermPopup("Secondary Term", secondaryTerm, aTerms); }
//////////////////////////////////////// ///////////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); } }
new public static ReflectedActionWrapper Create(MethodInfo method, IBlackboard bb) { Type type = null; Type[] argTypes = null; var parameters = method.GetParameters(); if (parameters.Length == 0) { type = typeof(ReflectedAction); } if (parameters.Length == 1) { type = typeof(ReflectedAction <>); } if (parameters.Length == 2) { type = typeof(ReflectedAction <,>); } if (parameters.Length == 3) { type = typeof(ReflectedAction <, ,>); } argTypes = parameters.Select(p => p.ParameterType).ToArray(); var o = (ReflectedActionWrapper)Activator.CreateInstance(argTypes.Length > 0? type.RTMakeGenericType(argTypes) : type); o._targetMethod = new SerializedMethodInfo(method); BBParameter.SetBBFields(o, bb); var bbParams = o.GetVariables(); for (int i = 0; i < parameters.Length; i++) { var p = parameters[i]; if (p.IsOptional) { bbParams[i].value = p.DefaultValue; } } return(o); }
protected GameObject FindObj() { if (Application.isPlaying) { _init = true; } if (keys != null && typeControl != null && typeControl.value == StringTypeControl.Name && usePrefab != null && usePrefab.value && prefabName != null && prefabName.value != null) { if (!keys.value.IsAlmostSpecificCount()) { keys.value = new string[1]; } keys.value[0] = prefabName.value.name; } if (typeControl != null && keys != null && includeInactiveRoot != null && isEqualCountTags != null) { if (useRoot != null && useRoot.value) { if ((rootTransform == null || rootTransform.value == null) && typeControlRoot != null && keysRoot != null && isEqualCountTagsRoot != null) { if (useCanvas != null && useCanvas.value && canvasTiplogy != null) { rootTransform = CanvasManager.GetChild(canvasTiplogy.value); } else { rootTransform = GameObjectExtend.Find <Transform>(typeControlRoot.value, keysRoot.value, isEqualCountTagsRoot.value); } } return(GameObjectExtend.FindInHierarchy(typeControl.value, keys.value, rootTransform.value, includeInactiveRoot.value, isEqualCountTags.value)); } else { return(GameObjectExtend.Find(typeControl.value, keys.value, isEqualCountTags.value)); } } return(null); }
protected override void OnNodeInspectorGUI() { selectionMode = (CaseSelectionMode)UnityEditor.EditorGUILayout.EnumPopup("Selection Mode", selectionMode); if (selectionMode == CaseSelectionMode.IndexBased) { intCase = (BBParameter <int>)EditorUtils.BBParameterField("Int", intCase); outOfRangeMode = (OutOfRangeMode)UnityEditor.EditorGUILayout.EnumPopup("When Out Of Range", outOfRangeMode); } else { enumCase = (BBObjectParameter)EditorUtils.BBParameterField("Enum", enumCase, true); if (enumCase.value != null) { GUILayout.BeginVertical("box"); foreach (var s in System.Enum.GetNames(enumCase.value.GetType())) { GUILayout.Label(s); } 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); } }
protected override void OnNodeInspectorGUI() { EditorUtils.BBParameterField("Behaviour SubTree", _subTree); if (subTree == this.graph) { Debug.LogWarning("You can't have a Graph nested to iteself! Please select another"); subTree = null; } if (subTree != null) { _subTreeName = subTree.name; var defParams = subTree.GetDefinedParameters(); if (defParams.Length != 0) { EditorUtils.TitledSeparator("Defined SubTree Parameters"); GUI.color = Color.yellow; UnityEditor.EditorGUILayout.LabelField("Name", "Type"); GUI.color = Color.white; var added = new List <string>(); foreach (var bbVar in defParams) { if (!added.Contains(bbVar.name)) { UnityEditor.EditorGUILayout.LabelField(bbVar.name, bbVar.varType.FriendlyName()); added.Add(bbVar.name); } } if (GUILayout.Button("Check/Create Blackboard Variables")) { subTree.CreateDefinedParameterVariables(graphBlackboard); } } } }
void OnValueChanged(float value) { this.value.value = value; YieldReturn(true); }
//////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { DrawDefaultInspector(); if (GUILayout.Button("Select Type")) { EditorUtils.ShowPreferedTypesSelectionMenu(typeof(object), (t) => { newValue = BBParameter.CreateInstance(t, blackboard); }); } }
//a special object field for the BBParameter class to let user choose either a constant value or link to a Blackboard Variable. public static BBParameter BBParameterField(string prefix, BBParameter bbParam, bool blackboardOnly = false, MemberInfo member = null, object context = null) { return(BBParameterField(string.IsNullOrEmpty(prefix)? GUIContent.none : new GUIContent(prefix), bbParam, blackboardOnly, member, context)); }
//a special object field for the BBParameter class to let user choose either a real value or enter a string to read data from a Blackboard public static BBParameter BBParameterField(string prefix, BBParameter bbParam, bool blackboardOnly = false, MemberInfo member = null) { if (bbParam == null) { EditorGUILayout.LabelField(prefix, "Non Set Variable"); return(null); } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); //override if we have a memeber info if (member != null) { blackboardOnly = member.RTGetAttribute <BlackboardOnlyAttribute>(false) != null; } //Direct assignement if (!blackboardOnly && !bbParam.useBlackboard) { GUILayout.BeginVertical(); bbParam.value = GenericField(prefix, bbParam.value, bbParam.varType, member); GUILayout.EndVertical(); //Dropdown variable selection } else { GUI.color = new Color(0.9f, 0.9f, 1f, 1f); var varNames = new List <string>(); //Local if (bbParam.bb != null) { varNames.AddRange(bbParam.bb.GetVariableNames(bbParam.varType)); } //Seperator varNames.Add("/"); //Globals foreach (var globalBB in GlobalBlackboard.allGlobals) { var globalVars = globalBB.GetVariableNames(bbParam.varType); if (globalVars.Length == 0) { varNames.Add(globalBB.name + "/"); } for (var i = 0; i < globalVars.Length; i++) { globalVars[i] = globalBB.name + "/" + globalVars[i]; } varNames.AddRange(globalVars); } //Dynamic varNames.Add("(DynamicVar)"); //New if (bbParam.bb != null) { varNames.Add("(Create New)"); } var isDynamic = !string.IsNullOrEmpty(bbParam.name) && !varNames.Contains(bbParam.name); if (!isDynamic) { bbParam.name = StringPopup(prefix, bbParam.name, varNames, false, true); if (bbParam.name == "(DynamicVar)") { bbParam.name = "_"; } if (bbParam.bb != null && bbParam.name == "(Create New)") { if (bbParam.bb.AddVariable(prefix, bbParam.varType) != null) { bbParam.name = prefix; } else { bbParam.name = null; } } } else { bbParam.name = EditorGUILayout.TextField(prefix + " (" + bbParam.varType.FriendlyName() + ")", bbParam.name); } } GUI.color = Color.white; GUI.backgroundColor = Color.white; if (!blackboardOnly) { bbParam.useBlackboard = EditorGUILayout.Toggle(bbParam.useBlackboard, EditorStyles.radioButton, GUILayout.Width(18)); } GUILayout.EndHorizontal(); if (bbParam.isNone || bbParam.bb == null) { GUI.backgroundColor = new Color(0.8f, 0.8f, 1f, 0.5f); GUI.color = new Color(1f, 1f, 1f, 0.5f); GUILayout.BeginVertical("textfield"); var info = string.Empty; if (bbParam.bb == null) { info = "<i>No current Blackboard reference</i>"; } else if (bbParam.isNone) { info = "Select '" + bbParam.varType.FriendlyName() + "' Assignable Blackboard Variable"; } GUILayout.Label(info); GUILayout.EndVertical(); GUILayout.Space(2); } GUILayout.EndVertical(); GUI.backgroundColor = Color.white; GUI.color = Color.white; return(bbParam); }
///An editor for BBParameter type to let user choose either a constant value or link to a Blackboard Variable. public static BBParameter ParameterField(GUIContent content, BBParameter bbParam, bool blackboardOnly = false, object[] attributes = null) { if (bbParam == null) { EditorGUILayout.LabelField(content, new GUIContent("BBParameter is null")); return(null); } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); //Direct assignement if (!blackboardOnly && !bbParam.useBlackboard) { GUILayout.BeginVertical(); var internalField = bbParam.GetType().RTGetField("_value"); bbParam.value = EditorUtils.ReflectedFieldInspector(content, bbParam.value, bbParam.varType, internalField, bbParam, attributes); GUILayout.EndVertical(); //Dropdown variable selection } else { GUI.color = new Color(0.9f, 0.9f, 1f, 1f); var varNames = new List <string>(); //Local if (bbParam.bb != null) { varNames.AddRange(bbParam.bb.GetVariableNames(bbParam.varType)); } //Seperator varNames.Add("/"); //Globals foreach (var globalBB in GlobalBlackboard.allGlobals) { var globalVars = globalBB.GetVariableNames(bbParam.varType); if (globalVars.Length == 0) { varNames.Add(globalBB.name + "/"); } for (var i = 0; i < globalVars.Length; i++) { globalVars[i] = globalBB.name + "/" + globalVars[i]; } varNames.AddRange(globalVars); } //Dynamic varNames.Add("(DynamicVar)"); //New if (bbParam.bb != null) { varNames.Add("(Create New)"); } var isDynamic = !string.IsNullOrEmpty(bbParam.name) && !varNames.Contains(bbParam.name); if (!isDynamic) { bbParam.name = EditorUtils.StringPopup(content, bbParam.name, varNames, false, true); if (bbParam.name == "(DynamicVar)") { bbParam.name = "_"; } if (bbParam.bb != null && bbParam.name == "(Create New)") { if (bbParam.bb.AddVariable(content.text, bbParam.varType) != null) { bbParam.name = content.text; } else { bbParam.name = null; } } } else { bbParam.name = EditorGUILayout.DelayedTextField(content.text + " (" + bbParam.varType.FriendlyName() + ")", bbParam.name); GUI.backgroundColor = new Color(1, 1, 1, 0.2f); if (bbParam.bb != null && GUILayout.Button(new GUIContent("+", "Promote To Variable"), GUILayout.Width(20), GUILayout.Height(14))) { bbParam.PromoteToVariable(bbParam.bb); } } } GUI.color = Color.white; GUI.backgroundColor = Color.white; if (!blackboardOnly) { bbParam.useBlackboard = EditorGUILayout.Toggle(bbParam.useBlackboard, EditorStyles.radioButton, GUILayout.Width(18)); } GUILayout.EndHorizontal(); string info = null; if (bbParam.useBlackboard) { if (bbParam.bb == null) { info = "<i>No current Blackboard reference</i>"; } else if (bbParam.isNone) { info = "Select a '" + bbParam.varType.FriendlyName() + "' Assignable Blackboard Variable"; } else if (bbParam.varRef != null && bbParam.varType != bbParam.refType) { var setPossible = bbParam.varRef.CanConvertFrom(bbParam.varType); info = string.Format("AutoConvert: ({0} ➲ {1}){2}", bbParam.refType.FriendlyName(), bbParam.varType.FriendlyName(), setPossible ? "" : " [GET ONLY]"); } } if (info != null) { GUI.backgroundColor = new Color(0.8f, 0.8f, 1f, 0.5f); GUI.color = new Color(1f, 1f, 1f, 0.5f); GUILayout.BeginVertical("textfield"); GUILayout.Label(info, GUILayout.Width(0), GUILayout.ExpandWidth(true)); GUILayout.EndVertical(); GUILayout.Space(2); } GUILayout.EndVertical(); GUI.backgroundColor = Color.white; GUI.color = Color.white; return(bbParam); }
///An editor for BBParameter type to let user choose either a constant value or link to a Blackboard Variable. public static BBParameter ParameterField(string name, BBParameter bbParam, bool blackboardOnly = false, object[] attributes = null) { return(ParameterField(string.IsNullOrEmpty(name) ? GUIContent.none : new GUIContent(name), bbParam, blackboardOnly, attributes)); }
//a special object field for the BBParameter class to let user choose either a real value or enter a string to read data from a Blackboard public static BBParameter BBParameterField(string prefix, BBParameter bbParam, bool blackboardOnly = false, MemberInfo member = null) { if (bbParam == null) { EditorGUILayout.LabelField(prefix, "Non Set Variable"); return(null); } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); //override if we have a memeber info if (member != null) { blackboardOnly = member.RTGetAttribute <BlackboardOnlyAttribute>(false) != null; } //Direct assignement if (!blackboardOnly && !bbParam.useBlackboard) { bbParam.value = GenericField(prefix, bbParam.value, bbParam.varType, member); //Dropdown variable selection } else { GUI.color = new Color(0.9f, 0.9f, 1f, 1f); var varNames = new List <string>(); //Local if (bbParam.bb != null) { varNames.AddRange(bbParam.bb.GetVariableNames(bbParam.varType)); } //Globals foreach (var globalBB in GlobalBlackboard.allGlobals.Where(globalBB => globalBB != bbParam.bb)) { varNames.Add(globalBB.name + "/"); var globalVars = globalBB.GetVariableNames(bbParam.varType); for (var i = 0; i < globalVars.Length; i++) { globalVars[i] = globalBB.name + "/" + globalVars[i]; } varNames.AddRange(globalVars); } //Dynamic varNames.Add("(DynamicVar)"); var isDynamic = !string.IsNullOrEmpty(bbParam.name) && !varNames.Contains(bbParam.name); if (!isDynamic) { bbParam.name = StringPopup(prefix, bbParam.name, varNames, false, true); if (bbParam.name == "(DynamicVar)") { bbParam.name = "_"; } } else { bbParam.name = EditorGUILayout.TextField(prefix + " (" + bbParam.varType.FriendlyName() + ")", bbParam.name); } } GUI.color = Color.white; GUI.backgroundColor = Color.white; if (!blackboardOnly) { bbParam.useBlackboard = EditorGUILayout.Toggle(bbParam.useBlackboard, EditorStyles.radioButton, GUILayout.Width(18)); } GUILayout.EndHorizontal(); if (bbParam.useBlackboard && string.IsNullOrEmpty(bbParam.name)) { GUI.backgroundColor = new Color(0.8f, 0.8f, 1f, 0.5f); GUI.color = new Color(1f, 1f, 1f, 0.5f); GUILayout.BeginVertical("textfield"); GUILayout.BeginHorizontal(); if (bbParam.bb != null && bbParam.varType != typeof(object)) { if (GUILayout.Button("<b>+</b>", (GUIStyle)"label", GUILayout.Width(20))) { if (bbParam.bb.AddVariable(prefix, bbParam.varType) != null) { bbParam.name = prefix; } } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.ArrowPlus); } if (bbParam.bb != null) { GUILayout.Label("Select a '" + bbParam.varType.FriendlyName() + "' Blackboard Variable"); } else { GUILayout.Label("<i>No current Blackboard reference</i>"); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.Space(2); } GUILayout.EndVertical(); GUI.backgroundColor = Color.white; GUI.color = Color.white; return(bbParam); }
///An editor for BBParameter type to let user choose either a constant value or link to a Blackboard Variable. public static BBParameter ParameterField(GUIContent content, BBParameter bbParam, bool blackboardOnly = false, bool required = false, InspectedFieldInfo info = default(InspectedFieldInfo)) { if (bbParam == null) { EditorGUILayout.LabelField(content, EditorUtils.GetTempContent("BBParameter is null")); return(null); } //ensure we use blackboard if 'blackboardOnly' if (blackboardOnly && !bbParam.useBlackboard) { bbParam.useBlackboard = true; } GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { if (bbParam.useBlackboard) { ParameterDropDown(content, bbParam); } else { //we mutate inspected info field and parentInstance, but keep attributes and of course unity object context //this way, attributes work on internal field info.field = bbParam.GetType().RTGetField("_value"); info.wrapperInstanceContext = info.parentInstanceContext; info.parentInstanceContext = bbParam; if (info.attributes != null) { info.attributes = info.attributes.Where(a => !(a is DrawerAttribute) || !((DrawerAttribute)a).isDecorator).ToArray(); } GUILayout.BeginVertical(); bbParam.value = EditorUtils.ReflectedFieldInspector(content, bbParam.value, bbParam.varType, info); GUILayout.EndVertical(); } if (!blackboardOnly) { bbParam.useBlackboard = EditorGUILayout.Toggle(bbParam.useBlackboard, EditorStyles.radioButton, GUILayout.Width(18)); } } GUILayout.EndHorizontal(); //warn/error marks if (content != GUIContent.none) { if (bbParam.varRef == null && !string.IsNullOrEmpty(bbParam.name)) { if (!bbParam.isPresumedDynamic) { EditorUtils.MarkLastFieldError($"Missing Variable. Type of '{bbParam.varType.FriendlyName()}'"); } if (bbParam.isPresumedDynamic) { EditorUtils.MarkLastFieldWarning($"Dynamic Variable. Type of '{bbParam.varType.FriendlyName()}'"); } } else { if (required && bbParam.isNone) { EditorUtils.MarkLastFieldError("An instance is required"); } if (required && !string.IsNullOrEmpty(bbParam.name) && bbParam.isNull) { EditorUtils.MarkLastFieldWarning("An instance is required but currently resolves to null. If it is set in runtime you can ignore this warning."); } } } string textInfo = null; if (bbParam.useBlackboard) { if (bbParam.bb == null) { textInfo = "<i>No current Blackboard reference</i>"; } else if (bbParam.isNone) { textInfo = "Select a '" + bbParam.varType.FriendlyName() + "' Assignable Blackboard Variable"; } else if (bbParam.varRef != null && bbParam.varType != bbParam.refType) { var setPossible = bbParam.varRef.CanConvertFrom(bbParam.varType); textInfo = string.Format("AutoConvert: ({0} ➲ {1}){2}", bbParam.refType.FriendlyName(), bbParam.varType.FriendlyName(), setPossible ? string.Empty : " [GET ONLY]"); } } if (textInfo != null) { GUI.color = Color.white.WithAlpha(0.5f); GUILayout.BeginVertical(GUI.skin.textField); GUILayout.Label(textInfo, GUILayout.Width(0), GUILayout.ExpandWidth(true)); GUILayout.EndVertical(); GUILayout.Space(2); GUI.color = Color.white; } } GUILayout.EndVertical(); return(bbParam); }
//... static void ParameterDropDown(GUIContent content, BBParameter bbParam) { if (bbParam.varRef == null && !string.IsNullOrEmpty(bbParam.name)) { bbParam.name = EditorGUILayout.DelayedTextField(content, bbParam.name); GUI.backgroundColor = Color.white.WithAlpha(0.5f); if (bbParam.bb != null && GUILayout.Button(EditorUtils.GetTempContent(Icons.plusIcon, "Promote To Variable"), Styles.centerLabel, GUILayout.Width(18), GUILayout.Height(16))) { var menu = new GenericMenu(); foreach (var bb in bbParam.bb.GetAllParents(true).Reverse()) { menu.AddItem(new GUIContent($"Promote Variable in '{bb.identifier}' Blackboard"), false, () => { UndoUtility.RecordObject(bb.unityContextObject, "Promote Variable"); bbParam.PromoteToVariable(bb); UndoUtility.SetDirty(bb.unityContextObject); }); } menu.ShowAsContext(); } GUI.backgroundColor = Color.white; return; } GUI.color = new Color(0.9f, 0.9f, 1f, 1f); EditorGUILayout.PrefixLabel(content); var rect = EditorGUILayout.GetControlRect(false); rect.xMin += 2; // O.o var cachedContentTextForNew = string.IsNullOrEmpty(content.text) ? string.Format("new{0}", bbParam.varType.Name) : content.text; var displayName = bbParam.isNone ? "[NONE]" : bbParam.name; var pop = EditorGUI.DropdownButton(rect, EditorUtils.GetTempContent(displayName), FocusType.Passive); GUI.color = Color.white; if (pop) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("[NONE]"), false, () => { bbParam.name = string.Empty; }); foreach (var globalBB in GlobalBlackboard.GetAll()) { var globalVars = globalBB.GetVariables(bbParam.varType); if (globalVars.Count() == 0) { menu.AddDisabledItem(new GUIContent(globalBB.identifier + "/No Assignable Variables")); continue; } foreach (var variable in globalVars) { menu.AddItem(new GUIContent(globalBB.identifier + "/" + variable.name), bbParam.targetVariableID == variable.ID, () => { bbParam.SetTargetVariable(globalBB, variable); }); } } if (bbParam.bb != null) { foreach (var actualBB in bbParam.bb.GetAllParents(true).Reverse()) { var variables = actualBB.variables.Values.Where(v => v.CanConvertTo(bbParam.varType)); if (variables.Count() == 0) { menu.AddDisabledItem(new GUIContent(actualBB.identifier + "/No Assignable Variables")); continue; } foreach (var variable in variables) { menu.AddItem(new GUIContent(actualBB.identifier + "/" + variable.name), bbParam.targetVariableID == variable.ID, () => { bbParam.SetTargetVariable(actualBB, variable); }); } } } menu.AddSeparator(string.Empty); if (bbParam.bb != null) { foreach (var targetBB in bbParam.bb.GetAllParents(true).Reverse()) { menu.AddItem(new GUIContent("(Create New)/In '" + targetBB.identifier + "' Blackboard"), false, () => { UndoUtility.RecordObject(targetBB.unityContextObject, "New Variable"); if (targetBB.AddVariable(cachedContentTextForNew, bbParam.varType) != null) { bbParam.name = cachedContentTextForNew; } else { bbParam.name = null; } UndoUtility.SetDirty(targetBB.unityContextObject); }); } } menu.AddItem(new GUIContent("(DynamicVar)"), false, () => { bbParam.name = "_"; }); menu.DropDown(rect); } }
void OnClick(bool value) { this.value.value = value; YieldReturn(true); }
///An editor for BBParameter type to let user choose either a constant value or link to a Blackboard Variable. public static BBParameter ParameterField(string name, BBParameter bbParam, UnityEngine.Object context) { return(ParameterField(name, bbParam, false, context)); }
//This is called once each time the task is enabled. //Call EndAction() to mark the action as finished, either in success or failure. //EndAction can be called from anywhere. protected override void OnExecute() { startPosition = agent.StartPosition; EndAction(true); }
new public static ReflectedActionWrapper Create(MethodInfo method, IBlackboard bb) { if (method == null) { return(null); } Type type = null; var parameters = method.GetParameters(); if (parameters.Length == 0) { type = typeof(ReflectedAction); } if (parameters.Length == 1) { type = typeof(ReflectedAction <>); } if (parameters.Length == 2) { type = typeof(ReflectedAction <,>); } if (parameters.Length == 3) { type = typeof(ReflectedAction <, ,>); } if (parameters.Length == 4) { type = typeof(ReflectedAction <, , ,>); } if (parameters.Length == 5) { type = typeof(ReflectedAction <, , , ,>); } if (parameters.Length == 6) { type = typeof(ReflectedAction <, , , , ,>); } var argTypes = new Type[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; var pType = parameter.ParameterType.IsByRef ? parameter.ParameterType.GetElementType() : parameter.ParameterType; argTypes[i] = pType; } var o = (ReflectedActionWrapper)Activator.CreateInstance(argTypes.Length > 0 ? type.RTMakeGenericType(argTypes) : type); o._targetMethod = new SerializedMethodInfo(method); BBParameter.SetBBFields(o, bb); var bbParams = o.GetVariables(); for (int i = 0; i < parameters.Length; i++) { var p = parameters[i]; if (p.IsOptional) { bbParams[i].value = p.DefaultValue; } } return(o); }
public static BBParameter BBParameterField(GUIContent content, BBParameter bbParam, bool blackboardOnly = false, MemberInfo member = null, object context = null) { if (bbParam == null) { EditorGUILayout.LabelField(content, new GUIContent("Variable is null")); return(null); } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); //override if we have a memeber info if (member != null) { blackboardOnly = member.RTIsDefined <BlackboardOnlyAttribute>(true); } //Direct assignement if (!blackboardOnly && !bbParam.useBlackboard) { GUILayout.BeginVertical(); if (content.text.Equals("Lua Cls")) { GUILayout.BeginHorizontal(); GUILayout.Label("Lua Cls"); bool isAction = context is LuaAction; string[] options = GetFileList(isAction); int index = 0; if (bbParam.value != null) { for (int i = 0; i < options.Length; i++) { if (options[i].Equals(bbParam.value)) { index = i; break; } } } index = EditorGUILayout.Popup(index, options); if (index <= 0) { bbParam.value = null; } else { bbParam.value = options[index]; } GUILayout.EndHorizontal(); } else { bbParam.value = GenericField(content.text, bbParam.value, bbParam.varType, member, context); } GUILayout.EndVertical(); //Dropdown variable selection } else { GUI.color = new Color(0.9f, 0.9f, 1f, 1f); var varNames = new List <string>(); //Local if (bbParam.bb != null) { varNames.AddRange(bbParam.bb.GetVariableNames(bbParam.varType)); } //Seperator varNames.Add("/"); //Globals foreach (var globalBB in GlobalBlackboard.allGlobals) { var globalVars = globalBB.GetVariableNames(bbParam.varType); if (globalVars.Length == 0) { varNames.Add(globalBB.name + "/"); } for (var i = 0; i < globalVars.Length; i++) { globalVars[i] = globalBB.name + "/" + globalVars[i]; } varNames.AddRange(globalVars); } //Dynamic varNames.Add("(DynamicVar)"); //New if (bbParam.bb != null) { varNames.Add("(Create New)"); } var isDynamic = !string.IsNullOrEmpty(bbParam.name) && !varNames.Contains(bbParam.name); if (!isDynamic) { bbParam.name = StringPopup(content, bbParam.name, varNames, false, true); if (bbParam.name == "(DynamicVar)") { bbParam.name = "_"; } if (bbParam.bb != null && bbParam.name == "(Create New)") { if (bbParam.bb.AddVariable(content.text, bbParam.varType) != null) { bbParam.name = content.text; } else { bbParam.name = null; } } } else { bbParam.name = EditorGUILayout.DelayedTextField(content.text + " (" + bbParam.varType.FriendlyName() + ")", bbParam.name); GUI.backgroundColor = new Color(1, 1, 1, 0.2f); if (bbParam.bb != null && GUILayout.Button(new GUIContent("▲", "Promote To Variable"), GUILayout.Width(20), GUILayout.Height(14))) { bbParam.PromoteToVariable(bbParam.bb); } } } GUI.color = Color.white; GUI.backgroundColor = Color.white; if (!blackboardOnly) { bbParam.useBlackboard = EditorGUILayout.Toggle(bbParam.useBlackboard, EditorStyles.radioButton, GUILayout.Width(18)); } GUILayout.EndHorizontal(); string info = null; if (bbParam.useBlackboard) { if (bbParam.bb == null) { info = "<i>No current Blackboard reference</i>"; } else if (bbParam.isNone) { info = "Select a '" + bbParam.varType.FriendlyName() + "' Assignable Blackboard Variable"; } else if (bbParam.varRef != null && bbParam.varType != bbParam.refType) { if (blackboardOnly) { info = string.Format("AutoConvert: ({0} ➲ {1})", bbParam.varType.FriendlyName(), bbParam.refType.FriendlyName()); } else { info = string.Format("AutoConvert: ({0} ➲ {1})", bbParam.refType.FriendlyName(), bbParam.varType.FriendlyName()); } } } if (info != null) { GUI.backgroundColor = new Color(0.8f, 0.8f, 1f, 0.5f); GUI.color = new Color(1f, 1f, 1f, 0.5f); GUILayout.BeginVertical("textfield"); GUILayout.Label(info, GUILayout.Width(0), GUILayout.ExpandWidth(true)); GUILayout.EndVertical(); GUILayout.Space(2); } GUILayout.EndVertical(); GUI.backgroundColor = Color.white; GUI.color = Color.white; return(bbParam); }