Station.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnityEngine;
  2. using System.Collections;
  3. public class Station : BattleObject
  4. {
  5. public enum State
  6. {
  7. Start,
  8. Idle,
  9. }
  10. public GameObject[] haloPrefabs;
  11. public CrystalBase crystalBase;
  12. private State state;
  13. private float startTime;
  14. private float buildDuration = 5f;
  15. public override void Init (Map map)
  16. {
  17. base.Init (map);
  18. SetState(State.Start);
  19. startTime = GameTime.time;
  20. hpRecoverSpeed = 0.025f;
  21. if(map.id == MapData.MapID.Challenge)
  22. _originMaxHp = hp = maxHp = 6000f;
  23. else
  24. _originMaxHp = hp = maxHp = 60000f;
  25. }
  26. public override TeamUtil.Team team {
  27. get {
  28. return base.team;
  29. }
  30. set {
  31. base.team = value;
  32. try
  33. {
  34. headBar.UpdateColor();
  35. GameObject haloObj = Instantiate<GameObject>(haloPrefabs[value.GetHashCode()-1]);
  36. haloObj.transform.SetParent(this.transform);
  37. haloObj.transform.localPosition = Vector3.zero;
  38. }
  39. catch(System.Exception e)
  40. {
  41. Debuger.LogException(e);
  42. }
  43. }
  44. }
  45. public void SetState(State state)
  46. {
  47. this.state = state;
  48. if(this.animation != null)
  49. this.animation.Play(state.ToString());
  50. }
  51. public State GetState()
  52. {
  53. return this.state;
  54. }
  55. void Update()
  56. {
  57. if(state == State.Start && GameTime.time - startTime > buildDuration)
  58. {
  59. SetState(State.Idle);
  60. }
  61. CheckHpRecover();
  62. DealBuff();
  63. }
  64. public override void Dead ()
  65. {
  66. base.Dead ();
  67. crystalBase.SetStation(null);
  68. MapItem mapItem = map.GetMapItem(crystalBase.id);
  69. if(mapItem != null)
  70. mapItem.Remove();
  71. }
  72. }