GameObjectSurrogate.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using SimpleJSON;
  5. namespace Newgrounds {
  6. public class GameObjectSurrogate:MonoBehaviour {
  7. // A script to serve as a GameObject surrogate/proxy
  8. // ================================================================================================================
  9. // PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
  10. void Awake() {
  11. // Actual initialization
  12. // Instructs the game object to survive level changes
  13. DontDestroyOnLoad(this);
  14. }
  15. public void doPost(WWW __wwww, Action __doneCallback) {
  16. StartCoroutine(doPostWithYield(__wwww, __doneCallback));
  17. }
  18. public void setContainerURL(string __url) {
  19. // Receives the current URL with user data and passes everything to the static class
  20. // This is a private method, but JavaScript don't care; it is still called by SendMessage()
  21. API.setContainerURLStatic(__url);
  22. }
  23. // ================================================================================================================
  24. // INTERNAL INTERFACE ---------------------------------------------------------------------------------------------
  25. private IEnumerator doPostWithYield(WWW _www, Action __doneCallback) {
  26. yield return _www;
  27. Debug.Log("Service sent; response: " + _www.text);
  28. //JSONNode medals = JSON.Parse(_w.text);
  29. //Debug.Log("There are " + medals["medals"].Count + " medals loaded");
  30. //Debug.Log("The name of the first medal is: [" + medals["medals"][0]["medal_name"] + "]");
  31. if (__doneCallback != null) __doneCallback();
  32. }
  33. }
  34. }