源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

135 行
4.2 KiB

  1. GuideSpiritItem = GuideSpiritItem or BaseClass(BaseItem)
  2. function GuideSpiritItem:__init()
  3. self.base_file = "guide"
  4. self.layout_file = "GuideSpiritItem"
  5. self.layer_name = "Main"
  6. self.destroy_imm = true
  7. self.use_background = true
  8. -- self.use_local_view = true
  9. self:Load()
  10. end
  11. function GuideSpiritItem:Load_callback()
  12. self.ModelBtn
  13. = GetChildGameObjects (self.transform,
  14. {
  15. "ModelBtn"
  16. })
  17. self.con,self.SpiritCon
  18. = GetChildTransforms(self.transform,
  19. {
  20. "Con","SpiritCon",
  21. })
  22. self:InitEvent()
  23. local function load_callback()
  24. self:SetSpiritModel()
  25. end
  26. local data = {
  27. clothe_res_id = GuideModel.SpiritBgId,
  28. type = SceneBaseType.StarSoul,
  29. layer_name = self.layer_name,
  30. rotate = Vector3(-15,0,0),
  31. action_name_list = {"idle"},
  32. can_rotate = false,
  33. scale = 50,
  34. position = Vector3(0, 12, 0),
  35. callBack = load_callback,
  36. layout_file = self.layout_file
  37. }
  38. lua_resM:SetRoleModel(self, self.con,data)
  39. end
  40. function GuideSpiritItem:SetSpiritModel()
  41. local function load_callback()
  42. if self.curr_Model == nil then
  43. self.curr_Model = lua_resM:GetPartModel(self, self.con)
  44. end
  45. if self.curr_Model then
  46. self.spirit_root = self.curr_Model.transform:Find("Bone001")
  47. if self.spirit_root then
  48. local function load_finish(go)
  49. if go then
  50. self:SetUILayer(go.transform)
  51. go.transform.localPosition = Vector3(0,0,0)
  52. go.transform.localScale = Vector3.one
  53. go.transform.localRotation = Quaternion.Euler(Vector3.zero)
  54. end
  55. end
  56. local function load_finish_func(go)
  57. if go then
  58. self.BGEffect = go.transform
  59. self:SetUILayer(go.transform)
  60. go.transform.localPosition = Vector3(0,0,0)
  61. go.transform.localScale = Vector3.one
  62. go.transform.localRotation = Quaternion.Euler(Vector3.zero)
  63. end
  64. end
  65. self:AddUIEffect("501001_bone001fx",self.spirit_root.transform,self.layer_name, nil, -1, false, -1, nil, nil, load_finish, nil, nil, true)
  66. self:AddUIEffect("ui_partnershow",self.curr_Model.transform,self.layer_name, nil, -1, false, -1, nil, nil, load_finish_func, nil, nil, true)
  67. self.SpiritCon:SetParent(self.spirit_root.transform)
  68. end
  69. end
  70. end
  71. local data = {
  72. clothe_res_id = GuideModel.SpiritId,
  73. type = SceneBaseType.StarSoul,
  74. layer_name = self.layer_name,
  75. rotate = Vector3(0,180,0),
  76. action_name_list = {"idle2"},
  77. can_rotate = false,
  78. scale = 1,
  79. position = Vector3(2.1, -144.2, 0),
  80. callBack = load_callback,
  81. layout_file = self.layout_file
  82. }
  83. lua_resM:SetRoleModel(self,self.SpiritCon.transform,data)
  84. end
  85. function GuideSpiritItem:InitEvent()
  86. local function clickFunc(target)
  87. if target == self.ModelBtn then
  88. GlobalEventSystem:Fire(EventName.OPEN_GUIDE_SPIRIT_VIEW)
  89. end
  90. end
  91. AddClickEvent(self.ModelBtn,clickFunc)
  92. local function onChangeMainCanvasVisible(ref,visible)
  93. if visible then
  94. local spirt_model = lua_resM:GetPartModel(self, self.SpiritCon)
  95. if spirt_model and spirt_model.gameObject then
  96. local animator = spirt_model.gameObject:GetComponent("Animator")
  97. if animator then
  98. if not self.timer_out then
  99. local onDelay = function( )
  100. if self.timer_out then
  101. GlobalTimerQuest:CancelQuest(self.timer_out)
  102. self.timer_out = nil
  103. end
  104. if animator then
  105. animator:Update(0)
  106. animator:CrossFade("idle2",0.1, 0)
  107. end
  108. end
  109. self.timer_out = setTimeout(onDelay, 0.1)
  110. end
  111. end
  112. end
  113. end
  114. end
  115. self.change_canvas_id = LuaViewManager:getInstance():Bind(LuaViewManager.CHANGE_MAIN_CANVAS_VISIBLE,onChangeMainCanvasVisible)
  116. end
  117. function GuideSpiritItem:__delete()
  118. if self.timer_out then
  119. TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_out)
  120. self.timer_out = false
  121. end
  122. if self.event_id then
  123. self.model:UnBind(self.event_id)
  124. end
  125. if self.change_canvas_id then
  126. LuaViewManager:getInstance():UnBind(self.change_canvas_id)
  127. self.change_canvas_id = nil
  128. end
  129. end