public void DropItem(Vector3 dropPos, ITEM_ID[] dropItemList) { int randomIndex = Random.Range(0, dropItemList.Length); GameObject instance = null; foreach (GameObject obj in boardScript.itemTiles) { ItemObject itemObj = obj.GetComponent <ItemObject>(); if (itemObj.itemId == dropItemList[randomIndex]) { instance = Instantiate(obj, dropPos, Quaternion.identity); break; } } if (instance) { GameManager.instance.AddObj(instance, curDungeon.GetCurLevel().id); StartCoroutine(DropObjectEffect(instance)); } }
private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Exit") { GameManager.instance.ShowAllMap(true); SoundManager.instance.RandomizeSfx(levelClearSound, levelClearSound); GameManager.instance.ShowResult(); enabled = false; } else if (other.tag == "Gem") { Renderer renderer = other.gameObject.GetComponent <SpriteRenderer>(); if (renderer) { renderer.enabled = true; } SoundManager.instance.PlaySingle(gemSound); GetGem(1); StartCoroutine(HideAni(other.gameObject)); GameManager.instance.dungeonPlayData.gemCount++; if (bHideMode) { BreakedHiding(LocalizationManager.instance.GetLocalString(GAME_STRING.HIDE_BROKEN_GEM)); } Analytics.CustomEvent("Discover Gem", new Dictionary <string, object> { { "Dungeon id", GameManager.instance.GetDungeonInfo().id }, { "Level id", GameManager.instance.GetDungeonInfo().GetCurLevel().id }, }); } else if (other.tag == "Item") { ItemObject item = other.gameObject.GetComponent <ItemObject>(); string itemName = ItemManager.instance.GetNameByItemId(item.itemId); if (item.itemId == ITEM_ID.EXTEND_MAX_HP) { if (GameManager.instance.ExtendHp(1)) { Notice.instance.Show(LocalizationManager.instance.GetLocalString(GAME_STRING.INC_MAXHP), 1f, Color.yellow); } else { Notice.instance.Show(LocalizationManager.instance.GetLocalString(GAME_STRING.LIMIT_MAXHP), 1f, Color.yellow); } StartCoroutine(HideAni(other.gameObject)); SoundManager.instance.PlaySingle(skillSound); } else if (item.itemId == ITEM_ID.EXTEND_BAG) { if (GameManager.instance.ExtendBagSize()) { Notice.instance.Show(LocalizationManager.instance.GetLocalString(GAME_STRING.INC_BAG), 1f, Color.yellow); } else { Notice.instance.Show(LocalizationManager.instance.GetLocalString(GAME_STRING.LIMIT_BAG), 1F, Color.white); } StartCoroutine(HideAni(other.gameObject)); SoundManager.instance.PlaySingle(skillSound); } else if (GameManager.instance.AddItemInBag(item.itemId)) { SoundManager.instance.PlaySingle(itemSound); StartCoroutine(HideAni(other.gameObject)); Controller controller = FindObjectOfType(typeof(Controller)) as Controller; controller.SetupSlots(); GameManager.instance.dungeonPlayData.getItems.Add(itemName); if (bHideMode) { BreakedHiding(LocalizationManager.instance.GetLocalString(GAME_STRING.HIDE_BROKEN_PICK_ITEM)); } Analytics.CustomEvent("Discover Item", new Dictionary <string, object> { { "Item id", item.itemId }, { "Dungeon id", GameManager.instance.GetDungeonInfo().id }, { "Level id", GameManager.instance.GetDungeonInfo().GetCurLevel().id }, }); if (GameManager.instance.GetDungeonInfo().id == 0) { ShowExplainTextItem(item.itemId); } } else { Notice.instance.Show(LocalizationManager.instance.GetLocalString(GAME_STRING.NO_SPACE_BAG), 2f, Color.white); } } }
public void SetupTutorialLevel(Level levelInfo) { //for(int i =0; i< itemTiles.Length; i++) //{ // int x = i%6+1; // int y = i/6+1; // GameObject itemIns = Instantiate(itemTiles[i], new Vector3(x, y, 0f), Quaternion.identity); // GameManager.instance.AddObj(itemIns, levelInfo.id); //} //return; GameObject showItemTile = null; GameObject healItemTile = null; foreach (GameObject itemTile in itemTiles) { ItemObject itemObj = itemTile.GetComponent <ItemObject>(); if (itemObj.itemId == ITEM_ID.FRAGMENT_NEAR) { showItemTile = itemTile; } if (itemObj.itemId == ITEM_ID.HEAL1) { healItemTile = itemTile; } } Vector3 pos = new Vector3(2f, 7f, 0f); GameObject instance = Instantiate(showItemTile, pos, Quaternion.identity); GameManager.instance.AddObj(instance, levelInfo.id); pos = new Vector3(7f, 3f, 0f); instance = Instantiate(healItemTile, pos, Quaternion.identity); GameManager.instance.AddObj(instance, levelInfo.id); pos = new Vector3(1f, 3f, 0f); instance = Instantiate(gemTiles[0], pos, Quaternion.identity); GameManager.instance.AddObj(instance, levelInfo.id); pos = new Vector3(4f, 3f, 0f); instance = Instantiate(gemTiles[0], pos, Quaternion.identity); GameManager.instance.AddObj(instance, levelInfo.id); Vector3[] tutorialTrapPositions = { new Vector3(0, 2, 0), new Vector3(0, 3, 0), new Vector3(0, 4, 0), new Vector3(1, 6, 0), new Vector3(2, 0, 0), new Vector3(2, 1, 0), new Vector3(2, 3, 0),new Vector3(2, 6, 0), new Vector3(3, 0, 0), new Vector3(3, 1, 0), new Vector3(3, 2, 0),new Vector3(3, 3, 0),new Vector3(3, 4, 0), new Vector3(3, 5, 0), new Vector3(4, 0, 0), new Vector3(4, 1, 0), new Vector3(4, 2, 0), new Vector3(5, 4, 0), new Vector3(5, 6, 0), new Vector3(5, 7, 0), new Vector3(6, 1, 0), new Vector3(6, 2, 0), new Vector3(6, 3, 0),new Vector3(6, 4, 0),new Vector3(6, 5, 0), new Vector3(6, 6, 0),new Vector3(6, 7, 0) }; for (int i = 0; i < tutorialTrapPositions.Length; i++) { pos = tutorialTrapPositions[i]; instance = Instantiate(trapTiles[0], pos, Quaternion.identity); GameManager.instance.AddTrap(instance, levelInfo.id); } }