public static RenameWindow Open(System.Action <ModalWindow> owner, string title, string text, Vector2 position)
        {
            RenameWindow renameWindow = RenameWindow.CreateInstance <RenameWindow>();

            renameWindow.Del          = owner;
            renameWindow.titleContent = new GUIContent(title);
            renameWindow._text        = text;

            float halfWidth = Width / 2;

            float x = position.x - halfWidth;
            float y = position.y;

            float height = Height + (FieldHeight);

            Rect rect = new Rect(x, y, 0, 0);

            renameWindow.position = rect;
            renameWindow.ShowAsDropDown(rect, new Vector2(Width, height));

            return(renameWindow);
        }
示例#2
0
        protected override void OnBeginDrawEditors()
        {
            var selected      = this.MenuTree.Selection.FirstOrDefault();
            var toolbarHeight = this.MenuTree.Config.SearchToolbarHeight;

            SirenixEditorGUI.BeginHorizontalToolbar(toolbarHeight);
            if (SirenixEditorGUI.ToolbarButton("Backup DBs"))
            {
                SaveDbs();
            }
            if (SirenixEditorGUI.ToolbarButton("Load DB Backup"))
            {
                LoadDbs();
            }
            if (selected == null)
            {
                if (SirenixEditorGUI.ToolbarButton(new GUIContent("Close")))
                {
                    Close();
                }
                SirenixEditorGUI.EndHorizontalToolbar();
                return;
            }
            GUILayout.Label(selected.Name);
            if (selected.Value is ScriptableDatabase db)
            {
                GUILayout.Label(db.DbType?.Name);
            }
            else
            {
                if (SirenixEditorGUI.ToolbarButton(new GUIContent("Rename " + selected.Name)))
                {
                    RenameWindow.Open(
                        (m) => {
                        AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(selected.Value as UnityEngine.Object), ((RenameWindow)m).Text);
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                        BuildMenuTree();
                    },
                        "Rename",
                        selected.Name);
                }
                if (SirenixEditorGUI.ToolbarButton(new GUIContent("Duplicate " + selected.Name)))
                {
                    var dupePath     = AssetDatabase.GetAssetPath(selected.Value as UnityEngine.Object);
                    var newAssetPath = AssetDatabase.GenerateUniqueAssetPath(dupePath);
                    AssetDatabase.CopyAsset(dupePath, newAssetPath);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                    var newObj = AssetDatabase.LoadMainAssetAtPath(newAssetPath);
                    if (newObj != null)
                    {
                        BuildMenuTree();
                        base.TrySelectMenuItemWithObject(newObj);
                    }
                }
                if (SirenixEditorGUI.ToolbarButton(new GUIContent("Save " + selected.Name)))
                {
                    string path = EditorUtility.SaveFilePanel("Location", Application.streamingAssetsPath, selected.Name, "json");
                    if (path.Length > 0)
                    {
                        var serialized = JsonConvert.SerializeObject(new SerializedScriptableObject(selected.Value as ScriptableObject), Formatting.Indented, Serializer.ConverterSettings);
                        FileUtility.SaveFile(path, serialized);
                    }
                }
                if (SirenixEditorGUI.ToolbarButton(new GUIContent("Load Over " + selected.Name)))
                {
                    string path = EditorUtility.OpenFilePanel("Location", Application.streamingAssetsPath, "json");
                    if (path.Length > 0)
                    {
                        var converted = JsonConvert.DeserializeObject <SerializedScriptableObject>(FileUtility.ReadFile(path), Serializer.ConverterSettings);
                        converted.Restore();
                        UnityEditor.EditorJsonUtility.FromJsonOverwrite(converted.SerializedValue, converted.Value);
                        EditorUtility.CopySerialized(converted.Value, selected.Value as ScriptableObject);
                    }
                }
            }
            if (SirenixEditorGUI.ToolbarButton(new GUIContent("Select " + selected.Name)))
            {
                Selection.activeObject = selected.Value as UnityEngine.Object;
            }
            if (SirenixEditorGUI.ToolbarButton(new GUIContent("Close")))
            {
                Close();
            }
            SirenixEditorGUI.EndHorizontalToolbar();
        }