Ejemplo n.º 1
0
 public override IEnumerator DoPut(string key, object value, BoolAction <Exception> action)
 {
     try
     {
         IList <string> keys = GetKeys();
         if (value == null)
         {
             PlayerPrefs.DeleteKey(prefix + key);
             keys.Remove(key);
         }
         else
         {
             PlayerPrefs.SetString(prefix + key, value.ToString());
             if (!keys.Contains(key))
             {
                 keys.Add(key);
             }
         }
         SetKeys(keys);
         PlayerPrefs.Save();
         action?.Invoke(true, null);
     }catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 2
0
        public override IEnumerator DoPutObjects(BoolAction <Exception> action, Action <float> progress, IStorableObject[] storableObjects)
        {
            try
            {
                progress(0);
                IList <string> keys = GetKeys();
                foreach (IStorableObject storableObject in storableObjects)
                {
                    string key = storableObject.GetStorableKey(), value = JSON.ToJson(storableObject.GetStorableObject());
                    PlayerPrefs.SetString(prefix + key, value);

                    if (!keys.Contains(key))
                    {
                        keys.Add(key);
                    }
                }
                progress(0.95f);
                SetKeys(keys);
                PlayerPrefs.Save();
                progress(1f);
                action?.Invoke(true, null);
            }catch (Exception e)
            {
                action?.Invoke(false, e);
            }
            yield return(null);
        }
Ejemplo n.º 3
0
 public override IEnumerator DoPutMultiple(IDictionary <string, object> keyValuePairs, BoolAction <Exception> action, Action <float> progess)
 {
     try
     {
         progess(0);
         IList <string> keys = GetKeys();
         foreach (KeyValuePair <string, object> keyValuePair in keyValuePairs)
         {
             if (keyValuePair.Value == null)
             {
                 PlayerPrefs.DeleteKey(prefix + keyValuePair.Key);
                 keys.Remove(keyValuePair.Key);
             }
             else
             {
                 PlayerPrefs.SetString(prefix + keyValuePair.Key, keyValuePair.Value.ToString());
                 if (!keys.Contains(keyValuePair.Key))
                 {
                     keys.Add(keyValuePair.Key);
                 }
             }
         }
         progess(0.95f);
         SetKeys(keys);
         PlayerPrefs.Save();
         progess(1);
         action?.Invoke(true, null);
     }catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 4
0
        protected virtual IEnumerator DoSetDataMultiple(IDictionary <string, object> keyValuePairs, MonoBehaviour context, BoolAction <Exception> action)
        {
            foreach (KeyValuePair <string, object> kv in keyValuePairs)
            {
                bool      t1 = false;
                Exception t2 = null;
                Coroutine c;
                try
                {
                    c = context.StartCoroutine(DoSetData(kv.Key, kv.Value, context, (s, e) =>
                    {
                        t1 = s;
                        t2 = e;
                    }));
                }
                catch (Exception e)
                {
                    action?.Invoke(false, e);
                    yield break;
                }
                yield return(c);

                if (!t1)
                {
                    action?.Invoke(false, t2);
                    yield break;
                }
            }
        }
Ejemplo n.º 5
0
 public override IEnumerator DoPut(string key, object value, BoolAction <Exception> action)
 {
     try
     {
         Map[key] = value;
         action?.Invoke(true, null);
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 6
0
 public override IEnumerator DoClear(BoolAction <Exception> action)
 {
     try
     {
         Map.Clear();
         action?.Invoke(true, null);
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 7
0
 public override IEnumerator DoPutMultiple(IDictionary <string, object> keyValuePairs, BoolAction <Exception> action, Action <float> progess)
 {
     try
     {
         progess(0);
         foreach (KeyValuePair <string, object> kv in keyValuePairs)
         {
             Map[kv.Key] = kv.Value;
         }
         progess(1);
         action?.Invoke(true, null);
     }catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 8
0
 public override IEnumerator DoPutObjects(BoolAction <Exception> action, Action <float> progress, IStorableObject[] storableObjects)
 {
     try
     {
         progress(0);
         foreach (IStorableObject storableObject in storableObjects)
         {
             Map[storableObject.GetStorableKey()] = storableObject.GetStorableObject();
         }
         progress(1);
         action?.Invoke(true, null);
     }catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 9
0
 public void PutObjects(MonoBehaviour context, BoolAction <Exception> action, Action <float> progess, params IStorableObject[] storableObjects)
 {
     try
     {
         context.StartCoroutine(DoPutObjects(action, progess, storableObjects));
     }catch (Exception e)
     {
         action?.Invoke(false, e);
     }
 }
Ejemplo n.º 10
0
 public void Clear(MonoBehaviour context, BoolAction <Exception> action)
 {
     try
     {
         context.StartCoroutine(DoClear(action));
     }catch (Exception e)
     {
         action?.Invoke(false, e);
     }
 }
Ejemplo n.º 11
0
 public override IEnumerator DoClear(BoolAction <Exception> action)
 {
     try
     {
         IList <string> keys = GetKeys();
         foreach (string key in keys)
         {
             PlayerPrefs.DeleteKey(prefix + key);
         }
         keys.Clear();
         SetKeys(keys);
         PlayerPrefs.Save();
         action?.Invoke(true, null);
     }catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 12
0
 public void Put(string key, MonoBehaviour context, object value, BoolAction <Exception> action)
 {
     try
     {
         context.StartCoroutine(DoPut(key, value, action));
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
 }
Ejemplo n.º 13
0
 public void PutMultiple(IDictionary <string, object> keyValuePairs, MonoBehaviour context, BoolAction <Exception> action, Action <float> progess)
 {
     try
     {
         context.StartCoroutine(DoPutMultiple(keyValuePairs, action, progess));
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
 }
Ejemplo n.º 14
0
 public override IEnumerator DoRestoreObjects(BoolAction <Exception> action, Action <float> progess, IStorableObject[] storableObjects)
 {
     try
     {
         progess(0);
         foreach (IStorableObject storableObject in storableObjects)
         {
             if (Map.ContainsKey(storableObject.GetStorableKey()))
             {
                 storableObject.OnStorableObjectRestore(Map[storableObject.GetStorableKey()]);
             }
         }
         progess(1);
         action?.Invoke(true, null);
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 15
0
 public override IEnumerator DoRestoreObjects(BoolAction <Exception> action, Action <float> progess, IStorableObject[] storableObjects)
 {
     try
     {
         progess(0);
         foreach (IStorableObject storableObject in storableObjects)
         {
             string json = PlayerPrefs.GetString(prefix + storableObject.GetStorableKey());
             if (json == null)
             {
                 continue;
             }
             storableObject.OnStorableObjectRestore(JSON.FromJson(json, storableObject.GetStorableObjectType()));
         }
         progess(1);
         action?.Invoke(true, null);
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
     yield return(null);
 }
Ejemplo n.º 16
0
 public void RestoreObjects(MonoBehaviour context, BoolAction <Exception> action, Action <float> progess, params IStorableObject[] storableObjects)
 {
     if (action == null)
     {
         Debug.Log("Action is null!");
         return;
     }
     try
     {
         context.StartCoroutine(DoRestoreObjects(action, progess, storableObjects));
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
 }
Ejemplo n.º 17
0
 public void PutMultiple(string[] keys, object[] values, MonoBehaviour context, BoolAction <Exception> action, Action <float> progess)
 {
     try
     {
         int len = Math.Min(keys.Length, values.Length);
         Dictionary <string, object> map = new Dictionary <string, object>();
         for (int i = 0; i < len; i++)
         {
             map[keys[i]] = values[i];
         }
         PutMultiple(map, context, action, progess);
     }
     catch (Exception e)
     {
         action?.Invoke(false, e);
     }
 }
Ejemplo n.º 18
0
 public bool TearDownSubclass()
 {
     return((_tearDownFunc != null) ? _tearDownFunc.Invoke() : false);
 }
Ejemplo n.º 19
0
 public bool IsSubclassed()
 {
     return((_isSubclassedFunc != null) ? _isSubclassedFunc.Invoke() : false);
 }