private void OnGUI() { if (ERP.discord == null && !ERP.Failed) { ERP.DelayStart(); } if (ERP.Failed | ERP.Errored) { GUILayout.Label($"ERP Failed to start", EditorStyles.boldLabel); if (GUILayout.Button("Retry")) { ERP.Errored = false; ERP.Failed = false; ERP.Init(); } return; } GUILayout.Label("Editor Rich Presence", EditorStyles.boldLabel); GUILayout.Label("Current Project: " + ERP.projectName); GUILayout.Label("Current Scene: " + ERP.sceneName); GUILayout.Label(string.Empty); GUILayout.Label($"Scene Name Visible: {ERP.showSceneName}"); GUILayout.Label($"Project Name Visible: {ERP.showProjectName}"); GUILayout.Label($"Reset Timestap on scene change: {ERP.resetOnSceneChange}"); if (ToggleButton("Hide Scene name", "Show Scene name", ref ERP.showSceneName)) { ERP.UpdateActivity(); ERPSettings.SaveSettings(); } if (ToggleButton("Hide Project name", "Show Project name", ref ERP.showProjectName)) { ERP.UpdateActivity(); ERPSettings.SaveSettings(); } if (ToggleButton("Don't reset timestap on scene change", "Reset timestap on scene change", ref ERP.resetOnSceneChange)) { ERP.UpdateActivity(); ERPSettings.SaveSettings(); } if (ToggleButton("Disable Debug Mode", "Enable Debug Mode", ref ERP.debugMode)) { ERPSettings.SaveSettings(); } GUILayout.Label(string.Empty); GUILayout.BeginHorizontal(); if (GUILayout.Button("GitHub Repository")) { Application.OpenURL("https://github.com/MarshMello0/Editor-Rich-Presence"); } if (GUILayout.Button("Asset Store Page")) { Application.OpenURL("https://assetstore.unity.com/packages/tools/utilities/editor-rich-presence-178736"); } GUILayout.EndHorizontal(); }
public static void SaveSettings() { ERPSettings settings = new ERPSettings(ERP.showSceneName, ERP.showProjectName, ERP.resetOnSceneChange, ERP.debugMode, ERP.EditorClosed, ERP.lastTimestamp, ERP.lastSessionID, ERP.Errored); XmlSerializer serializer = new XmlSerializer(typeof(ERPSettings)); var stream = new FileStream(path, FileMode.Create); serializer.Serialize(stream, settings); stream.Close(); ERP.Log("Saved Settings"); }
public static void GetSettings() { if (File.Exists(path)) { XmlSerializer serializer = new XmlSerializer(typeof(ERPSettings)); FileStream stream = new FileStream(path, FileMode.Open); ERPSettings settings = serializer.Deserialize(stream) as ERPSettings; ApplySettings(settings); stream.Close(); } }
private static void ApplySettings(ERPSettings settings) { ERP.showSceneName = settings.showSceneName; ERP.showProjectName = settings.showProjectName; ERP.resetOnSceneChange = settings.resetOnSceneChange; ERP.debugMode = settings.debugMode; ERP.EditorClosed = settings.EditorClosed; ERP.lastTimestamp = settings.LastTimestamp; ERP.lastSessionID = settings.LastSessionID; ERP.Log("Applied Settings from file"); }
public static void Init() { if (Errored && lastSessionID == EditorAnalyticsSessionInfo.id) { if (debugMode) { LogWarning($"Error but in same session"); } return; } if (!DiscordRunning()) { LogWarning("Can't find Discord's Process"); Failed = true; Errored = true; ERPSettings.SaveSettings(); return; } try { discord = new Discord.Discord(long.Parse(applicationId), (long)CreateFlags.Default); } catch (Exception e) { if (debugMode) { LogWarning("Expected Error, retrying\n" + e.ToString()); } if (!Failed) { DelayStart(2000); } Failed = true; return; } if (!resetOnSceneChange || EditorAnalyticsSessionInfo.id != lastSessionID) { lastTimestamp = GetTimestamp(); ERPSettings.SaveSettings(); } lastSessionID = EditorAnalyticsSessionInfo.id; projectName = Application.productName; sceneName = EditorSceneManager.GetActiveScene().name; UpdateActivity(); EditorApplication.update += Update; EditorSceneManager.sceneOpened += SceneOpened; Log("Started!"); }
public static void LoadSettings(ERPSettings settings) { _showSceneName = settings.showSceneName; _showProjectName = settings.showProjectName; _resetOnSceneChange = settings.resetOnSceneChange; _debugMode = settings.debugMode; EditorClosed = settings.EditorClosed; lastTimestamp = settings.LastTimestamp; lastSessionID = settings.LastSessionID; Errored = settings.Errored; Log("Applied Settings from file"); GetNames(); }
private static void UpdateActivity() { Log("Updating Activity"); if (discord == null) { Init(); } if (Failed) { return; } ProjectName = Application.productName; SceneName = EditorSceneManager.GetActiveScene().name; var activityManager = discord.GetActivityManager(); Activity activity = new Activity { State = ShowProjectName ? ProjectName : "", Details = ShowSceneName ? SceneName : "", Timestamps = { Start = lastTimestamp }, Assets = { LargeImage = "logo", LargeText = "Unity " + Application.unityVersion, SmallImage = "marshmello", SmallText = "ERP on Unity Asset Store", }, }; activityManager.UpdateActivity(activity, result => { if (result != Result.Ok) { LogError("Error from discord (" + result.ToString() + ")"); } else { Log("Discord Result = " + result.ToString()); } }); ERPSettings.SaveSettings(); }
private void OnGUI() { if (ERP.discord == null && !ERP.Failed) { ERP.DelayStart(); } if (ERP.Failed) { GUILayout.Label($"ERP Failed to start", EditorStyles.boldLabel); if (GUILayout.Button("Retry")) { ERP.Init(); } return; } GUILayout.Label("Editor Rich Presence", EditorStyles.boldLabel); GUILayout.Label("Current Project: " + ERP.projectName); GUILayout.Label("Current Scene: " + ERP.sceneName); GUILayout.Label(string.Empty); GUILayout.Label($"Scene Name Visible: {ERP.showSceneName}"); GUILayout.Label($"Project Name Visible: {ERP.showProjectName}"); GUILayout.Label($"Reset Timestap on scene change: {ERP.resetOnSceneChange}"); if (ToggleButton("Hide Scene name", "Show Scene name", ref ERP.showSceneName)) { ERP.UpdateActivity(); } if (ToggleButton("Hide Project name", "Show Project name", ref ERP.showProjectName)) { ERP.UpdateActivity(); } if (ToggleButton("Don't reset timestap on scene change", "Reset timestap on scene change", ref ERP.resetOnSceneChange)) { ERP.UpdateActivity(); } if (ToggleButton("Disable Debug Mode", "Enable Debug Mode", ref ERP.debugMode)) { ERPSettings.SaveSettings(); } GUILayout.Label(string.Empty); if (GUILayout.Button("Open ERP on Github")) { Application.OpenURL("https://github.com/MarshMello0/Editor-Rich-Presence"); } }
public static void Init() { if (Errored && lastSessionID == EditorAnalyticsSessionInfo.id) { if (DebugMode) { LogWarning($"Error but in same session"); } return; } if (!DiscordRunning()) { LogWarning("Can't find Discord's Process"); Failed = true; Errored = true; ERPSettings.SaveSettings(); return; } try { if (discord == null) { Log("Creating new discord"); discord = new Discord.Discord(long.Parse(_applicationId), (long)CreateFlags.NoRequireDiscord); } else { Log("Discord isn't null but we are trying to creating a new one"); } } catch (Exception e) { if (DebugMode) { LogWarning($"Expected Error, retrying\n{e}"); } if (!Failed) { DelayStart(2000); } Failed = true; return; } if (!ResetOnSceneChange || EditorAnalyticsSessionInfo.id != lastSessionID) { lastTimestamp = GetTimestamp(); ERPSettings.SaveSettings(); } lastSessionID = EditorAnalyticsSessionInfo.id; GetNames(); UpdateActivity(); EditorApplication.update += Update; EditorSceneManager.sceneOpened += SceneOpened; Log("Started!"); if (ERPWindow.Window != null) { ERPWindow.Window.Repaint(); } }
static ERP() { ERPSettings.GetSettings(); DelayStart(); }
private static void Quitting() { Log("Quitting ERP"); EditorClosed = true; ERPSettings.SaveSettings(); }