当前位置:网站首页>Unity multiple UI page turning left and right
Unity multiple UI page turning left and right
2022-06-30 04:57:00 【Bigfield】
On the effect

It's also very easy to implement , coordination DoTween plug-in unit , An array , An index can be implemented . Specify five locations , Get the picture through the index in five places tween That's all right. .
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MySelect : MonoBehaviour
{
public Image[] all;
public int StartIndex = 0;
public Transform pos_left_2;
public Transform pos_left;
public Transform pos_Mid;
public Transform pos_right;
public Transform pos_right_2;
int length = 0;
public float speed = 1f;
[HideInInspector]
public bool IsTweening = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
TurnLeft();
if (Input.GetKeyDown(KeyCode.RightArrow))
TurnRight();
}
private void Start()
{
length = all.Length;
Mid_Index = StartIndex;
init();
}
int Mid_Index = 0;
int left_Index;
int left_Index_2;
int right_Index;
int right_Index_2;
public void init()
{
for (int i = 0; i < length; i++)
{
all[i].transform.localScale = Vector3.zero;
all[i].gameObject.SetActive(false);
}
all[Mid_Index].transform.position = pos_Mid.position;
all[Mid_Index].transform.localScale = pos_Mid.localScale;
all[Mid_Index].gameObject.SetActive(true);
left_Index = Mid_Index - 1;
if (left_Index < 0) left_Index += length;
all[left_Index].transform.position = pos_left.position;
all[left_Index].transform.localScale = pos_left.localScale;
all[left_Index].gameObject.SetActive(true);
right_Index = Mid_Index + 1;
if (right_Index >= length) right_Index -= length;
all[right_Index].transform.position = pos_right.position;
all[right_Index].transform.localScale = pos_right.localScale;
all[right_Index].gameObject.SetActive(true);
all[right_Index].transform.SetAsLastSibling();
all[left_Index].transform.SetAsLastSibling();
all[Mid_Index].transform.SetAsLastSibling();
}
// towards the left The index has increased
public void TurnLeft()
{
if (!IsTweening)
StartCoroutine(ITurnLeft());
}
IEnumerator ITurnLeft()
{
IsTweening = true;
// On the right side Generate a
right_Index_2 = right_Index + 1;
if (right_Index_2 >= length) right_Index_2 -= length;
all[right_Index_2].transform.position = pos_right_2.position;
all[right_Index_2].transform.localScale = pos_right_2.localScale;
all[right_Index_2].gameObject.SetActive(true);
all[right_Index_2].transform.SetAsLastSibling();
all[right_Index].transform.SetAsLastSibling();
all[Mid_Index].transform.SetAsLastSibling();
// slide
all[right_Index_2].transform.DOMove(pos_right.position, speed);
all[right_Index_2].transform.DOScale(pos_right.localScale, speed);
all[right_Index].transform.DOMove(pos_Mid.position, speed);
all[right_Index].transform.DOScale(pos_Mid.localScale, speed);
all[Mid_Index].transform.DOMove(pos_left.position, speed);
all[Mid_Index].transform.DOScale(pos_left.localScale, speed);
all[left_Index].transform.DOMove(pos_left_2.position, speed); ;
all[left_Index].transform.DOScale(pos_left_2.localScale, speed);
yield return new WaitForSeconds(speed);
all[left_Index].gameObject.SetActive(false);
Mid_Index++;
if (Mid_Index >= length) Mid_Index -= length;
left_Index = Mid_Index - 1;
if (left_Index < 0) left_Index += length;
right_Index = Mid_Index + 1;
if (right_Index >= length) right_Index -= length;
IsTweening = false;
}
// towards the right Index decrease
public void TurnRight()
{
Debug.LogError($"left_2={left_Index_2},left={left_Index},mid={Mid_Index},right={right_Index},right_2={right_Index_2}");
// left Generate a
if (!IsTweening)
StartCoroutine(ITurnRight());
}
IEnumerator ITurnRight()
{
IsTweening = true;
left_Index_2 = left_Index - 1;
if (left_Index_2 < 0) left_Index_2 += length;
all[left_Index_2].transform.position = pos_left_2.position;
all[left_Index_2].transform.localScale = pos_left_2.localScale;
all[left_Index_2].gameObject.SetActive(true);
all[left_Index_2].transform.SetAsLastSibling();
all[left_Index].transform.SetAsLastSibling();
all[Mid_Index].transform.SetAsLastSibling();
// slide
all[left_Index_2].transform.DOMove(pos_left.position, speed);
all[left_Index_2].transform.DOScale(pos_left.localScale, speed);
all[left_Index].transform.DOMove(pos_Mid.position, speed);
all[left_Index].transform.DOScale(pos_Mid.localScale, speed);
all[Mid_Index].transform.DOMove(pos_right.position, speed);
all[Mid_Index].transform.DOScale(pos_right.localScale, speed);
all[right_Index].transform.DOMove(pos_right_2.position, speed); ;
all[right_Index].transform.DOScale(pos_right_2.localScale, speed);
yield return new WaitForSeconds(speed);
all[right_Index].gameObject.SetActive(false);
Mid_Index--;
if (Mid_Index < 0) Mid_Index += length;
left_Index = Mid_Index - 1;
if (left_Index < 0) left_Index += length;
right_Index = Mid_Index + 1;
if (right_Index >= length) right_Index -= length;
IsTweening = false;
}
}
边栏推荐
- Preorder traversal of Li Kou 589:n fork tree
- 圆心科技,很焦虑?
- Qos(Quality of Service)
- 为什么win10开热点后电脑没有网络?
- LxC and LXD container summary
- Pourquoi l'ordinateur n'a - t - il pas de réseau après l'ouverture du Hotspot win10?
- 【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
- Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok
- Tcp/ip protocol details Volume I (Reading Guide)
- National Museum of Singapore - give you spiritual and physical satisfaction
猜你喜欢

Output directory of log files after unity3d packaging

Force buckle 349 Intersection of two arrays

为什么win10开热点后电脑没有网络?

Unreal 4 learning notes - set player birth point

Sailing experience not to be missed in New York Tourism: take you to enjoy the magnificent city scenery from different perspectives

LxC and LXD container summary

力扣589:N 叉树的前序遍历

Beanfactory creation process

PBR material: basic principle and simple fabrication

Lambda&Stream
随机推荐
力扣292周赛题解
Unreal 4 unavigationsystemv1 compilation error
Deep learning ----- different methods to realize inception-10
Preorder traversal of Li Kou 589:n fork tree
力扣2049:统计最高分的节点数目
【Paper】2006_ Time-Optimal Control of a Hovering Quad-Rotor Helicopter
Important knowledge points in unity3d
brew安装nvm报nvm command not found解决方案
Unreal 4 learning notes - Animated Montage
Recommended cultural landmarks of these tourist attractions in Bangkok
Passing values between classes using delegates and events
How to apply for SSL certificate from the manufacturer
【Paper】2017_ Distributed control for high-speed trains movements
0 basic unity course. Bricklaying
Bean creation process and lazy init delay loading mechanism
Unit screenshot saved on the phone
力扣704. 二分查找
Pycharm database tool
Moore Manor diary I: realize the reclamation, sowing, watering and harvest in Moore Manor
Is the Flink connector JDBC open source? Where can I download it