Exemplo n.º 1
0
    void Update()
    {
        UtilityAIAction bestAction = agent.GetBestAction();

        if (bestAction != null)
        {
            print(gameObject.name + " - " + bestAction.name);
        }
    }
    private void AddAction()
    {
        UtilityAIAction action = new UtilityAIAction();

        utilityAIAgent.actions.Add(action);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        UpdateActions();
    }
Exemplo n.º 3
0
 public UtilityAIAction(UtilityAIAction action)
 {
     this.name           = action.name;
     this.enabled        = action.enabled;
     this.action         = new ExposedDelegate(action.action);
     this.considerations = new List <UtilityAIConsideration>();
     foreach (UtilityAIConsideration consideration in action.considerations)
     {
         this.considerations.Add(new UtilityAIConsideration(consideration));
     }
 }
Exemplo n.º 4
0
    public UtilityAIActionEditor(Editor utilityAIAgentEditor, UtilityAIAction action)
    {
        this.utilityAIAgentEditor = utilityAIAgentEditor;
        this.action = action;
        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/UtilityAI/Scripts/Editor/Utility AI Action Editor/UtilityAIActionEditor.uxml");

        visualTree.CloneTree(this);

        StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/UtilityAI/Scripts/Editor/Utility AI Action Editor/UtilityAIActionEditor.uss");

        this.styleSheets.Add(stylesheet);

        this.AddToClassList("utilityAIActionEditor");

        Button moveUpButton = this.Query <Button>("moveUpButton").First();

        moveUpButton.BringToFront();
        moveUpButton.clickable.clicked += MoveActionUp;

        Button moveDownButton = this.Query <Button>("moveDownButton").First();

        moveDownButton.BringToFront();
        moveDownButton.clickable.clicked += MoveActionDown;

        Button deleteButton = this.Query <Button>("deleteButton").First();

        deleteButton.BringToFront();
        deleteButton.clickable.clicked += DeleteAction;


        actionContainerFoldout      = this.Query <Foldout>("action").First();
        actionContainerFoldout.text = action.name + ": ";

        actionContainerFoldout.Query <Toggle>().First().AddToClassList("actionFoldout");

        actionDelegateContainer = actionContainerFoldout.Query <VisualElement>("actionContainer").First();

        considerationsFoldout = this.Query <Foldout>("considerationsList").First();
        considerationsFoldout.Query <Toggle>().First().AddToClassList("considerationsFoldout");
        considerationsContainer = considerationsFoldout.Query <VisualElement>("considerationsContainer").First();

        TextField nameField = this.Query <TextField>("actionName").First();

        nameField.value = action.name;
        nameField.RegisterCallback <ChangeEvent <string> >(
            e =>
        {
            if (e.newValue != "")
            {
                action.name = (string)e.newValue;
                actionContainerFoldout.text = (string)e.newValue + ":";
            }
        }
            );

        Toggle enabledField = this.Query <Toggle>("actionEnabled").First();

        enabledField.value = action.enabled;
        enabledField.RegisterCallback <ChangeEvent <bool> >(
            e =>
        {
            action.enabled = (bool)e.newValue;
        }
            );

        UpdateAction();

        UpdateConsiderations();

        Button btnAddConsideration = this.Query <Button>("btnAddNewConsideration").First();

        btnAddConsideration.BringToFront();
        btnAddConsideration.clickable.clicked += AddConsideration;

        Button btnRemoveAllConsiderations = this.Query <Button>("btnRemoveAllConsiderations").First();

        btnRemoveAllConsiderations.BringToFront();
        btnRemoveAllConsiderations.clickable.clicked += RemoveAllConsiderations;
    }