Unity球形分布+UGUI滑屏切图(恶趣味)

欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群


demo链接:https://download.csdn.net/download/qq_37310110/12068839

https://github.com/romantic123fly/SlidingScreenAndSurfaceBall

今天以这个恶趣味的小demo终结2019年的最后一天,希望明年大家都加官进爵,升职加薪。

 

一:球形分布

 /// 实例个数
   /// 球体半径
    public void CreatPointOnSphere(int bornPointNum, float radius)
    {
        //生成
        for (int i = 0; i < bornPointNum; i++)
        {
            float y = (float)i * 2.0f / bornPointNum + (1 / bornPointNum) - 1.0f;
            float r = Mathf.Sqrt(1.0f - y * y);
            float  phi = i * 2.4f;
            Vector3 pos = new Vector3(Mathf.Cos(phi) * r * radius, y * radius, Mathf.Sin(phi) * r * radius); 
            BornPoint(pos, i);
        }
    }
   
    void BornPoint(Vector3 pos, int tempIndex)
    {
        GameObject obj = Instantiate( Resources.Load("Cube"));
        obj.GetComponent().material = Resources.Load("Materials/"+ tempIndex%5);
        obj.transform.SetParent(container);
        obj.transform.localPosition = pos;
        obj.name = tempIndex+"";
        transforms.Add(obj.transform);
    }

二:鼠标控制

RaycastHit m_hitInfo;
    private void Update()
    {
        if (container != null)
        {
            if (Input.GetMouseButtonUp(0)) //点击鼠标右键
            {
                object ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                bool isHit = Physics.Raycast((Ray)ray, out hit);
                if (isHit)
                {
                    Debug.Log(hit.transform.name);
                    GameManager.GetInstance().SetTargetItemIndex(int.Parse( hit.transform.name));
                }
            }

            if (Input.GetMouseButton(0)&& !EventSystem.current.IsPointerOverGameObject())
            {
                float hor = Input.GetAxis("Mouse X");
                float ver = Input.GetAxis("Mouse Y");
                container.Rotate(new Vector3(ver, -hor, 0) * Time.deltaTime * 100, Space.World);
            }
        }
        if (transforms!=null&& transforms.Count>0)
        {
            foreach (var item in transforms)
            {
                item.LookAt(Camera.main.transform);
            }
        }
    }

三:滑屏切图

滑屏切图这个是参考网上的,写的挺复杂的后期会优化一下,没有用插件用的unity的AnimationCurve组件


欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群

 

你可能感兴趣的:(工具插件类,Unity相关功能模块,Unity球形分布,UGUI滑屏切换卡牌)