其他分享
首页 > 其他分享> > NGUI实现滑动屏幕的时候,进行环形旋转

NGUI实现滑动屏幕的时候,进行环形旋转

作者:互联网

在滑动屏幕的时候,上图中的内容饶圆中心旋转,并且箭头的方向保持不变

每个Item上挂载的脚本:

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

父结点上挂载的脚本:

 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 }

标签:Vector3,float,itemArray,posArray,radius,centerPos,滑动,屏幕,NGUI
来源: https://www.cnblogs.com/luguoshuai/p/10764468.html