Skip to content

Instantly share code, notes, and snippets.

@Novack
Forked from LotteMakesStuff/LayoutUtils.cs
Last active April 20, 2019 13:56
Show Gist options
  • Select an option

  • Save Novack/adc8a97cef139289b2f8a1576eeae707 to your computer and use it in GitHub Desktop.

Select an option

Save Novack/adc8a97cef139289b2f8a1576eeae707 to your computer and use it in GitHub Desktop.
Simple tool for importing editor layout files (.wlt files) from the asset folder. this is cool cos you can then share layouts with your team via source control
// put me in an Editor folder
using System.IO;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
public static class LayoutUtils
{
// unity stores layouts in a path referenced in WindowLayout.LayoutsPreferencesPath.
// Unfortunately, thats internal - well just creat the path in the same way they do!
// github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/GUI/WindowLayout.cs#L980
static string layoutsPreferencesPath => Path.Combine(InternalEditorUtility.unityPreferencesFolder, "Layouts");
[MenuItem("Assets/Import Editor Layout", priority = 10000)]
static void ImportEditorLayout()
{
Debug.Log("Attempting to import layout: " + Selection.activeObject.name);
// install the layout file by copying it to the layout folder
string sourcePath = AssetDatabase.GetAssetPath(Selection.activeObject);
// https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/GUI/WindowLayout.cs#L1088
string destinationPath = Path.Combine(layoutsPreferencesPath, Selection.activeObject.name + ".wlt");
File.Copy(sourcePath, destinationPath, true);
// instruct unity to reload layouts
InternalEditorUtility.ReloadWindowLayoutMenu();
}
[MenuItem("Assets/Import Editor Layout", priority = 10000, validate = true)]
static bool ValidateImportEditorLayout()
{
// we only work on a single selected asset...
if (Selection.objects.Length != 1)
return false;
// lets check if the asset is a layout file
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
return path.EndsWith(".wlt");
}
[MenuItem("Window/Open Editor Layouts folder", priority = 10000)]
static void OpenlayoutsFolder()
{
Debug.Log("Attempting to import layout: " + Selection.activeObject.name);
EditorUtility.RevealInFinder(layoutsPreferencesPath+"/default");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment