/// <summary> /// 将上下文入栈,但是会受到<see cref="AbsContent.Priority"/>的优先级限制 /// </summary> /// <param name="content"></param> private void PushStack([NotNull] AbsContent content) { //如果有覆盖层则剔除这个层 if (content.Priority == UIContentType.OverView.ValueToInt() && (GetUICamera().cullingMask | GetOutUILayer()) == GetUICamera().cullingMask) { GetUICamera().cullingMask ^= GetOutUILayer(); } if (_stack.Count <= 0) { _stack.Add(content); return; } for (int i = _stack.Count - 1; i >= 0; i--) { if (_stack[i].Priority <= content.Priority) { if (i == _stack.Count - 1) { _stack.Add(content); } else { _stack.Insert(i + 1, content); } return; } } _stack.Insert(0, content); }
private void PopStack([NotNull] AbsContent content) { _stack.Remove(content); //如果没有覆盖层则增加显示剔除层 if (content.Priority == UIContentType.OverView.ValueToInt()) { if (_stack.Find(c => c.Priority == UIContentType.OverView.ValueToInt()) == null && (GetUICamera().cullingMask | GetOutUILayer()) != GetUICamera().cullingMask) { GetUICamera().cullingMask ^= GetOutUILayer(); } } }
protected override void PlayEnterAnim(AbsContent content, Action <AbsContent> end) { gameObject.SetActive(true); _animation.clip = _animation.GetClip(displayAnimName); _animation.Play(); if (_waitForSeconds != null) { StopCoroutine(_waitForSeconds); } _waitForSeconds = StartCoroutine(WaitForSeconds(_animation.GetClip(displayAnimName).length, () => { _waitForSeconds = null; end?.Invoke(content); } ) ); }
protected override void PlayExitAnim(AbsContent content, Action <AbsContent> end) { if (!gameObject.activeInHierarchy) { return; } _animation.Play(disableAnimName); if (_waitForSeconds != null) { StopCoroutine(_waitForSeconds); } _waitForSeconds = StartCoroutine(WaitForSeconds(_animation.GetClip(disableAnimName).length, () => { end?.Invoke(content); gameObject.SetActive(false); _waitForSeconds = null; } ) ); }
/// <summary> /// 禁用视图,可被强制禁用函数<see cref="ForcedDisable"/>截断,导致禁用时不执行 /// </summary> /// <param name="content"></param> public void Disable([CanBeNull] AbsContent content = null) { _content = content; PlayExitAnim(content, ExitAnimEnd); }
/// <summary> /// 强制禁用时调用,比如两个同视图的上下文在一起,上面的上下文Disable时会调用这个函数,而不是Disable /// </summary> /// <param name="content"></param> public virtual void ForcedDisable([NotNull] AbsContent content) { _content = content; }
/// <summary> /// 覆盖在自己上面的视图被Disable后,调用 /// </summary> /// <param name="content"></param> public virtual void Resume([NotNull] AbsContent content) { _content = content; }
/// <summary> /// 当有视图覆盖到此视图上时调用,如果展示窗口时优先级没能在第一个,则会立即调用此函数 /// </summary> /// <param name="content"></param> public virtual void Pause([NotNull] AbsContent content) { _content = content; }
/// <summary> /// 进入动画结束时调用 /// </summary> /// <param name="content"></param> public virtual void EnterAnimEnd([NotNull] AbsContent content) { }
/// <summary> /// 播放进入的动画,可重写动画 /// </summary> /// <param name="content"></param> /// <param name="end">动画结束的回调</param> protected virtual void PlayEnterAnim([NotNull] AbsContent content, Action <AbsContent> end) { gameObject.SetActive(true); end?.Invoke(content); }
/// <summary> /// 展示窗口 /// </summary> /// <param name="content"></param> public void Display([NotNull] AbsContent content) { _content = content; PlayEnterAnim(content, EnterAnimEnd); }
/// <summary> /// 退出动画结束后调用 /// </summary> /// <param name="content"></param> public virtual void ExitAnimEnd([CanBeNull] AbsContent content = null) { }
/// <summary> /// 播放退出动画 /// </summary> /// <param name="content"></param> /// <param name="end"></param> protected virtual void PlayExitAnim([CanBeNull] AbsContent content, Action <AbsContent> end) { gameObject.SetActive(false); end?.Invoke(content); }