示例#1
0
        private void BindTreeItem(VisualElement element, int index)
        {
            ITreeViewItem item          = this.m_ItemWrappers[index].item;
            VisualElement visualElement = element.Q(TreeView.s_ItemIndentsContainerName, null);

            visualElement.Clear();
            for (int i = 0; i < this.m_ItemWrappers[index].depth; i++)
            {
                VisualElement visualElement2 = new VisualElement();
                visualElement2.AddToClassList(TreeView.s_ItemIndentName);
                visualElement.Add(visualElement2);
            }
            Toggle toggle = element.Q(TreeView.s_ItemToggleName, null);

            toggle.SetValueWithoutNotify(this.IsExpandedByIndex(index));
            toggle.userData = index;
            bool hasChildren = item.hasChildren;

            if (hasChildren)
            {
                toggle.visible = true;
            }
            else
            {
                toggle.visible = false;
            }
            bool flag = this.m_BindItem == null;

            if (!flag)
            {
                VisualElement arg = element.Q(TreeView.s_ItemContentContainerName, null).ElementAt(0);
                this.m_BindItem(arg, item);
            }
        }
    public SpeakEasyNode InitializeNode(SpeakEasyNode node, Vector2 position, NodeType nodeTypeChoice)
    {
        //Actual logic for the creation of the node
        //This is the UI layout

        //Set the color of the node so it's not super transparent.
        node.mainContainer.style.backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f);

        //Initialize the Label of the Node, determining if it's a SPEECH or RESPONSE node
        Label nodeTypeLabel = new Label();

        nodeTypeLabel.style.fontSize  = 15;
        nodeTypeLabel.style.alignSelf = Align.Center;
        if (node.nodeType == NodeType.speech)
        {
            nodeTypeLabel.text = "SPEECH";
            node.titleContainer.style.backgroundColor = speechColor;
        }

        else
        {
            nodeTypeLabel.text = "RESPONSE";
            node.titleContainer.style.backgroundColor = responseColor;
        }

        node.titleContainer.Add(nodeTypeLabel);

        //The integer field, this field references the index in the Localization file. It's a read only field.
        IntegerField stringIndexField = new IntegerField("String Index:");

        stringIndexField.SetEnabled(false); //We shouldn't be able to directly edit this value.
        node.mainContainer.Add(stringIndexField);

        //This is the "text preview" which we morphed into a auto-localization file. The editor on save stores this data back into the specified XML file.
        TextField textPreviewField = new TextField();

        textPreviewField.multiline        = true;
        textPreviewField.style.maxWidth   = 350;
        textPreviewField.style.whiteSpace = WhiteSpace.Normal;
        textPreviewField.SetEnabled(false);
        textPreviewField.isDelayed = true;
        node.mainContainer.Add(textPreviewField);


        //adds an ID reference so we can see the GUID
        Label idReference = new Label(node.nodeID);

        node.mainContainer.Add(idReference);
        idReference.style.color = new Color(0.75f, 0.75f, 0.75f);


        //This is the stringRefField, aka the identifier for our string. This is what we store in our file data.
        TextField stringRefField = new TextField("String Reference:");

        stringRefField.isDelayed = true;
        stringRefField.RegisterValueChangedCallback(evt =>
        {
            node.stringReference = evt.newValue;                       //set the node's string reference to the new Value
            Debug.Log("Saving localization data");
            SetLocalizationIdentifier(node.stringIndex, evt.newValue); //Sets the localization identifier for the index if one is specified.
        });
        node.mainContainer.Add(stringRefField);
        stringRefField.SetValueWithoutNotify(node.stringReference);
        stringIndexField.SetValueWithoutNotify(FindStringIndex(node.stringReference)); //Look up our string reference identifier and return the index if one exists.
        //We need to set the stringIndex of the node too.
        node.stringIndex = stringIndexField.value;                                     // set the node's internal value to the stringIndexField value.
        textPreviewField.SetValueWithoutNotify(GetStringIndex(node.stringIndex));      //Update the localized box auto match the .. you know what this does.

        textPreviewField.RegisterValueChangedCallback(evt =>
        {
            Debug.Log("Saving localization data");
            SetLocalizationText(node.stringIndex, evt.newValue); //If we change the text in this field, update the localization table to match our new entry.
        });

        //This button will give us a brand new spanking place in the localization file hashtag smiley face
        Button addNewTableEntryButton = null;  //I do not understand this logic...

        addNewTableEntryButton = new Button(() => AddNewTableEntry(addNewTableEntryButton, node, stringIndexField, textPreviewField))
        {
            text = "Add Table Entry"
        };

        if (localText == null)
        {
            addNewTableEntryButton.SetEnabled(false);
        }

        node.mainContainer.Add(addNewTableEntryButton);
        //Check if we already have this data
        if (CheckIfStringReferenceExists(node.stringReference))
        {
            //We already have our connection
            addNewTableEntryButton.SetEnabled(false);
            textPreviewField.SetEnabled(true);
        }

        //Serialize Save/Load for Audio Clips and Animation Trigger
        ObjectField audioField = new ObjectField("Audio Field");

        audioField.objectType        = typeof(AudioClip);
        audioField.allowSceneObjects = false;
        audioField.SetEnabled(false);
        node.mainContainer.Add(audioField);

        TextField animationTriggerField = new TextField("Animation Trigger");

        animationTriggerField.SetEnabled(false);
        node.mainContainer.Add(animationTriggerField);

        UnityEngine.UIElements.Toggle entryPointToggle = new UnityEngine.UIElements.Toggle("Entry Point");
        entryPointToggle.RegisterValueChangedCallback(evt =>
        {
            node.isEntryPoint = evt.newValue;
        });
        node.mainContainer.Add(entryPointToggle);

        entryPointToggle.SetValueWithoutNotify(node.isEntryPoint);

        IntegerField priorityField = new IntegerField("Priority:");

        priorityField.RegisterValueChangedCallback(evt =>
        {
            node.priority = evt.newValue;
        });
        priorityField.SetValueWithoutNotify(node.priority);
        node.mainContainer.Add(priorityField);

        /*
         * ObjectField testRef = new ObjectField("OnConditional");
         * testRef.objectType = typeof(SpeakEasyLogics_Test);
         * testRef.allowSceneObjects = false;
         * node.mainContainer.Add(testRef);
         *
         * ObjectField eventRef = new ObjectField("OnFire");
         * eventRef.objectType = typeof(SpeakEasyLogics_Event);
         * eventRef.allowSceneObjects = false;
         * node.mainContainer.Add(eventRef);
         */

        //adds a OnConditional reference
        ObjectField testRefField = new ObjectField("Test Script Ref:");

        testRefField.objectType        = typeof(SpeakEasyLogics_Test);
        testRefField.allowSceneObjects = false;
        testRefField.RegisterValueChangedCallback(evt =>
        {
            node.scriptTest = (evt.newValue as SpeakEasyLogics_Test);
            //SpeakEasyNode startNode = (startPort.node as SpeakEasyNode);
        });

        node.mainContainer.Add(testRefField);
        testRefField.SetValueWithoutNotify(node.scriptTest);

        //adds a OnFire reference
        ObjectField eventRefField = new ObjectField("Event Script Ref:");

        eventRefField.objectType        = typeof(SpeakEasyLogics_Event);
        eventRefField.allowSceneObjects = false;
        eventRefField.RegisterValueChangedCallback(evt =>
        {
            node.scriptEvent = (evt.newValue as SpeakEasyLogics_Event);
        });

        node.mainContainer.Add(eventRefField);
        eventRefField.SetValueWithoutNotify(node.scriptEvent);

        //This port is the IN connection, this is where we will lead the conversation TO. The Input can recieve a number of connections from conversation choices
        Port inputPort = GetPortInstance(node, Direction.Input, Port.Capacity.Multi);

        node.inputConnection = inputPort;
        inputPort.portName   = "Connections";
        node.inputContainer.Add(inputPort);


        Port outputPort = GetPortInstance(node, Direction.Output, Port.Capacity.Multi);

        node.outputConnection = outputPort;
        outputPort.portName   = "Responses";
        node.outputContainer.Add(outputPort);


        //
        //node.outputContainer.style.flexDirection <-- this is what I was looking for last night! controls the direction of the container?

        node.RefreshExpandedState();
        node.RefreshPorts();

        node.SetPosition(new Rect(position, defaultNodeSize));

        Button debugTestValues = new Button(() => PrintValues(node, inputPort, outputPort))
        {
            text = "Print Values"
        };

        node.mainContainer.Add(debugTestValues);

        return(node);
    }
示例#3
0
 public void SetExpandedWithoutNotify(bool expanded)
 {
     m_Toggle?.SetValueWithoutNotify(expanded);
 }
        public static void BuildInspectorPropertiesElement(string elementPath, IEditorContainer editor, System.Collections.Generic.HashSet <System.Type> usedComponents, SerializedProperty obj, UnityEngine.UIElements.VisualElement container, bool noFields, System.Action <int, PropertyField> onBuild = null)
        {
            obj = obj.Copy();
            container.Clear();
            var source = obj.Copy();
            SerializedProperty iterator = obj;

            if (iterator.NextVisible(true) == false)
            {
                return;
            }
            if (iterator.NextVisible(true) == false)
            {
                return;
            }
            var depth        = iterator.depth;
            var i            = 0;
            var iteratorNext = iterator.Copy();

            do
            {
                if (string.IsNullOrEmpty(elementPath) == false)
                {
                    iterator = iteratorNext.FindPropertyRelative(elementPath);
                }
                else
                {
                    iterator = iteratorNext;
                }
                if (iterator.propertyType != SerializedPropertyType.ManagedReference)
                {
                    continue;
                }

                var element = new VisualElement();
                element.AddToClassList("element");

                var itCopy = iterator.Copy();
                GetTypeFromManagedReferenceFullTypeName(iterator.managedReferenceFullTypename, out var type);
                element.AddToClassList(i % 2 == 0 ? "even" : "odd");
                element.RegisterCallback <UnityEngine.UIElements.ContextClickEvent, int>((evt, idx) => {
                    var menu = new GenericMenu();
                    if (usedComponents != null)
                    {
                        menu.AddItem(new GUIContent("Delete"), false, () => {
                            RemoveComponent((DataConfigEditor)editor, usedComponents, source, type, noFields);
                            editor.Save();
                            BuildInspectorProperties(editor, usedComponents, source, container, noFields);
                        });

                        menu.AddItem(new GUIContent("Copy JSON"), false, () => {
                            var instance = itCopy.GetValue();
                            var json     = JsonUtility.ToJson(instance, true);
                            EditorGUIUtility.systemCopyBuffer = json;
                        });
                    }

                    editor.OnComponentMenu(menu, idx);
                    menu.ShowAsContext();
                }, i);

                if (type != null && usedComponents?.Contains(type) == false)
                {
                    usedComponents?.Add(type);
                }
                if (type == null)
                {
                    var label = new UnityEngine.UIElements.Label("MISSING: " + iterator.managedReferenceFullTypename);
                    element.name = "missing";
                    label.AddToClassList("inner-element");
                    label.AddToClassList("missing-label");
                    element.Add(label);
                }
                else if (iterator.hasVisibleChildren == false || noFields == true)
                {
                    var horizontal = new UnityEngine.UIElements.VisualElement();
                    horizontal.AddToClassList("inner-element");
                    horizontal.AddToClassList("no-fields-container");
                    element.name = type.Name;

                    var toggle = new UnityEngine.UIElements.Toggle();
                    toggle.AddToClassList("no-fields-toggle");
                    toggle.SetEnabled(false);
                    toggle.SetValueWithoutNotify(true);
                    horizontal.Add(toggle);

                    var label = new UnityEngine.UIElements.Label(GUILayoutExt.GetStringCamelCaseSpace(type.Name));
                    label.AddToClassList("no-fields-label");
                    horizontal.Add(label);

                    element.Add(horizontal);
                }
                else
                {
                    var label = GUILayoutExt.GetStringCamelCaseSpace(type.Name);
                    if (iterator.hasVisibleChildren == true)
                    {
                        var childs = iterator.Copy();
                        //var height = EditorUtilities.GetPropertyHeight(childs, true, new GUIContent(label));
                        var cnt = EditorUtilities.GetPropertyChildCount(childs);
                        if (cnt == 1 /*&& height <= 22f*/)
                        {
                            iterator.NextVisible(true);
                        }
                    }

                    var propertyField = new PropertyField(iterator.Copy(), label);
                    propertyField.BindProperty(iterator);
                    onBuild?.Invoke(i, propertyField);
                    propertyField.AddToClassList("property-field");
                    propertyField.AddToClassList("inner-element");
                    element.name = type.Name;
                    element.Add(propertyField);
                }

                if (type != null)
                {
                    var helps = type.GetCustomAttributes(typeof(ComponentHelpAttribute), false);
                    if (helps.Length > 0)
                    {
                        var label = new UnityEngine.UIElements.Label(((ComponentHelpAttribute)helps[0]).comment);
                        label.AddToClassList("comment");
                        element.Add(label);
                    }

                    if (typeof(IComponentStatic).IsAssignableFrom(type) == true)
                    {
                        var label = new UnityEngine.UIElements.Label("Static");
                        label.AddToClassList("static-component");
                        element.AddToClassList("has-static-component");
                        element.Add(label);
                    }

                    if (typeof(IComponentShared).IsAssignableFrom(type) == true)
                    {
                        var label = new UnityEngine.UIElements.Label("Shared");
                        label.AddToClassList("shared-component");
                        element.AddToClassList("has-shared-component");
                        element.Add(label);
                    }
                }

                container.Add(element);
                ++i;
            } while (iteratorNext.NextVisible(false) == true && depth <= iteratorNext.depth);
        }