Exemple #1
0
        public static void CreateWindow()
        {
            ItemEditor wnd = GetWindow <ItemEditor>();

            wnd.minSize      = ItemEditorSettings.GetOrCreate().minWindowSize;
            wnd.titleContent = new GUIContent("道具编辑器");
        }
Exemple #2
0
        public static void CreateWindow(ItemNew item)
        {
            ItemEditor wnd = GetWindow <ItemEditor>();

            wnd.minSize                  = ItemEditorSettings.GetOrCreate().minWindowSize;
            wnd.titleContent             = new GUIContent("道具编辑器");
            EditorApplication.delayCall += () => wnd.itemList.SetSelection(wnd.items.IndexOf(item));
        }
Exemple #3
0
        public static void CreateWindow(ItemTemplate template)
        {
            ItemEditor wnd = GetWindow <ItemEditor>();

            wnd.minSize                  = ItemEditorSettings.GetOrCreate().minWindowSize;
            wnd.titleContent             = new GUIContent("道具编辑器");
            EditorApplication.delayCall += () =>
            {
                wnd.funcTab.SetSelected(2);
                wnd.StartCoroutine(selete());

                IEnumerator selete()
                {
                    yield return(new WaitForEndOfFrame());

                    wnd.templateList.SetSelection(wnd.templates.IndexOf(template));
                }
            };
        }
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("编辑"))
            {
                bool isSub    = AssetDatabase.IsSubAsset(target);
                bool database = ItemEditorSettings.GetOrCreate().useDatabase;
                if (isSub && database || !isSub && !database)
                {
                    ItemEditor.CreateWindow(target as ItemNew);
                }
                else if (database)
                {
                    EditorUtility.DisplayDialog("错误", "道具编辑器处于数据库模式,不支持混用!", "确定");
                }
                else
                {
                    EditorUtility.DisplayDialog("错误", "道具编辑器处于非数据库模式,不支持混用!", "确定");
                }
            }
            serializedObject.UpdateIfRequiredOrScript();
            EditorGUI.BeginDisabledGroup(true);
            SerializedProperty iterator = serializedObject.GetIterator();

            if (iterator != null)
            {
                bool enterChildren = true;
                while (iterator.NextVisible(enterChildren) && iterator.propertyPath != "modules")
                {
                    if ("m_Script" != iterator.propertyPath)
                    {
                        EditorGUILayout.PropertyField(iterator, true);
                    }
                    enterChildren = false;
                }
            }
            EditorGUI.EndDisabledGroup();
        }
Exemple #5
0
        public void CreateGUI()
        {
            try
            {
                settings    = settings ? settings : ItemEditorSettings.GetOrCreate();
                useDatabase = settings.useDatabase;

                VisualElement root = rootVisualElement;

                var visualTree = settings.treeUxml;
                visualTree.CloneTree(root);
                var styleSheet = settings.treeUss;
                root.styleSheets.Add(styleSheet);

                searchField = root.Q <ToolbarSearchField>("search-input");
                searchField.RegisterValueChangedCallback(new EventCallback <ChangeEvent <string> >(evt =>
                {
                    DoSearchDropdown(evt.newValue);
                }));
                searchDropdown          = root.Q <UnityEngine.UIElements.ListView>("search-dropdown");
                searchDropdown.makeItem = () => new Label()
                {
                    enableRichText = true
                };
                searchDropdown.onSelectionChange += OnSearchListSelected;
                root.RegisterCallback <PointerDownEvent>(evt =>
                {
                    if (!string.IsNullOrEmpty(searchField.value) && !searchDropdown.Contains(evt.target as VisualElement))
                    {
                        searchField.value = string.Empty;
                    }
                });
                DoSearchDropdown();
                searchSelector = root.Q <DropdownField>("search-selector");
                searchSelector.RegisterValueChangedCallback(evt =>
                {
                    keyType = (SearchKeyType)searchSelector.choices.IndexOf(evt.newValue);
                });

                funcTab = root.Q <TabbedBar>();
                funcTab.Refresh(new string[] { "道具", "模板" }, OnFuncTab);
                funcTab.onRightClick = OnRightFuncTab;

                Button refresh = root.Q <Button>("refresh-button");
                refresh.clicked += Refresh;
                Button newButton = root.Q <Button>("new-button");
                newButton.clicked    += OnNewClick;
                deleteButton          = root.Q <Button>("delete-button");
                deleteButton.clicked += OnDeleteClick;
                RefreshDeleteButton();

                oldItem            = root.Q <ObjectField>("old-item");
                oldItem.objectType = typeof(ItemBase);
                Button oldButton = root.Q <ToolbarButton>("copy-button");
                oldButton.clicked += OnCopyClick;
                oldButton          = root.Q <ToolbarButton>("copy-all-button");
                oldButton.clicked += OnCopyAllClick;

                listLabel = root.Q <Label>("list-label");

                templateSelector = root.Q <DropdownField>("template-dropdown");
                templateSelector.RegisterValueChangedCallback(OnTemplateSelected);
                RefreshTemplateSelector();

                itemList = root.Q <UnityEngine.UIElements.ListView>("item-list");
                itemList.selectionType = SelectionType.Multiple;
                itemList.makeItem      = () =>
                {
                    var label = new Label();
                    label.AddManipulator(new ContextualMenuManipulator(evt =>
                    {
                        if (label.userData is ItemNew item)
                        {
                            evt.menu.AppendAction("定位", a => EditorGUIUtility.PingObject(item));
                            evt.menu.AppendAction("删除", a => DeleteItem(item));
                        }
                    }));
                    return(label);
                };
                itemList.bindItem = (e, i) =>
                {
                    (e as Label).text = !string.IsNullOrEmpty(items[i].Name) ? items[i].Name : "(未命名道具)";
                    e.userData        = items[i];
                };
                itemList.onSelectionChange += (os) => OnListItemSelected(os.Select(x => x as ItemNew));
                RefreshItems();

                templateList = root.Q <UnityEngine.UIElements.ListView>("template-list");
                templateList.selectionType = SelectionType.Multiple;
                templateList.makeItem      = () =>
                {
                    var label = new Label();
                    label.AddManipulator(new ContextualMenuManipulator(evt =>
                    {
                        if (label.userData is ItemTemplate template)
                        {
                            evt.menu.AppendAction("定位", a => EditorGUIUtility.PingObject(template));
                            evt.menu.AppendAction("删除", a => DeleteTemplate(template));
                        }
                    }));
                    return(label);
                };
                templateList.bindItem = (e, i) =>
                {
                    (e as Label).text = !string.IsNullOrEmpty(templates[i].Name) ? templates[i].Name : "(未命名模板)";
                    e.userData        = templates[i];
                };
                templateList.onSelectionChange += (os) => OnListTemplateSelected(os.Select(x => x as ItemTemplate));
                RefreshTemplates();

                rightPanel        = root.Q <ScrollView>("right-panel");
                itemContainer     = root.Q("item-container");
                templateContainer = root.Q("template-container");

                Undo.undoRedoPerformed += RefreshModules;

                funcTab.SetSelected(1);

                root.RegisterCallback(new EventCallback <KeyDownEvent>(evt =>
                {
                    if (hasFocus && evt.keyCode == KeyCode.Delete)
                    {
                        OnDeleteClick();
                    }
                }));
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }