public static void InitializeOrLogOut(bool forceUI, AfterAuthenticateD afterSuccess = null, AfterAuthenticateD afterFailure = null, MonoBehaviour mb = null) { if (!Authenticated) { InitializeSocial(forceUI, afterSuccess, afterFailure, mb); } else { Authenticated = false; if (afterSuccess != null) { afterSuccess(); } } }
public static void InitializeSocial(bool forceUI, AfterAuthenticateD afterSuccess = null, AfterAuthenticateD afterFailure = null, MonoBehaviour mb = null) { AuthenticationAnswer aa = GetPreviousAnswer(); if (!Authenticated && aa == AuthenticationAnswer.NeverAsked && mb != null) { ScreenAsk sa = mb.gameObject.AddComponent <ScreenAsk>(); Destroy(mb); sa.PrepareMe(delegate() { CarSmasherSocial.SaveAnswerForAuthentication(CarSmasherSocial.AuthenticationAnswer.Accepted); sa.gameObject.AddComponent <ScreenSplash>(); Destroy(sa); }, delegate() { CarSmasherSocial.SaveAnswerForAuthentication(CarSmasherSocial.AuthenticationAnswer.Denied); sa.gameObject.AddComponent <ScreenSplash>(); Destroy(sa); }); } else if (!Authenticated && (aa == AuthenticationAnswer.Accepted || forceUI)) { Social.localUser.Authenticate((bool success) => { Authenticated = success; SaveAnswerForAuthentication(success ? AuthenticationAnswer.Accepted : AuthenticationAnswer.Denied); if (Authenticated) { if (afterSuccess != null) { afterSuccess(); } } else { if (afterFailure != null) { afterFailure(); } } }); } else { if (afterFailure != null) { afterFailure(); } } }