• unity中将多张图片进行椭圆运动


        GameObject canvas;
        int num = 20;
        float angle = 0;
        private float shortRadius=200;
        float longRadius = 450;
        Dictionary<int,GO> storeItem;
        GameObject main;
        public static bool run = true;
        public static int index = 0;
        void Start()
        {
            storeItem = new Dictionary<int,GO>();
            angle = 360.0f / num;
    
            canvas = GameObject.Find("Canvas");
            main = GameObject.Find("main");
            for (int i = 0; i < num; i++)
            {
                GameObject a = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("prefab/item"));
                a.transform.SetParent(canvas.transform);
                a.GetComponent<RectTransform>().anchoredPosition = new Vector2(Mathf.Cos(i * angle * Mathf.Deg2Rad) * longRadius, Mathf.Sin(i * angle * Mathf.Deg2Rad) * longRadius);
                a.transform.Find("content").GetComponent<Text>().text = (i * angle).ToString();
    
                GO _go = new GO();
                _go._o = a;
                _go._o.GetComponent<hintPanelEvent>().index = i;
                _go.angle = i * angle;
                _go.index = i;
                storeItem.Add(i,_go);
            }
        }
    
        // Update is called once per frame
        GameObject name =null;
        void Update()
        {
            if(run)
            {
                foreach (var kk in storeItem.Values)
                {
                    kk.angle = kk.angle + 0.1f;
                    if (kk.angle >= 360)
                    {
                        kk.angle = kk.angle - 360;
                    }
                    kk._o.GetComponent<RectTransform>().anchoredPosition = new Vector2(Mathf.Cos(kk.angle * Mathf.Deg2Rad) * longRadius, Mathf.Sin(kk.angle * Mathf.Deg2Rad) * shortRadius);
    
    
                    if (kk._o.GetComponent<RectTransform>().anchoredPosition.y <= 450 && kk._o.GetComponent<RectTransform>().anchoredPosition.y >= 449.9)
                    {
                        if (name != kk._o)
                        {
                            name = kk._o;
                            var _text = kk._o.transform.Find("content").GetComponent<Text>().text;
                            Debug.LogError(_text);
                            main.transform.Find("content").GetComponent<Text>().text = _text;
                            //先把所有的隐藏掉
                            foreach (var hh in storeItem.Values)
                            {
                                hh._o.transform.Find("back").gameObject.SetActive(false);
                            }
    
                            kk._o.transform.Find("back").gameObject.SetActive(true);
                        }
    
                    }
                }
            }
            else
            {
                var text=storeItem[index]._o.transform.Find("content").GetComponent<Text>().text;
                main.transform.Find("content").GetComponent<Text>().text = text;
    
                //先把所有的隐藏掉
                foreach (var hh in storeItem.Values)
                {
                    hh._o.transform.Find("back").gameObject.SetActive(false);
                }
    
                storeItem[index]._o.transform.Find("back").gameObject.SetActive(true);
            }
           
        }
      
        class GO
        {
            public GameObject _o;
            public int index = 0;
            public float angle = 0;
        }
  • 相关阅读:
    php mysqli 查询个门店数据(面向对象)
    php 上锁 概述
    php 小程序渠道推广,转发
    php 微信公众号获取用户信息
    php 小程序获取用户信息
    php 生成小程序二维码
    1、收集日志至指定主题
    hihoCoder 网络流四·最小路径覆盖
    hihocoder1393 网络流三·二分图多重匹配
    hihocoder1398 网络流五之最大权闭合子图
  • 原文地址:https://www.cnblogs.com/Study088/p/7816500.html
Copyright © 2020-2023  润新知