static AuthController() { settings = StreamlabsSettings.LoadFromResources(); #if UNITY_WEBGL && !UNITY_EDITOR // WebGL doesn't support loopback method; using redirection scheme instead. accessTokenProvider = new RedirectAccessTokenProvider(settings); #elif UNITY_ANDROID && !UNITY_EDITOR // On Android a native OpenID lib is used for better UX. accessTokenProvider = new AndroidAccessTokenProvider(settings); #elif UNITY_IOS && !UNITY_EDITOR // On iOS a native OpenID lib is used for better UX. accessTokenProvider = new IOSAccessTokenProvider(settings); #else // Loopback scheme is used on other platforms. accessTokenProvider = new LoopbackAccessTokenProvider(settings); #endif }
private static StreamlabsSettings GetOrCreateSettings() { var settings = StreamlabsSettings.LoadFromResources(true); if (!settings) { settings = CreateInstance <StreamlabsSettings>(); Directory.CreateDirectory(Application.dataPath + "/UnityStreamlabs/Resources"); const string path = "Assets/UnityStreamlabs/Resources/StreamlabsSettings.asset"; AssetDatabase.CreateAsset(settings, path); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); Debug.Log($"UnityStreamlabs: Settings file didn't exist and was created at: {path}.\n" + "You're free to move it, just make sure it stays in the root of a 'Resources' folder."); } return(settings); }
/// <summary> /// Connect to the Streamlabs server to begin sending and receiving events. /// The connection process is async; listen for <see cref="OnConnectionStateChanged"/> to handle the result. /// </summary> public static void Connect() { if (ConnectionState == ConnectionState.Connected || ConnectionState == ConnectionState.Connecting) { return; } settings = StreamlabsSettings.LoadFromResources(); unitySyncContext = SynchronizationContext.Current; ChangeConnectionState(ConnectionState.Connecting); AuthController.OnAccessTokenRefreshed += HandleAccessTokenRefreshed; AuthController.RefreshAccessToken(); void HandleAccessTokenRefreshed(bool success) { AuthController.OnAccessTokenRefreshed -= HandleAccessTokenRefreshed; InitializeWebSocket(); } }