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);
                }
            }
        }
Beispiel #2
0
        protected void Awake()
        {
            s_Instance = this;

            if (defaultCloudDataSheet == null)
            {
                var sheets = GetComponentsInChildren <BaseCloudDataSheet>();
                defaultCloudDataSheet = (sheets != null && sheets.Length > 0) ? sheets[0] : null;
            }

#if UNITY_EDITOR
            if (String.IsNullOrEmpty(organizationId))
            {
                organizationId = UnityEditor.PlayerSettings.companyName;
            }
            if (String.IsNullOrEmpty(projectId))
            {
                projectId = UnityEditor.PlayerSettings.productName;
            }
            if (String.IsNullOrEmpty(accessToken))
            {
                Debug.LogError("[Unity Cloud Data] No AccessToken defined in CloudDataManager (required to use cloud data)!");
            }
#endif

            if (refreshSheetsOnAwake)
            {
                RefreshAll(null);
            }
        }
        // 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
            }
        }