private void EnterTreasureBox(Transform treasureBoxTrans) { TreasureBox tb = treasureBoxTrans.GetComponent <TreasureBox>(); // 如果mapitem已打开,则直接返回 if (tb.unlockItemName != "" && !tb.locked) { return; } // 如果该宝箱不需要使用钥匙开启 if (tb.unlockItemName == "") { // SoundManager.Instance.PlayAudioClip ("MapEffect/" + tb.audioClipName); mapGenerator.mapWalkableInfoArray [(int)tb.transform.position.x, (int)tb.transform.position.y] = 1; tb.GetComponent <BoxCollider2D> ().enabled = false; // 如果该地图物品不需要使用特殊物品开启 tb.UnlockTreasureBox(() => { mapGenerator.SetUpAwardInMap(tb.awardItem, tb.transform.position); }); return; } // 宝箱需要使用钥匙开启 // 查找背包中是否有钥匙 Consumables key = Player.mainPlayer.allConsumablesInBag.Find(delegate(Consumables obj) { return(obj.itemName == tb.unlockItemName); }); // 如果背包中有钥匙,则进入工具选择栏 if (key != null) { expUICtr.GetComponent <BattlePlayerUIController> ().SetUpToolChoicePlane(tb, key); } else { expUICtr.SetUpTintHUD("缺少钥匙x1", null); } }
/// <summary> /// 选择了一种工具后的响应方法 /// </summary> /// <param name="tool">Tool.</param> /// <param name="mapItem">Map item.</param> private void OnToolChoiceButtonClick(Consumables tool, MapItem mapItem) { QuitToolChoicePlane(); // 背包中的工具数量-1 player.RemoveItem(tool, 1); // 播放对应的音效 SoundManager.Instance.PlayAudioClip("MapEffects/" + mapItem.audioClipName); Vector3 mapItemPos = mapItem.transform.position; MapGenerator mapGenerator = TransformManager.FindTransform("ExploreManager").GetComponent <MapGenerator> (); int[,] mapWalkableInfoArray = mapGenerator.mapWalkableInfoArray; switch (mapItem.mapItemType) { case MapItemType.Stone: case MapItemType.Tree: (mapItem as Obstacle).DestroyObstacle(null); mapWalkableInfoArray [(int)mapItemPos.x, (int)mapItemPos.y] = 1; break; case MapItemType.TreasureBox: TreasureBox tb = mapItem as TreasureBox; tb.UnlockTreasureBox(null); mapWalkableInfoArray [(int)mapItemPos.x, (int)mapItemPos.y] = 1; mapGenerator.SetUpAwardInMap(tb.awardItem, mapItemPos); break; case MapItemType.Plant: Plant plant = mapItem as Plant; mapGenerator.AddMapItemInPool(mapItem.transform); mapWalkableInfoArray [(int)mapItemPos.x, (int)mapItemPos.y] = 1; mapGenerator.SetUpAwardInMap(plant.attachedItem, mapItemPos); break; } SetUpBottomConsumablesButtons(); }