Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Client Side Script:
- public class BuildData
- {
- public string hull;
- public List<string> mods;
- public int buildTime;
- public BuildData(string h, List<string> m, int time)
- {
- hull = h;
- m = mods;
- buildTime = time;
- }
- }
- "hull" is the base of the ship, an object that contains the Catalog Inventory Item from PlayFab, I pull the "ItemId" value from it
- "time" is the total time in minutes that it takes to build a ship
- "clear" is true/false if we are going to remove keys instead of add them in User Title Data
- "mods" are the modifications the player has chosen to put on the ship (also Catalog items that I pull the ItemId from)
- "keys" is what is set if the "clear" value is true
- public void saveBuildData(dataMod hull, int time, bool clear = false)
- {
- Debug.Log("saveBuildData");
- List<string> keys = new List<string>();
- List<string> mods = new List<string>();
- time *= 60;
- if (!PlayFabClientAPI.IsClientLoggedIn())
- {
- return;
- }
- foreach (modSlot slot in ConstructionController.Instance.armorSlots)
- {
- mods.Add(slot.mod.ItemId);
- }
- foreach (modSlot slot in ConstructionController.Instance.weaponSlots)
- {
- mods.Add(slot.mod.ItemId);
- }
- BuildData bD = new BuildData(hull.ItemId, mods, time);
- Debug.Log(bD.hull);
- if (clear)
- keys.Add("ShipyardBuildData");
- ExecuteCloudScriptRequest req = new ExecuteCloudScriptRequest()
- {
- FunctionName = "saveBuildData",
- FunctionParameter = new
- {
- data = bD,
- keys = keys
- }
- };
- PlayFabClientAPI.ExecuteCloudScript(req, (result)=>
- {
- Debug.Log(result.FunctionResult);
- //setDateTime(result);
- //ConstructionController.Instance.buildActive = true;
- //ConstructionController.Instance.CancelInvoke("updateBuildTime");
- //ConstructionController.Instance.InvokeRepeating("updateBuildTime", 0f, 1f);
- //FeedbackCtrl.Instance.SetFeedback("Ship construction started.");
- //ConstructionController.Instance.timerFrame.transform.GetChild(1).gameObject.SetActive(false);
- }, (error) =>
- {
- Debug.Log("saveBuildData: Error");
- });
- }
- CloudScript:
- handlers.saveBuildData = function (args) {
- var data = args.data;
- var date = new Date();
- var buildTime = new Date(date.GetTime() + data.buildTime * 1000);
- data.buildTime = buildTime;
- var theData = {};
- theData["ShipyardBuildData"] = data;
- server.UpdateUserData({
- "PlayFabId": currentPlayerId,
- "KeysToRemove": keys,
- "Data": theData
- });
- return {
- data: data,
- date: date
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement