看效果
上代码
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)
|