public void SaveAllAssociatedSheets() { var sheetPathsToSave = new List <string>(); sheetPathsToSave.Add(defaultCloudDataSheet.path); // find all of the associated sheets var cloudDataFields = GetAllCloudDataFields(); foreach (var pair in cloudDataFields) { var cloudDataAttr = pair.Value; if (cloudDataAttr.sheetPath != null) { sheetPathsToSave.Add(cloudDataAttr.sheetPath); } } // save each sheet sheetPathsToSave = sheetPathsToSave.Distinct().ToList(); m_NumSheetsToSave = sheetPathsToSave.Count; foreach (var path in sheetPathsToSave) { var sheet = CloudDataManager.GetSheet(path); if (sheet != null) { sheet.Save(SaveSheetFinished); } } }
// Finds all fields in current object with the CloudDataField attribute and attempts to set the value from cloud data public virtual void UpdateCloudDataFields(bool forceInsertNewValues = false) { var cloudDataFields = GetAllCloudDataFields(); foreach (var pair in cloudDataFields) { var info = pair.Key; var cloudDataAttr = pair.Value; // try to load the custom cloud data sheet specified by the attribute BaseCloudDataSheet sheet = defaultCloudDataSheet; if (cloudDataAttr.sheetPath != null) { sheet = CloudDataManager.GetSheet(cloudDataAttr.sheetPath); if (sheet == null) { Debug.LogWarning(string.Format("[CloudDataField] No CloudDataSheet with path '{0}' found for {1}.{2}", cloudDataAttr.sheetPath, this.GetType().FullName, info.Name)); } } // make sure a sheet was found if (sheet == null) { Debug.LogWarning(string.Format("[CloudDataField] No cloud data sheet found for field {0}.{1}", this.GetType().FullName, info.Name)); continue; } // get the key for this field and check if the sheet contains it string cloudDataKey = this.GetType().FullName + "." + info.Name; if (sheet.ContainsKey(cloudDataKey)) { object newFieldValue = sheet.GetValue(cloudDataKey); CloudDataTypeSerialization.DeserializeValue(this, info, newFieldValue); } #if UNITY_EDITOR else if (forceInsertNewValues || (CloudDataManager.instance.autoSaveNewFieldsToCloudOnPlay && Application.isPlaying)) { object newVal = info.GetValue(this); sheet.InsertValue(cloudDataKey, newVal, info.FieldType); } #endif } }