//----------------------------------------------
// Custom Cursor: Customize cursor based on NGUI objects
// Writted by: Joreldraw
//----------------------------------------------
// Use: Add to your main or simple attach to a Empty child.
using UnityEngine;
using System.Collections;
public class CustomCursor : MonoBehaviour {
private Texture2D cursorImage;
public Texture2D PointerCursor;
public Texture2D ClickCursor;
public Texture2D ClickedCursor;
public Texture2D TextCursor;
public Texture2D MoveCursor;
public Texture2D MovingCursor;
public Texture2D RotateCursor;
private GameObject Seleccion;
private bool Dragging = false;
void Start()
{
if (Application.platform != RuntimePlatform.Android && Application.platform != RuntimePlatform.IPhonePlayer)
{
Screen.showCursor = false;
cursorImage = PointerCursor;
}
}
void OnGUI()
{
if (Application.platform != RuntimePlatform.Android && Application.platform != RuntimePlatform.IPhonePlayer)
{
Seleccion = null;
Vector3 mousePos = Input.mousePosition;
Rect pos
= new Rect
(mousePos
.x,Screen
.height - mousePos
.y,cursorImage
.width,cursorImage
.height);
if (UICamera.hoveredObject)
{
Seleccion = UICamera.hoveredObject.transform.gameObject ;
}
else Seleccion = null;
if (Seleccion)
{
if (TextCursor)
{
UIInput NguiInput = Seleccion.GetComponentInChildren<UIInput>();
if (NguiInput) cursorImage = TextCursor;
}
if (ClickCursor)
{
UIButtonColor NguiButton = Seleccion.GetComponent<UIButtonColor>();
UIButtonSound NguiSound = Seleccion.GetComponent<UIButtonSound>();
MeshRenderer Rigido = Seleccion.GetComponent<MeshRenderer>();
if (NguiButton || NguiSound || Rigido)
{
cursorImage = ClickCursor;
if(Input.GetMouseButton(0) && ClickedCursor){ cursorImage = ClickedCursor;}
}
}
if (RotateCursor)
{
Rotando RotarScript = Seleccion.GetComponent<Rotando>();
if (RotarScript) cursorImage = RotateCursor;
}
if (MoveCursor)
{
UIDragObject NguiDragable = Seleccion.GetComponent<UIDragObject>();
if (NguiDragable && !Dragging) cursorImage = MoveCursor;
else if (NguiDragable && Dragging ) {cursorImage = MovingCursor;}
}
}
GUI.Label(pos,cursorImage);
}
}
void Update()
{
if (Application.platform != RuntimePlatform.Android && Application.platform != RuntimePlatform.IPhonePlayer)
{
Vector2 mouseFlatPos
= new Vector2
(Input
.mousePosition.x,Input
.mousePosition.y); if (mouseFlatPos != UICamera.lastTouchPosition && cursorImage != PointerCursor) cursorImage = PointerCursor;
if (!Dragging)
{
if(Input.GetMouseButtonDown(0)) { Dragging = true;}
}
if (Dragging)
{
if(Input.GetMouseButtonUp(0)){ Dragging = false;}
}
}
}
}