Ejemplo n.º 1
0
    public ExposedDelegateEditor(UtilityAIActionEditor utilityAIActionEditor, ExposedDelegate exposedDelegate)
    {
        this.utilityAIActionEditor = utilityAIActionEditor;
        this.exposedDelegate       = exposedDelegate;

        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/UtilityAI/Scripts/Editor/Exposed Delegate Editor/ExposedDelegateEditor.uxml");

        visualTree.CloneTree(this);

        StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/UtilityAI/Scripts/Editor/Exposed Delegate Editor/ExposedDelegateEditor.uss");

        this.styleSheets.Add(stylesheet);

        this.AddToClassList("exposedDelegateEditor");

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

        btnAddDelegateEntry.BringToFront();
        btnAddDelegateEntry.clickable.clicked += AddDelegateEntry;

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

        btnRemoveAllDelegateEntries.BringToFront();
        btnRemoveAllDelegateEntries.clickable.clicked += RemoveAllDelegateEntries;

        delegateEntriesList = this.Query <Foldout>("delegateEntries");
        delegateEntriesList.Query <Toggle>().First().AddToClassList("delegateEntryFoldout");

        delegateEntriesContainer = delegateEntriesList.Query <VisualElement>("delegateEntriesContainer").First();

        UpdateDelegateEntries();
    }
Ejemplo n.º 2
0
        void TurnFoldoutIntoHeader(Foldout x)
        {
            x.value = true;
            x.RemoveFromClassList("unity-foldout");

            x.Query <Toggle>().First().pickingMode = PickingMode.Ignore;
            x.Query <Toggle>().Children <VisualElement>().ForEach(e => e.pickingMode = PickingMode.Ignore);
        }
    public override VisualElement CreateInspectorGUI()
    {
        rootElement.AddToClassList("actionSetContainer");

        actionList      = rootElement.Query <Foldout>("actionList").First();
        actionContainer = actionList.Query <VisualElement>("actionsContainer").First();

        //Set up the Inheriting Object Field Logic:
        ObjectField inheritingObjectField = rootElement.Query <ObjectField>("inheritingObjectField");

        inheritingObjectField.objectType = typeof(GameObject);
        if (utilityAIAgent.inheritingGameObject != null && utilityAIAgent.inheritingGameObject.GetComponent <UtilityAIAgent>() != null && utilityAIAgent.inheritingGameObject.GetComponent <UtilityAIAgent>().actionSet == utilityAIAgent)
        {
            inheritingObjectField.value = utilityAIAgent.inheritingGameObject;
        }
        else
        {
            inheritingObjectField.value = utilityAIAgent.inheritingGameObject = SearchForObjectUsingActionSet();
            if (utilityAIAgent.inheritingGameObject == null)
            {
                if (EditorUtility.DisplayDialog("No agents are using this action set!", "No agents are currently using this action set, would you like to delete it?", "Yes", "No"))
                {
                    utilityAIAgent.DeleteFromFiles();
                }
            }
        }
        inheritingObjectField.RegisterCallback <ChangeEvent <UnityEngine.Object> >(
            e =>
        {
            HandleInheritingObjectChange(inheritingObjectField, e);
        }
            );

        actionList.Query <Toggle>().First().AddToClassList("actionListFoldout");

        Button btnAddAction = rootElement.Query <Button>("btnAddNewAction").First();

        btnAddAction.BringToFront();
        btnAddAction.clickable.clicked += AddAction;

        Button btnDeleteAllActions = rootElement.Query <Button>("btnRemoveAll").First();

        btnDeleteAllActions.BringToFront();
        btnDeleteAllActions.clickable.clicked += RemoveAllActions;

        UpdateActions();
        return(rootElement);
    }
Ejemplo n.º 4
0
        private void DoLabelsDisplay()
        {
            m_LabelsFoldOut = new Foldout {
                text = L10n.Tr("Labels"), name = k_LabelsFoldOutName, classList = { k_FoldoutClass }
            };
            var i = 0;

            foreach (var label in m_Labels)
            {
                var toggle = new Toggle(L10n.Tr(label))
                {
                    name = label, classList = { k_ToggleClass }
                };
                toggle.RegisterValueChangedCallback(evt =>
                {
                    if (evt.newValue)
                    {
                        // Uncheck Unlabeled if checked
                        m_StatusFoldOut.Q <Toggle>(PageFilters.k_UnlabeledStatus.ToLower()).value = false;
                    }
                    UpdateFiltersIfNeeded();
                });
                m_LabelsFoldOut.Add(toggle);

                if (++i > k_MaxDisplayLabels)
                {
                    UIUtils.SetElementDisplay(toggle, false);
                }
            }

            m_LabelsFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
            m_Container.Add(m_LabelsFoldOut);
        }
Ejemplo n.º 5
0
 private void AddLinkChoiceUI(DialogueBranch branchA, DialogueBranch branchB, Foldout linksFoldout, int linkIndex)
 {
     if (linksFoldout == null)
     {
         Debug.LogError("AddLinkUI failed with null parent.");
         return;
     }
     if (branchB.id != branchA.id)
     {
         // add a link choice
         //linkPrefabVS.CloneTree(linkPrefab.parent);
         //Button linkButton = blockUI.Query("LinkPrefab").Last() as Button;
         Button linkButton = new Button();
         linksFoldout.Query("unity-content").First().Add(linkButton);
         linkButton.text = "[" + branchB.id + "]";
         if (linkButton != null)
         {
             int    nextID     = branchB.id;
             string nextSpeech = branchB.speech;
             linkButton.clicked += () =>
             {
                 OnLinkClicked(linksFoldout, dialogueDatam, branchA, linkIndex, nextID, nextSpeech);
             };
         }
     }
 }
Ejemplo n.º 6
0
        private Foldout AddHeaderFoldout(VisualElement header, bool expanded)
        {
            var foldout = new Foldout {
                pickingMode = PickingMode.Ignore, value = expanded
            };

            foldout.Query().Descendents <VisualElement>().ForEach(el => el.pickingMode = PickingMode.Ignore);
            foldout.AddToClassList(itemHeaderFoldoutUssClassName);
            header.Add(foldout);
            return(foldout);
        }
Ejemplo n.º 7
0
        private void BuildAnimatorSelection(UIController controller)
        {
            var animatorLayers = controller.ExpressionInfo.AvatarDescriptor.baseAnimationLayers;

            void CleanObjectField(ObjectField field)
            {
                field.objectType = typeof(AnimatorController);
                field.RemoveObjectSelector();
                // field.Q(null, "unity-object-field-display__label").Display(true);
                field.RegisterValueChangedCallback(e => field.SetValueWithoutNotify(e.previousValue));
            }

            CleanObjectField(_activeAnimator);
            foreach (var objectField in _avatarAnimators.Query <ObjectField>().Build().ToList())
            {
                CleanObjectField(objectField);
                switch (objectField.name)
                {
                case "animator-base": objectField.SetValueWithoutNotify(animatorLayers[0].animatorController); break;

                case "animator-additive": objectField.SetValueWithoutNotify(animatorLayers[1].animatorController); break;

                case "animator-gesture": objectField.SetValueWithoutNotify(animatorLayers[2].animatorController); break;

                case "animator-action": objectField.SetValueWithoutNotify(animatorLayers[3].animatorController); break;

                case "animator-fx": objectField.SetValueWithoutNotify(animatorLayers[4].animatorController); break;
                }
                objectField.SetEnabled(objectField.value != null);
                var button = objectField.Q <Button>(null, "unity-button");
                button.clickable.clicked += () => SetAnimator(objectField.value as AnimatorController);
            }

            SetAnimator(controller.ExpressionInfo.Controller);

            void SetAnimator(AnimatorController obj)
            {
                if (!controller.ExpressionInfo.AvatarDescriptor.OwnsAnimator(obj))
                {
                    var last = animatorLayers.Last();
                    obj = !last.isDefault && last.animatorController != null ? last.animatorController as AnimatorController: null;
                }

                _activeAnimator.SetValueWithoutNotify(obj);
                if (controller.ExpressionInfo.Controller != obj)
                {
                    controller.ExpressionInfo.Controller = obj;
                }

                _avatarAnimators.value = obj == null;
                ErrorValidate();
            }
        }
Ejemplo n.º 8
0
        protected override void DoDisplay()
        {
            m_StatusFoldOut = new Foldout {
                text = L10n.Tr("Status"), name = k_StatusFoldOutName, classList = { k_FoldoutClass }
            };
            foreach (var status in k_Statuses)
            {
                var toggle = new Toggle(status)
                {
                    name = status.ToLower(), classList = { k_ToggleClass }
                };
                toggle.RegisterValueChangedCallback(evt =>
                {
                    if (evt.newValue)
                    {
                        foreach (var t in m_StatusFoldOut.Children().OfType <Toggle>())
                        {
                            if (t == toggle)
                            {
                                continue;
                            }

                            t.SetValueWithoutNotify(false);
                        }

                        if (status == k_Statuses[0] && m_LabelsFoldOut != null)
                        {
                            // Uncheck labels if checked
                            foreach (var t in m_LabelsFoldOut.Children().OfType <Toggle>())
                            {
                                t.value = false;
                            }
                        }
                    }

                    UpdateFiltersIfNeeded();
                });

                m_StatusFoldOut.Add(toggle);
            }
            m_Container.Add(m_StatusFoldOut);

            if (m_Categories.Any())
            {
                m_CategoriesFoldOut = new Foldout {
                    text = L10n.Tr("Categories"), name = k_CategoriesFoldOutName, classList = { k_FoldoutClass }
                };
                foreach (var category in m_Categories)
                {
                    var toggle = new Toggle(L10n.Tr(category))
                    {
                        name = category.ToLower(), classList = { k_ToggleClass }
                    };
                    toggle.RegisterValueChangedCallback(evt => UpdateFiltersIfNeeded());
                    m_CategoriesFoldOut.Add(toggle);
                }

                m_CategoriesFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
                m_Container.Add(m_CategoriesFoldOut);
            }

            if (m_Labels.Any())
            {
                m_LabelsFoldOut = new Foldout {
                    text = L10n.Tr("Labels"), name = k_LabelsFoldOutName, classList = { k_FoldoutClass }
                };
                var i = 0;
                foreach (var label in m_Labels)
                {
                    var toggle = new Toggle(L10n.Tr(label))
                    {
                        name = label, classList = { k_ToggleClass }
                    };
                    toggle.RegisterValueChangedCallback(evt =>
                    {
                        if (evt.newValue)
                        {
                            // Uncheck Unlabeled if checked
                            m_StatusFoldOut.Q <Toggle>(k_Statuses[0].ToLower()).value = false;
                        }
                        UpdateFiltersIfNeeded();
                    });
                    m_LabelsFoldOut.Add(toggle);

                    if (++i > k_MaxDisplayLabels)
                    {
                        UIUtils.SetElementDisplay(toggle, false);
                    }
                }

                m_LabelsFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
                m_Container.Add(m_LabelsFoldOut);
            }
        }
Ejemplo n.º 9
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;
    }
Ejemplo n.º 10
0
        protected override void DoDisplay(IPage page)
        {
            m_StatusFoldOut = new Foldout {
                text = L10n.Tr("Status"), name = k_StatusFoldOutName, classList = { k_FoldoutClass }
            };
            foreach (var status in k_Statuses)
            {
                var toggle = new Toggle(status)
                {
                    name = status.ToLower(), classList = { k_ToggleClass }
                };
                toggle.RegisterValueChangedCallback(evt =>
                {
                    if (evt.newValue)
                    {
                        foreach (var t in m_StatusFoldOut.Children().OfType <Toggle>())
                        {
                            if (t == toggle)
                            {
                                continue;
                            }

                            t.SetValueWithoutNotify(false);
                        }

                        if (status == PageFilters.k_UnlabeledStatus && m_LabelsFoldOut != null)
                        {
                            foreach (var t in m_LabelsFoldOut.Children().OfType <Toggle>())
                            {
                                t.value = false;
                            }
                        }

                        if (status == PageFilters.k_UpdateAvailableStatus)
                        {
                            m_AssetStoreCallQueue.CheckUpdateForUncheckedLocalInfos();
                        }
                    }

                    UpdateFiltersIfNeeded();
                });

                m_StatusFoldOut.Add(toggle);
            }
            m_Container.Add(m_StatusFoldOut);

            if (m_Categories.Any())
            {
                m_CategoriesFoldOut = new Foldout {
                    text = L10n.Tr("Categories"), name = k_CategoriesFoldOutName, classList = { k_FoldoutClass }
                };
                foreach (var category in m_Categories)
                {
                    var toggle = new Toggle(L10n.Tr(category))
                    {
                        name = category.ToLower(), classList = { k_ToggleClass }
                    };
                    toggle.RegisterValueChangedCallback(evt => UpdateFiltersIfNeeded());
                    m_CategoriesFoldOut.Add(toggle);
                }

                m_CategoriesFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
                m_Container.Add(m_CategoriesFoldOut);
            }
        }
    public UtilityAIConsiderationEditor(UtilityAIActionEditor utilityAIActionEditor, UtilityAIConsideration consideration)
    {
        this.consideration         = consideration;
        this.utilityAIActionEditor = utilityAIActionEditor;

        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/UtilityAI/Scripts/Editor/Utility AI Consideration Editor/UtilityAIConsiderationEditor.uxml");

        visualTree.CloneTree(this);

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

        this.styleSheets.Add(stylesheet);

        this.AddToClassList("utilityAIActionEditor");

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

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

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

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

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

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

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

        considerationContainerFoldout.Query <Toggle>().First().AddToClassList("considerationFoldout");

        responseCurveContainer = this.Query <VisualElement>("responseCurve").First();

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

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

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

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

        VisualElement     inputFieldContainer                  = this.Query <VisualElement>("considerationInput").First();
        List <GameObject> considerationInputsPrefabs           = FindPrefabsWithComponent <UtilityAIConsiderationInput>();
        List <UtilityAIConsiderationInput> considerationInputs = new List <UtilityAIConsiderationInput>();

        foreach (GameObject prefab in considerationInputsPrefabs)
        {
            considerationInputs.Add(prefab.GetComponent <UtilityAIConsiderationInput>());
        }
        if (consideration.considerationInput == null)
        {
            consideration.considerationInput = considerationInputs[0];
        }
        Debug.Log(consideration.considerationInput);
        int currentIndex = considerationInputs.IndexOf(consideration.considerationInput);
        PopupField <UtilityAIConsiderationInput> inputFieldPopup = new PopupField <UtilityAIConsiderationInput>("Consideration Inputs: ", considerationInputs, currentIndex);

        inputFieldPopup.RegisterCallback <ChangeEvent <UtilityAIConsiderationInput> >(
            e =>
        {
            consideration.considerationInput = (UtilityAIConsiderationInput)e.newValue;
        }
            );
        inputFieldContainer.Add(inputFieldPopup);

        UpdateResponseCurve();
    }
Ejemplo n.º 12
0
    public DelegateEntryEditor(ExposedDelegateEditor exposedDelegateEditor, DelegateEntry delegateEntry)
    {
        this.exposedDelegateEditor = exposedDelegateEditor;
        this.delegateEntry         = delegateEntry;

        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/UtilityAI/Scripts/Editor/Delegate Entry Editor/DelegateEntryEditor.uxml");

        visualTree.CloneTree(this);

        StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/UtilityAI/Scripts/Editor/Delegate Entry Editor/DelegateEntryEditor.uss");

        this.styleSheets.Add(stylesheet);

        this.AddToClassList("delegateEntryEditor");
        if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor.GetType() == typeof(UtilityAIAgentEditor))
        {
            UtilityAIAgentEditor editorWindow = (UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor;
            if (delegateEntry.TargetGO != editorWindow.utilityAIAgent.gameObject)
            {
                delegateEntry.TargetGO = editorWindow.utilityAIAgent.gameObject;
            }
        }

        delegateEntryFoldout = this.Query <Foldout>("delegateEntry");

        delegateEntryFoldout.Query <Toggle>().First().AddToClassList("delegateEntryFoldout");

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

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

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

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

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

        deleteButton.BringToFront();
        deleteButton.clickable.clicked += DeleteEntry;
        List <Component> components = new List <Component>();

        if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIAgentEditor)
        {
            components = delegateEntry.TargetGO.GetComponents <Component>().ToList();
        }
        else if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIActionSetEditor)
        {
            if (((UtilityAIActionSetEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.inheritingGameObject != null)
            {
                components = ((UtilityAIActionSetEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.inheritingGameObject.GetComponents <Component>().ToList();
            }
        }
        if (components.Count > 0)
        {
            int index = 0;
            if (delegateEntry.Target != null)
            {
                List <Component> sharedComponents = components.Where(o => o.GetType() == delegateEntry.Target.GetType()).ToList();
                if (sharedComponents.Count > 0)
                {
                    index = components.IndexOf(sharedComponents[0]);
                }
                else
                {
                    if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIAgentEditor && ((UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.actionSet != null)
                    {
                        ((UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.MakeActionsSetUnique();
                        ((UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).CreateInspectorGUI();
                        return;
                    }
                }
            }
            PopupField <Component> targetComponentField = new PopupField <Component>("Component: ", components, index);

            delegateEntry.Target = targetComponentField.value;
            targetComponentField.RegisterCallback <ChangeEvent <Component> >(
                e =>
            {
                delegateEntry.Target = (Component)e.newValue;
                exposedDelegateEditor.UpdateDelegateEntries();
            }
                );
            delegateEntryFoldout.Add(targetComponentField);
            if (delegateEntry.Target != null)
            {
                Type         selectedComponentType = delegateEntry.Target.GetType();
                BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
                //Get a list of methods attached to the component, and create a dropdown menu:
                List <MethodInfo>       methods           = selectedComponentType.GetMethods(flags).ToList();
                PopupField <MethodInfo> targetMethodField = new PopupField <MethodInfo>("Method: ", methods, methods.Contains(delegateEntry.Method) ? methods.IndexOf(delegateEntry.Method) : 0);
                if (delegateEntry.Method == null || delegateEntry.Method.Name != targetMethodField.value.Name)
                {
                    delegateEntry.SetMethod(selectedComponentType, targetMethodField.value.Name);
                }
                targetMethodField.RegisterCallback <ChangeEvent <MethodInfo> >(
                    e =>
                {
                    delegateEntry.SetMethod(selectedComponentType, e.newValue.Name);
                    exposedDelegateEditor.UpdateDelegateEntries();
                }
                    );
                delegateEntryFoldout.Add(targetMethodField);
                if (delegateEntry.Method != null && delegateEntry.Parameters.Length > 0)
                {
                    Foldout parametersFoldout = new Foldout();
                    parametersFoldout.text = "Parameters: ";

                    foreach (SerializableObject parameter in delegateEntry.Parameters)
                    {
                        if (parameter.obj is int)
                        {
                            IntegerField parameterField = new IntegerField();
                            parameterField.value = (int)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <int> >(
                                e =>
                            {
                                parameter.obj = (int)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is float)
                        {
                            FloatField parameterField = new FloatField();
                            parameterField.value = (float)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <float> >(
                                e =>
                            {
                                parameter.obj = (float)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is bool)
                        {
                            Toggle parameterField = new Toggle();
                            parameterField.value = (bool)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <bool> >(
                                e =>
                            {
                                parameter.obj = (bool)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is string)
                        {
                            TextField parameterField = new TextField();
                            parameterField.value = (string)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <string> >(
                                e =>
                            {
                                parameter.obj = (string)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is Vector3)
                        {
                            Vector3Field parameterField = new Vector3Field();
                            parameterField.value = (Vector3)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <Vector3> >(
                                e =>
                            {
                                parameter.obj = (Vector3)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is Vector2)
                        {
                            Vector2Field parameterField = new Vector2Field();
                            parameterField.value = (Vector2)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <Vector2> >(
                                e =>
                            {
                                parameter.obj = (Vector2)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is Bounds)
                        {
                            BoundsField parameterField = new BoundsField();
                            parameterField.value = (Bounds)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <Bounds> >(
                                e =>
                            {
                                parameter.obj = (Bounds)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is Rect)
                        {
                            RectField parameterField = new RectField();
                            parameterField.value = (Rect)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <Rect> >(
                                e =>
                            {
                                parameter.obj = (Rect)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is Color)
                        {
                            ColorField parameterField = new ColorField();
                            parameterField.value = (Color)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <Color> >(
                                e =>
                            {
                                parameter.obj = (Color)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                        else if (parameter.obj is UnityEngine.Object)
                        {
                            ObjectField parameterField = new ObjectField();
                            parameterField.value = (UnityEngine.Object)parameter.obj;
                            parameterField.RegisterCallback <ChangeEvent <UnityEngine.Object> >(
                                e =>
                            {
                                parameter.obj = (UnityEngine.Object)e.newValue;
                            }
                                );
                            parametersFoldout.Add(parameterField);
                        }
                    }

                    delegateEntryFoldout.Add(parametersFoldout);
                }
            }
        }

        if (delegateEntry.TargetGO != null)
        {
            delegateEntryFoldout.text += delegateEntry.TargetGO.name;
            if (delegateEntry.Target != null)
            {
                delegateEntryFoldout.text += "(" + delegateEntry.Target.GetType() + ") ";
                if (delegateEntry.Method != null)
                {
                    delegateEntryFoldout.text += delegateEntry.Method.Name;
                }
            }
            delegateEntryFoldout.text += ": ";
        }
        else
        {
            delegateEntryFoldout.text = "New Delegate Entry:";
        }
        if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIActionSetEditor && components.Count <= 0)
        {
            delegateEntryFoldout.text = "No inheriting object selected!";
        }
    }
Ejemplo n.º 13
0
    public override VisualElement CreateInspectorGUI()
    {
        actionList      = rootElement.Query <Foldout>("actionList").First();
        actionContainer = actionList.Query <VisualElement>("actionsContainer").First();

        ObjectField actionSetField = rootElement.Query <ObjectField>("actionSetField").First();

        actionSetField.objectType = typeof(UtilityAIActionSet);
        actionSetField.value      = utilityAIAgent.actionSet;
        actionSetField.RegisterCallback <ChangeEvent <UnityEngine.Object> >(
            e =>
        {
            if (e.newValue == null)
            {
                rootElement.RemoveFromClassList("Derived");
                rootElement.AddToClassList("NotDerived");
                utilityAIAgent.MakeActionsSetUnique();
                UpdateActions();
            }
            else
            {
                rootElement.RemoveFromClassList("NotDerived");
                rootElement.AddToClassList("Derived");
                utilityAIAgent.actionSet = (UtilityAIActionSet)e.newValue;
                utilityAIAgent.actions   = utilityAIAgent.actionSet.actions;
                UpdateActions();
            }
        }
            );

        if (utilityAIAgent.actionSet != null)
        {
            utilityAIAgent.actions = utilityAIAgent.actionSet.actions;
            if (rootElement.ClassListContains("NotDerived"))
            {
                rootElement.RemoveFromClassList("NotDerived");
            }
            rootElement.AddToClassList("Derived");
        }
        else
        {
            if (rootElement.ClassListContains("Derived"))
            {
                rootElement.RemoveFromClassList("Derived");
            }
            rootElement.AddToClassList("NotDerived");
        }

        Button actionSetSaveButton = rootElement.Query <Button>("saveActionSetButton").First();

        actionSetSaveButton.clickable.clicked += SaveActionSet;

        actionList.Query <Toggle>().First().AddToClassList("actionListFoldout");

        UpdateActions();

        Button btnAddAction = rootElement.Query <Button>("btnAddNewAction").First();

        btnAddAction.BringToFront();
        btnAddAction.clickable.clicked += AddAction;

        Button btnDeleteAllActions = rootElement.Query <Button>("btnRemoveAll").First();

        btnDeleteAllActions.BringToFront();
        btnDeleteAllActions.clickable.clicked += RemoveAllActions;

        return(rootElement);
    }