private void LoadElements() { for (int i = 0; i < m_serializedBlackboardElements.arraySize; i++) { string name = m_serializedBlackboardElements.GetArrayElementAtIndex(i).FindPropertyRelative(BlackboardElement.Name_VarName).stringValue; BlackboardElement ele = m_blackboardProperties.GetElementByName(name); AddBlackboardRow(ele, m_serializedBlackboardElements.GetArrayElementAtIndex(i), i); } }
public override void OnDrawPrimaryBody(VisualElement primaryBodyContainer) { base.OnDrawPrimaryBody(primaryBodyContainer); string blackboardEleId = TargetProperty.FindPropertyRelative(BlackboardConditional.BlackboardElementIdVarName).stringValue; BlackboardElement blackboardElement = NodeGraph.BlackboardProperties.GetElementById(blackboardEleId); Label selectedEleLabel = new Label(blackboardElement == null ? "None" : blackboardElement.Name); selectedEleLabel.style.unityTextAlign = TextAnchor.MiddleCenter; selectedEleLabel.style.fontSize = 18; primaryBodyContainer.Add(selectedEleLabel); }
public bool Evaluate(BlackboardElement element) { int intVal = (int)element.Value; switch (m_comparator) { case IntComparator.Equals: if (intVal == m_comparedValue) { return(true); } break; case IntComparator.Does_Not_Equal: if (intVal != m_comparedValue) { return(true); } break; case IntComparator.Less_Than: if (intVal < m_comparedValue) { return(true); } break; case IntComparator.Greater_Than: if (intVal > m_comparedValue) { return(true); } break; case IntComparator.Less_Than_or_Equal_To: if (intVal <= m_comparedValue) { return(true); } break; case IntComparator.Greater_Than_Or_Equal_To: if (intVal >= m_comparedValue) { return(true); } break; case IntComparator.Else: return(true); } return(false); }
public override void OnNodeEnter(GraphControls graphControls) { base.OnNodeEnter(graphControls); if (string.IsNullOrEmpty(m_blackboardElementId)) { Debug.LogError("BlackboardSetter: Blackboard element is not set!"); return; } BlackboardElement element = graphControls.BlackboardProperties.GetElementById(m_blackboardElementId); m_setterValue.Evaluate(element); graphControls.TraverseEdge(0, this); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); property.serializedObject.Update(); bool blackboardEleIsSet = true; SerializedProperty setterValueProp = property.FindPropertyRelative(BlackboardSetter.SetterValueVarName); List <BlackboardElement> blackboardElements = (property.serializedObject.targetObject as NodeGraph).BlackboardProperties.GetAllElements(); SerializedProperty blackboardElementIdProp = property.FindPropertyRelative(BlackboardSetter.BlackboardElementIdVarName); int selectedIndex = blackboardElements.FindIndex(x => x.GUID == blackboardElementIdProp.stringValue); if (selectedIndex == -1) // Trying to handle this here causes the apocalypse. Just rely on the NodeView. { blackboardEleIsSet = false; } EditorGUI.BeginChangeCheck(); selectedIndex = EditorGUILayout.Popup("Blackboard Element", selectedIndex, blackboardElements.Select(x => x.Name).ToArray()); if (EditorGUI.EndChangeCheck()) { int group = Undo.GetCurrentGroup(); Undo.RecordObject(property.serializedObject.targetObject, "Switching BlackboardConditional element"); blackboardElementIdProp.stringValue = blackboardElements[selectedIndex].GUID; BlackboardElement ele = blackboardElements[selectedIndex]; BlackboardSetter.BlackboardSetterElementTypes.TryGetValue(ele.GetType(), out Type setterElementType); if (setterElementType == null) { setterValueProp.managedReferenceValue = null; blackboardEleIsSet = false; } else { IBlackboardSetterElement newSetterEle = Activator.CreateInstance(setterElementType) as IBlackboardSetterElement; setterValueProp.managedReferenceValue = newSetterEle; } property.serializedObject.ApplyModifiedProperties(); Undo.CollapseUndoOperations(group); } if (blackboardEleIsSet) { GUILayout.BeginVertical("box"); EditorGUILayout.PropertyField(setterValueProp); GUILayout.EndVertical(); } EditorGUI.EndProperty(); }
private void AddBlackboardRow(BlackboardElement blackboardEle, SerializedProperty serializedBlackboardEle, int index) { BlackboardElementView elementView = new BlackboardElementView(blackboardEle, serializedBlackboardEle, () => { DeleteElement(index); }); PropertyField propF = new PropertyField(serializedBlackboardEle .FindPropertyRelative(BlackboardElement.ValueWrapper_VarName) .FindPropertyRelative(BlackboardElement.Value_VarName)); propF.Bind(serializedBlackboardEle.serializedObject); BlackboardRow br = new BlackboardRow(elementView, propF); m_allElementRows.Add(br); Add(br); }
public void Evaluate(BlackboardElement element) { bool boolValue = (bool)element.Value; switch (m_setterCommand) { case BoolSetterCommand.Set_To: boolValue = m_newValue; break; case BoolSetterCommand.Toggle: boolValue = !boolValue; break; } element.Value = boolValue; }
private void AddNewElement(Type type) { int undoGroup = Undo.GetCurrentGroup(); BlackboardElement newElement = Activator.CreateInstance(m_blackboardElementLookup[type]) as BlackboardElement; m_blackboardProperties.AddElement(newElement); m_serializedBlackboardElements.serializedObject.Update(); int lastIndex = m_serializedBlackboardElements.arraySize - 1; SerializedProperty serializedBlackboardElement = m_serializedBlackboardElements.GetArrayElementAtIndex(lastIndex); AddBlackboardRow(newElement, serializedBlackboardElement, lastIndex); OnBlackboardElementChanged?.Invoke(undoGroup); }
public override void OnNodeEnter(GraphControls graphControls) { base.OnNodeEnter(graphControls); if (string.IsNullOrEmpty(m_blackboardElementId)) { Debug.LogError("BlackboardConditional: Blackboard element is not set!"); return; } BlackboardElement element = graphControls.BlackboardProperties.GetElementById(m_blackboardElementId); for (int i = 0; i < m_conditionals.Count; i++) { if (m_conditionals[i].Evaluate(element)) { graphControls.TraverseEdge(i, this); return; } } }
public void Evaluate(BlackboardElement element) { float floatValue = (float)element.Value; switch (m_setterCommand) { case FloatSetterCommand.Set_To: floatValue = m_newValue; break; case FloatSetterCommand.Increment: floatValue += m_newValue; break; case FloatSetterCommand.Decrement: floatValue -= m_newValue; break; } element.Value = floatValue; }
public void Evaluate(BlackboardElement element) { int intValue = (int)element.Value; switch (m_setterCommand) { case IntSetterCommand.Set_To: intValue = m_newValue; break; case IntSetterCommand.Increment: intValue += m_newValue; break; case IntSetterCommand.Decrement: intValue -= m_newValue; break; } element.Value = intValue; }
public void Evaluate(BlackboardElement element) { string strValue = (string)element.Value; switch (m_setterCommand) { case StringSetterCommand.Set_To: strValue = m_newValue; break; case StringSetterCommand.Append: strValue += m_newValue; break; case StringSetterCommand.Prepend: strValue = m_newValue + strValue; break; } element.Value = strValue; }
public BlackboardElementView(BlackboardElement blackboardElement, SerializedProperty serializedBlackboardElement, Action onDeleteElement) { m_blackboardElement = blackboardElement; m_serializedBlackboardElement = serializedBlackboardElement; text = m_blackboardElement.Name; typeText = m_blackboardElement.Type.Name; if (typeText == "Single") { typeText = "Float"; } else if (typeText == "Int32") { typeText = "Int"; } m_onDeleteElement = onDeleteElement; this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu)); capabilities &= ~Capabilities.Deletable; }
public bool Evaluate(BlackboardElement element) { bool boolValue = (bool)element.Value; switch (m_boolComparator) { case BoolComparator.Equals: if (m_comparedValue == boolValue) { return(true); } break; case BoolComparator.Does_Not_Equal: if (m_comparedValue != boolValue) { return(true); } break; } return(false); }
public bool Evaluate(BlackboardElement element) { string strValue = (string)element.Value; switch (m_comparator) { case StringComparator.Equals: if (m_comparedValue == strValue) { return(true); } break; case StringComparator.Does_Not_Equal: if (m_comparedValue != strValue) { return(true); } break; } return(false); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); property.serializedObject.Update(); List <BlackboardElement> blackboardElements = (property.serializedObject.targetObject as NodeGraph).BlackboardProperties.GetAllElements(); SerializedProperty conditionalsList = property.FindPropertyRelative(BlackboardConditional.ConditionalsVarName); // Selected Blackboard Element dropdown SerializedProperty blackboardElementIdProp = property.FindPropertyRelative(BlackboardConditional.BlackboardElementIdVarName); int selectedIndex = blackboardElements.FindIndex(x => x.GUID == blackboardElementIdProp.stringValue); if (selectedIndex == -1) // Trying to handle this here causes the apocalypse. Just rely on the NodeView. { } EditorGUI.BeginChangeCheck(); selectedIndex = EditorGUILayout.Popup("Blackboard Element", selectedIndex, blackboardElements.Select(x => x.Name).ToArray()); if (EditorGUI.EndChangeCheck()) { int group = Undo.GetCurrentGroup(); Undo.RecordObject(conditionalsList.serializedObject.targetObject, "Switching BlackboardConditional element"); blackboardElementIdProp.stringValue = blackboardElements[selectedIndex].GUID; NodeGraph.RemoveAllOutportsFromNode(property); conditionalsList.arraySize = 0; conditionalsList.serializedObject.ApplyModifiedProperties(); Undo.CollapseUndoOperations(group); } GUILayout.Space(8); // Conditional Elements for (int i = 0; i < conditionalsList.arraySize; i++) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical("box"); GUILayout.Label("Condition:"); EditorGUILayout.PropertyField(conditionalsList.GetArrayElementAtIndex(i), true); GUILayout.EndVertical(); if (GUILayout.Button("X", GUILayout.ExpandHeight(true), GUILayout.Width(20))) // Delete { int group = Undo.GetCurrentGroup(); Undo.RecordObject(conditionalsList.serializedObject.targetObject, "Delete blackboard conditional"); conditionalsList.DeleteArrayElementAtIndex(i); conditionalsList.serializedObject.ApplyModifiedProperties(); NodeGraph.RemoveOutportFromNode(property, i); Undo.CollapseUndoOperations(group); } GUILayout.EndHorizontal(); GUILayout.Space(4); } if (GUILayout.Button("Add Conditional")) { if (selectedIndex == -1) { return; } BlackboardElement ele = blackboardElements[selectedIndex]; Type conditionalElementType = null; BlackboardConditional.BlackboardConditionalElementTypes.TryGetValue(ele.GetType(), out conditionalElementType); if (conditionalElementType != null) { conditionalsList.serializedObject.Update(); int group = Undo.GetCurrentGroup(); Undo.RecordObject(conditionalsList.serializedObject.targetObject, "Add blackboard conditional"); IBlackboardConditionalElement newConditionalEle = Activator.CreateInstance(conditionalElementType) as IBlackboardConditionalElement; conditionalsList.InsertArrayElementAtIndex(conditionalsList.arraySize); conditionalsList.GetArrayElementAtIndex(conditionalsList.arraySize - 1).managedReferenceValue = newConditionalEle; conditionalsList.serializedObject.ApplyModifiedProperties(); NodeGraph.AddOutportToNode(property); Undo.CollapseUndoOperations(group); } else { Debug.LogError("There is no implementation of BlackboardConditional for type " + ele.GetType().Name); } } EditorGUI.EndProperty(); }