Unity實(shí)現(xiàn)3D循環(huán)滾動(dòng)效果
本文實(shí)例為大家分享了Unity實(shí)現(xiàn)3D循環(huán)滾動(dòng)效果展示的具體代碼,供大家參考,具體內(nèi)容如下
然后通過SetDepthAndPosition這個(gè)方法,實(shí)現(xiàn)圖片的空間空間展開
Z軸和Y軸,系數(shù)是一樣的
經(jīng)過上面設(shè)置,空間就擺開了
using UnityEngine; using System.Collections; using System.Collections.Generic; public class SelectRole : MonoBehaviour { public GameObject rolesObj; private int _half = 0;//一側(cè)的卡片數(shù) private int _movX = 150;//X軸移動(dòng)距離 private int _movY = 50;//Y軸移動(dòng)距離 private int _movZ = 60;//Z軸移動(dòng)距離 private int count = 3;//組件數(shù) 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++) { //加載角色圖片預(yù)設(shè) 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; //設(shè)置角色卡片排序命名 role.name = maxDepth.ToString(); if (i > 0) { //奇數(shù)設(shè)置為右邊,下標(biāo)為正數(shù) if (i % 2 == 1) { maxDepth--; role.name = maxDepth.ToString(); } //偶數(shù)設(shè)置為左邊,下標(biāo)為負(fù)數(shù) else { role.name = "-" + maxDepth.ToString(); } } SetDepthAndPosition(item,0,0); _roleList.Add(item); } } private void SetDepthAndPosition(RoleItem role,int dir,int index) { int indexDepth = 0; //左右移動(dòng)后,重新排序命名 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> /// 鼠標(biāo)選中某個(gè)角色 /// </summary> public void RoleToggleChange() { if(UIToggle.current.value) { int index = int.Parse(UIToggle.current.name); int moveCount = _half - System.Math.Abs(index);//移動(dòng)個(gè)數(shù) for (int i = 0; i < moveCount;i++ ) { if (index > 0) LeftClick(); else RightClick(); } } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:UnityShader使用速度映射圖實(shí)現(xiàn)運(yùn)動(dòng)模糊
欄 目:C#教程
下一篇:c#多線程程序設(shè)計(jì)實(shí)例方法
本文標(biāo)題:Unity實(shí)現(xiàn)3D循環(huán)滾動(dòng)效果
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/4878.html
您可能感興趣的文章
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新聞效果的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已安裝軟件變化的方法
- 01-10C#實(shí)現(xiàn)多線程下載文件的方法
- 01-10C#實(shí)現(xiàn)Winform中打開網(wǎng)頁頁面的方法
- 01-10C#實(shí)現(xiàn)遠(yuǎn)程關(guān)閉計(jì)算機(jī)或重啟計(jì)算機(jī)的方法
- 01-10C#自定義簽名章實(shí)現(xiàn)方法
- 01-10C#文件斷點(diǎn)續(xù)傳實(shí)現(xiàn)方法
- 01-10winform實(shí)現(xiàn)創(chuàng)建最前端窗體的方法


閱讀排行
- 1C語言 while語句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
- 3利用C語言實(shí)現(xiàn)“百馬百擔(dān)”問題方法
- 4C語言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10C#中split用法實(shí)例總結(jié)
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 04-02jquery與jsp,用jquery
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10delphi制作wav文件的方法