//Helper to ensure that BBVariables are not null. void InitBBFields() { BBVariable.InitBBFields(this); }
//Set the target blackboard for all BBVariables found on node. Done when creating node, OnValidate as well as when graphBlackboard set to a new value. public void UpdateNodeBBFields(Blackboard bb) { BBVariable.SetBBFields(bb, this); }
//Set the target blackboard for all BBVariables found in class. This is done every time the blackboard of the Task is set to a new value void UpdateBBFields(Blackboard bb) { BBVariable.SetBBFields(bb, this); taskAgent.bb = bb; }
//a special object field for the BBVariable class to let user choose either a real value or enter a string to read data from a Blackboard public static BBVariable BBVariableField(string prefix, BBVariable bbVar, MemberInfo member = null) { if (bbVar == null) { EditorGUILayout.LabelField(prefix, "NULL"); return(null); } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (!bbVar.blackboardOnly && !bbVar.useBlackboard) { var field = bbVar.GetType().GetField("_value", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(bbVar, GenericField(prefix, field.GetValue(bbVar), bbVar.varType, member)); } else { GUI.color = new Color(0.9f, 0.9f, 1f, 1f); if (bbVar.bb) { List <string> dataNames = bbVar.bb.GetDataNames(bbVar.varType).ToList(); dataNames.Add("/ "); foreach (KeyValuePair <string, Blackboard> pair in Blackboard.allBlackboards) { if (pair.Value == bbVar.bb || !pair.Value.isGlobal) { continue; } dataNames.Add(pair.Key + "/"); foreach (string dName in pair.Value.GetDataNames(bbVar.varType)) { dataNames.Add(pair.Key + "/" + dName); } } dataNames.Add("(DynamicVar)"); if (dataNames.Contains(bbVar.dataName) || string.IsNullOrEmpty(bbVar.dataName)) { if (bbVar.isDynamic) { GUIUtility.keyboardControl = 0; bbVar.isDynamic = false; } bbVar.dataName = StringPopup(prefix, bbVar.dataName, dataNames, false, true); if (bbVar.dataName == "(DynamicVar)") { bbVar.isDynamic = true; bbVar.dataName = "_"; } } else { bbVar.dataName = EditorGUILayout.TextField(prefix + " (" + TypeName(bbVar.varType) + ")", bbVar.dataName); } } else { bbVar.dataName = EditorGUILayout.TextField(prefix + " (" + TypeName(bbVar.varType) + ")", bbVar.dataName); } } GUI.color = Color.white; GUI.backgroundColor = Color.white; if (!bbVar.blackboardOnly) { bbVar.useBlackboard = EditorGUILayout.Toggle(bbVar.useBlackboard, EditorStyles.radioButton, GUILayout.Width(18)); } GUILayout.EndHorizontal(); if (bbVar.bb && bbVar.useBlackboard && string.IsNullOrEmpty(bbVar.dataName)) { GUI.backgroundColor = new Color(0.8f, 0.8f, 1f, 0.5f); GUI.color = new Color(1f, 1f, 1f, 0.5f); GUILayout.BeginHorizontal("textfield"); if (string.IsNullOrEmpty(bbVar.dataName)) { GUILayout.Label("Select a '" + TypeName(bbVar.varType) + "' Blackboard Variable"); } else { GUILayout.Label("Variable name does not exist in blackboard"); } GUILayout.EndHorizontal(); GUILayout.Space(2); } GUILayout.EndVertical(); //RequiresCoponent attribute should be checked here unfortunately if (member != null && bbVar.GetType() == typeof(BBGameObject)) { var rc = member.GetCustomAttributes(typeof(RequiresComponentAttribute), true).FirstOrDefault() as RequiresComponentAttribute; if (rc != null && typeof(Component).IsAssignableFrom(rc.type) && !bbVar.isNull) { if ((bbVar as BBGameObject).value.GetComponent(rc.type) == null) { GUI.backgroundColor = new Color(1f, 0.8f, 0.8f, 0.5f); GUI.color = new Color(1f, 1f, 1f, 0.5f); GUILayout.BeginHorizontal("textfield"); GUILayout.Label("GameObject requires '" + TypeName(rc.type) + "' Component"); GUILayout.EndHorizontal(); GUILayout.Space(2); } } } GUI.backgroundColor = Color.white; GUI.color = Color.white; return(bbVar); }