CreastmasTree.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using UnityEngine;
  2. using System.Collections;
  3. public class CreastmasTree : MonoBehaviour
  4. {
  5. public float Max = 100000;
  6. public UISprite Current;
  7. public UILabel Label;
  8. public UITexture CurrentStar;
  9. public UITexture WhiteStar;
  10. // Use this for initialization
  11. void Start () {
  12. }
  13. // Update is called once per frame
  14. void OnEnable () {
  15. ServerGiftManager.Instance.RequestTreeUpdate(meals =>
  16. {
  17. if (meals == -1)
  18. {
  19. Debug.Log("Error");
  20. //todo: server error, or wrong number filled
  21. }
  22. else
  23. {
  24. var s = meals.ToString().ToCharArray();
  25. Debug.Log(s.Length);
  26. string curFormat = "";
  27. for (int i = 0; i < s.Length; i++)
  28. {
  29. if (s.Length == 4)
  30. {
  31. if (i == 0)
  32. {
  33. curFormat = curFormat + s[i] + " ";
  34. }
  35. else
  36. {
  37. curFormat = curFormat + s[i];
  38. }
  39. }
  40. else if (s.Length == 5)
  41. {
  42. if (i == 1)
  43. {
  44. curFormat = curFormat + s[i] + " ";
  45. }
  46. else
  47. {
  48. curFormat = curFormat + s[i];
  49. }
  50. }
  51. else
  52. {
  53. if (i == 2)
  54. {
  55. curFormat = curFormat + s[i] + " ";
  56. }
  57. else
  58. {
  59. curFormat = curFormat + s[i];
  60. }
  61. }
  62. }
  63. Label.text = string.Format("Just nu har vi tillsammans donerat {0} måltider", curFormat);
  64. Current.fillAmount = (1 / Max) * (Max - meals);
  65. Debug.Log(meals + Current.fillAmount);
  66. //todo: handle meals amount (everything goes good)
  67. if (meals == Max)
  68. {
  69. CurrentStar.gameObject.SetActive(false);
  70. WhiteStar.gameObject.SetActive(true);
  71. }
  72. }
  73. });
  74. }
  75. }