隐式游标显示游标
Hi,
你好
During the last ninja camp Shawn and I worked on getting hardware cursors into Unity, and now in Unity 4.0 they are ready. Built in support for cursors in Unity has been a heavily requested feature, and we are happy to see it in a state ready for you to use.
在上一个忍者训练营中,Shawn和我致力于使硬件游标进入Unity,现在在Unity 4.0中,它们已经准备就绪。 强烈要求在Unity中内置对光标的支持,我们很高兴看到它处于可以使用的状态。
The cursor API is very simple and allows you to configure a default cursor for your project as well as change the cursor on demand. When setting a cursor you can specify if you want the cursor to be a hardware cursor or a software cursor. If you use a hardware cursor then rendering will be handled by the OS, otherwise Unity will render the cursor for you after everything else in the scene has been rendered.
游标API非常简单,它允许您为项目配置默认游标以及按需更改游标。 设置游标时,您可以指定是将其作为硬件游标还是软件游标。 如果您使用硬件光标,则渲染将由操作系统处理,否则在场景中的所有其他内容都渲染完毕后,Unity将为您渲染光标。
So why would I want to use hardware cursors? Hardware cursors are cursors managed by the operating system. They are framerate independent and work in the same way that operating system cursors work. This means that if your game is running slowly mouse input will still feel nice and not be laggy. This helps with the user experience.
那么,为什么要使用硬件游标? 硬件游标是由操作系统管理的游标。 它们独立于帧速率,并且以与操作系统游标相同的方式工作。 这意味着,如果您的游戏运行缓慢,则鼠标输入仍然会感觉不错并且不会显得迟钝。 这有助于用户体验。
Why would I ever use a software cursor over a hardware cursor? On some platforms hardware cursors have limitations, for example on Windows the cursor is limited to a version specific resolution (32×32). In situations where you want a larger cursor you may be required to use a software cursor.
为什么在硬件游标上使用软件游标? 在某些平台上,硬件游标有限制,例如,在Windows上,游标限于特定于版本的分辨率(32×32)。 在需要较大光标的情况下,可能需要使用软件光标。
How do I configure cursors? In the project settings for your project you will notice that there are some new options for cursors:
如何配置游标? 在项目的项目设置中,您会注意到游标有一些新选项:
By setting the ‘Default Cursor’ and the ‘Cursor Hotspot’ (click position in pixels from the top left of image) you can configure the default cursor for your application. The default cursor will replace the standard operating system arrow that is normally used.
通过设置“默认光标”和“光标热点”(单击图像左上角的位置,以像素为单位),可以为应用程序配置默认光标。 默认光标将替换通常使用的标准操作系统箭头。
The API to change cursor at runtime is quite simple: static void SetCursor (Texture2D texture, CursorMode cursorMode); static void SetCursor (Texture2D texture, Vector2 hotspot, CursorMode cursorMode);
在运行时更改光标的API非常简单:静态void SetCursor(Texture2D纹理,CursorMode cursorMode); 静态void SetCursor(Texture2D纹理,Vector2热点,CursorMode cursorMode);
Where CursorMode is either Auto or ForceSoftware. When using Auto hardware cursors will be used if supported on the platform (with the texture being resized if required). ForceSoftware does as the name indicates. It is safe to mix hardware and software cursors.
其中CursorMode为Auto或ForceSoftware。 使用自动硬件时,如果平台支持,将使用游标(如果需要,可以调整纹理的大小)。 顾名思义,ForceSoftware会这样做。 混合使用硬件和软件游标是安全的。
Example:
例:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// mouse over cursor
var cursorTexture : Texture2D;
// cursor mode to use
var cursorMode : CursorMode = CursorMode.Auto;
// cursor hotspot (pixels from top left of image)
var hotSpot : Vector2 = Vector2.zero;
function OnMouseEnter () {
// when we mouse over this object, set the cursor
Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
}
function OnMouseExit () {
// when we mouse off this object restore the default cursor (passing null)
Cursor.SetCursor(null, Vector2.zero, cursorMode);
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// mouse over cursor
var cursorTexture : Texture2D ;
// cursor mode to use
var cursorMode : CursorMode = CursorMode . Auto ;
// cursor hotspot (pixels from top left of image)
var hotSpot : Vector2 = Vector2 . zero ;
function OnMouseEnter ( ) {
// when we mouse over this object, set the cursor
Cursor . SetCursor ( cursorTexture , hotSpot , cursorMode ) ;
}
function OnMouseExit ( ) {
// when we mouse off this object restore the default cursor (passing null)
Cursor . SetCursor ( null , Vector2 . zero , cursorMode ) ;
}
|
隐式游标显示游标