public BattleUnit LoadUnit(Unit unit) { GameObject newUnit = Instantiate(unitPrefab, (unit.IsHero)? heroesContent : enemiesContent); int sortingLayer = 0; foreach (Transform child in ((unit.IsHero)? heroesContent : enemiesContent)) { sortingLayer++; sortingLayer++; } BattleUnit battleUnit = newUnit.GetComponentInChildren <BattleUnit>(); battleUnit.GetComponent <SpriteRenderer>().sortingOrder = sortingLayer; battleUnit.Configure(unit); Sprite unitSprite = battleUnit.GetComponent <SpriteRenderer>().sprite; AxisInteractableItem newItem = battleUnit.GetComponent <AxisInteractableItem>(); AIIManager manager = (unit.IsHero)? heroesManager : enemiesManager; battleUnit.battleItem = battleUnit.GetComponent <UnitItem>(); battleUnit.battleItem.layout.preferredWidth = unit.BoundsSizeX * 64; battleUnit.battleItem.layout.preferredHeight = unit.BoundsSizeY * 64; newUnit.transform.rotation = Quaternion.identity; Image[] unitImages = newUnit.GetComponentsInChildren <Image>(); unitImages[0].sprite = (unit.GetType() == typeof(Hero))? heroIndicator : enemyIndicator; unitImages[1].sprite = unitSprite; // Ordena o item na lista if (manager.lastItem != null) { newItem.upItem = manager.lastItem; manager.lastItem.downItem = newItem; } else { manager.firstItem = newItem; } manager.lastItem = newItem; return(battleUnit); }
public BattleUnit GetTarget(BattleUnit requester) { var tags = requester.GetComponent <TagCollection>(); if (tags.tags.Contains("Player")) { return(enemyInstances[Random.Range(0, enemiesThisBattle)].GetComponent <BattleUnit>()); } else { return(playerInstances[Random.Range(0, playerPrefabs.Length)].GetComponent <BattleUnit>()); } }
private Tuple <BattleUnit, Tile> GetMoveInfo() { List <GameObject> nextUnits = Manager.NextController.GetUnits(); BattleUnit battleUnit = Units[UnityEngine.Random.Range(0, Units.Count)].GetComponent <BattleUnit>(); BattleUnit target = battleUnit.ClosestUnit(); target.GetComponent <CharacterPicker>().PickerEnabled = true; List <Tile> tiles = GridController.GetGridController().GetTiles(); tiles = tiles.FindAll((Tile t) => { return(TileInRange(t, target.gameObject)); }); Tile targetTile = battleUnit.CurrentTile.GetClosestTile(tiles); targetTile = GridController.GetDestinationTileInRange(battleUnit.CurrentTile, targetTile, battleUnit.GetComponent <UnitAttributes>().GetAttributeValue(Attribute.Range)); return(new Tuple <BattleUnit, Tile>(battleUnit, targetTile)); }
IEnumerator DeadEnemies(int index) { BattleUnit deadGhost = ghostTarget[index]; totalExp += deadGhost.Ghost.GiveExp(); deadGhost.Ghost.alive = false; deadGhost.GetComponent <BattleHud>().Dead(); ghostTarget.RemoveAt(index); if (ghostTarget.Count != 0) { currentChooseTarget = 0; } else { //TODO: SHOW +EXP state = BattleState.Busy; currentAction = 0; currentActionBattle = 0; currentActionBattleMove = 0; currentChooseTarget = 0; currentDialogue = 0; currentMultiChoice = 0; currentTalkTarget = 0; StartCoroutine(audioScript.FadeOut(battleAudio, 0.3f)); StartCoroutine(audioScript.FadeIn(exploreAudio, 0.3f)); dialogueBox.ActivateDialogue(); yield return(dialogueBox.TypeDialogue("Dara berhasil mengalahkan semua musuh")); if (!finalBattle) { onBattleOver(true, totalExp); } else { StartCoroutine(scene.LoadNextScene("Main Menu")); } } }