在unity中实现分页扩展(旋转3D)功能(UGUI)(3)

这篇博客是第三个阶段了 我们在上一篇博客的基础上 给每个子物体的加上旋转的效果
老规矩 先给demo
在这里插入图片描述

这次的效果不是很明显 原因是我的场景中的参数设置不是很好
导致在game模式下很难看清 所以这次的gif图我在scene模式下做的

大家可以很清楚的看到 旋转
同样这次的代码还是继承上一次的代码 下边我放一个我这个专栏的链接 大家可以自行查看
专栏链接

然后就是代码了

public class RotateScalePaveView : ScalePageView
{
    //继承scale的代码(三)
    [Header("旋转参数")]
    public float rotations;

    protected override void Update()
    {
        base.Update();

        ListenRotation();
    }
    public void ListenRotation()
    {
        //监听旋转
        if (nextpage == lastpage)
        {
            return;
        }

        float percent = (rect.horizontalNormalizedPosition-pages[lastpage]) / (pages[nextpage] - pages[lastpage]);

        items[lastpage].transform.localRotation = Quaternion.Euler(-Vector3.Lerp(Vector3.zero, new Vector3(0, rotations, 0), percent));
        items[nextpage].transform.localRotation = Quaternion.Euler(Vector3.Lerp(Vector3.zero, new Vector3(0, rotations, 0), 1 - percent));


        for (int i = 0; i < items.Length; i++)
        {
            if (i != lastpage && i != nextpage)
            {
                if (i < currentindex)
                {
                    items[i].transform.localRotation = Quaternion.Euler(new Vector3(0, -rotations, 0));
                }
                if (i > currentindex)
                {
                    items[i].transform.localRotation = Quaternion.Euler(new Vector3(0, rotations, 0));
                }
            }
            
        }
    }
}

其实核心思想是和第二篇的思想一样的
如果你对这个专栏的内容感兴趣 欢迎关注我
有问题也可以去主页找我的联系方式 联系我(知无不答)

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值