public override void Exit(AState to) { missionPopup.gameObject.SetActive(false); inventoryCanvas.gameObject.SetActive(false); if (m_Character != null) { Destroy(m_Character); } GameState gamestate = to as GameState; skyMeshFilter.gameObject.SetActive(false); UIGroundFilter.gameObject.SetActive(false); if (gamestate != null) { gamestate.currentModifier = m_CurrentModifier; //重置人物选择的装饰为初始状态,为了下一次的游戏开始。 m_CurrentModifier = new Modifier(); //给游戏状态加载道具 if (m_PowerupToUse != Consumable.ConsumableType.NONE) { PlayerData.instance.Consume(m_PowerupToUse); Consumable inventory = Instantiate(ConsumableDatabase.GetConsumable(m_PowerupToUse)); inventory.gameObject.SetActive(false); gamestate.trackManager.characterController.inventory = inventory; } } }
/// <summary> /// 从数据库查询并加载道具信息 /// </summary> void PopulatePowerup() { powerupIcon.gameObject.SetActive(true); if (PlayerData.instance.consumables.Count > 0) { Consumable csm = ConsumableDatabase.GetConsumable(m_PowerupToUse); powerupSelect.gameObject.SetActive(true); if (csm != null) { powerupIcon.sprite = csm.icon; powerupCount.text = PlayerData.instance.consumables[m_PowerupToUse].ToString(); } else { powerupIcon.sprite = noItemIcon; powerupCount.text = ""; } } else { powerupSelect.gameObject.SetActive(false); } }
static public void AddConsumables() { for (int i = 0; i < ShopItemList.s_ConsumablesTypes.Length; ++i) { Consumable c = ConsumableDatabase.GetConsumable(ShopItemList.s_ConsumablesTypes[i]); if (c != null) { PlayerData.instance.consumables[c.GetConsumableType()] = 10; } } PlayerData.instance.Save(); }
//填充显示的内容,道具 public override void Populate() { m_RefreshCallback = null; foreach (Transform t in listRoot) { Destroy(t.gameObject); } for (int i = 0; i < s_ConsumablesTypes.Length; ++i) { Consumable c = ConsumableDatabase.GetConsumable(s_ConsumablesTypes[i]); if (c != null) { GameObject newEntry = Instantiate(prefabItem); newEntry.transform.SetParent(listRoot, false); ShopItemListItem item = newEntry.GetComponent <ShopItemListItem>(); item.buyButton.image.sprite = item.buyButtonSprite; item.nameText.text = c.GetConsumableName(); item.pricetext.text = c.GetPrice().ToString(); if (c.GetPremiumCost() > 0) { item.diamondText.transform.parent.gameObject.SetActive(true); item.diamondText.text = c.GetPremiumCost().ToString(); } else { item.diamondText.transform.parent.gameObject.SetActive(false); } item.icon.sprite = c.icon; item.countText.gameObject.SetActive(true); item.buyButton.onClick.AddListener(delegate() { Buy(c); }); m_RefreshCallback += delegate() { RefreshButton(item, c); }; RefreshButton(item, c); } } }