12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class UIButtonHandler : MonoBehaviour
- {
- public GameObject target;
- public string functionName;
- public bool includeChildren = false;
- private void Start()
- {
- GetComponent<Button>().onClick.AddListener(Send);
- }
- void Send()
- {
- var curLive = PlayerPrefs.GetInt("Live");
- if (LivesManager.Instance.Lives == 0 && gameObject.name == "ButtonRequest")
- {
- //Debug.Log("curLive " + curLive);
- if (curLive == 1)
- {
- //MediaPlayerCtrl.Instance.PlayAd();
- MenuManager._instance.CurState = MenuManager.StateAd.Life;
- #if UNITY_EDITOR
- LivesManager.Instance.RechargeLife();
- #endif
- }
- }
- if (string.IsNullOrEmpty(functionName)) return;
- if (target == null) target = gameObject;
- if (includeChildren)
- {
- Transform[] transforms = target.GetComponentsInChildren<Transform>();
- for (int i = 0, imax = transforms.Length; i < imax; ++i)
- {
- Transform t = transforms[i];
- t.gameObject.SendMessage(functionName, gameObject, SendMessageOptions.DontRequireReceiver);
- }
- }
- else
- {
- target.SendMessage(functionName, gameObject, SendMessageOptions.DontRequireReceiver);
- }
- }
- }
|