public void HandleInheritingObjectChange(ObjectField inheritingObjectField, ChangeEvent <UnityEngine.Object> e) { GameObject newValue = (GameObject)e.newValue; if (newValue != null) { UtilityAIAgent newValueAgent = newValue.GetComponent <UtilityAIAgent>(); //If the new object has a Utility AI Agent script attached, and that agent is using this action set, update the value: if (newValueAgent != null && newValueAgent.actionSet == utilityAIAgent) { utilityAIAgent.inheritingGameObject = (GameObject)e.newValue; } //Else reset the object field to the previous value: else { inheritingObjectField.value = (GameObject)e.previousValue; } } //If the new value is null, and the last value was not null, reset the field to the previous value: else if (e.newValue == null && e.previousValue != null) { inheritingObjectField.value = (GameObject)e.previousValue; } //Update the UI: UpdateActions(); }
public void OnEnable() { utilityAIAgent = (UtilityAIAgent)target; rootElement = new VisualElement(); VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/UtilityAI/Scripts/Editor/Utility AI Agent Editor/UtilityAIAgentEditor.uxml"); visualTree.CloneTree(rootElement); StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/UtilityAI/Scripts/Editor/Utility AI Agent Editor/UtilityAIAgentEditor.uss"); rootElement.styleSheets.Add(stylesheet); }
public GameObject SearchForObjectUsingActionSet() { List <GameObject> allGOs = Resources.FindObjectsOfTypeAll <GameObject>().ToList(); foreach (GameObject GO in allGOs) { UtilityAIAgent agent = GO.GetComponent <UtilityAIAgent>(); if (agent != null && agent.actionSet == utilityAIAgent) { return(agent.gameObject); } } return(null); }
void Start() { agent = GetComponent <UtilityAIAgent>(); }