Skip to content

Instantly share code, notes, and snippets.

@tylertomaseski
Created February 9, 2021 22:53
Show Gist options
  • Save tylertomaseski/1ff2c7977d238a3b3e6ab807a8165255 to your computer and use it in GitHub Desktop.
Save tylertomaseski/1ff2c7977d238a3b3e6ab807a8165255 to your computer and use it in GitHub Desktop.
A simple server file explorer for Unisave and OdinInspector
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities.Editor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public class ServerFileExplorer : OdinMenuEditorWindow
{
const string FolderLocation = "Assets/Conceptual/Backend";
[MenuItem("Tools/Server File Explorer")]
public static void CreateMenu()
{
GetWindow<ServerFileExplorer>();
}
protected override OdinMenuTree BuildMenuTree()
{
var tree = new OdinMenuTree();
//Code
tree.AddAllAssetsAtPath("Server Code", FolderLocation, true, false).AddThumbnailIcons();
return tree;
}
protected override void OnBeginDrawEditors()
{
base.OnBeginDrawEditors();
if (this.MenuTree == null)
return;
OdinMenuTreeSelection selected = this.MenuTree.Selection;
SirenixEditorGUI.BeginHorizontalToolbar();
{
if (SirenixEditorGUI.ToolbarButton("OPEN"))
{
if (typeof(ScriptableObject).IsAssignableFrom(selected.SelectedValue.GetType()))
{
Selection.SetActiveObjectWithContext(selected.SelectedValue as UnityEngine.ScriptableObject, null);
}
else
{
bool opened = AssetDatabase.OpenAsset(selected.SelectedValue as UnityEngine.Object);
}
}
GUILayout.FlexibleSpace();
}
SirenixEditorGUI.EndHorizontalToolbar();
}
protected override void OnDestroy()
{
base.OnDestroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment