示例#1
0
 private void _init()
 {
     _lastUpdated = DateTime.Now;
     // events
     clickerButton.onClick.AddListener(() => Click());
     // init player
     player = Player.GetInstance();
     player.Init();
     // init UI
     dropController.Init();
     UnityEngine.Object buttonPrefab = Resources.Load("ItemButton");
     buttons  = new ItemButton[player.items.Count];
     _itemIds = new int[player.items.Count];
     for (int i = 0; i < player.items.Count; ++i)
     {
         hardwares[i].SetActive(false);
         GameObject    obj  = Instantiate(buttonPrefab) as GameObject;
         RectTransform rect = obj.GetComponent <RectTransform>();
         rect.SetParent(buttonContainer);
         rect.anchoredPosition = new Vector2(0, i * -58);
         int index = i;
         _itemIds[i] = player.items[i].id;
         ItemButton button = obj.GetComponent <ItemButton>();
         button.SetOnMouseCallback(() => ShowTip(index));
         button.SetItem(player.items[i]);
         button.SetSprite(player.items[i].id);
         buttons[i] = button;
         obj.GetComponent <Button>().onClick.AddListener(() => BuyItem(index));
     }
     // load data & refresh
     player.Load();
     for (int i = 0; i < player.items.Count; ++i)
     {
         buttons[i].SetItem(player.items[i]);
         if (player.items[i].unlocked)
         {
             buttons[i].Unlock();
         }
         if (player.items[i].level > 0)
         {
             hardwares[i].SetActive(true);
         }
         dropController.SetMaxUnlockedNum(player.unlockedItem);
         dropController.SetSpeed(player.autoValue);
     }
     RefreshScore();
 }