private IEnumerator Routine() { if (Condition == null) { Condition = (material) => { return(true); } } ; if (Condition(Material)) { try { Job(); } catch (Exception ex) { if (OnFail != null) { OnFail(ex); } } yield return(new WaitForSeconds(Delay)); MonoBridge.StartCoroutine(Routine()); } else { try { if (OnFinish != null) { OnFinish(); } } catch (Exception ex) { if (OnFail != null) { OnFail(ex); } } Dispose(); } }
private IEnumerator Progress(WWW www) { yield return(new WaitForSeconds(.1f)); if (Material != null) { if (Material.UI_Text != null) { Material.UI_Text.text = Material.Template.Replace("{0}", Math.Round(www.progress * 100) + "%"); } } if (!www.isDone) { MonoBridge.StartCoroutine(Progress(www)); } }
protected void Perform() { if (OnStart != null) { try { OnStart(); } catch (Exception ex) { if (OnFail != null) { OnFail(ex); } } } MonoBridge.StartCoroutine(Routine()); }
public void Destroy() { try { Events.Listeners.Where(l => l.Owner == Name).ToList().ForEach ( (l) => { l.Remove = true; } ); Events.OnTouch_Listeners.Where(o => o.Owner == Name).ToList().ForEach ( (o) => { o.Remove = true; } ); if (this.Type == UIType.LIST) { List <string> keys = Variables.UI.Keys.Where(k => k.Contains(this.Name + "Item_")).ToList(); foreach (string key in keys) { Variables.UI[key].Destroy(); } } else { foreach (UIComponent component in this.Components) { component.Destroy(); } } Variables.UI.Remove(Name); MonoBridge.Destroy(Object); } catch (Exception ex) { throw ex; } }
public pnlPreviewFrame(Action <Exception> onFail) { this.Name = "pnlPreviewFrame"; this.Idle = new UIIdlePanel() { Float = Float.MIDDLE_CENTER, Width = Styles.Screen_Width, Height = Styles.Screen_Height * 1.5f, BackgroundColor = Media.colorTransparent }; this.States = new Dictionary <string, UIState>() { { "Previewing", new UIStatePanel() { Width = Styles.Screen_Width, Height = Styles.Screen_Height, BackgroundColor = Media.colorTransparent } } }; this.Components = new List <UIComponent>() { new UIImage() { Name = "imgFade", Idle = new UIIdleImage() { Float = Float.MIDDLE_CENTER, Width = Styles.Screen_Width, Height = Styles.Screen_Height * 1.5f, BackgroundColor = Color.black, Url = "Images/faded_background" }, States = new Dictionary <string, UIState>() { { "Previewing", new UIStateImage() { Width = Styles.Screen_Width, Height = Styles.Screen_Height, BackgroundColor = Color.black } } } }, new UIImage() { Name = "imgBottomIcon", Idle = new UIIdleImage() { Float = Float.BOTTOM_CENTER, Width = Styles.Side_Tall_Bar_Icon, Height = Styles.Side_Tall_Bar_Icon, Bottom = Styles.Padding_For_Anything, BackgroundColor = Media.colorOneThirdsTransparent, Url = "Images/icon_mj" } }, new UIPanel() { Name = "clckFrameBack", Idle = new UIIdlePanel() { Float = Float.BOTTOM_LEFT, Width = Styles.Width_Bar_Single, Height = Styles.Height_Bar_Medium, BackgroundColor = Media.colorTransparent }, Components = new List <UIComponent>() { new UIText() { Name = "txtBack", Idle = new UIIdleText() { Float = Float.MIDDLE_CENTER, Width = Styles.Width_Bar_Single, Alignment = TextAnchor.MiddleCenter, Font = Media.fontExoLight, FontColor = Media.colorGreyLight, FontSize = Styles.Font_Size_Larger, LineHeight = 1, Text = "Back" } } }, OnTouchInitialization = (component) => { return(new List <OnTouchListener>() { new OnTouchListener() { Owner = component.Name, Target = component.Name, Enabled = true, Released = true, OnRelease = (go) => { Directives.Sense_Touch = false; if (Variables.Current_Mojo.soundtrack.touch) { Events.Listeners.FirstOrDefault(l => l.Name == "On_Swiping_Horizontally").Enabled = false; Events.Listeners.FirstOrDefault(l => l.Name == "Swipe_Listener").Remove = true; } new StateBroadcaster() { Material = new StateBroadcasterMaterial() { State = "Preview_Back" }, OnFinish = () => { Variables.UI["pnlApp"].Object.transform.SetAsLastSibling(); new StateBroadcaster() { Material = new StateBroadcasterMaterial() { State = "App" }, OnFinish = () => { MonoBridge.Destroy(Objects.Environment); MonoBridge.Destroy(Objects.Avatar); Objects.AudioSource.Stop(); Variables.UI["pnlPreviewFrame"].Destroy(); Variables.UI["pnlKeyboard"].Object.transform.SetAsLastSibling(); Directives.Sense_Touch = true; } } .Broadcast(); } } .Broadcast(); } } }); } }, new UIPanel() { Name = "pnlCountdown", Idle = new UIIdlePanel() { Float = Float.BOTTOM_RIGHT, Width = Styles.Width_Bar_Single, Height = Styles.Height_Bar_Medium, BackgroundColor = Media.colorTransparent }, Components = new List <UIComponent>() { new UIText() { Name = "txtCountdown", Idle = new UIIdleText() { Float = Float.MIDDLE_CENTER, Width = Styles.Width_Bar_Single, Alignment = TextAnchor.MiddleCenter, Font = Media.fontExoLight, FontColor = Media.colorGreyLight, FontSize = Styles.Font_Size_Larger, LineHeight = 1, Text = "00:00", FurtherAccess = true } } } }, new UIPanel() { Name = "pnlContent", Idle = new UIIdlePanel() { Float = Float.TOP_CENTER, Width = Styles.Screen_Width, Height = Styles.Height_Bar_Tall, Bottom = Styles.Height_Bar_Tall, BackgroundColor = Media.colorTransparent }, States = new Dictionary <string, UIState>() { { "Delayed_Preview", new UIStatePanel() { Width = Styles.Screen_Width, Height = Styles.Height_Bar_Tall, BackgroundColor = Media.colorTransparent } } }, Components = new List <UIComponent>() { new UIImage() { Name = "imgProfile", Idle = new UIIdleImage() { Float = Float.TOP_LEFT, Width = Styles.Side_Frame_Profile, Height = Styles.Side_Frame_Profile, Top = Styles.Top_Frame_Profile, Left = Styles.Left_Frame_Profile, BackgroundColor = Media.colorOpaque, Url = Variables.Self.picture, LazyLoad = true, LazyLoadSuspension = 1 }, Components = new List <UIComponent>() { new UIImage() { Name = "imgProfileMaskRounded", Idle = new UIIdleImage() { Float = Float.TOP_LEFT, Width = Styles.Side_Frame_Profile, Height = Styles.Side_Frame_Profile, BackgroundColor = Media.colorBlack, Url = "Images/in_rounded" } }, new UIImage() { Name = "imgProfileMask", Idle = new UIIdleImage() { Float = Float.TOP_LEFT, Width = Styles.Side_Frame_Profile, Height = Styles.Side_Frame_Profile, BackgroundColor = Media.colorBlackOneThirdsTransparent, Url = "Images/solid" } } } }, new UIText() { Name = "txtTopMessage", Idle = new UIIdleText() { Float = Float.MIDDLE_LEFT, Width = Styles.Width_Frame_Message, Height = Styles.Height_Bar_Tall, Left = Styles.Left_Frame_Message, Alignment = TextAnchor.MiddleLeft, Font = Media.fontExoLight, FontColor = Media.colorWhite, FontSize = Styles.Font_Size_Smaller, LineHeight = 1.25f, Text = (Variables.Current_Mojo.message.Length == 0)?Variables.Self.name + ":\n" + Variables.Current_Mojo.soundtrack.name + " - " + Variables.Current_Mojo.soundtrack.belongsTo :(Variables.Current_Mojo.message.Length <= 40)?Variables.Self.name + ":\n" + Variables.Current_Mojo.message :Variables.Current_Mojo.message } } } } }; }
protected override IEnumerator Routine() { string url = Material.Url; if (Material.Parameters != null) { foreach (string param in Material.Parameters) { url += "/" + param; } } WWW www = new WWW(url); if (Material.UI_Text != null) { MonoBridge.StartCoroutine(Progress(www)); } yield return(www); while (!www.isDone) { } if (Material.UI_Text != null) { Material.UI_Text.text = ""; } if (www.error != null) { Exception ex = null; if (www.error.Contains("java.net.UnknownHostException")) { ex = new NoConnectionException(); } else if (www.error.Contains("Failed to connect to")) { ex = new ServerException(); } else if (www.error.Contains("Recv failure: Connection was reset")) { ex = new ConnectionDropException(); } else { try { string status = www.responseHeaders["STATUS"]; if (status.Contains("404 Not Found")) { ex = new NotFoundException(); } else if (status.Contains("500 Internal Server Error")) { ex = new InternalServerException(); } } catch (Exception) { ex = new Exception(www.error); Debug.LogAssertion(www.error); } } if (OnFail != null) { OnFail(ex); } else { Events.Exception(ex); } } else { try { OnSuccess(www); } catch (Exception ex) { if (OnFail != null) { OnFail(ex); } else { Events.Exception(ex); } } } Dispose(); }
private Task Instantiate() { return(new Task() { Mission = "Instantiate", Action = (seekTo, currentTask, nextTask, delivery) => { JsonBundle avatarBundle = Cache.Bundle_Cache.FirstOrDefault(b => b.pk == Variables.Current_Mojo.character.pk && b.type == BundleType.AVATAR); JsonBundle animatorBundle = Cache.Bundle_Cache.FirstOrDefault(b => b.pk == Variables.Current_Mojo.soundtrack.animator.pk && b.type == BundleType.ANIMATOR); JsonBundle skyboxBundle = Cache.Bundle_Cache.FirstOrDefault(b => b.pk == Variables.Current_Mojo.soundtrack.skybox.pk && b.type == BundleType.SKYBOX); JsonBundle environmentBundle = Cache.Bundle_Cache.FirstOrDefault(b => b.pk == Variables.Current_Mojo.soundtrack.environment.pk && b.type == BundleType.ENVIRONMENT); Objects.Environment = MonoBridge.Instantiate("Environment", environmentBundle.bundle.LoadAllAssets <GameObject>()[0]); Objects.Environment.transform.localPosition = new Vector3(0, 0, 0); Objects.Environment.transform.localEulerAngles = new Vector3(0, 0, 0); Objects.Environment.transform.localScale = new Vector3(1, 1, 1); Objects.Avatar = MonoBridge.Instantiate("Avatar", avatarBundle.bundle.LoadAllAssets <GameObject>()[0]); Objects.Avatar.transform.localPosition = new Vector3(0, 0, 0); Objects.Avatar.transform.localEulerAngles = new Vector3(0, 0, 0); Objects.Avatar.transform.localScale = new Vector3(1, 1, 1); Objects.Transform = GameObject.Find("Transform"); JsonVector position = Variables.Current_Mojo.soundtrack.position; JsonVector rotation = Variables.Current_Mojo.soundtrack.rotation; JsonVector scale = Variables.Current_Mojo.soundtrack.scale; Objects.Transform.transform.localPosition = new Vector3(position.x, position.y, position.z); Objects.Transform.transform.localEulerAngles = new Vector3(rotation.x, rotation.y, rotation.z); Objects.Transform.transform.localScale = new Vector3(scale.x, scale.y, scale.z); Objects.Body = GameObject.Find("Body"); Objects.Animator = Objects.Body.GetComponent <Animator>(); if (Objects.Animator == null) { Objects.Animator = Objects.Body.AddComponent <Animator>(); } Objects.Animator.runtimeAnimatorController = animatorBundle.bundle.LoadAllAssets <RuntimeAnimatorController>()[0]; Objects.Animator.applyRootMotion = true; Objects.Animator.cullingMode = AnimatorCullingMode.AlwaysAnimate; RenderSettings.skybox = skyboxBundle.bundle.LoadAllAssets <Material>()[0]; AudioClip audio = Cache.Audio_Cache.FirstOrDefault(a => a.pk == Variables.Current_Mojo.soundtrack.pk).clip; Objects.AudioSource.clip = audio; Objects.AudioSource.loop = Variables.Current_Mojo.soundtrack.loop; Objects.AudioSource.Play(); new DownCounter() { Material = new DownCounterMaterial() { Seconds = Variables.Current_Mojo.soundtrack.length }, Delay = 1, Condition = (material) => { if (Objects.Body == null) { return false; } if (Variables.Current_Mojo.soundtrack.loop) { if (material.Seconds == 0) { material.Seconds = Variables.Current_Mojo.soundtrack.length; } return true; } else { return material.Seconds != 0; } }, OnFinish = () => { if (Variables.Current_Mojo.soundtrack.touch) { Events.Listeners.FirstOrDefault(l => l.Name == "On_Swiping_Horizontally").Enabled = false; Events.Listeners.FirstOrDefault(l => l.Name == "Swipe_Listener").Remove = true; } new StateBroadcaster() { Material = new StateBroadcasterMaterial() { State = "Preview_Back" }, OnFinish = () => { Variables.UI["pnlApp"].Object.transform.SetAsLastSibling(); new StateBroadcaster() { Material = new StateBroadcasterMaterial() { State = "App" }, OnFinish = () => { MonoBridge.Destroy(Objects.Environment); MonoBridge.Destroy(Objects.Avatar); Objects.AudioSource.Stop(); Variables.UI["pnlPreviewFrame"].Destroy(); Variables.UI["pnlKeyboard"].Object.transform.SetAsLastSibling(); } } .Broadcast(); } } .Broadcast(); } } .Start(); Objects.Mojo_Camera.transform.localRotation = Quaternion.Euler(0, 0, 0); nextTask(null); } }); }
protected void Perform() { MonoBridge.StartCoroutine(Routine()); }