Files
Pal3.Unity/Assets/Scripts/Pal3.Game/UI/CursorManager.cs
Jiaqi Liu b1d9e3b0ac Bug fix + Bump Unity version + Update copyright text
- Fixed a bug caused by inconsistent state check between managed and native object.
- Bump Unity version.
- Update copyright text
2025-03-05 21:13:59 -08:00

56 lines
2.0 KiB
C#

// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2025, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Pal3.Game.UI
{
using System;
using Command;
using Command.Extensions;
using Core.Command;
using Core.Utilities;
using Data;
using Engine.Core.Abstraction;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.DualShock;
public sealed class CursorManager : IDisposable,
ICommandExecutor<ActiveInputDeviceChangedNotification>
{
private readonly ITexture2D _cursorTextureNormal;
public CursorManager(GameResourceProvider gameResourceProvider)
{
Requires.IsNotNull(gameResourceProvider, nameof(gameResourceProvider));
_cursorTextureNormal = gameResourceProvider.GetCursorTexture();
Cursor.SetCursor(_cursorTextureNormal.NativeObject as Texture2D, Vector2.zero, CursorMode.Auto);
CommandExecutorRegistry<ICommand>.Instance.Register(this);
}
public void Dispose()
{
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
Cursor.visible = true;
}
public void Execute(ActiveInputDeviceChangedNotification command)
{
if (command.Device == Gamepad.current ||
command.Device == Joystick.current ||
command.Device == Touchscreen.current ||
command.Device == DualShockGamepad.current)
{
Cursor.visible = false;
}
else if (command.Device == Mouse.current ||
command.Device == Pointer.current)
{
Cursor.visible = true;
}
}
}
}