Created
February 26, 2019 04:36
-
-
Save Cotoff/0bf3636dee91a56777767e9a87804a06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DiscordRunner:MonoBehaviour | |
{ | |
private const long CLIENT_ID = ...; | |
private static DiscordRunner s_Instance; | |
public static void Initialize() | |
{ | |
#if !DISABLEDISCORD | |
s_Instance = new GameObject("[Discord runner]").AddComponent<DiscordRunner>(); | |
try | |
{ | |
s_Instance.m_Discord = new Discord.Discord(CLIENT_ID, (ulong)Discord.CreateFlags.Default); | |
s_Instance.m_Discord.GetStoreManager().FetchEntitlements( | |
r => | |
{ | |
if (r != Result.Ok) | |
{ | |
UberDebug.LogErrorChannel("System", $"Could not get DLC from discord store: {r}"); | |
return; | |
} | |
UberDebug.LogSystem($"Discord entitlements {s_Instance.m_Discord.GetStoreManager().CountEntitlements()}"); | |
foreach (var entitlement in s_Instance.m_Discord.GetStoreManager().GetEntitlements()) | |
{ | |
UberDebug.LogSystem( | |
$"Discord entitlement detected: {entitlement.Type} # {entitlement.Id} (sku {entitlement.SkuId})"); | |
} | |
}); | |
s_Instance.m_Discord.GetStoreManager().FetchSkus( | |
r => | |
{ | |
if (r != Result.Ok) | |
{ | |
UberDebug.LogErrorChannel("System", $"Could not get SKU from discord store: {r}"); | |
return; | |
} | |
UberDebug.LogSystem($"Discord skus {s_Instance.m_Discord.GetStoreManager().CountSkus()}"); | |
foreach (var entitlement in s_Instance.m_Discord.GetStoreManager().GetSkus()) | |
{ | |
UberDebug.LogSystem( | |
$"Discord sku detected: {sku.Name} # {sku.Id}"); | |
} | |
UberDebug.Log($"Discord sku name: {s_Instance.m_Discord.GetStoreManager().GetSku(...).Name}"); // this line throws NotFound | |
}); | |
DontDestroyOnLoad(s_Instance); | |
} | |
catch (Exception ex) | |
{ | |
UberDebug.LogErrorChannel("System", $"Could not initialize discord store: {ex}"); | |
Destroy(s_Instance.gameObject); | |
} | |
#endif | |
} | |
private Discord.Discord m_Discord; | |
void Update() | |
{ | |
m_Discord?.RunCallbacks(); | |
} | |
public static bool IsDLCEnabled(long id) | |
{ | |
if (!s_Instance) | |
return false; | |
return s_Instance.m_Discord.GetStoreManager().GetEntitlements().Any(e => e.Id == id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment