在unity中实现分页扩展(旋转3D)功能(UGUI)(3)
程序员文章站
2022-07-12 23:34:04
...
这篇博客是第三个阶段了 我们在上一篇博客的基础上 给每个子物体的加上旋转的效果
老规矩 先给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));
}
}
}
}
}
其实核心思想是和第二篇的思想一样的
如果你对这个专栏的内容感兴趣 欢迎关注我
有问题也可以去主页找我的联系方式 联系我(知无不答)
上一篇: Unity3D之物体运动(二)
下一篇: Week03-3DHomwork