Unity實現3D循環(huán)滾動效果
來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次
本文實例為大家分享了Unity實現3D循環(huán)滾動效果展示的具體代碼,供大家參考,具體內容如下
然后通過SetDepthAndPosition這個方法,實現圖片的空間空間展開
Z軸和Y軸,系數是一樣的
經過上面設置,空間就擺開了
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SelectRole : MonoBehaviour {
public GameObject rolesObj;
private int _half = 0;//一側的卡片數
private int _movX = 150;//X軸移動距離
private int _movY = 50;//Y軸移動距離
private int _movZ = 60;//Z軸移動距離
private int count = 3;//組件數
private List<RoleItem> _roleList = new List<RoleItem>();
// Use this for initialization
void Start () {
//加載圖片
Object[] textureList = (Object[])Resources.LoadAll("Pictures");
int maxDepth = textureList.Length % 2 == 1 ? textureList.Length / 2 + 1 : textureList.Length / 2;//最大深度
_half = maxDepth;
for (int i = 0; i < textureList.Length; i++)
{
//加載角色圖片預設
GameObject role = Instantiate(Resources.Load("Role", typeof(GameObject))) as GameObject;
role.transform.parent = rolesObj.transform;
role.transform.localScale = Vector3.one;
EventDelegate.Add(role.GetComponent<UIToggle>().onChange , RoleToggleChange);
RoleItem item = role.GetComponent<RoleItem>();
item.texture.mainTexture = textureList[i] as Texture;
//設置角色卡片排序命名
role.name = maxDepth.ToString();
if (i > 0)
{
//奇數設置為右邊,下標為正數
if (i % 2 == 1)
{
maxDepth--;
role.name = maxDepth.ToString();
}
//偶數設置為左邊,下標為負數
else
{
role.name = "-" + maxDepth.ToString();
}
}
SetDepthAndPosition(item,0,0);
_roleList.Add(item);
}
}
private void SetDepthAndPosition(RoleItem role,int dir,int index)
{
int indexDepth = 0;
//左右移動后,重新排序命名
if (dir != 0)
{
if (index*dir > _half )
indexDepth = -dir * (_half - 1);
else
indexDepth = index > -1 && index < 1 ? dir : index;
role.name = indexDepth.ToString();
}
else
{
indexDepth = int.Parse(role.name);
}
TweenPosition tp = role.GetComponent<TweenPosition>();
int x = indexDepth < 0 ? -(_half + indexDepth) * _movX : (_half - indexDepth) * _movX;
indexDepth = System.Math.Abs(indexDepth);
tp.to = new Vector3(x, (_half - indexDepth) * _movY, (_half - indexDepth) * _movZ);
role.bg.depth = count * indexDepth;
role.active.depth = 1 + count * indexDepth;
role.texture.depth = 2 + count * indexDepth;
role.GetComponent<UIToggle>().value = indexDepth == _half ? true:false;
tp.PlayForward();
}
/// <summary>
/// 左邊
/// </summary>
public void LeftClick()
{
//重新排列順序
foreach (RoleItem role in _roleList)
{
int index = int.Parse(role.name);
print(index);
SetDepthAndPosition(role,1,++index);
}
}
/// <summary>
/// 右邊
/// </summary>
public void RightClick()
{
//重新排列順序
foreach (RoleItem role in _roleList)
{
int index = int.Parse(role.name);
SetDepthAndPosition(role,-1,--index);
}
}
/// <summary>
/// 鼠標選中某個角色
/// </summary>
public void RoleToggleChange()
{
if(UIToggle.current.value)
{
int index = int.Parse(UIToggle.current.name);
int moveCount = _half - System.Math.Abs(index);//移動個數
for (int i = 0; i < moveCount;i++ )
{
if (index > 0)
LeftClick();
else
RightClick();
}
}
}
}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。
您可能感興趣的文章
- 01-10C#實現txt定位指定行完整實例
- 01-10WinForm實現仿視頻播放器左下角滾動新聞效果的方法
- 01-10C#實現清空回收站的方法
- 01-10C#實現讀取注冊表監(jiān)控當前操作系統(tǒng)已安裝軟件變化的方法
- 01-10C#實現多線程下載文件的方法
- 01-10C#實現Winform中打開網頁頁面的方法
- 01-10C#實現遠程關閉計算機或重啟計算機的方法
- 01-10C#自定義簽名章實現方法
- 01-10C#文件斷點續(xù)傳實現方法
- 01-10winform實現創(chuàng)建最前端窗體的方法


閱讀排行
本欄相關
- 01-10C#通過反射獲取當前工程中所有窗體并
- 01-10關于ASP網頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實現txt定位指定行完整實例
- 01-10WinForm實現仿視頻播放器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實現清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實現讀取注冊表監(jiān)控當前操作系統(tǒng)已
隨機閱讀
- 01-10C#中split用法實例總結
- 08-05dedecms(織夢)副欄目數量限制代碼修改
- 04-02jquery與jsp,用jquery
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 01-11ajax實現頁面的局部加載
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10delphi制作wav文件的方法


