NGUI动画——Tween Unity-UGUI Tween 一、属性表
除此之外 ,还有TweenColor(颜色动画) Rotation(旋转)TweenLetter(文字动画) 和上面的类似的
都是(特定属性 + Tweener)
二、使用场景 1、打开场景的动画效果 --伪代码 大致实现的思路 -- 定义动画类型 TweenType = { Position = 1, Alpha = 2, Scale = 3, TweenColor = 4, Rotation = 5, TweenLetter, } --定义面板动画配置 local Config = { ["页面1"] = { ["控件1"] = { {type = 1,from = Vector3(0,0,0),to = Vector3(300,0,0),duration = 0.3, delay_time =0,method=TweenType.Cubic_EaseOut}, }, ["控件2"] = { {type = 2,from = 0,to = 1,duration = 0.3, delay_time = 0,method=TweenType.Linear}, {type = 3,from = Vector3(0,0,0),to = Vector3(1,1,1),duration = 0.3, delay_time = 0}, }, }, } local InitTween = function() local tween_list = {} --设置面板大小 local pixelSize_adj = UIRoot.GetPixelSizeAdjustment(self.panel_root) local screen_x = math.floor(NGUITools.screenSize.x * pixelSize_adj) local screen_y = math.floor(NGUITools.screenSize.y * pixelSize_adj) local scale_x = screen_x / 720 local scale_y = screen_y / 1440 local sub_x = (screen_x - 720)/2 local sub_y = (screen_y - 1440)/2 --读取配置 以Position 为例 for k,v in pairs(Config) do if v and next(v) then for kk,vv in pairs(v) then local tween = nil tween.form = vv.from tween.to = vv.to tween.method = vv.method obj.gameObject.transform.localPosition = tween.form tween.duration = vv.duration tween.enabled = false tween.delay = vv.delay_time or 0 table.insert(tween_list, tween) end end end return tween_list end local PlayUITween = function(tween_list) for k,v in pairs(tween_list) do if v then --调用动画 v:ResetToBeginning() v:PlayForward() end end end local Start = function() local tween_list = InitTween() PlayUITween(tween_list) end Start()值得注意的是ResetToBeginning 和 PlayForward 每次执行动画时最好ResetToBeginning 一下 ,可以看成原子操作吧
2、点击动画点击效果一般可以看做三步,开始,进行,结束。动画就是进行了,点击出现的效果就是结束处理的结果
--伪代码 local is_tween = false local is_start = false local on_start = function() --初始化状态 设置标志位 if is_tween then return end is_start = true end local on_drag = function(obj,param) if not is_start then return end local pos = obj.gameObject.transform.localPosition local old_pos = UVector2(pos.x, pos.y) local new_pos = UVector2(pos.x + param.x, pos.y + param.y) obj.gameObject.transform.localPosition = new_pos end local on_dragEnd = function() --[[ 根据 new_pos 与原坐标比较 根据各种差异 可以处理不同的效果动画效果 再来个callback ]] end
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。 |