miduo_client/Assets/ManagedResources/~Lua/Modules/Story/SpineControl.lua

83 lines
2.2 KiB
Lua

--- 封装一层立绘加载处理方法,在这里扩展立绘处理方法
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by Steven Hawking.
--- DateTime: 2019/11/20 14:21
---
SpineHandle = {}
SpineHandle.__index = SpineHandle
local function LoadAssert(resName, parent, scale, pos)
if not resName or resName == "" then
Log("resource can not find ")
return
end
local live2d = poolManager:LoadLive(resName, parent.transform, scale, pos)
return live2d
end
function SpineHandle:New(resName, parent, scale, pos, initAnim)
local _o = {}
_o = {} or _o
setmetatable(_o, self)
-- 设置成员属性
_o.live2d = LoadAssert(resName, parent, scale, pos)
_o.graphic = _o.live2d:GetComponent("SkeletonGraphic")
_o.resName = resName
-- 默认循环播放
_o.graphic.AnimationState:SetAnimation(0, initAnim, true)
-- 预留字段
_o.initDone = true
return _o
end
------------ 动画资源处理 -----------------------
--- 设置每次动画播放后的回调
function SpineHandle:SetCallBack(func)
if self.graphic and func then
self.graphic.AnimationState.Complete = self.graphic.AnimationState.Complete + func
self.callback = func
end
end
function SpineHandle:SetAnimation(aniName, loop)
if self.graphic then
self.graphic.AnimationState:SetAnimation(0, aniName, loop)
end
end
function SpineHandle:StopAnimation(delay)
if self.graphic then
self.graphic.AnimationState:SetEmptyAnimation (0, delay)
end
end
--------------------------------------------------------------------
function SpineHandle:SetSlot(slotName, attachmentName)
if self.graphic then
--self.graphic.Skeleton:SetAttachment(slotName, attachmentName)
end
end
function SpineHandle:UnLoadSpine()
if self.live2d and self.graphic and self.graphic.AnimationState then
if self.callback then
self.graphic.AnimationState.Complete = self.graphic.AnimationState.Complete - self.callback
end
poolManager:UnLoadLive(self.resName, self.live2d)
self.live2d = nil
self.graphic = nil
self.callback = nil
self.initDone = false
end
end
return SpineHandle