예제 #1
0
    public void Start()
    {
        var elementsInDOM = new List <UnityEngine.UIElements.VisualElement>();

        this.getAllContainedElements(uIDocument.rootVisualElement, ref elementsInDOM);

        for (int i = 0; i < elementsInDOM.Count; i++)
        {
            if (BUTTON_TOWER_1 == elementsInDOM[i].name)
            {
                buttonSelectTower1 = (UnityEngine.UIElements.Button)elementsInDOM[i];
            }
            else if (BUTTON_TOWER_2 == elementsInDOM[i].name)
            {
                buttonSelectTower2 = (UnityEngine.UIElements.Button)elementsInDOM[i];
            }
            else if (BUTTON_TOWER_3 == elementsInDOM[i].name)
            {
                buttonSelectTower3 = (UnityEngine.UIElements.Button)elementsInDOM[i];
            }
            else if (BUTTON_TOWER_4 == elementsInDOM[i].name)
            {
                buttonSelectTower4 = (UnityEngine.UIElements.Button)elementsInDOM[i];
            }
            else if (BUTTON_TOWER_5 == elementsInDOM[i].name)
            {
                buttonSelectTower5 = (UnityEngine.UIElements.Button)elementsInDOM[i];
            }
            else if (BUTTON_TOWER_6 == elementsInDOM[i].name)
            {
                buttonSelectTower6 = (UnityEngine.UIElements.Button)elementsInDOM[i];
            }
            else if (BUTTON_TOWER_7 == elementsInDOM[i].name)
            {
                buttonSelectTower7 = (UnityEngine.UIElements.Button)elementsInDOM[i];
            }
            else if (LABEL_MONEY == elementsInDOM[i].name)
            {
                moneyLabel = (UnityEngine.UIElements.Label)elementsInDOM[i];
            }
        }

        buttonSelectTower1.clicked += ButtonSelectTower1Clicked;
        buttonSelectTower2.clicked += ButtonSelectTower2Clicked;
        buttonSelectTower3.clicked += ButtonSelectTower3Clicked;
        buttonSelectTower4.clicked += ButtonSelectTower4Clicked;
        buttonSelectTower5.clicked += ButtonSelectTower5Clicked;
        buttonSelectTower6.clicked += ButtonSelectTower6Clicked;
        buttonSelectTower7.clicked += ButtonSelectTower7Clicked;
    }
예제 #2
0
    public StartNode(Vector2 _position, LevelEditorWindow _editorWindow, LevelFlowGraphView _graphView)
    {
        title = "Enter";
        SetPosition(new Rect(_position, defaultNodeSize));

        UnityEngine.UIElements.Label label_statName = new UnityEngine.UIElements.Label("name");
        mainContainer.Add(label_statName);

        startNameTextField = new TextField(""); //傳入label標籤,會跟對應到的label同行,否則獨立一行
        startNameTextField.RegisterValueChangedCallback(value =>
        {
            startName = value.newValue;
        });

        startNameTextField.SetValueWithoutNotify(startName);
        mainContainer.Add(startNameTextField);

        _graphView.AddToClassList("GraphViewStyleSheet");

        SetUpPort();

        RefreshExpandedState();
        RefreshPorts();
    }
예제 #3
0
        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);
        }