using UnityEngine; using System.Collections; public class CodeColaHelper : MonoBehaviour { public static CodeColaHelper Instance; const int MAX_CODE_LENGTH = 9; private string _fbUid; private int _Count; //private LifesManager _LM; private GameObject _EnterCode; public UIAtlas _atlas; public string _spriteName; public GameObject _scrollRoot; public UIFont _font; // Use this for initialization void Start () { if (Instance == null) { Instance = this; } //_fbUid = FaceBookRequester.instance.userID; //_LM = this.gameObject.GetComponent(); _EnterCode = GameObject.Find("EnterCode"); } private void AddAnswerWindow(string Result) { // ---- CREATE SPRITE var go = NGUITools.AddSprite(_scrollRoot, _atlas, _spriteName); //go.MakePixelPerfect(); go.gameObject.AddComponent(); go.gameObject.AddComponent(); go.gameObject.GetComponent().size = new Vector3(450, 450, 0); go.type = UISprite.Type.Simple; go.width = 450; go.height = 450; // ---- ADD ANSWER TO SPRITE var place = NGUITools.AddChild(go.gameObject); place.name = "Answer"; place.pivot = UIWidget.Pivot.Left; place.font = _font; if (Result == null) { place.text = "Good Job!\n You got 2 lifes.\n Tap to close."; } else { place.text = Result; } place.depth = 80; place.transform.localPosition = new Vector3(-152, -14, -1); place.transform.localScale = new Vector3(1.04F, 1, 1); go.gameObject.AddComponent(); } public void StartCheckCode(string Code) { _fbUid = "fb_id_test"; //develop if (Code.Length == MAX_CODE_LENGTH) { StartCoroutine(CheckCode(_fbUid, Code)); } else { AddAnswerWindow("Wrong length!\nTap to close."); } } private IEnumerator CheckCode(string fbUid, string Code) { var form = new WWWForm(); form.AddField("CheckCode", 1); form.AddField("fb_uid", fbUid); form.AddField("code", Code); var download = new WWW("http://game.gamatic.com/NewSantaRunner/RequestCheck.php", form); yield return download; //Debug.Log("CHECK CODE = " + download.text); if (download.text == "1") { LifeManager.BottleCap(); AddAnswerWindow(null); // result of check code in DB } else { AddAnswerWindow(download.text); } yield break; } public void GetCountCodes() { StartCoroutine(GetCount()); } private IEnumerator GetCount() { var form = new WWWForm(); form.AddField("GetCountCodes", 1); form.AddField("fb_uid", _fbUid); var download = new WWW("http://game.gamatic.com/NewSantaRunner/RequestCheck.php", form); yield return download; //Debug.Log("COUNT CODES = " + download.text); int.TryParse(download.text, out _Count); yield break; } public int GetCountCodesUser() { return _Count; } }