public static void SaveSettings()
        {
            ERPCSettings settings = new ERPCSettings(ERPC.details, ERPC.state, ERPC.largeImageKey, ERPC.largeImageText, ERPC.smallImageKey, ERPC.smallImageText,
                                                     ERPC.firstButtonLabel, ERPC.firstButtonUrl, ERPC.secondButtonLabel, ERPC.secondButtonUrl, ERPC.resetOnSceneChange, ERPC.autoUpdate, ERPC.enableOnStartup);

            XmlSerializer serializer = new XmlSerializer(typeof(ERPCSettings));
            var           stream     = new FileStream(path, FileMode.Create);

            serializer.Serialize(stream, settings);
            stream.Close();
        }
 public static void GetSettings()
 {
     if (File.Exists(path))
     {
         XmlSerializer serializer = new XmlSerializer(typeof(ERPCSettings));
         FileStream    stream     = new FileStream(path, FileMode.Open);
         ERPCSettings  settings   = serializer.Deserialize(stream) as ERPCSettings;
         ApplySettings(settings);
         stream.Close();
     }
 }
 private static void ApplySettings(ERPCSettings settings)
 {
     ERPC.details           = settings.details;
     ERPC.state             = settings.state;
     ERPC.largeImageKey     = settings.largeImageKey;
     ERPC.largeImageText    = settings.largeImageText;
     ERPC.smallImageKey     = settings.smallImageKey;
     ERPC.smallImageText    = settings.smallImageText;
     ERPC.firstButtonLabel  = settings.firstButtonLabel;
     ERPC.firstButtonUrl    = settings.firstButtonUrl;
     ERPC.secondButtonLabel = settings.secondButtonLabel;
     ERPC.secondButtonUrl   = settings.secondButtonUrl;
     ERPC.autoUpdate        = settings.autoUpdate;
     ERPC.enableOnStartup   = settings.enableOnStartup;
 }
Example #4
0
        static ERPC()
        {
            projectName = Application.productName;
            sceneName   = SceneManager.GetActiveScene().name;

            EditorApplication.update += Update;

            start = GetTimeStamp();

            if (!EditorApplication.isPlaying)
            {
                CreateClient();
            }
            ERPCSettings.GetSettings();
            if (enableOnStartup)
            {
                enabled = true;
            }
            ;
        }
Example #5
0
        public static void Initialize()
        {
            Debug.Log("[ERP] Creating Client");

            //Prepare the logger
            DiscordRPC.Logging.ILogger logger = null;

            //Update the logger to the unity logger
            if (Debug.isDebugBuild)
            {
                logger = new FileLogger("discordrpc.log")
                {
                    Level = logLevel
                }
            }
            ;
            if (Application.isEditor)
            {
                logger = new UnityLogger()
                {
                    Level = logLevel
                }
            }
            ;

            client = new DiscordRpcClient(
                applicationID,                                  //The Discord Application ID
                pipe: (int)targetPipe,                          //The target pipe to connect too
                                                                // logger: logger,                              //The logger. Will Uncomment after when Lachee fixes issue #136 in Lachee/discord-rpc-csharp
                autoEvents: false,                              //WE will manually invoke events
                client: new UnityNamedPipe()                    //The client for the pipe to use. Unity MUST use a NativeNamedPipeClient since its managed client is broken.
                );

            Debug.Log("[ERP] Initialize");

            client.Initialize();                                //Connects the client

            ERPCSettings.GetSettings();
            UpdateActivity();
        }
Example #6
0
        public static void UpdateActivity()
        {
            if (!ERPCWindow.customDetailsState)
            {
                details = projectName;
                state   = sceneName;
            }

            if (ERPCWindow.secondButtonIsValid)
            {
                client.SetPresence(new RichPresence()
                {
                    Details = details,
                    State   = state,
                    Assets  = new Assets()
                    {
                        LargeImageKey  = largeImageKey,
                        LargeImageText = largeImageText,
                        SmallImageKey  = smallImageKey,
                        SmallImageText = smallImageText
                    },
                    Timestamps = new Timestamps
                    {
                        Start = start
                    },
                    Buttons = new Button[]
                    {
                        new Button()
                        {
                            Label = firstButtonLabel, Url = firstButtonUrl
                        },
                        new Button()
                        {
                            Label = secondButtonLabel, Url = secondButtonUrl
                        }
                    }
                });
            }
            else if (ERPCWindow.firstButtonIsValid)
            {
                client.SetPresence(new RichPresence()
                {
                    Details = details,
                    State   = state,
                    Assets  = new Assets()
                    {
                        LargeImageKey  = largeImageKey,
                        LargeImageText = largeImageText,
                        SmallImageKey  = smallImageKey,
                        SmallImageText = smallImageText
                    },
                    Timestamps = new Timestamps
                    {
                        Start = start
                    },
                    Buttons = new Button[]
                    {
                        new Button()
                        {
                            Label = firstButtonLabel, Url = firstButtonUrl
                        }
                    }
                });
            }
            else
            {
                client.SetPresence(new RichPresence()
                {
                    Details = details,
                    State   = state,
                    Assets  = new Assets()
                    {
                        LargeImageKey  = largeImageKey,
                        LargeImageText = largeImageText,
                        SmallImageKey  = smallImageKey,
                        SmallImageText = smallImageText
                    },
                    Timestamps = new Timestamps
                    {
                        Start = start
                    }
                });
            }

            Debug.Log("[ERP] Updated Presence");

            ERPCSettings.SaveSettings();

            client.Logger.Level = logLevel;
        }