/// <summary> /// Finds the behaviour that is currently weighted as the top priority. /// </summary> private uaiBehaviour GetTopPriorityBehaviour() { uaiBehaviour topPriority = null; float topScore = 0.0f; // Loop through each behaviour to find highest score foreach (uaiBehaviour b in _behaviours) { if (!b) { continue; } float commitment = (b == _currentBehaviour) ? _commitmentValue : 0; float score = commitment + b.Evaluate(); if (score > topScore) { topScore = score; topPriority = b; } } return(topPriority); }
/// <summary> /// Add the specified behaviour to the agent. /// </summary> public void AddBehaviour(uaiBehaviour b) { if (!_behaviours.Contains(b)) { _behaviours.Add(b); } }
void Update() { // Find the top priority behaviour uaiBehaviour topPriority = GetTopPriorityBehaviour(); if (topPriority != null) { _currentBehaviour = topPriority; } if (_currentBehaviour != null) { _currentBehaviour.ExecuteAction(); } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.Space(); // Show help message to explain the purpose of considerations & action delegates lists EditorGUILayout.LabelField(new GUIContent("Hover for help", "Considerations list:\nA list of properties that will be considered by this behaviour.Use the animation curve to specify how each property will be weighted when the value is 0 - 1\n\nPre-Evaluation Delegates:\nA list of delegate functions which will be triggered immediately before the behaviour is evaluated by the agent.\n\nAction Delegates:\nA list of delegate functions which will be triggered by this behaviour when it is run."), EditorStyles.boldLabel); // Draw name property field SerializedProperty behaviourNameProperty = serializedObject.FindProperty("_behaviourName"); if (behaviourNameProperty != null) { EditorGUILayout.TextField(new GUIContent("Behaviour Name"), behaviourNameProperty.stringValue); } EditorGUILayout.Space(); // Draw the consideration list if (considerations != null) { considerations.DoLayoutList(); } // Draw current priority uaiBehaviour script = target as uaiBehaviour; float priority = script.Evaluate(); ProgressBar(priority, "Current Priority"); serializedObject.ApplyModifiedProperties(); DrawDefaultInspector(); }