NGUI-动画Tween

NGUI动画——Tween

Unity-UGUI Tween

一、属性表

属性效果
From开始状态
To结束状态
Play Style播放方式
Animation Curve运动曲线(插值曲线)调整From 到 To的变化
Duration播放一次动画的时间
Start Delay是否延迟
Tween Group可以控制在同一个GameObject的多个Tween 具体触发那个Tween
Ignore TimeScale忽略时间精度
Tween Position模式(坐标)

在这里插入图片描述

Tween Alpha模式 (透明度)

在这里插入图片描述

Tween Scale模式(缩放)

在这里插入图片描述

其他模式

除此之外 ,还有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

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值