コード例 #1
0
 protected void OnMarketOpen(PlayerOpenedMarketEvent e)
 {
     foreach (KeyValuePair <string, ResourceSlotModel> resourceSlot in e.star.resourceList)
     {
         Texture2D              texture = UnityEngine.Resources.Load("Sprites/" + resourceSlot.Value.name) as Texture2D;
         Sprite                 sprite  = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
         GameObject             instantiatedResourceSlot = Instantiate(resourceSlotPrefab, resourcesPanel) as GameObject;
         ResourceSlotController resourceSlotController   = instantiatedResourceSlot.GetComponent <ResourceSlotController>();
         resourceSlotController.resourceSlot         = resourceSlot.Value;
         resourceSlotController.nameText.text        = resourceSlot.Value.name;
         resourceSlotController.amountText.text      = resourceSlot.Value.amount.ToString();
         resourceSlotController.resourceImage.color  = Color.white;
         resourceSlotController.resourceImage.sprite = sprite;
         resourceSlotController.marketMenuController = this;
     }
 }
コード例 #2
0
 public void SetSelectedResourceSlot(ResourceSlotController resourceSlotRef)
 {
     resourceSlotRef.backgroundImage.color = Color.blue;
     if (selectedResourceSlotRef != null)
     {
         selectedResourceSlotRef.backgroundImage.color = Color.white;
     }
     if (selectedResourceSlotRef == resourceSlotRef)
     {
         selectedResourceSlotRef = null;
         DisableMarketButtons();
         return;
     }
     selectedResourceSlotRef = resourceSlotRef;
     buyButton.GetComponentInChildren <Text>().text  = "Buy for " + resourceSlotRef.resourceSlot.buyPrice.ToString("C0");
     sellButton.GetComponentInChildren <Text>().text = "Sell for " + resourceSlotRef.resourceSlot.sellPrice.ToString("C0");
     EnableMarketButtons();
 }