ArrowHint = ArrowHint or BaseClass()
|
|
|
|
function ArrowHint:__init()
|
|
self.mPanel = nil -- scrowView 物体
|
|
self.mScroll = nil -- scrowView 组件
|
|
self.mContent = nil --content物体
|
|
|
|
self.mHorizontal = false --是否是水平
|
|
|
|
self.transform = nil
|
|
self.left_down_tra = nil --左或者下的特效挂载父物体
|
|
self.right_top_tra = nil --右或者上的特效挂载父物体
|
|
end
|
|
|
|
function ArrowHint:__delete()
|
|
if self.mScroll then
|
|
self.mScroll.onValueChanged:RemoveAllListeners()
|
|
end
|
|
|
|
if self.transfrom then
|
|
if self.left_down_tra then
|
|
self.transfrom:ClearUIEffect(self.left_down_tra)
|
|
end
|
|
|
|
if self.right_top_tra then
|
|
self.transfrom:ClearUIEffect(self.right_top_tra)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- is_hor 外部定义是否水平,覆盖掉内部判断,传空内部可自己判断
|
|
function ArrowHint:Init(transfrom, mPanel, mContent, left_down_tra, right_top_tra, layer_name, pos, scale, is_hor)
|
|
self.transfrom = transfrom
|
|
self.mPanel = mPanel
|
|
self.mContent = mContent
|
|
self.mScroll = self.mPanel:GetComponent("ScrollRect")
|
|
self.left_down_tra = left_down_tra
|
|
self.right_top_tra = right_top_tra
|
|
|
|
if not self.transfrom or not self.mPanel or not self.mContent or not self.mScroll then return end
|
|
|
|
self:SetArrowEffect(layer_name, pos, scale, is_hor)
|
|
|
|
--self.mScroll.onValueChanged:RemoveAllListeners()
|
|
self.mScroll.onValueChanged:AddListener(function()
|
|
self:ShowArrow()
|
|
end)
|
|
end
|
|
|
|
function ArrowHint:SetArrowEffect(layer_name, pos, scale, is_hor)
|
|
if is_hor == nil then
|
|
if self.mScroll.horizontal then
|
|
self.mHorizontal = true
|
|
elseif self.mScroll.vertical then
|
|
self.mHorizontal = false
|
|
end
|
|
else
|
|
self.mHorizontal = is_hor
|
|
end
|
|
|
|
layer_name = layer_name or "UI"
|
|
local l_effect, r_effect
|
|
if self.mHorizontal then
|
|
l_effect = "effect_tubiao_007"
|
|
r_effect = "effect_tubiao_009"
|
|
else
|
|
l_effect = "effect_tubiao_006"
|
|
r_effect = "effect_tubiao_008"
|
|
end
|
|
if self.left_down_tra then
|
|
self.transfrom:AddUIEffect(l_effect, self.left_down_tra, layer_name, pos, scale, true)
|
|
end
|
|
if self.right_top_tra then
|
|
self.transfrom:AddUIEffect(r_effect, self.right_top_tra, layer_name, pos, scale, true)
|
|
end
|
|
|
|
self:ShowArrow()
|
|
end
|
|
|
|
function ArrowHint:ShowArrow()
|
|
local offset, value
|
|
if self.mHorizontal then
|
|
value = self.mScroll.horizontalNormalizedPosition
|
|
if self.mContent.sizeDelta.x > self.mPanel.sizeDelta.x then
|
|
offset = self.mPanel.sizeDelta.x / (self.mContent.sizeDelta.x * 8)
|
|
end
|
|
else
|
|
value = self.mScroll.verticalNormalizedPosition
|
|
if self.mContent.sizeDelta.y > self.mPanel.sizeDelta.y then
|
|
offset = self.mPanel.sizeDelta.y / (self.mContent.sizeDelta.y * 8)
|
|
end
|
|
end
|
|
|
|
if offset and value then
|
|
if self.left_down_tra then
|
|
if value < offset then
|
|
if self.left_down_tra.gameObject.activeInHierarchy then
|
|
self.left_down_tra.gameObject:SetActive(false)
|
|
end
|
|
else
|
|
if not self.left_down_tra.gameObject.activeInHierarchy then
|
|
self.left_down_tra.gameObject:SetActive(true)
|
|
end
|
|
end
|
|
end
|
|
if self.right_top_tra then
|
|
if value > 1 - offset then
|
|
if self.right_top_tra.gameObject.activeInHierarchy then
|
|
self.right_top_tra.gameObject:SetActive(false)
|
|
end
|
|
else
|
|
if not self.right_top_tra.gameObject.activeInHierarchy then
|
|
self.right_top_tra.gameObject:SetActive(true)
|
|
end
|
|
end
|
|
end
|
|
else
|
|
self:SetArrowShow()
|
|
end
|
|
end
|
|
|
|
--自行设置初始箭头指向,刚开始时,NormalizedPosition没有值,如果content用的自适应也没法立刻获取实际的长宽,所以需要自行设置一次
|
|
function ArrowHint:SetArrowShow(left_down, right_top)
|
|
if self.left_down_tra then
|
|
self.left_down_tra.gameObject:SetActive(left_down and true or false)
|
|
end
|
|
if self.right_top_tra then
|
|
self.right_top_tra.gameObject:SetActive(right_top and true or false)
|
|
end
|
|
end
|