Unity ToLua & LuaFramework_UGUI中使用DoTween

在做一些弹窗动画或Tips以及缩放,渐变震动等效果时,常常会间接引入第三方库,最近就尝试了一下在ToLua & LuaFramework_UGUI中的使用,细心的初学者都会发现,其实LuaFramework框架已经为我们加入了DoTween库的引用,只是开源作者加了一个宏定义限制,我们只要稍微处理就能在项目中使用具体方法。
说明,看了一些资料(http://blog.csdn.net/lyh916/article/details/45888117 http://www.it610.com/article/5341538.htm),不少人去改框架的东西自己去重新加一次,本人不是赞成这样做,太麻烦,还生产过多的Wrap文件,也是浪费时间。

下面看一下具体操作

Unity ToLua & LuaFramework_UGUI中使用DoTween_第1张图片
[宏定义]

Unity ToLua & LuaFramework_UGUI中使用DoTween_第2张图片
库方法注册
local go = GameObject('go')
go:AddComponent(typeof(UnityEngine.ParticleSystem))
go.transform.position = Vector3.zero
go.transform:Rotate(Vector3(0,90,0), UnityEngine.Space.World)
go.transform:Rotate(Vector3(0, 1, 0), 0)

--DoTween 需要在CustomSetting导出前定义USING_DOTWEENING宏,或者取消相关注释
go.transform:DORotate(Vector3(0,0,360), 2, DG.Tweening.RotateMode.FastBeyond360)

Shop = {}

function Shop:Awake()
    self.OnUpdate = UpdateBeat:CreateListener(Shop.Update, self)
    UpdateBeat:AddListener(self.OnUpdate)
end

function Shop:OnDestroy()
    UpdateBeat:RemoveListener(self.OnUpdate)
end

function Shop:OnClick()
    print("OnClick")
end

function Shop:OnToggle()
    print("OnToggle")
end

function Shop:Update()
end

--委托
local listener = UIEventListener.Get(go)
listener.onClick = function() print("OnClick") end
listener.onClick = nil
listener.onClick = UIEventListener.VoidDelegate(Shop.OnClick, Shop)
listener.onClick = listener.onClick + UIEventListener.VoidDelegate(Shop.OnClick, Shop)
listener.onClick = listener.onClick - UIEventListener.VoidDelegate(Shop.OnClick, Shop)

local toggle = go:GetComponent(typeof(UIToggle))
EventDelegate.Add(toggle.onChange, EventDelegate.Callback(Shop.OnToggle, Shop))
EventDelegate.Remove(toggle.onChange, EventDelegate.Callback(Shop.OnToggle, Shop))

--事件
local Client = {}

function Client:Log(str)
end

Application.logMessageReceived = Application.logMessageReceived + Application.LogCallback(Clent.Log, Client)
Application.logMessageReceived = Application.logMessageReceived - Application.LogCallback(Clent.Log, Client)

--out参数
local _layer = 2 ^ LayerMask.NameToLayer('Default')
local flag, hit = UnityEngine.Physics.Raycast(ray, nil, 5000, _layer)

if flag then
    print('pick from lua, point: '..tostring(hit.point))
end

实现一个简易的弹窗动画

--弹窗动画 
function CUIManager:ShowWindows(uiobj)
    local rt = uiobj.transform
    rt.transform.position = Vector3.New(0, 0, 0)                        
    rt.transform.localScale = Vector3.New(1, 1, 1)
    local scalTime = 0.05
    local m_scale = rt:DOScale(Vector3(1.1, 1.1, 1), scalTime)
    m_scale:SetEase(DG.Tweening.Ease.Linear)
    m_scale:SetLoops(2, DG.Tweening.LoopType.Yoyo) 
    m_scale = rt:DOScale(Vector3(0.9, 0.9, 1), scalTime)
    m_scale:SetEase(DG.Tweening.Ease.Linear)
    m_scale:SetLoops(2, DG.Tweening.LoopType.Yoyo) 
    rt.transform:DOShakePosition(scalTime, Vector3(10, 10, 10))
end  

你可能感兴趣的:(Unity ToLua & LuaFramework_UGUI中使用DoTween)