首页 > 其他 > 详细

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

时间:2019-04-24 20:12:29      阅读:118      评论:0      收藏:0      [点我收藏+]

技术分享图片

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

每个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 }

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

原文:https://www.cnblogs.com/luguoshuai/p/10764468.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!