private void OnEnable() { // Apply Title titleContent = new GUIContent("JEM DiscordRPC Configuration"); // Load config, JEMDiscordConfiguration.LoadConfiguration(); }
/// <summary> /// Makes full presence refresh to resolve new state. /// </summary> /// <exception cref="ArgumentOutOfRangeException"/> public static void RefreshPresence(bool clear = false) { // Check if we should clear RPC. var shouldClear = clear || !JEMDiscordConfiguration.Resolve().Enable; if (shouldClear) { JEMDiscordController.ClearRPC(); return; } // Construct new presence. var scene = ResolveSceneName(); var presence = new DiscordRpc.RichPresence(); presence.details = $"Developing {Application.productName}"; string str; if (_inPlayMode) { str = $"In playmode ({scene})"; } else { switch (_drawState) { case State.DrawScene: str = $"Editing {scene}"; break; case State.DrawPrefab: str = "N/A"; break; default: throw new ArgumentOutOfRangeException(nameof(_drawState), _drawState, null); } } presence.state = str; presence.largeImageKey = JEMDiscordController.GetImageName(JEMDiscordImageKey.UnityDefault); presence.largeImageText = Application.unityVersion; // Apply presence. JEMDiscordController.SetFullRPC(false, presence); }
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); } }