【装备合成】添加长按自动增加数量功能
parent
00dc90f4bb
commit
613380a99f
|
@ -0,0 +1,110 @@
|
||||||
|
local LongPressEvent = {}
|
||||||
|
|
||||||
|
function LongPressEvent:ctor(go)
|
||||||
|
self.go = go
|
||||||
|
self.isTriggerPoint = false
|
||||||
|
self.triggerTime = 0
|
||||||
|
self.triggerBeatTime = 0
|
||||||
|
self.isInvoke = false
|
||||||
|
|
||||||
|
self.trigger = Util.GetEventTriggerListener(self.go.gameObject)
|
||||||
|
self.trigger.onPointerDown = self.trigger.onPointerDown + function()
|
||||||
|
self:onPointerDown()
|
||||||
|
end
|
||||||
|
self.trigger.onPointerUp = self.trigger.onPointerUp + function()
|
||||||
|
self:onPointerUp()
|
||||||
|
end
|
||||||
|
self.trigger.onPointerExit = self.trigger.onPointerExit + function()
|
||||||
|
self:onPointerUp()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LongPressEvent:SetPressStartFunc(func)
|
||||||
|
self.onPressStart = func
|
||||||
|
end
|
||||||
|
function LongPressEvent:SetPressEndFunc(func)
|
||||||
|
self.onPressEnd = func
|
||||||
|
end
|
||||||
|
function LongPressEvent:SetPressTime(pressTime)
|
||||||
|
self.pressTime = pressTime
|
||||||
|
end
|
||||||
|
function LongPressEvent:SetPressBeatFunc(func)
|
||||||
|
self.onPressBeat = func
|
||||||
|
end
|
||||||
|
function LongPressEvent:SetPressBeatTime(beatTime)
|
||||||
|
self.beatTime = beatTime
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function LongPressEvent:onPointerDown()
|
||||||
|
self.isTriggerPoint = true
|
||||||
|
self.triggerTime = Time.time
|
||||||
|
end
|
||||||
|
function LongPressEvent:onPointerUp()
|
||||||
|
self.isTriggerPoint = false
|
||||||
|
-- 触发过开始就触发结束
|
||||||
|
if self.isInvoke then
|
||||||
|
if self.onPressEnd then
|
||||||
|
self.onPressEnd()
|
||||||
|
end
|
||||||
|
self.isInvoke = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LongPressEvent:Update()
|
||||||
|
|
||||||
|
if self.isTriggerPoint then
|
||||||
|
-- 没触发过start
|
||||||
|
if not self.isInvoke then
|
||||||
|
-- 触发开始事件
|
||||||
|
if self.pressTime and Time.time - self.triggerTime > self.pressTime then
|
||||||
|
if self.onPressStart then
|
||||||
|
self.onPressStart()
|
||||||
|
end
|
||||||
|
self.isInvoke = true
|
||||||
|
--
|
||||||
|
self.triggerBeatTime = 0
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- 长按连续触发事件
|
||||||
|
if self.beatTime and Time.time - self.triggerBeatTime > self.beatTime then
|
||||||
|
if self.onPressBeat then
|
||||||
|
self.onPressBeat()
|
||||||
|
end
|
||||||
|
self.triggerBeatTime = Time.time
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LongPressEvent:Destroy()
|
||||||
|
-- 清除原来的事件
|
||||||
|
if self.trigger then
|
||||||
|
self.trigger:Destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LongPressManager = {}
|
||||||
|
local list = {}
|
||||||
|
local function update()
|
||||||
|
for go, o in pairs(list) do
|
||||||
|
o:Update()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
UpdateBeat:Add(update, LongPressManager)
|
||||||
|
|
||||||
|
|
||||||
|
function LongPressManager.New(go)
|
||||||
|
if list[go] then
|
||||||
|
list[go]:Destroy()
|
||||||
|
list[go] = nil
|
||||||
|
end
|
||||||
|
local o = {}
|
||||||
|
setmetatable(o, {__index = LongPressEvent})
|
||||||
|
o:ctor(go)
|
||||||
|
list[go] = o
|
||||||
|
return o
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a652b12a5b40f5489e86134fa4e9e29
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -69,6 +69,21 @@ function this:BindEvent()
|
||||||
Util.AddClick(this.subtractBtn, function()
|
Util.AddClick(this.subtractBtn, function()
|
||||||
this.CompoundNumChange(2)
|
this.CompoundNumChange(2)
|
||||||
end)
|
end)
|
||||||
|
-- 长按加
|
||||||
|
require("Common.LongPressManager")
|
||||||
|
local lp = LongPressManager.New(this.addBtn)
|
||||||
|
lp:SetPressTime(1)
|
||||||
|
lp:SetPressBeatFunc(function()
|
||||||
|
this.CompoundNumChange(1)
|
||||||
|
end)
|
||||||
|
lp:SetPressBeatTime(0.1)
|
||||||
|
-- 长按减
|
||||||
|
local lp = LongPressManager.New(this.subtractBtn)
|
||||||
|
lp:SetPressTime(1)
|
||||||
|
lp:SetPressBeatFunc(function()
|
||||||
|
this.CompoundNumChange(2)
|
||||||
|
end)
|
||||||
|
lp:SetPressBeatTime(0.1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function this:AddListener()
|
function this:AddListener()
|
||||||
|
@ -281,9 +296,16 @@ function this.SingleItemDataShow(_go,_itemData,curEquipStarsConfig)
|
||||||
end
|
end
|
||||||
--加减方法
|
--加减方法
|
||||||
function this.CompoundNumChange(type)
|
function this.CompoundNumChange(type)
|
||||||
|
|
||||||
if type == 1 then--加
|
if type == 1 then--加
|
||||||
|
if compoundNum >= compoundMaxNum then
|
||||||
|
return
|
||||||
|
end
|
||||||
compoundNum = compoundNum + 1
|
compoundNum = compoundNum + 1
|
||||||
else--减
|
else--减
|
||||||
|
if compoundNum <= 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
compoundNum = compoundNum - 1
|
compoundNum = compoundNum - 1
|
||||||
end
|
end
|
||||||
--LogError("compoundNum "..compoundNum)
|
--LogError("compoundNum "..compoundNum)
|
||||||
|
|
Loading…
Reference in New Issue