Пример #1
0
    /// <summary>
    /// 绘制边界
    /// </summary>
    private void FlagAndCreateBorder()
    {
        Transform borderContainer = new GameObject("Border").transform;

        borderContainer.transform.SetParent(transform);

        Sprite bottomWall = Resources.Load <Sprite>("Textures/wallButtom");

        //绘制横向
        for (int x = 0; x < Width; x++)
        {
            grids.SetBorder(x, 0);
            GameObject top = CreateObject(m_BorderPref.name, m_BorderPref, x, 0);
            top.transform.parent = borderContainer;

            grids.SetBorder(x, Height - 1);
            GameObject     bottom = CreateObject(m_BorderPref.name, m_BorderPref, x, Height - 1);
            SpriteRenderer br     = bottom.GetComponent <SpriteRenderer>();
            br.sprite = bottomWall;
            bottom.transform.parent = borderContainer;
        }

        //绘制竖向
        for (int y = 0; y < Height; y++)
        {
            grids.SetBorder(0, y);
            GameObject left = CreateObject(m_BorderPref.name, m_BorderPref, 0, y);
            left.transform.parent = borderContainer;


            grids.SetBorder(Width - 1, y);
            GameObject right = CreateObject(m_BorderPref.name, m_BorderPref, Width - 1, y);
            right.transform.parent = borderContainer;
        }
    }