Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SmartButton for Unity3D
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
You can’t perform that action at this time.