這篇文章主要介紹Unity實(shí)現(xiàn)3D循環(huán)滾動(dòng)效果的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
成都創(chuàng)新互聯(lián)公司憑借在網(wǎng)站建設(shè)、網(wǎng)站推廣領(lǐng)域領(lǐng)先的技術(shù)能力和多年的行業(yè)經(jīng)驗(yàn),為客戶(hù)提供超值的營(yíng)銷(xiāo)型網(wǎng)站建設(shè)服務(wù),我們始終認(rèn)為:好的營(yíng)銷(xiāo)型網(wǎng)站就是好的業(yè)務(wù)員。我們已成功為企業(yè)單位、個(gè)人等客戶(hù)提供了成都網(wǎng)站建設(shè)、成都網(wǎng)站制作服務(wù),以良好的商業(yè)信譽(yù),完善的服務(wù)及深厚的技術(shù)力量處于同行領(lǐng)先地位。
具體內(nèi)容如下
然后通過(guò)SetDepthAndPosition這個(gè)方法,實(shí)現(xiàn)圖片的空間空間展開(kāi)
Z軸和Y軸,系數(shù)是一樣的
經(jīng)過(guò)上面設(shè)置,空間就擺開(kāi)了
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_roleList = new List (); // 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 ().onChange , RoleToggleChange); RoleItem item = role.GetComponent (); 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 (); 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 ().value = indexDepth == _half ? true:false; tp.PlayForward(); } /// /// 左邊 /// public void LeftClick() { //重新排列順序 foreach (RoleItem role in _roleList) { int index = int.Parse(role.name); print(index); SetDepthAndPosition(role,1,++index); } } ////// 右邊 /// public void RightClick() { //重新排列順序 foreach (RoleItem role in _roleList) { int index = int.Parse(role.name); SetDepthAndPosition(role,-1,--index); } } ////// 鼠標(biāo)選中某個(gè)角色 /// 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(); } } } }
以上是“Unity實(shí)現(xiàn)3D循環(huán)滾動(dòng)效果的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!