NGUI實現滑動屏幕的時候,進行環形旋轉

在滑動屏幕的時候,上圖中的內容饒圓中心旋轉,而且箭頭的方向保持不變spa

每一個Item上掛載的腳本:code

1 using UnityEngine; 2 
3 public class ItemTest : MonoBehaviour 4 { 5     void Update() 6  { 7         transform.eulerAngles = Vector3.zero; 8  } 9 }

父結點上掛載的腳本:orm

 1 using System.Collections;  2 using System.Collections.Generic;  3 using UnityEngine;  4 
 5 public class lgs : MonoBehaviour  6 {  7  [SerializeField]  8  ItemTest[] itemArray;  9  [SerializeField] 10  Vector3 centerPos; 11  [SerializeField] 12     float radius; 13 
14  Vector3[] posArray; 15     void Start() 16  { 17         UIEventListener.Get(gameObject).onDrag = Drag; 18         InitPosFromCircularRing(out posArray, centerPos, itemArray.Length, radius); 19         for (int i = 0, iMax = itemArray.Length; i < iMax; i++) 20  { 21             itemArray[i].transform.localPosition = posArray[i]; 22  } 23  } 24 
25     float tmpVal = 0; 26     void Drag(GameObject go, Vector2 vec2) 27  { 28         tmpVal += vec2.y > 0 ? 2 : -2; 29         transform.localEulerAngles = new Vector3(0, 0, tmpVal); 30  } 31 
32     void InitPosFromCircularRing(out Vector3[] posArray, Vector3 centerPos, int count, float radius) 33  { 34         posArray = new Vector3[count]; 35         float copies = (360.0f / count) * Mathf.Deg2Rad; 36         for (int i = 0, j = count; i < j; ++i) 37  { 38             float x = radius * Mathf.Cos(copies * i); 39             //float y = centerPos.y;
40             float z = radius * Mathf.Sin(copies * i); 41             Vector3 vec3 = new Vector3(x, z, 0) + centerPos; 42             posArray[i] = vec3; 43  } 44  } 45 }
相關文章
相關標籤/搜索