static JEMDiscordUnityHandler() { // Handle scene change. EditorSceneManager.sceneOpened += (scene, mode) => { if (!Application.isPlaying) { JEMDiscordUnityPresence.ReportSceneActivation(scene.name); } }; SceneManager.sceneLoaded += (scene, mode) => { if (Application.isPlaying) { JEMDiscordUnityPresence.ReportSceneActivation(scene.name); } }; EditorSceneManager.newSceneCreated += (scene, setup, mode) => { if (!Application.isPlaying) { JEMDiscordUnityPresence.ReportSceneActivation(scene.name); } }; // Handle playmode change. EditorApplication.playModeStateChanged += change => { switch (change) { case PlayModeStateChange.EnteredEditMode: JEMDiscordUnityPresence.ReportPlayModeActivation(false); break; case PlayModeStateChange.ExitingEditMode: case PlayModeStateChange.EnteredPlayMode: case PlayModeStateChange.ExitingPlayMode: JEMDiscordUnityPresence.ReportPlayModeActivation(true); break; default: throw new ArgumentOutOfRangeException(nameof(change), change, null); } }; EditorApplication.quitting += () => { // Shutdown discord and don't save anything for next session. JEMDiscordController.Shutdown(true); }; CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted; // Initialize. JEMDiscordController.Init(false); }
internal static void InternalDiscordInitialize() { if (IsConnected) { return; } _handlers = new DiscordRpc.EventHandlers(); Debug.Log("Discord: init"); DiscordRpc.Initialize(ApplicationId, ref _handlers, true, OptionalSteamId); IsConnected = true; JEMDiscordUnityPresence.RefreshPresence(); }
private void OnGUI() { var cfg = JEMDiscordConfiguration.Loaded; GUILayout.Label("Settings", EditorStyles.boldLabel); cfg.Enable = EditorGUILayout.Toggle("Enable RPC", cfg.Enable); cfg.ShowPresenceOnlyWhenActive = EditorGUILayout.Toggle("Show only when window focused", cfg.ShowPresenceOnlyWhenActive); cfg.RecompileTimeout = EditorGUILayout.IntSlider("Recompile Timeout", cfg.RecompileTimeout, 10, 360); EditorGUILayout.Space(); GUI.enabled = false; GUILayout.Label("Presence Status", EditorStyles.boldLabel); EditorGUILayout.LabelField("HasPresence", JEMDiscordController.HasPresence.ToString()); if (!JEMDiscordController.IsConnected) { var diff = DateTime.Now - JEMDiscordController._lastInitializationTime; EditorGUILayout.LabelField("Will connect in", $"{cfg.RecompileTimeout - diff.Seconds:0.00}"); } else { EditorGUILayout.LabelField("Connected"); } EditorGUILayout.LabelField("_drawState", JEMDiscordUnityPresence._drawState.ToString()); EditorGUILayout.LabelField("_sceneName", JEMDiscordUnityPresence._sceneName); EditorGUILayout.LabelField("_inPlayMode", JEMDiscordUnityPresence._inPlayMode.ToString()); GUI.enabled = true; GUILayout.FlexibleSpace(); if (GUILayout.Button("Save Configuration")) { JEMDiscordConfiguration.SaveConfiguration(); } if (GUILayout.Button("Refresh Presence")) { JEMDiscordUnityPresence.RefreshPresence(); } if (GUILayout.Button("Clear Presence")) { JEMDiscordUnityPresence.RefreshPresence(true); } }
private static void Update() { if (!IsInitialized) { return; } if (!IsConnected) { // While discord is not yet connected, we will try again after one min. if (CanInitialize()) { InternalDiscordInitialize(); } return; } // Hide unity presence if not focused. // TODO: Adjust timestamp after receiving focus again if (_wasWindowFocused == InternalEditorUtility.isApplicationActive) { return; } _wasWindowFocused = InternalEditorUtility.isApplicationActive; if (!JEMDiscordConfiguration.Resolve().ShowPresenceOnlyWhenActive) { return; } if (_wasWindowFocused) { JEMDiscordUnityPresence.RefreshPresence(); } else { JEMDiscordUnityPresence.RefreshPresence(true); } }