コード例 #1
0
 /// <summary>
 /// If not already disposed, it will dispose and deinitialize the discord client.
 /// </summary>
 public void Deinitialize()
 {
     //We dispose outside the scripting symbols as we always want to be able to dispose (just in case).
     if (_client != null)
     {
         Debug.Log("[DRP] Disposing Discord IPC Client...");
         _client.Dispose();
         _client = null;
         Debug.Log("[DRP] Finished Disconnecting");
     }
 }
コード例 #2
0
        void Init_discordrpc()
        {
            DiscordRPC.DiscordRpcClient client;
            client = new DiscordRPC.DiscordRpcClient("584200653203832853");

            //Set the logger
            client.Logger = new ConsoleLogger()
            {
                Level = LogLevel.Warning
            };

            //Subscribe to events
            client.OnReady += (sender, e) =>
            {
                Console.WriteLine("Received Ready from user {0}", e.User.Username);
            };

            client.OnPresenceUpdate += (sender, e) =>
            {
                Console.WriteLine("Received Update! {0}", e.Presence);
            };


            client.Initialize();


            client.SetPresence(new RichPresence()
            {
                Details = "Fight Evil With Evil",
                State   = "Closed Beta 1.3 by Zelly",
                Assets  = new Assets()
                {
                    LargeImageKey  = "demon2",
                    LargeImageText = "By Zelly",
                    SmallImageKey  = ""
                }
            });
        }
コード例 #3
0
ファイル: Lucifer_Main.cs プロジェクト: ZelliDev/LuciferGUI
        void Initialize()
        {
            client = new DiscordRpcClient("584200653203832853");

            //Set the logger
            client.Logger = new ConsoleLogger()
            {
                Level = LogLevel.Warning
            };

            //Subscribe to events
            client.OnReady += (sender, e) =>
            {
                Console.WriteLine("Received Ready from user {0}", e.User.Username);
            };

            client.OnPresenceUpdate += (sender, e) =>
            {
                Console.WriteLine("Received Update! {0}", e.Presence);
            };


            client.Initialize();


            client.SetPresence(new RichPresence()
            {
                Details = "Dans le menu de connexion",
                State   = "Closed Beta 1.3",
                Assets  = new Assets()
                {
                    LargeImageKey  = "demon2",
                    LargeImageText = "Created by Zelly⛧#6666",
                    SmallImageKey  = "none"
                }
            });
        }
コード例 #4
0
    /// <summary>
    /// Initializes the discord client if able to. Wont initialize if <see cref="active"/> is false, we are not in playmode, we already have a instance or we already have a client.
    /// <para>This function is empty unless UNITY_WSA || UNITY_WSA_10_0 || UNITY_STANDALONE) && !DISABLE_DISCORD is meet.</para>
    /// </summary>
    public void Initialize()
    {
#if (UNITY_WSA || UNITY_WSA_10_0 || UNITY_STANDALONE) && !DISABLE_DISCORD
        if (!active)
        {
            return;                         //Are we allowed to be active?
        }
        if (!Application.isPlaying)
        {
            return;                         //We are not allowed to initialize while in the editor.
        }
        //This has a instance already that isn't us
        if (_instance != null && _instance != this)
        {
            Debug.LogWarning("[DAPI] Multiple DiscordManagers exist already. Destroying self.", _instance);
            Destroy(this);
            return;
        }

        //Make sure the client doesnt already exit
        if (_client != null)
        {
            Debug.LogError("[DAPI] Cannot initialize a new client when one is already initialized.");
            return;
        }

        //Assign the instance
        _instance = this;
        DontDestroyOnLoad(this);

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

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

        //We are starting the client. Below is a break down of the parameters.
        Debug.Log("[DRP] Starting Discord Rich Presence");
        _client = new DiscordRPC.DiscordRpcClient(
            applicationID,                                  //The Discord Application ID
            pipe: (int)targetPipe,                          //The target pipe to connect too
            logger: logger,                                 //The logger,
            autoEvents: false,                              //WE will manually invoke events
            client: new DiscordRPC.Unity.UnityNamedPipe()   //The client for the pipe to use. Unity MUST use a NativeNamedPipeClient since its managed client is broken.
            );

        if (registerUriScheme)
        {
            client.RegisterUriScheme(steamID);
        }

        //Subscribe to some initial events
        #region Event Registration
        client.OnError         += (s, args) => Debug.LogError("[DRP] Error Occured within the Discord IPC: (" + args.Code + ") " + args.Message);
        client.OnJoinRequested += (s, args) => Debug.Log("[DRP] Join Requested");

        client.OnReady += (s, args) =>
        {
            //We have connected to the Discord IPC. We should send our rich presence just incase it lost it.
            Debug.Log("[DRP] Connection established and received READY from Discord IPC. Sending our previous Rich Presence and Subscription.");


            //Set the user and cache their avatars
            _currentUser = args.User;
            _currentUser.GetAvatar(this, DiscordAvatarSize.x128);
        };
        client.OnPresenceUpdate += (s, args) =>
        {
            Debug.Log("[DRP] Our Rich Presence has been updated. Applied changes to local store.");
            Debug.Log(args.Presence.State);
            _currentPresence = (DiscordPresence)args.Presence;
        };
        client.OnSubscribe += (s, a) =>
        {
            Debug.Log("[DRP] New Subscription. Updating local store.");
            _currentSubscription = client.Subscription.ToUnity();
        };
        client.OnUnsubscribe += (s, a) =>
        {
            Debug.Log("[DRP] Removed Subscription. Updating local store.");
            _currentSubscription = client.Subscription.ToUnity();
        };

        //Register the unity events
        events.RegisterEvents(client);
        #endregion

        //Set initial presence and sub. (This will enqueue it)
        SetSubscription(_currentSubscription);
        SetPresence(_currentPresence);

        //Start the client
        _client.Initialize();
        Debug.Log("[DRP] Discord Rich Presence intialized and connecting...");
#endif
    }