/// <summary> /// This routine does the movement animation. /// </summary> /// <returns>Nothing; IEnumerator is just for coroutines</returns> /// <param name="path">The path we want to move along</param> /// <param name="bCombatMenu">This combat Menu will be hide during animation</param> public IEnumerator MoveRoutine(BMapTile[] path, BCombatMenu bCombatMenu) { bCombatMenu.Hide(); for (int i = 1; i < path.Length; i++) { Vector3 nextWp = path[i].transform.position; Vector3 lookPoint = nextWp; lookPoint.y = 0; meshContainer.transform.LookAt(lookPoint); do { Vector3 translation = nextWp - transform.position; float distance = translation.magnitude; translation = translation.normalized * Time.deltaTime * movementSpeed; if (distance < translation.magnitude) { transform.position = nextWp; break; } else { transform.Translate(transform.InverseTransformDirection(translation)); } yield return(0); } while(transform.position != nextWp); } bCombatMenu.OpenForBUnit(parent); EventProxyManager.FireEvent(this, new EventDoneEvent()); }
/*public void Update (){ * bCombatMenu.backButton.gameObject.OpenForBUnit(this); * //bCombatMenu.backButton.gameObject.SetActive(true); * }*/ public void Init(BView context, BCombatMenu bCombatMenu) { this.context = context; this.bCombatMenu = bCombatMenu; this.bUnitAnimator = GetComponent <BUnitAnimator>(); defaultAttack = unit.AttacksArray[unit.defaultAttackIndex]; unitUI.Init(this); bUnitAnimator.Init(unit, this); }
public void Init(Attack attack, BCombatMenu parent) { this.parent = parent; this.attack = attack; nameLabel.text = attack.attackName; damageLabel.text = attack.damage.ToString(); //typeSprite.spriteName = attack.element.elementName; typeSprite.spriteName = attack.name; typeBackground.normalSprite = attack.element.elementName + backgroundPostfix; if (attack.IsRanged()) { //select arrow symbol arrowIcon.gameObject.SetActive(true); swordIcon.gameObject.SetActive(false); } else { //select sword symbol arrowIcon.gameObject.SetActive(false); swordIcon.gameObject.SetActive(true); } }
public void Init(BView context, Unit unit, BCombatMenu bCombatMenu) { this.unit = unit; Init(context, bCombatMenu); }
/// <summary> /// Routine to perfome a attack animation /// </summary> /// <returns>IEnumerator is needed for co-routines.<</returns> /// <param name="target">The BUnit whom is the attack target.</param> /// <param name="attack">The attack which will be performed.</param> /// <param name="efficeny">0 = not effectiv, 1 = normal efficeny, 2 = very effectiv</param> /// <param name="damage">The amount of damage dealt by this attack.</param> public IEnumerator AttackRoutine(UnitAttackedEvent e, BMapTile target, BUnit[] victims, BCombatMenu bCombatMenu) { meshContainer.transform.LookAt(target.transform.position); bCombatMenu.Hide(); // sound effect attackSound.Play(); // animation animator.SetTrigger("AttackTrigger"); // wait some time before starting the attack effect yield return(new WaitForSeconds(e.attack.effectDelay)); // caluclate the direction of the attack and project it on one of the 4 vectors: (0,1),(1,0),(0,-1),(-1,0) Vector direction = new Vector(Mathf.FloorToInt(target.transform.position.x - this.transform.position.x), Mathf.FloorToInt(target.transform.position.z - this.transform.position.z)); direction.NormalizeTo4Direction(); BParticleManager.PlayEffect(e.attack.attackName, target.transform.position, new Vector3(direction.x, 0, direction.y)); // wait some time before trigger the hit animtion/effect yield return(new WaitForSeconds(e.attack.hitDelay)); for (int i = 0; i < victims.Length; i++) { victims[i].PlayHitAnimation(e.efficiency, e.damage[i]); victims[i].unitUI.ShowDamage(e.damage[i]); } // wait the rest of the time for the animation before contuine with next event yield return(new WaitForSeconds(e.attack.fullAnimationTime - e.attack.effectDelay - e.attack.hitDelay)); EventProxyManager.FireEvent(this, new EventDoneEvent()); }
void Init() { performingEvent = true; // register event EventProxyManager.RegisterForEvent(EventName.Initialized, HandleEvent); EventProxyManager.RegisterForEvent(EventName.UnitSpawned, HandleEvent); EventProxyManager.RegisterForEvent(EventName.RoundSetup, HandleEvent); EventProxyManager.RegisterForEvent(EventName.UnitActivated, HandleEvent); EventProxyManager.RegisterForEvent(EventName.TurnStarted, HandleEvent); EventProxyManager.RegisterForEvent(EventName.BMapTileTapped, HandleEvent); EventProxyManager.RegisterForEvent(EventName.BUnitTapped, HandleEvent); EventProxyManager.RegisterForEvent(EventName.UnitMoved, HandleEvent); EventProxyManager.RegisterForEvent(EventName.UnitAttacked, HandleEvent); EventProxyManager.RegisterForEvent(EventName.UnitLoseHealth, HandleEvent); EventProxyManager.RegisterForEvent(EventName.UnitDied, HandleEvent); EventProxyManager.RegisterForEvent(EventName.ToppingSpawned, HandleEvent); EventProxyManager.RegisterForEvent(EventName.ToppingDestroyed, HandleEvent); EventProxyManager.RegisterForEvent(EventName.Gameover, HandleEvent); EventProxyManager.RegisterForEvent(EventName.EventDone, HandleEventDone); EventProxyManager.RegisterForEvent(EventName.DebugLog, HandleDebugLog); // find scene references bCombatMenu = GameObject.FindObjectOfType <BCombatMenu>(); bInputManager = GameObject.FindObjectOfType <BInputManager>(); bCameraMover = GameObject.FindObjectOfType <BCameraMover>(); // instatiate marker unitMarker = (GameObject)Instantiate(bActiveMarkerPrefab); MapTile[][] mapTiles = new MapTile[bMap.lengthX][]; for (int i = 0; i < bMap.lengthX; i++) { mapTiles[i] = new MapTile[bMap.lengthY]; for (int j = 0; j < bMap.lengthY; j++) { bMap[i, j].UpdateTopping(); // this is required to tranfer the topping data to the mapTile mapTiles[i][j] = bMap[i, j].mapTile; } } BUnit[] startBUnits = GameObject.FindObjectsOfType <BUnit>(); bUnits = new List <BUnit>(); Unit[] units = new Unit[startBUnits.Length]; for (int i = 0; i < units.Length; i++) { // add units from scene to an array units[i] = startBUnits[i].unit; // set maptile reference by scene position int x = Mathf.FloorToInt(startBUnits[i].transform.position.x); int y = Mathf.FloorToInt(startBUnits[i].transform.position.z); units[i].mapTile = mapTiles[x][y]; mapTiles[x][y].unit = units[i]; // add bUnit to list startBUnits[i].Init(this, bCombatMenu); bUnits.Add(startBUnits[i]); } // start the game controller = new Controller(this, mapTiles, units); EventProxyManager.FireEvent(this, new EventDoneEvent()); }