示例#1
0
    // Use this for initialization
    void Start()
    {
        numDailyGift = PreferencesSaver.GetNextDailyGiftNum();

        libraryMenu = GameObject.FindObjectOfType <LibraryMenu>();

        giftPrefab = Resources.Load("Prefabs/UI/Gift") as GameObject;

        scrollBox.GetComponent <RectTransform>().sizeDelta = new Vector2((giftPrefab.GetComponent <RectTransform>().sizeDelta.x + borderWidth) * (DailyGiftXml.GetGiftCount() - 1) + 800, giftPrefab.GetComponent <RectTransform>().sizeDelta.y);

        for (int i = 0; i < DailyGiftXml.GetGiftCount(); i++)
        {
            Gift gift = DailyGiftXml.GetGift(i);

            GameObject giftGO = Instantiate(giftPrefab) as GameObject;
            giftGO.transform.SetParent(scrollBox.transform, false);

            RectTransform rectTransform = giftGO.GetComponent <RectTransform>();
            Vector3       ancoredPos    = rectTransform.anchoredPosition;

            ancoredPos.x = ((rectTransform.rect.width + borderWidth) * i + 400);
            rectTransform.anchoredPosition = ancoredPos;

            GiftGO giftS = giftGO.GetComponent <GiftGO>();
            giftS.SetGift(gift, i + 1);

            if (i == numDailyGift)
            {
                currentGift = gift;
                giftS.SetToday();
            }
        }
    }