Arzi:
That’s very interesting. I jumped on SpriteUI when it first came out, as OnGUI was making my game unplayable, and as soon as I moved to a Sprite Manager based solution, I got the responsiveness back. Now, I use OnGUI for nearly all of my NON in-game GUIs, as SpriteUI was getting too heavy on StartUp. I had over 100 individual graphic elements, many layered, that had to be sorted, and it was taking measurable full seconds to process on Awake().
If OnGUI really has been improved in 1.5 (and we don’t know about it!) then I’d like to know that “fer sher”.
My only worry about OnGUI, even if it is more performant, is draw calls. The last time I looked OnGUI would not work well with atlases, and without an atlas, doesn’t that mean lots of small graphics and multiple draw calls?
sunnykhan4u21:
Check out this forum topic:
http://forum.unity3d.com/viewtopic.php?t=22371
Setting up a fire button in SpriteUI (once you have the scripts unpacked and setup) is as simple as:
var shipController : ShipController; // Link to call a related function
private var fireButton : Sprite; // Var to assign a graphic element
function Start () {
fireButton = DefaultSpriteUI.AddButton (new Vector2 (40, 420), 60, 60, 1, 0, 120, 60, 60, this);
DefaultSpriteUI.GetSpriteButton (fireButton).mouseOverUV = DefaultSpriteUI.PixelCoordToUVCoord (0, 180);
DefaultSpriteUI.GetSpriteButton (fireButton).mouseOverUVDimensions = DefaultSpriteUI.PixelSpaceToUVSpace (60, 60);
}
function OnMouseDown (sprite : Sprite, pos : Vector2) {
if (sprite == fireButton)
shipController.Fire (); // Related function Fire ();
// Fire(); // Local function Fire ();
}
All the empty functions are in the script. You just need to set a variable, record the location on the atlas in Start(), and call a fire function either in the MyUIManager script or in an associated script with a cached link.
If you read thru the code it’s very simple:
- Set up an exposed variable to drag your ShipController script to (assuming you are having a SHIP fire. This could be playerController, or what ever is firing. You could also make a local function that controls firing, but I’d assume that organizationally this would be somewhere else.
- Set up a private variable that is of type Sprite that will contain your graphic element.
- Assign your private Sprite variable the location on the iPhone Screen, the size of the displayed button, the layer, the location on the atlas, the size from the atlas. (This is all documented both on the forum and in the script itself behind a layer of //'s)
- function OnMouseDown (and Up, Moved, Exit - etc.) is already defined in the SampleUIManager script that comes with the package.
- Add the "if (sprite == myPrivateVar) line and define what it does in code.
Done!