Beispiel #1
0
 public void UIExit(UIBase ui, UIExitStyle style)
 {
     if (ui == null)
     {
         Debug.LogWarning("需要退出的UI不存在!");
         return;
     }
     if (!_uiList.Contains(ui))
     {
         Debug.LogWarning("需要退出的UI不在UI列表中!UI:" + ui.ToString());
         return;
     }
     _uiList.Remove(ui);
     OnUIExitStyle(ui.GetComponent <RectTransform>(), style, () => { Destroy(ui.gameObject); });
 }
Beispiel #2
0
    /// <summary>
    /// 移除UI的方式
    /// </summary>
    /// <param name="style"></param>
    private void OnUIExitStyle(RectTransform rect, UIExitStyle style, TweenCallback onComplete = null, float time = 1)
    {
        Vector2 startPos = rect.anchoredPosition;
        Vector2 endPos   = Vector2.zero;

        switch (style)
        {
        case UIExitStyle.Null:
            return;

        case UIExitStyle.ToLeft:
            float endX_l = startPos.x - rect.rect.width;
            endPos = new Vector2(endX_l, startPos.y);
            break;

        case UIExitStyle.ToRight:
            float endX_r = startPos.x + rect.rect.width;
            endPos = new Vector2(endX_r, startPos.y);
            break;

        case UIExitStyle.ToTop:
            float endY_t = startPos.y + rect.rect.height;
            endPos = new Vector2(startPos.x, endY_t);
            break;

        case UIExitStyle.ToBottom:
            float endY_b = startPos.y - rect.rect.height;
            endPos = new Vector2(startPos.x, endY_b);
            break;

        default:
            break;
        }
        rect.anchoredPosition = startPos;
        Tweener tweener = rect.DOAnchorPos(endPos, time);

        if (onComplete != null)
        {
            tweener.OnComplete(onComplete);
        }
    }