Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MIT License
- //Copyright (c) 2019 William Herrera
- //Permission is hereby granted, free of charge, to any person obtaining a copy
- //of this software and associated documentation files (the "Software"), to deal
- //in the Software without restriction, including without limitation the rights
- //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- //copies of the Software, and to permit persons to whom the Software is
- //furnished to do so, subject to the following conditions:
- //The above copyright notice and this permission notice shall be included in all
- //copies or substantial portions of the Software.
- //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- //SOFTWARE.
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- namespace OpenScaffolding
- {
- public static class PlayerPrefsEx
- {
- public static void AddInt(string key, int val, int defaultValue = 0)
- {
- int v = PlayerPrefs.GetInt(key, defaultValue);
- PlayerPrefs.SetInt(key, v + val);
- }
- public static void AddFloat(string key, float val, float defaultValue = 0f)
- {
- float v = PlayerPrefs.GetFloat(key, defaultValue);
- PlayerPrefs.SetFloat(key, v + val);
- }
- public static void Clear(string key)
- {
- PlayerPrefs.SetString(key, string.Empty);
- }
- public static bool[] GetBools(string key)
- {
- string values = PlayerPrefs.GetString(key, string.Empty);
- if (values.Length == 0)
- return new bool[] { };
- bool[] result = new bool[values.Length];
- for (int i = 0; i < values.Length; i++)
- {
- result[i] = values[i] == '1' ? true : false;
- }
- return result;
- }
- public static void SetBools(string key, bool[] values)
- {
- StringBuilder stringBuilder = new StringBuilder(values.Length);
- foreach (bool value in values)
- stringBuilder.Append(value ? "1" : "0");
- string v = stringBuilder.ToString();
- PlayerPrefs.SetString(key, v);
- }
- public static void SetBools(string key, int count, bool value)
- {
- StringBuilder stringBuilder = new StringBuilder(count);
- for (int i = 0; i < count; i++)
- stringBuilder.Append(value ? "1" : "0");
- string v = stringBuilder.ToString();
- PlayerPrefs.SetString(key, v);
- }
- }
- public class Manager<T> : MonoBehaviour where T : MonoBehaviour
- {
- static T _instance;
- public static T Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = FindObjectOfType<T>();
- }
- return _instance;
- }
- set
- {
- _instance = value;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement