Unity 动态更改鼠标样式
生活随笔
收集整理的這篇文章主要介紹了
Unity 动态更改鼠标样式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
方法參考博客:https://gameinstitute.qq.com/community/detail/118295
using System.Runtime.InteropServices;public class CursorTools {[DllImport("User32.DLL")]public static extern IntPtr LoadCursorFromFile(string fileName);[DllImport("User32.DLL")]public static extern bool SetSystemCursor(IntPtr hcur, uint id);public const uint OCR_NORMAL = 32512;[DllImport("User32.DLL")]public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);public const uint SPI_SETCURSORS = 87;public const uint SPIF_SENDWININICHANGE = 2;/// <summary>/// 把準備好的.cur指針資源放在StreamingAssets/Cursors下,記得創建好這個文件夾/// </summary>private static string CursorPath(string fileName){return Path.Combine(Application.streamingAssetsPath, "Cursors", fileName) + ".cur";}/// <summary>/// 恢復Windows正常鼠標指針/// </summary>public static void Reset2NormalCursor(){SystemParametersInfo(SPI_SETCURSORS, 0, IntPtr.Zero, SPIF_SENDWININICHANGE);}/// <summary>/// 設置拖拽移動樣式的指針/// </summary>public static void SetDragCursor(){IntPtr hcur_drag = LoadCursorFromFile(CursorPath("aero_move"));SetSystemCursor(hcur_drag, OCR_NORMAL);} }以拖拽功能為例,想拖拽的時候調用:
CursorTools.SetDragCursor();用完記得把指針變回來:
CursorTools.Reset2NormalCursor();C:\Windows\Cursors文件夾下面有很多Windows默認鼠標資源。
總結
以上是生活随笔為你收集整理的Unity 动态更改鼠标样式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 豆瓣评分预测(如何用自己的数据集进行文本
- 下一篇: HP 5100打印机在Windows 8