Hi.
I created a little bit of code to change the mouse cursor when hovering over a button. It sends message to actionscript class, that does the actual change. I named my NGUI-class as "UIBUttonFlashCursor":
using UnityEngine;
/// <summary>
/// Changes mouse cursor in Flash
/// </summary>
[AddComponentMenu("NGUI/Interaction/Button Flash Cursor")]
public class UIButtonFlashCursor : MonoBehaviour
{
bool mStarted = false;
bool mHighlighted = false;
void Start () { mStarted = true; }
void OnEnable () { if (mStarted && mHighlighted) OnHover(UICamera.IsHighlighted(gameObject)); }
void OnHover (bool isOver)
{
if (enabled)
{
if(isOver)
{
FlashProxy.showCursor("button");
}
else
{
FlashProxy.showCursor("arrow");
}
mHighlighted = isOver;
}
}
}
As you can see, it calls a method
showCursor from static class
FlashProxyHere's the AS-version (FlashProxy.as):
package
{
import flash.ui.Mouse;
import flash.ui.MouseCursor;
public class FlashProxy
{
public static function showCursor(type:String):void
{
Mouse.cursor = type;
}
}
}
And the corresponding JS-version, which is only to make things work smoothly in editor (FlashProxy.js):
#pragma strict
@NotConverted
@NotRenamed
public class FlashProxy
{
@NotRenamed
public static function showCursor(type:String):void
{
}
}
As usual, the .as version goes to "ActionScript" -folder in your assets, but this time also the js-version has to be placed differently, so that it compiles before NGUI. I placed it inside Plugins.
Now when you want to have this cursor change in your button, just drag the "UIBUttonFlashCursor.cs" into it.
Sometimes the cursor will stay as "hand", if the button click removes to button underneath mouse or something like that. I wonder would it be possible to trap that event inside NGUI and change the cursor to arrow? Or even better, is there a simple way to integrate this functionality somewhere inside UIRoot or similar? That when ever mouse hovers on NGUI-element, it changes to hand? Now I just call
FlashProxy.showCursor("arrow") in the code whenever I know this kind of "bug" is coming up.