Advertisement
Guest User

CloudScript Questions

a guest
Sep 6th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. Client Side Script:
  2.  
  3. public class BuildData
  4. {
  5. public string hull;
  6. public List<string> mods;
  7. public int buildTime;
  8.  
  9. public BuildData(string h, List<string> m, int time)
  10. {
  11. hull = h;
  12. m = mods;
  13. buildTime = time;
  14. }
  15. }
  16.  
  17. "hull" is the base of the ship, an object that contains the Catalog Inventory Item from PlayFab, I pull the "ItemId" value from it
  18. "time" is the total time in minutes that it takes to build a ship
  19. "clear" is true/false if we are going to remove keys instead of add them in User Title Data
  20. "mods" are the modifications the player has chosen to put on the ship (also Catalog items that I pull the ItemId from)
  21. "keys" is what is set if the "clear" value is true
  22.  
  23. public void saveBuildData(dataMod hull, int time, bool clear = false)
  24. {
  25. Debug.Log("saveBuildData");
  26. List<string> keys = new List<string>();
  27. List<string> mods = new List<string>();
  28.  
  29. time *= 60;
  30.  
  31. if (!PlayFabClientAPI.IsClientLoggedIn())
  32. {
  33. return;
  34. }
  35.  
  36. foreach (modSlot slot in ConstructionController.Instance.armorSlots)
  37. {
  38. mods.Add(slot.mod.ItemId);
  39. }
  40.  
  41. foreach (modSlot slot in ConstructionController.Instance.weaponSlots)
  42. {
  43. mods.Add(slot.mod.ItemId);
  44. }
  45.  
  46. BuildData bD = new BuildData(hull.ItemId, mods, time);
  47.  
  48. Debug.Log(bD.hull);
  49.  
  50. if (clear)
  51. keys.Add("ShipyardBuildData");
  52.  
  53. ExecuteCloudScriptRequest req = new ExecuteCloudScriptRequest()
  54. {
  55. FunctionName = "saveBuildData",
  56. FunctionParameter = new
  57. {
  58. data = bD,
  59. keys = keys
  60. }
  61. };
  62.  
  63. PlayFabClientAPI.ExecuteCloudScript(req, (result)=>
  64. {
  65. Debug.Log(result.FunctionResult);
  66. //setDateTime(result);
  67. //ConstructionController.Instance.buildActive = true;
  68. //ConstructionController.Instance.CancelInvoke("updateBuildTime");
  69. //ConstructionController.Instance.InvokeRepeating("updateBuildTime", 0f, 1f);
  70. //FeedbackCtrl.Instance.SetFeedback("Ship construction started.");
  71. //ConstructionController.Instance.timerFrame.transform.GetChild(1).gameObject.SetActive(false);
  72.  
  73. }, (error) =>
  74. {
  75. Debug.Log("saveBuildData: Error");
  76. });
  77. }
  78.  
  79. CloudScript:
  80.  
  81. handlers.saveBuildData = function (args) {
  82. var data = args.data;
  83. var date = new Date();
  84.  
  85. var buildTime = new Date(date.GetTime() + data.buildTime * 1000);
  86.  
  87. data.buildTime = buildTime;
  88.  
  89. var theData = {};
  90.  
  91. theData["ShipyardBuildData"] = data;
  92.  
  93. server.UpdateUserData({
  94. "PlayFabId": currentPlayerId,
  95. "KeysToRemove": keys,
  96. "Data": theData
  97. });
  98.  
  99. return {
  100. data: data,
  101. date: date
  102. };
  103. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement