首页 > 代码库 > Radar之获取排列的UITexture数组

Radar之获取排列的UITexture数组

1.定义UITexture二维数组

?
1
public UITexture[,] m_UITexture;

2.在 void start() 中分配内存

m_UITexture = new UITexture[30, 50];

3.遍历排列的UITexture

//用UITexture数组获取UITexture
    void GetUITexture()
    {
        Transform obj = GameObject.Find("Texture").transform;
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                for (int k = 0; k < 6; k++)
                {
                    GetTransform(obj.GetChild(i).GetChild(j).GetChild(k), i, j, k);
                }
            }
        }
    }

4.用数组存储UITexture

Transform GetTransform(Transform check, int i, int j, int k)
    {
        int m = -2;
        foreach (Transform t in check.GetComponentsInChildren<Transform>())
        {
            m++;
            if (m >= 0)
            {
                m_UITexture[i * 6 + k, j * 10 + m] = t.gameObject.GetComponent<UITexture>();
            }
        }
        return null;
    }