我有一个问题,我想获取当前光标,并将其作为Unity中的texture2D获取。
当我说当前光标时,我的意思是用户当前拥有的光标。例如,如果用户将光标更改为猫,我希望在 Unity 中拥有相同的猫光标。这就是为什么我不只是在线搜索默认光标的原因。
我试图在谷歌中搜索这个,但我得到的只是this,它是在 2009 年发布的,代码不起作用(如果你想知道的话,它会说“Handle does notpresent a ICON”)。
我想到的步骤是:
- 检查 Windows 中哪个光标处于活动状态
- 在 Unity 中将该图像读取为纹理
- 将纹理应用到光标
我看到的问题是这会随着操作系统的不同而改变,所以你很难让它与所有操作系统兼容。
我无法读取当前活动光标,因此我的答案不完整。也许有人能够完成缺失的事情:
//This is the part I am not sure how to complete
//String currentCursor =
//Here is where Windows store the cursors, you need to point to the one the
//user is using
String path = "C:\Windows\Cursors"+currentCursor;
//Here you load that image as a texture
Texture2D cursorTexture = new Texture2D(16, 16);
cursorTexture.LoadImage(File.ReadAllBytes(path));
public CursorMode cursorMode = CursorMode.Auto;
public Vector2 hotSpot = Vector2.zero;
//You apply the texture to the cursor in Unity
void Start()
{
Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
}
也许你可以找到here如何使用与此类似的东西执行第一步,但我不知道
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)