I don’t understand what I am doing wrong. I have messed with the path for this function a dozen different ways and it never loads my layout.
What this class is suppose to do is switch the Unity layout between two of my custom layouts for play mode and editor mode.
Could someone please help? I thought I was adding a basic feature and now I’ve wasted a bunch of time on this. ;(
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class LayoutSwitcher
{
private const string playLayout = "NdoggTesting";
private const string editorLayout = "Ndogg";
static LayoutSwitcher()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
private static void OnPlayModeStateChanged(PlayModeStateChange state)
{
if (state == PlayModeStateChange.EnteredPlayMode)
{
SwitchToLayout(playLayout);
}
else if (state == PlayModeStateChange.ExitingPlayMode)
{
SwitchToLayout(editorLayout);
}
}
private static void SwitchToLayout(string layoutName)
{
var layout = EditorGUIUtility.Load("Layouts/" + layoutName + ".wlt") as EditorWindow;
if (layout != null)
{
layout.Show();
EditorApplication.ExecuteMenuItem("Window/Layouts/" + layoutName);
}
else
{
Debug.LogError("Layout " + layoutName + " not found!");
}
}
}