SUIAlignPanel.lua.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. local SUIAlignPanel = {}
  2. local humancost
  3. local function ForTest()
  4. if CS.UnityEngine.Input.GetKeyDown(CS.UnityEngine.KeyCode.Space) then
  5. humancost:SetCostSuccess(true)
  6. end
  7. end
  8. -- using for Gaming
  9. local function GetAlignArea()
  10. local dataRelay = require("Base/DataRelay.lua")
  11. local ALIGN_AREA = dataRelay:GetCache(dataRelay.KEY_TYPE.ALIGN_AREA, nil)
  12. local tTransformPose = CS.zwn_common_data.single.zwn_transform_pose
  13. local nAreaNowX = tTransformPose[5].x - tTransformPose[6].x
  14. local nAreaNowY = tTransformPose[5].y - tTransformPose[11].y
  15. ALIGN_AREA = math.abs(nAreaNowX * nAreaNowY);
  16. dataRelay:SetCache(dataRelay.KEY_TYPE.ALIGN_AREA, ALIGN_AREA)
  17. end
  18. local function CostChange()
  19. ForTest()
  20. local costChange = humancost.Cost_Change
  21. if costChange then
  22. local sSoundPath
  23. local nAreaNum = humancost.Area_Num
  24. if nAreaNum == -1 then
  25. -- 没有人
  26. sSoundPath = "Audios/Align/keepDistance.mp3"
  27. elseif nAreaNum == 0 then
  28. -- 对齐成功
  29. sSoundPath = "Audios/Align/alignSuccess.mp3"
  30. elseif nAreaNum == 1 then
  31. -- 向右一点
  32. sSoundPath = "Audios/Align/goRight.mp3"
  33. elseif nAreaNum == 2 then
  34. -- 向左一点
  35. sSoundPath = "Audios/Align/goLeft.mp3"
  36. elseif nAreaNum == 3 then
  37. -- 向后一点
  38. sSoundPath = "Audios/Align/goBack.mp3"
  39. elseif nAreaNum == 4 then
  40. -- 向前一点
  41. sSoundPath = "Audios/Align/goAlong.mp3"
  42. end
  43. require("Base/SMusicManager.lua"):PlaySound(sSoundPath)
  44. humancost:SetCostChange(false)
  45. end
  46. if humancost.Cost_Success then
  47. GetAlignArea()
  48. humancost:human_end()
  49. humancost:SetCostSuccess(false)
  50. local SUIPreparePanel = require("UI/SUIPreparePanel.lua")
  51. SUIPreparePanel.SetRootPanelActive(true)
  52. SUIAlignPanel.SetRootPanelActive(false)
  53. -- require("Base/UIHelper.lua"):SwitchUI("UI/SUIPreparePanel.lua", "UI/SUIAlignPanel.lua")
  54. end
  55. end
  56. local function CheckAlignData()
  57. CostChange()
  58. end
  59. local function HalfBody()
  60. print("SUIAlignPanel.HalfBody")
  61. local rootPanel = SUIAlignPanel.rootPanel
  62. local zwnHumancost = rootPanel.transform:Find("ZWNHumancost02").gameObject
  63. humancost = zwnHumancost:GetComponent("humancost")
  64. humancost:halfbody()
  65. end
  66. local function RegisterButtonQuit()
  67. print("SUIAlignPanel.RegisterButtonQuit")
  68. local panelQuit = SUIAlignPanel.rootPanel.transform:Find("Panel_Quit").gameObject
  69. require("Base/UIHelper.lua"):RegisterButtonQuit(panelQuit, false, "UI/SUITeachPanel.lua", "UI/SUIAlignPanel.lua")
  70. end
  71. local function RefreshUI()
  72. HalfBody()
  73. end
  74. local function InitData()
  75. end
  76. local function InitAllData()
  77. InitData()
  78. RefreshUI()
  79. end
  80. function SUIAlignPanel.SetRootPanelActive(bShow)
  81. SUIAlignPanel.rootPanel:SetActive(bShow)
  82. if bShow then
  83. InitAllData()
  84. return
  85. end
  86. end
  87. function SUIAlignPanel.Awake(luaRoot)
  88. SUIAlignPanel.luaRoot = luaRoot
  89. local canvas = CS.UnityEngine.GameObject.Find("Canvas")
  90. SUIAlignPanel._rootCanvas = canvas
  91. local prefabPanelAlign = LoadResource("Prefabs/UI/SUIAlignPanel.prefab")
  92. local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabPanelAlign, SUIAlignPanel._rootCanvas.transform)
  93. SUIAlignPanel.rootPanel = rootPanel
  94. end
  95. function SUIAlignPanel.Start()
  96. print("SUIAlignPanel.Start")
  97. RegisterButtonQuit()
  98. end
  99. function SUIAlignPanel.Update()
  100. if not SUIAlignPanel.rootPanel.activeSelf then
  101. return
  102. end
  103. CheckAlignData()
  104. end
  105. function SUIAlignPanel.OnDestroy()
  106. CS.UnityEngine.GameObject.Destroy(SUIAlignPanel.rootPanel)
  107. print("SUIAlignPanel.OnDestroy")
  108. end
  109. return SUIAlignPanel