Skip to content

Commit

Permalink
Fixed Unity clearing GitWindows list when assigned during definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonradivoev committed Aug 10, 2017
1 parent f146d97 commit e82d7c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
11 changes: 7 additions & 4 deletions Assets/Plugins/UniGit/Editor/GitSettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ private void GoToHelp()

public void AddItemsToMenu(GenericMenu menu)
{
foreach (var settingsTab in tabs)
if (tabs != null)
{
var customMenu = settingsTab as IHasCustomMenu;
if (customMenu != null)
foreach (var settingsTab in tabs)
{
customMenu.AddItemsToMenu(menu);
var customMenu = settingsTab as IHasCustomMenu;
if (customMenu != null)
{
customMenu.AddItemsToMenu(menu);
}
}
}
menu.AddItem(new GUIContent("Help"),false, GoToHelp);
Expand Down
10 changes: 9 additions & 1 deletion Assets/Plugins/UniGit/Editor/GitWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ namespace UniGit
{
public static class GitWindows
{
private static readonly List<EditorWindow> windows = new List<EditorWindow>();
private static List<EditorWindow> windows;
public static IEnumerable<EditorWindow> Windows { get { return windows; } }

public static void Init()
{
//windows list needs to be assigned manualy and not directly on definition as unity might call it after windows have subscribed
windows = new List<EditorWindow>();
}

public static void AddWindow(EditorWindow window)
{
if(windows == null) return;
if (windows.Contains(window))
{
Debug.LogErrorFormat("Winodw {0} is already in list.",window.GetType().Name);
Expand All @@ -21,6 +28,7 @@ public static void AddWindow(EditorWindow window)

public static void RemoveWindow(EditorWindow window)
{
if(windows == null) return;
windows.Remove(window);
}
}
Expand Down
5 changes: 3 additions & 2 deletions Assets/Plugins/UniGit/Editor/UniGitLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class UniGitLoader
static UniGitLoader()
{
injectionHelper = new InjectionHelper();
GitWindows.Init();
var recompileChecker = ScriptableObject.CreateInstance<AssemblyReloadScriptableChecker>();
recompileChecker.OnBeforeReloadAction = OnBeforeAssemblyReload;

Expand Down Expand Up @@ -98,8 +99,8 @@ private static void Rebuild(InjectionHelper injectionHelper)

private static void OnDelayedInit()
{
//inject all windows that are open
//windows should add themselfs on OnEnable
//inject all windows that are open
//windows should add themselfs on OnEnable
foreach (var editorWindow in GitWindows.Windows)
{
injectionHelper.Inject(editorWindow);
Expand Down

0 comments on commit e82d7c8

Please sign in to comment.