/// <summary> /// 現在アクティブな指定型のUIに対して一つだけ処理を行います。 /// </summary> public bool ExecuteAnyOne <T>(Action <T> action) { UIControlLog.Debug("[ilib-ui] ExecuteAnyOne<{0}>(Action<T>)", typeof(T)); return(ExecuteAnyOne <T>(x => { action(x); return true; })); }
protected async Task <UIInstance> Open <T>(string path, TParam prm, UIInstance parent = null) where T : UControl { UIControlLog.Debug("[ilib-ui] Open:{0}, prm:{1}, parent:{2}", path, prm, parent); StartProcess(); try { await OnBeginOpen(); var prefab = await Load <T>(path, prm); var obj = Instantiate(prefab, transform); var ui = obj.GetComponent <T>(); ui.SetController(this); var behind = parent?.Control?.OnBehind(prm); await ui.OnCreated(prm); OnOpen(ui); if (behind != null && IsWaitBehindBeforeOnFront <T>(path, prm)) { var hide = await behind; behind = null; if (hide && parent != null && parent.Control != null) { parent.Object.SetActive(false); } } await ui.OnFront(open : true); if (behind != null) { var hide = await behind; if (hide && parent != null && parent.Control != null) { parent.Object.SetActive(false); } } await OnEndOpen(); var ret = new UIInstance(); ret.Control = ui; ret.Object = obj; ret.Parent = parent; return(ret); } finally { UIControlLog.Trace("[ilib-ui] Complete Open:{0}", path); EndProcess(); } }
/// <summary> /// 現在アクティブな指定型のUIに対して処理を行います。 /// </summary> public bool Execute <T>(Action <T> action) { bool ret = false; foreach (var ui in GetActive <T>()) { ret = true; action.Invoke(ui); } UIControlLog.Debug("[ilib-ui] Execute<{0}>(), ret:{1}", typeof(T), ret); return(ret); }
/// <summary> /// 現在アクティブな指定型のUIに対して一つだけ処理を行います。 /// </summary> public bool ExecuteAnyOne <T>(Func <T, bool> action) { UIControlLog.Debug("[ilib-ui] ExecuteAnyOne<{0}>(Func<{0}, bool>)", typeof(T)); foreach (var ui in GetActive <T>()) { var ret = action.Invoke(ui); if (ret) { return(true); } } return(false); }
protected async Task <UIInstance> Change <T>(string path, TParam prm, UIInstance parent, UIInstance[] releases) where T : UControl { UIControlLog.Debug("[ilib-ui] Change:{0}, prm:{1}, parent:{2}", path, prm, parent); StartProcess(); try { await OnBeginChange(); var loading = Load <T>(path, prm); var close = CloseControls(releases); var prefab = await loading; if (IsWaitCloseBeforeOnOpen <T>(path, prm)) { await close; } var obj = Instantiate(prefab, transform); var ui = obj.GetComponent <T>(); ui.SetController(this); await ui.OnCreated(prm); OnOpen(ui); await ui.OnFront(open : true); if (!close.IsCompleted) { await close; } await OnEndChange(); var ret = new UIInstance(); ret.Control = ui; ret.Object = obj; ret.Parent = parent; return(ret); } finally { UIControlLog.Trace("[ilib-ui] Complete Change:{0}", path); EndProcess(); } }
protected Task CloseControls(UIInstance[] controls) { if (controls == null || controls.Length == 0) { return(Util.Successed); } return(Task.WhenAll(controls.Select(async x => { UIControlLog.Debug("[ilib-ui] Close:{0}", x); await x.Control.OnClose(); OnClose(x.Control as UControl); Destroy(x.Object); }))); }
/// <summary> /// IExecuteBackを実装したUIに対してバック処理を行います。 /// </summary> public bool ExecuteBack() { // 実行中は処理した扱いにする if (HasProcess) { return(true); } UIControlLog.Trace("[ilib-ui] Do ExecuteBack()"); return(ExecuteAnyOne <IExecuteBack>(x => { var ret = x.TryBack(); if (ret) { UIControlLog.Debug("[ilib-ui] ExecuteBack:{0}", x); } return ret; })); }
protected async Task Close(UIInstance[] releases, UIInstance front = null) { UIControlLog.Debug("[ilib-ui] Close, next front:{0}", front); StartProcess(); try { await OnBeginClose(); var close = CloseControls(releases); if (front != null) { if (!front.Object.activeSelf) { front.Object.SetActive(true); } if (IsWaitCloseBeforeOnFront(front.Control as UControl)) { await close; } await front.Control.OnFront(open : false); } if (!close.IsCompleted) { await close; } await OnEndClose(); } finally { UIControlLog.Trace("[ilib-ui] Complete Close"); EndProcess(); } }