コード例 #1
0
 /// <summary>
 /// Sets the value.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 /// <param name="valueType"></param>
 /// <param name="writeNow">if set to <c>true</c> persists the value immediately.</param>
 /// <param name="persistentSerializer">The persistent serializer.</param>
 void IPersistentData.SetValue(string name, object value, Type valueType, bool writeNow, IPersistentSerializer persistentSerializer)
 {
     lock (_persistentValues)
     {
         // if the value is not found (this is probably rare), then a container is created
         if (!_persistentValues.TryGetValue(name, out var persistentValue))
         {
             persistentValue = new PersistentValue
             {
                 Name      = name,
                 ValueType = valueType,
             };
             _persistentValues[name] = persistentValue;
         }
         // then the value is set anyway
         // TODO: conditional dirty (if value actually changes)
         persistentValue.Value = value;
         persistentValue.Dirty = true;
         // if it has to be written immediately, then do it
         if (writeNow)
         {
             Write(persistentValue, persistentSerializer);
         }
     }
 }
コード例 #2
0
    protected PersistentValueState(string path, T initialValue)
    {
        _persistentData = PersistentValue <T> .At(path, initialValue);

        _undoValue = _defaltValue = initialValue;
        Value      = _persistentData.Get;
        OnChange.Register(OnValueChange);
    }
コード例 #3
0
    public static PersistentValue <T> At(string path)
    {
        PersistentValue <T> val;

        if (!_dict.TryGetValue(path, out val))
        {
            val         = new PersistentValue <T>(path);
            _dict[path] = val;
        }
        return(val);
    }
コード例 #4
0
    public static PersistentValue <T> At(string path, T startValue)
    {
        var has = PersistentValue <T> .Exists(path);

        var ret = PersistentValue <T> .At(path);

        if (!has)
        {
            ret.Set = startValue;
        }
        return(ret);
    }
コード例 #5
0
 /// <summary>
 /// Gets the persistent value.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="valueType">Type of the value.</param>
 /// <param name="defaultValue">The default value.</param>
 /// <param name="persistentSerializer">The persistent serializer.</param>
 /// <returns></returns>
 private PersistentValue GetPersistentValue(string name, Type valueType, object defaultValue, IPersistentSerializer persistentSerializer)
 {
     lock (_persistentValues)
     {
         if (!_persistentValues.TryGetValue(name, out var persistentValue))
         {
             // value is read from serializer only if not found in memory
             if (!persistentSerializer.TryLoadValue(name, valueType, out var value))
             {
                 value = defaultValue;
             }
             persistentValue = new PersistentValue
             {
                 Name      = name,
                 Value     = value,
                 ValueType = valueType,
                 Dirty     = false,
             };
         }
         return(persistentValue);
     }
 }
コード例 #6
0
ファイル: PersistentData.cs プロジェクト: ArxOne/Persistence
 /// <summary>
 /// Sets the value.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 /// <param name="valueType"></param>
 /// <param name="writeNow">if set to <c>true</c> persists the value immediately.</param>
 /// <param name="persistentSerializer">The persistent serializer.</param>
 void IPersistentData.SetValue(string name, object value, Type valueType, bool writeNow, IPersistentSerializer persistentSerializer)
 {
     lock (_persistentValues)
     {
         PersistentValue persistentValue;
         // if the value is not found (this is probably rare), then a container is created
         if (!_persistentValues.TryGetValue(name, out persistentValue))
         {
             persistentValue = new PersistentValue
             {
                 Name = name,
                 ValueType = valueType,
             };
             _persistentValues[name] = persistentValue;
         }
         // then the value is set anyway
         // TODO: conditional dirty (if value actually changes)
         persistentValue.Value = value;
         persistentValue.Dirty = true;
         // if it has to be written immediately, then do it
         if (writeNow)
             Write(persistentValue, persistentSerializer);
     }
 }
コード例 #7
0
 PersistentValue <bool> Fold(SerializedProperty property)
 {
     return(PersistentValue <bool> .At("Temp/K10/Audio/AudioSourceConfiguration/" + property.serializedObject.targetObject.name + property.propertyPath + ".bool"));
 }
コード例 #8
0
 /// <summary>
 /// Writes the specified persistent value.
 /// </summary>
 /// <param name="persistentValue">The persistent value.</param>
 /// <param name="persistentSerializer">The persistent serializer.</param>
 private static void Write(PersistentValue persistentValue, IPersistentSerializer persistentSerializer)
 {
     persistentSerializer.SaveValue(persistentValue.Name, persistentValue.ValueType, persistentValue.Value);
     persistentValue.Dirty = false;
 }
コード例 #9
0
ファイル: PersistentData.cs プロジェクト: ArxOne/Persistence
 /// <summary>
 /// Writes the specified persistent value.
 /// </summary>
 /// <param name="persistentValue">The persistent value.</param>
 /// <param name="persistentSerializer">The persistent serializer.</param>
 private static void Write(PersistentValue persistentValue, IPersistentSerializer persistentSerializer)
 {
     persistentSerializer.SaveValue(persistentValue.Name, persistentValue.ValueType, persistentValue.Value);
     persistentValue.Dirty = false;
 }
コード例 #10
0
ファイル: PersistentData.cs プロジェクト: ArxOne/Persistence
 /// <summary>
 /// Gets the persistent value.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="valueType">Type of the value.</param>
 /// <param name="defaultValue">The default value.</param>
 /// <param name="persistentSerializer">The persistent serializer.</param>
 /// <returns></returns>
 private PersistentValue GetPersistentValue(string name, Type valueType, object defaultValue, IPersistentSerializer persistentSerializer)
 {
     lock (_persistentValues)
     {
         PersistentValue persistentValue;
         if (!_persistentValues.TryGetValue(name, out persistentValue))
         {
             // value is read from serializer only if not found in memory
             object value;
             if (!persistentSerializer.TryLoadValue(name, valueType, out value))
                 value = defaultValue;
             persistentValue = new PersistentValue
             {
                 Name = name,
                 Value = value,
                 ValueType = valueType,
                 Dirty = false,
             };
         }
         return persistentValue;
     }
 }
コード例 #11
0
    public static void Set <T>(string key, T value)
    {
        Load();

        data[key] = new PersistentValue <T>(value);
    }