123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- ---@class CursorMgr
- ---@field LeftMouseDown function
- ---@field LeftMouseUp function
- ---@field LeftMouseHold function
- ---@field RightMouseDown function
- ---@field RightMouseUp function
- ---@field RightMouseHold function
- ---@field PointIn function
- ---@field PointExit function
- CursorMgr = class()
- local this = CursorMgr
- this. mSetCursor = CS.TCFramework.CursorUtil
- ---this. sceneTouch = SceneTouch
- this. PointIn = false
- this. interval = 5
- this. time = 0
- this.CursorChanged = false
- ---@type Vector2
- this.cursorOffset = nil
- this.CursorIcon = {
- Normal = { atlas = "", src = "Cursor/Cursor_Normal.png" },
- Select = { atlas = "", src = "Cursor/Cursor_Select.png" },
- Catch = { atlas = "", src = "Cursor/Cursor_Catch.png" }
- }
- function this.SetCursor(tex, offset)
- this.mSetCursor.SetCursor(tex, offset)
- end
- function this.SetSprite(atlasName, iconName)
- ---@type UnityEngine.Texture2D
- local t = SL:LoadAsset(iconName, typeof(CS.UnityEngine.Texture2D)).res
- if not this.cursorOffset then
- this.cursorOffset = Vector2(t.width / 4, t.height / 4)
- end
- this.SetCursor(t, this.cursorOffset)
- end
- function this.OnGoing()
- this.time = this.time + 1
- if this.time < this.interval then
- return
- end
- this.PointIn = false
- this.time = 0
- local hitX, hitY, hitZ = CSPreScene.LinearCastGround(SL.MainCamera:GetCamera()) --MainCamera.camera)
- local coord = Scene.WorldToTile(hitX, hitY, hitZ)
- ---@param cell Cell
- local cell = CellManager.GetCell(coord.x, coord.z)
- if cell then
- if cell.ids and table.count(cell.ids) >= 1 and DebugFlag.LogEnable then
- local id = table.getKey(cell.ids, 1)
- local item = DropItemManager.GetItem(id)
- if item and DebugFlag.LogEnable then
- this.SetSprite(this.CursorIcon.Catch.atlas, this.CursorIcon.Catch.src)
- this.PointIn = true
- this.CursorChanged = true
- logError("鼠标光标:悬浮状态" .. "#" .. this.CursorIcon.Catch.atlas .. "#" .. this.CursorIcon.Catch.src)
- end
- end
- end
- end
- function this.SetDefault()
- this.SetSprite(this.CursorIcon.Normal.atlas, this.CursorIcon.Normal.src)
- this.CursorChanged = false
- end
- function this.Init()
- this.LeftMouseDown = function()
- this.SetSprite(this.CursorIcon.Select.atlas, this.CursorIcon.Select.src)
- this.CursorChanged = true
- end
- this.LeftMouseHold = function()
- this.SetSprite(this.CursorIcon.Select.atlas, this.CursorIcon.Select.src)
- this.CursorChanged = true
- end
- this.SetDefault()
- end
- function this.Update()
- if Misc.IsOnUI() or (not SL:GetIsInGame()) then
- return
- end
- if (Input.GetMouseButtonDown(0) and this.LeftMouseDown) then
- this.LeftMouseDown()
- elseif (Input.GetMouseButtonUp(0) and this.LeftMouseUp) then
- this.LeftMouseUp()
- elseif (Input.GetMouseButton(0) and this.LeftMouseHold) then
- this.LeftMouseHold()
- elseif (Input.GetMouseButtonDown(1) and this.RightMouseDown) then
- this. RightMouseDown()
- elseif (Input.GetMouseButtonUp(1) and this.RightMouseUp) then
- this. RightMouseUp()
- elseif (Input.GetMouseButton(1) and this.RightMouseHold) then
- this.RightMouseHold()
- else
- this.OnGoing()
- if not this.PointIn and this.CursorChanged then
- this.SetDefault()
- end
- end
- end
|