|
|
-
-
- TweenLite = TweenLite or BaseClass()
- local TweenLite = TweenLite
- local math_min = math.min
- local Status = Status
- local table_insert = table.insert
- local IsTableEmpty = IsTableEmpty
- local GetLocalPositionX = GetLocalPositionX
- local GetLocalPositionY = GetLocalPositionY
- local SetLocalPositionX = SetLocalPositionX
- local SetLocalPositionY = SetLocalPositionY
- TweenLite.UiAnimationType = {
- POS = "POS",
- POSX = "POSX",
- POSY = "POSY",
- ALPHA = "ALPHA", --新版的alpha 不要用旧版的
- ALPHA_OLD = "ALPHA_OLD",--旧版的alpha变化 后续不要再调用
- WIDTH = "WIDTH",
- HEIGHT = "HEIGHT",
- ROTATION = "ROTATION", --rotateion.z
- CANVAS_POSX="CANVAS_POSX",
- CANVAS_POSY="CANVAS_POSY",
- SCALE = "SCALE",
- ROTATION_Y = "ROTATION_Y",
- SRECT_HORIZONTAL = "SRECT_HORIZONTAL",
- SRECT_VERTICAL = "SRECT_VERTICAL",
- ANCHORED_POS = "ANCHORED_POS",
- ANCHORED_POSX = "ANCHORED_POSX",
- ANCHORED_POSY = "ANCHORED_POSY",
- ALPHA_ALL = "ALPHA_ALL", --动态添加CanvasGroup设置透明度,也可以自己在prefab里添加然后调用TweenLite.UiAnimationType.ALPHA
- FILLAMOUNT = "FILLAMOUNT",
- DELAY = "DALAY", --延迟
- }
-
- TweenLite.moving_info_list = {} --当前正在缓动的列表
- TweenLite.moving_info_list_delay = {} -- 保存正在更新的过程中添加进来的对象 本次更新完以后才会添加到moving_info_list里 避免更新过程中触发rehash产生影响
- TweenLite.curr_info_index = 0
- TweenLite.is_updating = false --是否正在更新
-
- --[[
- 参数
- parent_wnd:父容器 继承baseclass的父容器 用来判断是否已经被删除
- anim_wnd:缓动对象
- tweentype:缓动类型
- endValue:结束值
- AnimaTime:缓动时间(s)
- anim_end_func:结束调用方法
- tween_type:缓动类型 默认线性
- ]]
- function TweenLite.to(parent_wnd, anim_wnd, tweentype, endValue, AnimaTime, anim_end_func, tween_type, loop)
- if not anim_wnd then
- return
- end
- local startvalue=0
- if tweentype == TweenLite.UiAnimationType.POS then
- startvalue = anim_wnd.localPosition
- elseif tweentype == TweenLite.UiAnimationType.POSX then
- startvalue = GetLocalPositionX(anim_wnd)
- elseif tweentype == TweenLite.UiAnimationType.POSY then
- startvalue = GetLocalPositionY(anim_wnd)
- elseif tweentype == TweenLite.UiAnimationType.ALPHA then
- startvalue = anim_wnd.alpha
- elseif tweentype == TweenLite.UiAnimationType.ALPHA_OLD then
- startvalue = GetAlpha(anim_wnd)
- elseif tweentype == TweenLite.UiAnimationType.WIDTH then
- startvalue = GetSizeDeltaX(anim_wnd)
- elseif tweentype == TweenLite.UiAnimationType.HEIGHT then
- startvalue = GetSizeDeltaY(anim_wnd)
- elseif tweentype == TweenLite.UiAnimationType.ROTATION then
- startvalue = anim_wnd.eulerAngles.z
- elseif tweentype == TweenLite.UiAnimationType.ROTATION_Y then
- startvalue = anim_wnd.eulerAngles.y
- -- elseif tweentype == TweenLite.UiAnimationType.CANVAS_POSY then
- -- startvalue=anim_wnd:GetVector2(ScrollViewProperty.CanvasPosition).y
- -- elseif tweentype == TweenLite.UiAnimationType.CANVAS_POSX then
- -- startvalue=anim_wnd:GetVector2(ScrollViewProperty.CanvasPosition).x
- elseif tweentype == TweenLite.UiAnimationType.SCALE then
- startvalue = anim_wnd.localScale
- elseif tweentype == TweenLite.UiAnimationType.SRECT_HORIZONTAL then
- startvalue = anim_wnd.horizontalNormalizedPosition
- elseif tweentype == TweenLite.UiAnimationType.SRECT_VERTICAL then
- startvalue = anim_wnd.verticalNormalizePosition
- elseif tweentype == TweenLite.UiAnimationType.ANCHORED_POS then
- startvalue = anim_wnd.anchoredPosition
- elseif tweentype == TweenLite.UiAnimationType.ANCHORED_POSX then
- startvalue = anim_wnd.anchoredPosition.x
- elseif tweentype == TweenLite.UiAnimationType.ANCHORED_POSY then
- startvalue = anim_wnd.anchoredPosition.y
- elseif tweentype == TweenLite.UiAnimationType.FILLAMOUNT then
- startvalue = anim_wnd:GetComponent("Image").fillAmount
- elseif tweentype == TweenLite.UiAnimationType.ALPHA_ALL then
- --添加一个CanvasGroup组件
- local component = anim_wnd:GetComponent("CanvasGroup")
- if not component then
- component = anim_wnd:AddComponent(typeof(UnityEngine.CanvasGroup))
- end
- startvalue = component.alpha
- elseif tweentype == TweenLite.UiAnimationType.DELAY then
- end
- local tid = TweenLite.AddMovingItem(parent_wnd, anim_wnd, tweentype, startvalue, endValue, AnimaTime, anim_end_func, tween_type, loop)
-
- if TweenLite.delayfun_timer == nil then
- local function delayfun()
- TweenLite.Update()
- end
- TweenLite.delayfun_timer = GlobalTimerQuest:AddPeriodQuest(delayfun, 0.02, -1)
- end
- return tid
- end
-
- function TweenLite.setMovingInfo(v,progress)
- if not v or v.parent_wnd._use_delete_method or IsNull(v.anim_wnd) then
- return true
- end
-
- local curr_value = v.startvalue + (v.endValue - v.startvalue) * progress
- if v.tweentype==TweenLite.UiAnimationType.POS then
- -- v.anim_wnd.localPosition = curr_value
- SetLocalPosition(v.anim_wnd, curr_value.x, curr_value.y , curr_value.z)
- elseif v.tweentype==TweenLite.UiAnimationType.POSX then
- -- local vect = Vector3(curr_value,v.anim_wnd.localPosition.y, v.anim_wnd.localPosition.z)
- -- v.anim_wnd.localPosition = vect
- SetLocalPositionX(v.anim_wnd, curr_value)
- elseif v.tweentype==TweenLite.UiAnimationType.POSY then
- -- local vect = Vector3(v.anim_wnd.localPosition.x,curr_value, v.anim_wnd.localPosition.z)
- -- v.anim_wnd.localPosition = vect
- SetLocalPositionY(v.anim_wnd, curr_value)
- elseif v.tweentype==TweenLite.UiAnimationType.ALPHA then
- v.anim_wnd.alpha = curr_value
- elseif v.tweentype==TweenLite.UiAnimationType.ALPHA_OLD then
- SetAlpha(v.anim_wnd,curr_value)
- elseif v.tweentype==TweenLite.UiAnimationType.WIDTH then
- SetSizeDeltaX(v.anim_wnd, curr_value)
- -- v.anim_wnd.sizeDelta = Vector2(curr_value,v.anim_wnd.sizeDelta.y)
- elseif v.tweentype==TweenLite.UiAnimationType.HEIGHT then
- SetSizeDeltaY(v.anim_wnd, curr_value)
- -- v.anim_wnd.sizeDelta = Vector2(v.anim_wnd.sizeDelta.x,curr_value)
- elseif v.tweentype == TweenLite.UiAnimationType.ROTATION then
- v.anim_wnd.localRotation = Quaternion.Euler(0,0,curr_value)
- elseif v.tweentype == TweenLite.UiAnimationType.ROTATION_Y then
- v.anim_wnd.localRotation = Quaternion.Euler(0,curr_value,0)
- elseif v.tweentype == TweenLite.UiAnimationType.FILLAMOUNT then
- v.anim_wnd:GetComponent("Image").fillAmount = curr_value
- -- elseif v.tweentype==TweenLite.UiAnimationType.CANVAS_POSY then
- -- anim_wnd:SetVectorR(ScrollViewProperty.CanvasPosition, pass_time)
- -- elseif v.tweentype==TweenLite.UiAnimationType.CANVAS_POSX then
- -- anim_wnd:SetVectorL(ScrollViewProperty.CanvasPosition, pass_time)
- elseif v.tweentype == TweenLite.UiAnimationType.SCALE then
- -- v.anim_wnd.localScale = curr_value
- SetLocalScale(v.anim_wnd, curr_value.x, curr_value.y)
- elseif v.tweentype == TweenLite.UiAnimationType.SRECT_HORIZONTAL then
- v.anim_wnd.horizontalNormalizedPosition = curr_value
- elseif v.tweentype == TweenLite.UiAnimationType.SRECT_VERTICAL then
- v.anim_wnd.verticalNormalizePosition = curr_value
- elseif v.tweentype==TweenLite.UiAnimationType.ANCHORED_POS and v.anim_wnd.anchoredPosition then
- v.anim_wnd.anchoredPosition = curr_value
- elseif v.tweentype==TweenLite.UiAnimationType.ANCHORED_POSX and v.anim_wnd.anchoredPosition then
- local vect = Vector2(curr_value,v.anim_wnd.anchoredPosition.y)
- v.anim_wnd.anchoredPosition = vect
- elseif v.tweentype==TweenLite.UiAnimationType.ANCHORED_POSY and v.anim_wnd.anchoredPosition then
- local vect = Vector2(v.anim_wnd.anchoredPosition.x, curr_value)
- v.anim_wnd.anchoredPosition = vect
- elseif v.tweentype==TweenLite.UiAnimationType.ALPHA_ALL then
- local component = v.anim_wnd:GetComponent("CanvasGroup")
- component.alpha = curr_value
- elseif v.tweentype==TweenLite.UiAnimationType.DELAY then
- end
- return false
- end
-
- function TweenLite.AddMovingItem(parent_wnd, anim_wnd, tweentype, startvalue, endValue, AnimaTime, anim_end_func, tween_type, loop)
- local info = {parent_wnd = parent_wnd, anim_wnd = anim_wnd, tweentype = tweentype, startvalue = startvalue, endValue = endValue, AnimaTime = AnimaTime,
- anim_end_func = anim_end_func, tween_func = tween_type and TweenFunc[tween_type] or TweenFunc[TweenFunc.LINEAR], startTime = Status.NowTime, loop = loop or false}
- TweenLite.curr_info_index = TweenLite.curr_info_index + 1
- if TweenLite.is_updating == false then
- TweenLite.moving_info_list[TweenLite.curr_info_index] = info
- else
- TweenLite.moving_info_list_delay[TweenLite.curr_info_index] = info
- end
- return TweenLite.curr_info_index
- end
-
- function TweenLite.Update()
- -- if G_DEBUG_STOP_ACTION then
- -- return
- -- end
- TweenLite.is_updating = true
- local delete_list = {} --更新完后再删除列表 避免更新过程中触发rehash产生影响
- for k, v in pairs(TweenLite.moving_info_list) do
- local usetime = Status.NowTime - v.startTime
- local need_delete = false
- if v.tween_func then
- --经过时间
- local ratio = math_min(usetime / v.AnimaTime,1)
- local progress = v.tween_func(ratio)
- need_delete = TweenLite.setMovingInfo(v,progress)
- end
- local timeout = false
- if usetime >= v.AnimaTime then
- if v.loop then
- v.startTime = Status.NowTime
- else
- timeout = true
- end
- end
- if need_delete or timeout then
- --结束回调
- if not need_delete and v.anim_end_func ~= nil then
- v.anim_end_func()
- end
- table_insert(delete_list,k)
- end
- end
- TweenLite.is_updating = false
-
- for i = 1,#delete_list do
- TweenLite.moving_info_list[delete_list[i]] = nil
- end
- for k, v in pairs(TweenLite.moving_info_list_delay) do
- v.startTime = Status.NowTime
- TweenLite.moving_info_list[k] = v
- end
- TweenLite.moving_info_list_delay = {}
-
- if IsTableEmpty(TweenLite.moving_info_list) then
- if TweenLite.delayfun_timer then
- GlobalTimerQuest:CancelQuest(TweenLite.delayfun_timer)
- TweenLite.delayfun_timer = nil
- -- print("GlobalTimerQuest:CancelQuest TweenLite.delayfun_timer")
- end
- end
- end
-
- function TweenLite.Stop(id)
- if not id then return end
- TweenLite.moving_info_list[id] = nil
- TweenLite.moving_info_list_delay[id] = nil
- end
|