コード例 #1
0
    public void BookExhibition(int key)
    {
        gameObject.SetActive(true);

        m_Trans.Clear();

        while (m_Grid.transform.childCount > 0)
        {
            DestroyImmediate(m_Grid.transform.GetChild(0).gameObject);
        }

        Texture2D texture = null;

        List <Sprite> sprites = SpriteMgr.singleton.GetSprs(key);

        for (int i = 0; i < sprites.Count; i++)
        {
            GameObject o = GameObject.Instantiate(m_Item);
            o.transform.parent        = m_Grid.transform;
            o.transform.localScale    = Vector3.one;
            o.transform.localPosition = Vector3.zero;
            o.gameObject.SetActive(true);
            m_Trans.Add(o.GetComponent <RectTransform>());
            BookItem item = o.GetComponent <BookItem>();
            item.ItemInit();
            item.m_Id          = i;
            item.m_Icon.sprite = sprites[i];
            item.m_Icon.SetNativeSize();
            item.m_Btn.onClick.AddListener(delegate(){ ClickItem(item); });

            Vector2 size   = item.m_Icon.GetComponent <RectTransform>().sizeDelta;
            float   xScale = size.x / 2048.0f;
            float   yScale = size.y / 1536.0f;
            if (xScale > yScale)
            {
                float scale = size.x / 2048.0f;
                item.m_Icon.GetComponent <RectTransform>().sizeDelta = new Vector2(2048, size.y / scale);
            }
            else
            {
                float scale = size.y / 1536.0f;
                item.m_Icon.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x / scale, 1536);
            }
            //string path = "animal/" + key + "/" + (i+1);
            //texture = (Texture2D)Resources.Load(path);
            //item.m_BG.color = texture.GetPixel(0, (int)texture.height);
            item.m_BG.color = Color.black;
        }
        //m_Grid.CalculateLayoutInputHorizontal();

        Vector3 vPos = new Vector3(-m_Trans[0].anchoredPosition.x + 1024, 0, 0);

        m_Grid.transform.localPosition = vPos;
        m_CurIndex = 0;
    }