2023-07-14 19:35:33 +00:00
|
|
|
|
local XEquipModel = XClass(nil, "XEquipModel")
|
|
|
|
|
|
|
|
|
|
-- go 为绑定生命周期的对象
|
|
|
|
|
-- luaBehaviour (XLuaBehaviour组件)提供生命周期回调
|
|
|
|
|
function XEquipModel:Ctor(go, luaBehaviour)
|
|
|
|
|
self.GameObject = go
|
|
|
|
|
self.LuaBehaviour = luaBehaviour
|
|
|
|
|
luaBehaviour.LuaOnDisable = function() self:OnDisable() end
|
|
|
|
|
luaBehaviour.LuaOnDestroy = function() self:OnDestroy() end
|
|
|
|
|
|
|
|
|
|
self.AudioInfoDict = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XEquipModel:OnDisable()
|
|
|
|
|
-- 清除音效
|
|
|
|
|
self:ClearAudioInfo()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XEquipModel:OnDestroy()
|
|
|
|
|
self:UnScheduleRotate()
|
|
|
|
|
XModelManager.RemoveLuaBehaviour(self.GameObject)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 记录模型音效
|
|
|
|
|
function XEquipModel:AddAudioInfo(audioInfo)
|
|
|
|
|
self.AudioInfoDict[audioInfo] = true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 停止模型音效
|
|
|
|
|
function XEquipModel:ClearAudioInfo()
|
|
|
|
|
if next(self.AudioInfoDict) then
|
|
|
|
|
for audioInfo, _ in pairs(self.AudioInfoDict) do
|
|
|
|
|
audioInfo:Stop()
|
|
|
|
|
end
|
|
|
|
|
self.AudioInfoDict = {}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--==============================--
|
|
|
|
|
--desc: 自转
|
|
|
|
|
--@rootGo: 根结点 提供XAutoRotation组件
|
|
|
|
|
--@model: 武器模型
|
|
|
|
|
--@modelId: 武器模型id
|
|
|
|
|
--==============================--
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XEquipModel:AutoRotateWeapon(rootGo, model, modelId, notWeapon, center)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
self:UnScheduleRotate()
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
local delay = notWeapon and 0 or XEquipConfig.GetEquipUiAutoRotateDelay(modelId)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
if delay and delay > 0 then
|
|
|
|
|
self.RotateScheduleId = XScheduleManager.ScheduleOnce(function()
|
2024-09-01 20:49:41 +00:00
|
|
|
|
self:DoAutoRotateWeapon(rootGo, model, center)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end, delay)
|
|
|
|
|
else
|
2024-09-01 20:49:41 +00:00
|
|
|
|
self:DoAutoRotateWeapon(rootGo, model, center)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
---@param rootGo UnityEngine.Transform
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XEquipModel:DoAutoRotateWeapon(rootGo, model, center)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
if XTool.UObjIsNil(rootGo) or XTool.UObjIsNil(model) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local rotate = rootGo:GetComponent("XAutoRotation")
|
|
|
|
|
if not rotate then
|
|
|
|
|
rootGo:AddComponent(typeof(CS.XAutoRotation))
|
|
|
|
|
rotate = rootGo:GetComponent(typeof(CS.XAutoRotation))
|
|
|
|
|
end
|
|
|
|
|
if rotate then
|
|
|
|
|
rotate.IsAutoRotation = true
|
|
|
|
|
rotate.RotateSelf = false
|
|
|
|
|
rotate.Inited = false
|
|
|
|
|
rotate.Target = model.transform
|
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
-- Inited实则是在找旋转中心, 外部设置的情况下, 不需要init
|
|
|
|
|
if center then
|
|
|
|
|
rotate:SetCenterPoint(center)
|
|
|
|
|
rotate.Inited = true
|
|
|
|
|
end
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--==============================--
|
|
|
|
|
--desc: 手动阻尼旋转
|
|
|
|
|
--@panelDrag: 滑动节点 提供XDragAutoRotate组件
|
|
|
|
|
--@model: 武器模型
|
|
|
|
|
--@modelId: 武器模型id
|
|
|
|
|
--@rotateCenter: 旋转参照节点(一般不需要)
|
|
|
|
|
--==============================--
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XEquipModel:DragRotateWeapon(panelDrag, model, modelId, rotateCenter, notWeapon, antiClockwise)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
self:UnScheduleRotate()
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
local delay
|
|
|
|
|
if notWeapon then
|
|
|
|
|
delay = 0
|
|
|
|
|
else
|
|
|
|
|
delay = XEquipConfig.GetEquipUiAutoRotateDelay(modelId)
|
|
|
|
|
end
|
2023-07-14 19:35:33 +00:00
|
|
|
|
if delay and delay > 0 then
|
|
|
|
|
self.RotateScheduleId = XScheduleManager.ScheduleOnce(function()
|
2024-09-01 20:49:41 +00:00
|
|
|
|
self:DoDragRotateWeapon(panelDrag, model, rotateCenter, antiClockwise)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end, delay)
|
|
|
|
|
else
|
2024-09-01 20:49:41 +00:00
|
|
|
|
self:DoDragRotateWeapon(panelDrag, model, rotateCenter, antiClockwise)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XEquipModel:DoDragRotateWeapon(panelDrag, model, rotateCenter, antiClockwise)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
if XTool.UObjIsNil(panelDrag) or XTool.UObjIsNil(model) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
---@type XDragAutoRotate
|
2023-07-14 19:35:33 +00:00
|
|
|
|
local rotate = panelDrag:GetComponent("XDragAutoRotate")
|
|
|
|
|
if rotate then
|
|
|
|
|
rotate:SetTarget(model.transform)
|
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
|
|
|
|
|
if rotate then
|
|
|
|
|
if rotateCenter then
|
|
|
|
|
rotate:SetCenterPoint(rotateCenter.transform)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if antiClockwise then
|
|
|
|
|
rotate:SetDirection(false)
|
|
|
|
|
end
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XEquipModel:UnScheduleRotate()
|
|
|
|
|
if self.RotateScheduleId then
|
|
|
|
|
XScheduleManager.UnSchedule(self.RotateScheduleId)
|
|
|
|
|
self.RotateScheduleId = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return XEquipModel
|