Posted By

abrady0 on 09/03/13


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

danfinrud55


GameStateManager.cs


 / Published in: C#
 

missing fb sdk code

  1. using System.Collections.Generic;
  2. using UnityEngine;
  3.  
  4. public class GameStateManager : MonoBehaviour
  5. {
  6. private static GameStateManager instance;
  7.  
  8. public static bool ScoringLockout = true;
  9.  
  10. public static int StartingLives = 3, StartingScore = 0;
  11. private int lives, score;
  12.  
  13. private string username = null;
  14. public static Texture UserTexture;
  15. public static Texture FriendTexture = null;
  16. private string friendName = null;
  17. private string friendID = null;
  18.  
  19. public static bool IsFullscreen = false;
  20.  
  21. public bool Immortal;
  22. private static bool immortal;
  23.  
  24. public static int ToSmash = -1;
  25.  
  26. public static string FriendID
  27. {
  28. set { Instance.friendID = value; }
  29. get { return Instance.friendID; }
  30. }
  31.  
  32. public static string FriendName
  33. {
  34. set { Instance.friendName = value; }
  35. get { return Instance.friendName == null ? "Blue Guy" : Instance.friendName; }
  36. }
  37.  
  38. public static Dictionary<string, Player> leaderboard;
  39.  
  40. void Start()
  41. {
  42. lives = StartingLives;
  43. score = StartingScore;
  44. immortal = Instance.Immortal;
  45. ScoringLockout = false;
  46. Time.timeScale = 1.0f;
  47. }
  48.  
  49. public void StartGame()
  50. {
  51. Start();
  52. }
  53.  
  54. void Awake()
  55. {
  56. DontDestroyOnLoad(this);
  57. }
  58.  
  59. public static GameStateManager Instance { get { return current(); } }
  60. public static int Score { get { return Instance.score; } }
  61. public static int LivesRemaining { get { return Instance.lives; } }
  62. public static string Username
  63. {
  64. get { return Instance.username == null ? "Friend" : Instance.username; }
  65. set { Instance.username = value; }
  66. }
  67. delegate GameStateManager InstanceStep();
  68.  
  69. static InstanceStep init = delegate()
  70. {
  71. GameObject container = new GameObject("GameStateManagerManager");
  72. instance = container.AddComponent<GameStateManager>();
  73. instance.lives = StartingLives;
  74. instance.score = StartingScore;
  75. current = then;
  76. return instance;
  77. };
  78. static InstanceStep then = delegate() { return instance; };
  79. static InstanceStep current = init;
  80.  
  81. public static void onFriendDie()
  82. {
  83. if (--Instance.lives == 0)
  84. {
  85. EndGame();
  86. }
  87. }
  88.  
  89. public static void onFriendSmash()
  90. {
  91. if (!ScoringLockout) ++Instance.score;
  92. }
  93.  
  94. public static void onEnemySmash(GameObject enemy)
  95. {
  96. // Instance.fatalEnemy = enemy;
  97. enemy.AddComponent<EnemyExploder>();
  98. }
  99.  
  100. public static void EndGame()
  101. {
  102. if (immortal) return;
  103. GameObject[] friends = GameObject.FindGameObjectsWithTag("Friend");
  104. GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
  105. foreach (GameObject t in friends)
  106. {
  107. Destroy(t);
  108. }
  109. foreach (GameObject t in enemies)
  110. {
  111. Destroy(t);
  112. }
  113. var query = new Dictionary<string, string>();
  114. query["score"] = Instance.score.ToString();
  115.  
  116. // xxxxx scores
  117. FB.API("/me/scores", Facebook.HttpMethod.POST, delegate(string r) { ; }, query);
  118.  
  119. Application.LoadLevel("MainMenu");
  120. Time.timeScale = 0.0f;
  121. }
  122. }

Report this snippet  

You need to login to post a comment.