unity3d:UGUI卷轴展开动画效果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luoyikun/article/details/88668051

卷轴式UI面板打开特效
思路:content用mask控制x方向大小,用dotween
两边的圆柱体同时dotween控制位置
在这里插入图片描述
面板的结构为
面板结构
content 增加mask组件
在这里插入图片描述

public class UGUIPanel : BasePanel
    {
        public UnityAction m_actOpenFinish;
        private CanvasGroup mCanvasGroup;
        public bool m_isOpen = false;

        Vector2? m_oriSize;
        Transform m_content;
        Transform m_left;
        Transform m_right;
        float m_radius = 10;
        float m_time = 1.0f;
        
        public override void OnEnter(bool isAni = true)
        {
            EventEnable(true);

            gameObject.SetActive(true);

            if (isAni == true)
            {
                if (m_content == null)
                {
                    m_content = transform.Find("Content");
                }
                if (m_oriSize.HasValue == false)
                {
                    m_oriSize = m_content.GetComponent<RectTransform>().sizeDelta;
                }

                if (m_left == null)
                {
                    m_left = transform.Find("Left");
                }

                if (m_right == null)
                {
                    m_right = transform.Find("Right");
                }
                m_content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, m_oriSize.Value.y);

                DOTween.To(() => m_content.GetComponent<RectTransform>().sizeDelta, x => m_content.GetComponent<RectTransform>().sizeDelta = x, m_oriSize.Value, m_time);

                m_left.localPosition = new Vector3(-m_radius, 0, 0);
                m_right.localPosition = new Vector3(m_radius, 0, 0);

                DOTween.To(() => m_left.localPosition, x => m_left.localPosition = x, new Vector3(-m_oriSize.Value.x/2,0,0), m_time);
                DOTween.To(() => m_right.localPosition, x => m_right.localPosition = x, new Vector3(m_oriSize.Value.x/2, 0, 0), m_time);
            }

            OnOpen();

            if (isAni == false)
            {
                m_isOpen = true;
                if (m_actOpenFinish != null) m_actOpenFinish();
            }
        }
        }

核心:

m_content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, m_oriSize.Value.y);

                DOTween.To(() => m_content.GetComponent<RectTransform>().sizeDelta, x => m_content.GetComponent<RectTransform>().sizeDelta = x, m_oriSize.Value, m_time);

                m_left.localPosition = new Vector3(-m_radius, 0, 0);
                m_right.localPosition = new Vector3(m_radius, 0, 0);

                DOTween.To(() => m_left.localPosition, x => m_left.localPosition = x, new Vector3(-m_oriSize.Value.x/2,0,0), m_time);
                DOTween.To(() => m_right.localPosition, x => m_right.localPosition = x, new Vector3(m_oriSize.Value.x/2, 0, 0), m_time);

猜你喜欢

转载自blog.csdn.net/luoyikun/article/details/88668051