コード例 #1
0
        public override void CreateNode()
        {
            title = "Colour Texture";

            outputPort          = NodeFactory.GeneratePort(this, Direction.Output, typeof(Texture2D), Port.Capacity.Multi);
            outputPort.portName = "Out";
            outputContainer.Add(outputPort);

            VisualElement colourContainer = new VisualElement();

            colourContainer.style.flexDirection = FlexDirection.Row;
            colourContainer.style.marginLeft    = colourContainer.style.marginRight = 5;

            var colourLabel = new Label("Colour");

            colourLabel.style.unityTextAlign = TextAnchor.MiddleLeft;
            colourContainer.Add(colourLabel);

            colourField             = new ColorField();
            colourField.value       = Color.white;
            colourField.style.width = 100f;
            colourContainer.Add(colourField);

            colourField.RegisterCallback <ChangeEvent <Color> >(e => UpdateTexture());

            inputContainer.Add(colourContainer);

            RefreshExpandedState();
            RefreshPorts();
        }
コード例 #2
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!";
        }
    }
コード例 #3
0
    public OrbitLineSubEditor(StarSystemEditor starSystemEditor, OrbitLine orbitLine)
    {
        this.starSystemEditor = starSystemEditor;
        this.orbitLine        = orbitLine;

        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Examples/StarSystemScene/Scripts/Editor/StarSystemEditor/OrbitLineSubEditor.uxml");

        visualTree.CloneTree(this);

        StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/StarSystemScene/Scripts/Editor/StarSystemEditor/OrbitLineSubEditor.uss");

        this.styleSheets.Add(stylesheet);

        this.AddToClassList("orbitLineSubEditor");

        // Store visual element that will contain the planet sub-inspectors.
        planetList = this.Query <VisualElement>("planetList").First();
        UpdatePlanets();

        noteList = this.Query <VisualElement>("noteList").First();
        UpdateNotes();


        #region Fields
        TextField stringField = this.Query <TextField>("orbitName").First();
        stringField.value = orbitLine.name;
        stringField.RegisterCallback <ChangeEvent <string> >(
            e =>
        {
            orbitLine.name = (string)e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        Slider distanceField = this.Query <Slider>("orbitDistance").First();
        distanceField.value = orbitLine.orbitDistance;
        distanceField.label = "Orbit Distance " + distanceField.value.ToString("F2");
        distanceField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            orbitLine.orbitDistance = e.newValue;
            distanceField.label     = "Orbit Distance " + e.newValue.ToString("F2");
            EditorUtility.SetDirty(orbitLine);
        }
            );


        Slider thicknessField = this.Query <Slider>("thickness").First();
        thicknessField.value = orbitLine.thickness;
        thicknessField.label = "Thickness " + thicknessField.value.ToString("F3");
        thicknessField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            orbitLine.thickness  = e.newValue;
            thicknessField.label = "Thickness " + e.newValue.ToString("F3");
            EditorUtility.SetDirty(orbitLine);
        }
            );

        IntegerField segmentsField = this.Query <IntegerField>("segments").First();
        segmentsField.value = orbitLine.segments;
        segmentsField.RegisterCallback <ChangeEvent <int> >(
            e =>
        {
            orbitLine.segments = e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        ColorField colorField = this.Query <ColorField>("color").First();
        colorField.value = orbitLine.color;
        colorField.RegisterCallback <ChangeEvent <Color> >(
            e =>
        {
            orbitLine.color = e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        Toggle waypointField = this.Query <Toggle>("useWaypoints").First();
        waypointField.value = orbitLine.useWaypoints;
        waypointField.RegisterCallback <ChangeEvent <bool> >(
            e =>
        {
            orbitLine.useWaypoints = e.newValue;
            EditorUtility.SetDirty(orbitLine);
        }
            );

        #endregion

        #region Buttons
        // Assign methods to the click events of the two buttons.
        Button btnAddPlanet = this.Query <Button>("btnAddNewPlanet").First();
        btnAddPlanet.clickable.clicked += AddPlanet;

        Button btnRemoveAllPlanets = this.Query <Button>("btnRemoveAllPlanets").First();
        btnRemoveAllPlanets.clickable.clicked += RemoveAllPlanets;

        // Assign methods to the click events of the two buttons.
        Button btnAddNote = this.Query <Button>("btnAddNewNote").First();
        btnAddNote.clickable.clicked += AddNote;

        Button btnRemoveAllNotes = this.Query <Button>("btnRemoveAllNotes").First();
        btnRemoveAllNotes.clickable.clicked += RemoveAllNotes;



        Button btnRemoveOrbit = this.Query <Button>("btnRemoveOrbitLine").First();
        btnRemoveOrbit.clickable.clicked += RemoveOrbitLine;
        #endregion
    }