Unity 图片滚动效果

Unity 图片滚动效果

看效果

效果展示

上代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class ControlMode : MonoBehaviour
{

    public int currentIndex;

    public float speedTime = 0.5f;

    private CanvasGroup canvasGroup;
    private void Start()
    {
        canvasGroup = this.GetComponent<CanvasGroup>();

        ResetPosition(this.currentIndex);
    }

    public void ResetPosition(int currentIndex)
    {

        switch (currentIndex)
        {
            case 0:
                transform.SetSiblingIndex(3);
                transform.DOLocalMove(Manger.instance.currentPositions[0], speedTime).SetEase(Ease.OutExpo);
                transform.DOScale(Manger.instance.currentScale[0], speedTime).SetEase(Ease.OutExpo);
                transform.DOLocalRotate(Manger.instance.currentRotation[0], speedTime).SetEase(Ease.OutExpo);
                canvasGroup.DOFade(Manger.instance.currentAple[0] / 2, speedTime / 2).OnComplete(() => { canvasGroup.DOFade(Manger.instance.currentAple[0], speedTime / 2); }).SetEase(Ease.OutExpo);

                break;
            case 1:
                transform.SetSiblingIndex(2);
                transform.DOLocalMove(Manger.instance.currentPositions[1], speedTime).SetEase(Ease.OutExpo);
                transform.DOScale(Manger.instance.currentScale[1], speedTime).SetEase(Ease.OutExpo);
                transform.DOLocalRotate(Manger.instance.currentRotation[1], speedTime).SetEase(Ease.OutExpo);
                canvasGroup.DOFade(Manger.instance.currentAple[1] / 2, speedTime / 2).OnComplete(() => { canvasGroup.DOFade(Manger.instance.currentAple[1], speedTime / 2); }).SetEase(Ease.OutExpo);
                break;
            case 2:
                transform.SetSiblingIndex(1);
                transform.DOLocalMove(Manger.instance.currentPositions[2], speedTime).SetEase(Ease.OutExpo);
                transform.DOScale(Manger.instance.currentScale[2], speedTime).SetEase(Ease.OutExpo);
                transform.DOLocalRotate(Manger.instance.currentRotation[2], speedTime).SetEase(Ease.OutExpo);
                canvasGroup.DOFade(Manger.instance.currentAple[2] / 2, speedTime / 2).OnComplete(() => { canvasGroup.DOFade(Manger.instance.currentAple[2], speedTime / 2); }).SetEase(Ease.OutExpo);
                break;
            case 3:
                transform.SetSiblingIndex(0);
                transform.DOLocalMove(Manger.instance.currentPositions[3], speedTime).SetEase(Ease.OutExpo);
                transform.DOScale(Manger.instance.currentScale[3], speedTime).SetEase(Ease.OutExpo);
                transform.DOLocalRotate(Manger.instance.currentRotation[3], speedTime).SetEase(Ease.OutExpo);
                canvasGroup.DOFade(Manger.instance.currentAple[3] / 2, speedTime / 2).OnComplete(() => { canvasGroup.DOFade(Manger.instance.currentAple[3], speedTime / 2); }).SetEase(Ease.OutExpo);
                break;
            default:
                break;
        }
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Manger : MonoBehaviour
{
    public static Manger instance;

    [Header("位置设置")]
    public Vector2[] currentPositions;
    [Header("大小设置")]
    public Vector2[] currentScale;
    [Header("透明度设置")]
    public float[] currentAple;
    [Header("角度")]
    public Vector3[] currentRotation;

    public float timer = 5f;
    public bool isOn = true;

    private ControlMode[] gameCards;
    private void Start()
    {
        instance = this;
    }

    private void Update()
    {
        if (isOn)
        {
            timer -= Time.deltaTime;
            if (timer <= 0.01f)
            {
                isOn = false;
               
                ButUp();
            }
        }
    }


    public void ButUp()
    {
        timer = 5f;
        isOn = true;
        gameCards = this.GetComponentsInChildren<ControlMode>();//获取卡片组件

        for (int i = 0; i <= gameCards.Length - 1; i++)
        {
            ControlMode item = gameCards[i];

            if (item.currentIndex == 0)
            {
                item.currentIndex = (gameCards.Length - 1);
            }
            else
            {
                item.currentIndex -= 1;
            }

            item.ResetPosition(item.currentIndex);
        }

    }

    public void ButDown()
    {
        gameCards = this.GetComponentsInChildren<ControlMode>();//获取卡片组件

        for (int i = 0; i <= gameCards.Length - 1; i++)
        {
            ControlMode item = gameCards[i];

            if (item.currentIndex == (gameCards.Length - 1))
            {
                item.currentIndex = 0;
            }
            else
            {
                item.currentIndex += 1;
            }

            item.ResetPosition(item.currentIndex);
        }
    }
}

源文件

源码连接
版本Unity 2020.3.0f1c1 (64-bit)

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值