FlagItem.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using UnityEngine;
  2. using System.Collections;
  3. public class FlagItem : MapItem
  4. {
  5. public enum State
  6. {
  7. Base,
  8. Ground,
  9. Craft,
  10. Waiting,
  11. }
  12. private State state;
  13. private int craftId;
  14. private Craft linkedCraft;
  15. public int linkedCraftId
  16. {
  17. get{
  18. if(linkedCraft != null)
  19. return linkedCraft.id;
  20. return -1;
  21. }
  22. }
  23. public void LinkToCraft(Craft craft)
  24. {
  25. this.linkedCraft = craft;
  26. state = State.Craft;
  27. CleanTiles();
  28. }
  29. public void WaitToLinkId(int craftId)
  30. {
  31. this.craftId = craftId;
  32. state = State.Waiting;
  33. }
  34. public override TeamUtil.Team team {
  35. get {
  36. return base.team;
  37. }
  38. set {
  39. base.team = value;
  40. int index = value.GetHashCode() - 1;
  41. Renderer[] renderers = this.GetComponentsInChildren<Renderer>();
  42. for(int i=0; i<renderers.Length; i++)
  43. {
  44. renderers[i].material.mainTexture = textureArr[index];
  45. }
  46. }
  47. }
  48. public void PutGround(Vector3 pos)
  49. {
  50. this.position = pos;
  51. LinkToCraft(null);
  52. TakeTiles();
  53. state = State.Ground;
  54. }
  55. public void PutToBase(Vector3 pos)
  56. {
  57. PutGround(pos);
  58. state = State.Base;
  59. }
  60. public bool IsInBase()
  61. {
  62. return state == State.Base;
  63. }
  64. public bool IsOnGround()
  65. {
  66. return state == State.Ground;
  67. }
  68. void Update()
  69. {
  70. if(linkedCraft != null)
  71. {
  72. if(!linkedCraft.IsDead())
  73. {
  74. transform.position = linkedCraft.position;
  75. }
  76. // else
  77. // {
  78. // PutGround(linkedCraft.position);
  79. // }
  80. }
  81. else if(state == State.Waiting)
  82. {
  83. Craft craft = map.GetBattleObject(craftId) as Craft;
  84. if(craft != null)
  85. {
  86. LinkToCraft(craft);
  87. }
  88. }
  89. }
  90. }