源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.4 KiB

пре 1 месец
  1. ArrowComponent = ArrowComponent or BaseClass(BaseItem)
  2. function ArrowComponent:__init(parent_wnd)
  3. self.base_file = "common"
  4. self.layout_file = "ArrowComponent"
  5. self.arrowType = 1
  6. self:Load()
  7. end
  8. function ArrowComponent:__delete()
  9. self:StopAnim()
  10. end
  11. function ArrowComponent:Load_callback()
  12. self.arrow = self:GetChild("Arrow")
  13. self:InitEvent()
  14. if self.need_refreshData then
  15. self:ShowArrow(self.type, self.pos, self.layer, self.show_type)
  16. end
  17. end
  18. function ArrowComponent:InitEvent()
  19. end
  20. function ArrowComponent:SetArrowType( arrowType )
  21. self.arrowType = arrowType
  22. if self.is_loaded then
  23. self:SetArrowImg()
  24. end
  25. end
  26. function ArrowComponent:SetArrowImg( )
  27. if self.arrowType == 1 then
  28. lua_resM:setImageSprite(self, self.arrow:GetComponent("Image"), "mainui_asset", "main_ui_tip", true)
  29. elseif self.arrowType == 2 then
  30. lua_resM:setImageSprite(self, self.arrow:GetComponent("Image"), "mainui_asset", "main_ui_tip2", true)
  31. --lua_resM:setImageSprite(self, self.arrow:GetComponent("Image"), "mainui_asset", "main_ui_tip2", true)
  32. elseif self.arrowType == 3 then
  33. lua_resM:setImageSprite(self, self.arrow:GetComponent("Image"), "mainui_asset", "main_ui_tip", true)
  34. --lua_resM:setImageSprite(self, self.arrow:GetComponent("Image"), "mainui_asset", "main_ui_tip3", true)
  35. end
  36. end
  37. --type --显示箭头 1 右 2 左 3 下 4 上 5左斜下 6右斜下 7左斜上 8右斜上
  38. function ArrowComponent:ShowArrow(itype, pos, layer, show_type)
  39. self.type = itype
  40. self.pos = pos
  41. self.layer = layer
  42. self.show_type = show_type
  43. if self.is_loaded then
  44. self.need_refreshData = false
  45. if self.type == 1 then
  46. self.arrow.localRotation = Quaternion.Euler(0,0,0)
  47. elseif self.type == 2 then
  48. self.arrow.localRotation = Quaternion.Euler(0,0,180)
  49. elseif self.type == 3 then
  50. self.arrow.localRotation = Quaternion.Euler(0,0,270)
  51. elseif self.type == 4 then
  52. self.arrow.localRotation = Quaternion.Euler(0,0,90)
  53. elseif self.type == 5 then
  54. self.arrow.localRotation = Quaternion.Euler(0,0,225)
  55. elseif self.type == 6 then
  56. self.arrow.localRotation = Quaternion.Euler(0,0,325)
  57. elseif self.type == 7 then
  58. self.arrow.localRotation = Quaternion.Euler(0,0,135)
  59. elseif self.type == 8 then
  60. self.arrow.localRotation = Quaternion.Euler(0,0,45)
  61. else
  62. self.arrow.localRotation = Quaternion.Euler(0,0,0)
  63. end
  64. self:SetArrowImg()
  65. self:SetPosition(self.pos.x,self.pos.y)
  66. self:SetLayer(self.layer)
  67. self:StopAnim()
  68. self:StartAnim()
  69. else
  70. self.need_refreshData = true
  71. end
  72. end
  73. function ArrowComponent:GetAnimEndPos(i_type)
  74. local pos = Vector3(0,0,0)
  75. if self.arrowType == 2 then
  76. if i_type == 1 or i_type == 2 then
  77. pos = Vector3(-10, 0, 0 )
  78. elseif i_type == 3 or i_type == 4 then
  79. pos = Vector3(0, -10 ,0)
  80. elseif i_type == 5 or i_type == 8 then
  81. pos = Vector3(-10, -10, 0)
  82. elseif i_type == 6 or i_type == 7 then
  83. pos = Vector3(-10, 10, 0)
  84. end
  85. else
  86. if i_type == 1 or i_type == 2 then
  87. pos = Vector3(-15, 0, 0 )
  88. elseif i_type == 3 or i_type == 4 then
  89. pos = Vector3(0, -15 ,0)
  90. elseif i_type == 5 or i_type == 8 then
  91. pos = Vector3(-15, -15, 0)
  92. elseif i_type == 6 or i_type == 7 then
  93. pos = Vector3(-15, 15, 0)
  94. end
  95. end
  96. return pos
  97. end
  98. function ArrowComponent:StartAnim()
  99. self:SetVisible(true)
  100. self.arrow.localPosition = Vector3(0,0,0)
  101. if self.twenn_id == nil then
  102. local function onCompleted()
  103. self:ArrowAnimation()
  104. end
  105. self.tween_id = TweenLite.to(self, self.arrow,TweenLite.UiAnimationType.POS, self:GetAnimEndPos(self.type) ,0.6,onCompleted,TweenFunc.EASE_IN_OUT)
  106. end
  107. end
  108. function ArrowComponent:ArrowAnimation()
  109. local call_fun = function ()
  110. local function onCompleted()
  111. self:ArrowAnimation()
  112. end
  113. self.tween_id3 =TweenLite.to(self, self.arrow,TweenLite.UiAnimationType.POS, self:GetAnimEndPos(self.type) ,0.6,onCompleted,TweenFunc.EASE_IN_OUT)
  114. end
  115. self.tween_id2 =TweenLite.to(self, self.arrow,TweenLite.UiAnimationType.POS,self:GetAnimEndPos(), 0.6, call_fun, TweenFunc.EASE_IN_OUT)
  116. end
  117. function ArrowComponent:StopAnim()
  118. if self.tween_id then
  119. TweenLite.Stop(self.tween_id)
  120. self.tween_id = nil
  121. end
  122. if self.tween_id2 then
  123. TweenLite.Stop(self.tween_id2)
  124. self.tween_id2 = nil
  125. end
  126. if self.tween_id3 then
  127. TweenLite.Stop(self.tween_id3)
  128. self.tween_id3 = nil
  129. end
  130. end
  131. function ArrowComponent:Hide()
  132. self:SetVisible(false)
  133. self:StopAnim()
  134. end
  135. function ArrowComponent:SetLayer(layer)
  136. if self.transform and layer then
  137. --self.transform.gameObject:GetComponent("Canvas").sortingOrder = layer
  138. end
  139. end