1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using UnityEngine;
- using System.Collections;
- public class CreastmasTree : MonoBehaviour
- {
- public float Max = 100000;
- public UISprite Current;
- public UILabel Label;
- public UITexture CurrentStar;
- public UITexture WhiteStar;
- // Use this for initialization
- void Start () {
-
- }
-
- // Update is called once per frame
- void OnEnable () {
- ServerGiftManager.Instance.RequestTreeUpdate(meals =>
- {
- if (meals == -1)
- {
- Debug.Log("Error");
- //todo: server error, or wrong number filled
- }
- else
- {
- var s = meals.ToString().ToCharArray();
- Debug.Log(s.Length);
- string curFormat = "";
-
- for (int i = 0; i < s.Length; i++)
- {
- if (s.Length == 4)
- {
- if (i == 0)
- {
- curFormat = curFormat + s[i] + " ";
- }
- else
- {
- curFormat = curFormat + s[i];
- }
- }
- else if (s.Length == 5)
- {
- if (i == 1)
- {
- curFormat = curFormat + s[i] + " ";
- }
- else
- {
- curFormat = curFormat + s[i];
- }
- }
- else
- {
- if (i == 2)
- {
- curFormat = curFormat + s[i] + " ";
- }
- else
- {
- curFormat = curFormat + s[i];
- }
- }
-
- }
-
- Label.text = string.Format("Just nu har vi tillsammans donerat {0} måltider", curFormat);
- Current.fillAmount = (1 / Max) * (Max - meals);
- Debug.Log(meals + Current.fillAmount);
- //todo: handle meals amount (everything goes good)
- if (meals == Max)
- {
- CurrentStar.gameObject.SetActive(false);
- WhiteStar.gameObject.SetActive(true);
- }
- }
- });
- }
- }
|