/// <summary> /// A preference that is stored in the cloud. Automatically added to the <see cref="DataManager"/>. /// </summary> /// <param name="key">A unique identifier used to identify this particular value.</param> /// <param name="type">The method of conflict resolution to be used in case of a data conflict. Can happen if the data is altered by a different device.</param> /// <param name="value">The starting value for this preference.</param> /// <param name="defaultValue">The value the preference will be set to if it is ever reset.</param> /// <param name="valueLoader"><c>delegate</c> used to get the preference.</param> /// <param name="valueSetter"><c>delegate</c> used to set the preference.</param> protected PersistentValue(string key, PersistenceType type, T value, T defaultValue, ValueLoaderDelegate valueLoader, ValueSetterDelegate valueSetter) { // Compiler directives need to be placed in the specific order they're in, don't move/combine them #if UNITY_EDITOR // Workaround for Unity Editor serialization weirdness if (Guid.NewGuid() == Guid.Empty) { return; } #endif Key = key; Value = value; PersistenceType = type; DefaultValue = defaultValue; ValueLoader = valueLoader; ValueSetter = valueSetter; DataManager.CloudPrefs[key] = this; #if UNITY_EDITOR // 1 is the main thread if (System.Threading.Thread.CurrentThread.ManagedThreadId != 1 || !Application.isPlaying) { return; } #endif DataManager.InitDataManager(); }
/// <summary> /// A preference that is stored in the cloud. Automatically added to the <see cref="DataManager"/>. /// </summary> /// <param name="key">A unique identifier used to identify this particular value.</param> /// <param name="type">The method of conflict resolution to be used in case of a data conflict. Can happen if the data is altered by a different device.</param> /// <param name="value">The starting value for this preference.</param> /// <param name="defaultValue">The value the preference will be set to if it is ever reset.</param> /// <param name="valueLoader"><c>delegate</c> used to get the preference.</param> /// <param name="valueSetter"><c>delegate</c> used to set the preference.</param> protected PersistentValue(string key, PersistenceType type, T value, T defaultValue, ValueLoaderDelegate valueLoader, ValueSetterDelegate valueSetter) { Key = key; Value = value; PersistenceType = type; DefaultValue = defaultValue; ValueLoader = valueLoader; ValueSetter = valueSetter; DataManager.CloudPrefs[key] = this; DataManager.InitDataManager(); Load(); }