-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathClientSimEditorRuntimeLinker.cs
More file actions
50 lines (43 loc) · 1.74 KB
/
ClientSimEditorRuntimeLinker.cs
File metadata and controls
50 lines (43 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using UnityEditor;
using UnityEngine;
using VRC.SDKBase;
namespace VRC.SDK3.ClientSim.Editor
{
/// <summary>
/// This class is used to link any editor specific method to a runtime event hook.
/// Currently only used for the Pause Menu to be able to open the Settings Window
/// and to check for proper project settings.
/// </summary>
public static class ClientSimEditorRuntimeLinker
{
private static void ModeStateChanged(PlayModeStateChange state)
{
if(state == PlayModeStateChange.EnteredPlayMode)
{
ClientSimMenu.openSettingsHook += ClientSimSettingsWindow.Init;
ClientSimMenu.checkValidSettingsHook += ClientSimProjectSettingsSetup.IsUsingCorrectSettings;
}
// On exiting playmode, remove the Editor method hooks.
if (state == PlayModeStateChange.ExitingPlayMode)
{
ClientSimMenu.openSettingsHook -= ClientSimSettingsWindow.Init;
ClientSimMenu.checkValidSettingsHook -= ClientSimProjectSettingsSetup.IsUsingCorrectSettings;
}
if (state == PlayModeStateChange.ExitingEditMode)
{
InitializeScene();
}
}
// When entering playmode, set Editor method hooks.
// Using this runtime initialized method due to timing issues with with Domain Reloading on and off.
[InitializeOnLoadMethod]
private static void OnProjectLoadedInEditor()
{
EditorApplication.playModeStateChanged += ModeStateChanged;
}
private static void InitializeScene()
{
ClientSimNetworkingUtilities.DoSceneSetup();
}
}
}