Created
May 9, 2014 01:24
-
-
Save nicolasmbatista/46199f91819e3751da4e to your computer and use it in GitHub Desktop.
SmartButton for Unity3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class SmartButton : MonoBehaviour { | |
public enum Usage { | |
Default, | |
URL, | |
SceneLoader, | |
PanelSwitcher, | |
IAPPurchase, | |
Exit, | |
CoroutineTrigger | |
} | |
public Usage UseAs; | |
public string Value; | |
public MonoBehaviour ComponentToUse; | |
public GameObject GoToPanel; | |
public GameObject OurParentPanel; | |
public static System.Action<SmartButton> OnSmartButtonClickEvent; | |
void Start () { | |
if(gameObject.collider == null && gameObject.collider2D == null) | |
{ | |
Debug.LogWarning("Warning! Smart button might not work without a collider or collider2D attached to the GameObject"); | |
} | |
} | |
void OnMouseDown() | |
{ | |
//For those NGUI Users ;) | |
OnClick(); | |
} | |
public virtual void OnClick() | |
{ | |
switch (UseAs) | |
{ | |
case Usage.Default: | |
if(OnSmartButtonClickEvent != null) | |
OnSmartButtonClickEvent(this); | |
break; | |
case Usage.URL: | |
Application.OpenURL(Value); | |
break; | |
case Usage.SceneLoader: | |
Application.LoadLevel(Value); | |
break; | |
case Usage.PanelSwitcher: | |
OurParentPanel.SetActive(false); | |
if(GoToPanel != null) | |
GoToPanel.SetActive(true); | |
break; | |
case Usage.IAPPurchase: | |
IAPManager.Buy(value); | |
break; | |
case Usage.Exit: | |
Application.Quit(); | |
break; | |
case Usage.CoroutineTrigger: | |
ComponentToUse.StartCoroutine(Value); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment