如何对菜单进行封面流动效果

时间:2018-03-14 16:49:05

标签: unity3d scrollview coverflow scrollrect

我正在尝试通过Scrollrect开发一个循环菜单,我想把它作为菜单的图片,我该怎么办? Picture Effect

对于这个效果,我有两个问题,一个是如何制作较小比例的长距离物体 另一个问题是如何为不同的按钮添加深度

这是我的代码,使用scrollrect循环按钮:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG;
public class ScrollRectSnap4 : MonoBehaviour {
public RectTransform panel;
public Button[] bttn;
public RectTransform center;
public float[] distance;
public float[] distReposition;
private bool dragging = false;
public int bttnDistance;
private int minButtonNum;
private int bttnLenght;
public float minDistance;
void Start () {
    bttnLenght = bttn.Length;
    distance = new float[bttnLenght];
    distReposition = new float[bttnLenght];
    bttnDistance = (int)Mathf.Abs(bttn[1].GetComponent<RectTransform>().anchoredPosition.x - bttn[0].GetComponent<RectTransform>().anchoredPosition.x);
}
void Update () {
    for (int i = 0; i < bttn.Length; i++) {
        distReposition[i] = center.transform.position.x - 
bttn[i].transform.position.x;
        distance [i] = Mathf.Abs (distReposition[i]);
        if (distReposition [i] > 1200) {
            float curX = bttn [i].GetComponent<RectTransform> ().anchoredPosition.x;
            float curY = bttn [i].GetComponent<RectTransform> ().anchoredPosition.y;
            Vector2 newAnchoredPos1 = new Vector2 (curX + (bttnLenght * bttnDistance), curY);
            //Debug.Log (bttn[i].name + "newAnchoredPos1:   " + newAnchoredPos1);
            bttn [i].GetComponent<RectTransform> ().anchoredPosition = newAnchoredPos1;
        }
        if (distReposition [i] < -1200) {
            float curX = bttn [i].GetComponent<RectTransform> ().anchoredPosition.x;
            float curY = bttn [i].GetComponent<RectTransform> ().anchoredPosition.y;
            Vector2 newAnchoredPos2 = new Vector2 (curX - (bttnLenght * bttnDistance), curY);
            bttn [i].GetComponent<RectTransform> ().anchoredPosition = newAnchoredPos2;
        }
    }
    minDistance = Mathf.Min (distance);
    for (int a = 0; a < bttn.Length; a++) {
        if (minDistance == distance [a]) {
            minButtonNum = a;
            bttn[a].transform.localScale = Vector3.Lerp(bttn[a].transform.localScale,new Vector3(1f,1f,1f),Time.deltaTime*5);
        } else {
            bttn[a].transform.localScale = Vector3.Lerp(bttn[a].transform.localScale,new Vector3(0.7f,0.7f,0.7f),Time.deltaTime*5);
        }
    }
    if (!dragging) {
        //LerpToBttn (minButtonNum * -bttnDistance);
        LerpToBttn (-bttn[minButtonNum].GetComponent<RectTransform>().anchoredPosition.x);
    }
}
void LerpToBttn (float position){
    //Debug.Log ("Position: " + -bttn[minButtonNum].GetComponent<RectTransform>().anchoredPosition.x);
    float newX = Mathf.Lerp (panel.anchoredPosition.x, position, Time.deltaTime * 5f);
    Vector2 newPosition = new Vector2 (newX, panel.anchoredPosition.y);
    panel.anchoredPosition = newPosition;
}
public void StartDrag(){
    dragging = true;
}
public void EndDrag(){
    dragging = false;
}
}

0 个答案:

没有答案