void OnApplicationPause(bool paused) { if (this.State == ControllerState.SceneWillAppear || this.State == ControllerState.SceneDidAppear) { if (paused) { Debug.Log("-> Paused unity application"); if (!this.Native.isWebViewVisible) { Debug.Log("-> Turning promo content off"); TurnPromoContentOff(false); } } else { Debug.Log("-> Unpaused unity application"); if (this.Native.isWebViewVisible) { ShouldReloadPromoAfterWebViewClose = true; } else { ReloadPromoContent(); } } } }
public void InvokeOnWebViewWillAppear(string data) { Debug.Log("Received a call for InvokeOnWebViewWillAppear. " + data); this.Native.isWebViewVisible = true; if (OnWebViewWillAppear != null) { OnWebViewWillAppear(); } }
void LogMixpanelProperties() { if (this.Options != null && this.Options.Mode == AnalyticsMode.Development) { string msg = string.Empty; foreach (KeyValuePair <string, object> kv in this.MixpanelProperties) { msg += string.Format("SAGO: {0} = {1}\n", kv.Key, kv.Value); } Debug.Log(msg); } }
public void InvokeOnWebViewDidDisappear(string data) { Debug.Log("Received a call for InvokeOnWebViewDidDisappear. " + data); if (ShouldReloadPromoAfterWebViewClose || data == "error") { ShouldReloadPromoAfterWebViewClose = false; ReloadPromoContent(true); } this.Native.isWebViewVisible = false; if (OnWebViewDidDisappear != null) { OnWebViewDidDisappear(); } #if !UNITY_EDITOR && !UNITY_WSA IsWebViewLoading = false; SagoTouch.TouchDispatcher.Instance.enabled = true; #endif }
public static void Init(SceneController sceneController = null) { // Automatically instantiating a quit button for any Android derived platform that requires this mechanism. // Right now doing this only for PanasonicEx platform but we can add more platforms to the macro. #if SAGO_PANASONIC_EX GameObject quitButtonResource = Resources.Load("SagoApp/QuitButton") as GameObject; if (quitButtonResource) { GameObject quitButtonObject = Instantiate(quitButtonResource) as GameObject; QuitButton quitButton = quitButtonObject.GetComponentInChildren <QuitButton>(); if (quitButton) { Debug.Log("QuitButton-> Successfully loaded and instantiated QuitButton."); if (sceneController != null) { quitButtonObject.transform.parent = sceneController.transform; } } } #endif }
/// <summary> /// Gets a list of installed url schemes. /// </summary> /// <param name="urlSchemes">The list of url schemes to check.</param> /// <returns>The subset of the list of url schemes which are installed on the device.</returns> public List <App> CheckAppsAvailability(List <App> apps) { #if UNITY_ANDROID && !UNITY_EDITOR string appArray = JsonConvert.SerializeObject(apps, JsonConvert.Formatting.None, JsonConvert.Settings.CSharpToJson); Debug.Log("Sending serialized app list to native:\n" + appArray); var result = this.AndroidDeviceInfo .CallStatic <string>("getInstalledAppsWithPackageNames", new object[] { this.AndroidActivity, appArray }); List <App> returnedList = JsonConvert.DeserializeObject <List <App> >(result, JsonConvert.Settings.CSharpToJson); return(returnedList); #elif !SAGO_DISABLE_SAGOBIZ && SAGO_IOS && !UNITY_EDITOR string appArray = JsonConvert.SerializeObject(apps, JsonConvert.Formatting.None, JsonConvert.Settings.CSharpToJson); string result = _GetInstalledAppsWithUrlSchemes(appArray); List <App> returnedList = JsonConvert.DeserializeObject <List <App> >(result, JsonConvert.Settings.CSharpToJson); return(returnedList); #else return(apps); #endif }
public void OnPromoWebViewReadyToShow() { Debug.Log("SAGO: OnPromoWebViewReadyToShow"); this.PromoWebViewReady = true; }
/// <summary> /// Turns the component's <see cref="Content" /> off. /// </summary> public void TurnContentOff(bool animated) { Debug.Log("Promo -> Turn Content off " + ((animated) ? "animated" : "")); this.Content.TurnOff(animated); }
/// <summary> /// Event handler called when the <see cref="Service" /> component has an error while loading. /// </summary> void OnServiceError(Service service) { Debug.Log(service.Error); }
/// <summary> /// Event handler called when the <see cref="Promo" /> component has an error while loading. /// </summary> void OnPromoError(Promo promo) { Debug.Log(promo.Error); this.TurnPromoContentOff(false); }
/// <summary> /// Event handler called when the <see cref="Parents" /> component has an error while loading. /// </summary> void OnParentsError(Parents parents) { Debug.Log(parents.Error); this.TurnParentsContentOff(false); }
/// <summary> /// Loads the <see cref="PromoData" /> asynchronously. /// </summary> /// <remarks>TODO: Remove 'Preferences' key after server side integrates direct access to web preferences through native code.</remarks> protected IEnumerator LoadPromoDataAsync() { string url; url = this.PromoUrl; Native native; native = Controller.Instance.Native; Dictionary <string, object> data; data = new Dictionary <string, object>(); data.Add("TotalMemory".PascalToUnderscoreCase(), native.TotalMemory); data.Add("BundleId".PascalToUnderscoreCase(), native.BundleId); data.Add("BundleVersion".PascalToUnderscoreCase(), native.BundleVersion); data.Add("BundleVersionCode".PascalToUnderscoreCase(), native.BundleVersionCode); ConfigData.Apps = native.CheckAppsAvailability(this.ConfigData.Apps); data.Add("apps", JsonConvert.SerializeObject(ConfigData.Apps, JsonConvert.Formatting.None, JsonConvert.Settings.CSharpToJson)); data.Add("Preferences".PascalToUnderscoreCase(), BizUtil.WebClientPreferences); data.Add("InternetConnectionType".PascalToUnderscoreCase(), native.InternetConnectionType); data.Add("Language".PascalToUnderscoreCase(), native.Language); data.Add("Locale".PascalToUnderscoreCase(), native.Locale); data.Add("OperatingSystem".PascalToUnderscoreCase(), native.OperatingSystem); data.Add("OperatingSystemVersion".PascalToUnderscoreCase(), native.OperatingSystemVersion); data.Add("Platform".PascalToUnderscoreCase(), native.Platform.ToString()); data.Add("PlatformFeatures".PascalToUnderscoreCase(), native.PlatformFeatures); data.Add("Region".PascalToUnderscoreCase(), native.Region); data.Add("ScreenDensity".PascalToUnderscoreCase(), native.ScreenDensity); data.Add("ScreenOrientation".PascalToUnderscoreCase(), native.ScreenOrientation.ToString()); data.Add("ScreenHeight".PascalToUnderscoreCase(), native.ScreenHeight); data.Add("ScreenWidth".PascalToUnderscoreCase(), native.ScreenWidth); data.Add("ScreenAdjustedHeight".PascalToUnderscoreCase(), native.ScreenAdjustedHeight); data.Add("ScreenAdjustedWidth".PascalToUnderscoreCase(), native.ScreenAdjustedWidth); data.Add("TimeZone".PascalToUnderscoreCase(), native.TimeZone); data.Add("UrlScheme".PascalToUnderscoreCase(), native.UrlScheme); data.Add("VendorId".PascalToUnderscoreCase(), native.VendorId); data.Add("CompanyName".PascalToUnderscoreCase(), CompanyName != "" ? CompanyName : CompanyNameSagoSago); data.Add("AppData".PascalToUnderscoreCase(), this.AppData != null ? this.AppData : ""); #if UNITY_ANDROID data.Add("AndroidDeviceArchitecture".PascalToUnderscoreCase(), native.AndroidDeviceArchitecture); #endif Dictionary <string, string> headers; headers = new Dictionary <string, string>(); headers.Add("content-type", "application/json"); string jsonData = JsonConvert.SerializeObject(data, JsonConvert.Formatting.None, JsonConvert.Settings.CSharpToJson); Debug.Log("Sending this to the server: " + jsonData); byte[] binaryData = System.Text.Encoding.UTF8.GetBytes(jsonData); Debug.Log("Promo url: " + url); WWW www; www = new WWW(url, binaryData, headers); yield return(www); if (!string.IsNullOrEmpty(www.error)) { string responseHeader = ""; foreach (var key in www.responseHeaders.Keys) { responseHeader += string.Format("\t{0} = {1}\n", key, www.responseHeaders[key]); } responseHeader = "{\n" + responseHeader + "}\n"; this.Error = string.Format("Could not download promo data.\n-> Response Header: {0}\n-> Actual Error: {1}\nResponse Text: {2}", responseHeader, www.error, string.IsNullOrEmpty(www.text) ? "no repsponse text" : www.text); this.State = ServiceState.Error; yield break; } try { Debug.Log("We got this back from the server:\n" + www.text); this.PromoData = JsonConvert.DeserializeObject <ServicePromoData>(www.text, JsonConvert.Settings.JsonToCSharp); this.PromoData.ImageUrl = this.PromoData.ImageUrl.Replace( "%streamingAssetsPath%", StreamingAssetsPath ); this.PromoData.PageUrl = this.PromoData.PageUrl.Replace( "%streamingAssetsPath%", StreamingAssetsPath ); } catch (System.Exception e) { this.PromoData = null; this.Error = string.Format("Could not parse promo data: {0}", e); this.State = ServiceState.Error; yield break; } }
/// <summary> /// Loads the <see cref="ConfigData" /> asynchronously. /// </summary> protected IEnumerator LoadConfigDataAsync() { string url; url = this.ConfigUrl; if (string.IsNullOrEmpty(url)) { this.Error = string.Format("Url is null -> Disabling the service."); this.State = ServiceState.Error; yield break; } Native native; native = Controller.Instance.Native; Dictionary <string, object> data; data = new Dictionary <string, object>(); data.Add("Platform".PascalToUnderscoreCase(), native.Platform.ToString()); data.Add("SagobizSdkVersion".PascalToUnderscoreCase(), Version.Current); Dictionary <string, string> headers; headers = new Dictionary <string, string>(); headers.Add("content-type", "application/json"); string jsonData = JsonConvert.SerializeObject(data, JsonConvert.Formatting.None, JsonConvert.Settings.CSharpToJson); byte[] binaryData = System.Text.Encoding.UTF8.GetBytes(jsonData); Debug.Log("Config url: " + url); WWW www; www = new WWW(url, binaryData, headers); yield return(www); if (!string.IsNullOrEmpty(www.error)) { string responseHeader = string.Empty; foreach (var key in www.responseHeaders.Keys) { responseHeader += string.Format("\t{0} = {1}\n", key, www.responseHeaders[key]); } responseHeader = "{\n" + responseHeader + "}\n"; this.Error = string.Format("Could not download config data.\n-> Response Header: {0}\n->Actual Error: {1}\nResponse Text: {2}", responseHeader, www.error, string.IsNullOrEmpty(www.text) ? "no repsponse text" : www.text); this.State = ServiceState.Error; yield break; } try { Debug.Log(www.text); this.ConfigData = JsonConvert.DeserializeObject <ServiceConfigData>(www.text, JsonConvert.Settings.JsonToCSharp); } catch (System.Exception e) { this.ConfigData = null; this.Error = string.Format("Could not parse config data: {0}", e); this.State = ServiceState.Error; yield break; } }