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

时间:2021-01-17 10:49:42

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

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

每个Item上挂载的脚本:

 using UnityEngine;

 public class ItemTest : MonoBehaviour
{
void Update()
{
transform.eulerAngles = Vector3.zero;
}
}

父结点上挂载的脚本:

 using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class lgs : MonoBehaviour
{
[SerializeField]
ItemTest[] itemArray;
[SerializeField]
Vector3 centerPos;
[SerializeField]
float radius; Vector3[] posArray;
void Start()
{
UIEventListener.Get(gameObject).onDrag = Drag;
InitPosFromCircularRing(out posArray, centerPos, itemArray.Length, radius);
for (int i = , iMax = itemArray.Length; i < iMax; i++)
{
itemArray[i].transform.localPosition = posArray[i];
}
} float tmpVal = ;
void Drag(GameObject go, Vector2 vec2)
{
tmpVal += vec2.y > ? : -;
transform.localEulerAngles = new Vector3(, , tmpVal);
} void InitPosFromCircularRing(out Vector3[] posArray, Vector3 centerPos, int count, float radius)
{
posArray = new Vector3[count];
float copies = (360.0f / count) * Mathf.Deg2Rad;
for (int i = , j = count; i < j; ++i)
{
float x = radius * Mathf.Cos(copies * i);
//float y = centerPos.y;
float z = radius * Mathf.Sin(copies * i);
Vector3 vec3 = new Vector3(x, z, ) + centerPos;
posArray[i] = vec3;
}
}
}