1
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public sealed class DictionaryReferenceScriptableObject : ScriptableObject
|
||||
{
|
||||
[SerializeField] private string mark;
|
||||
[SerializeField] internal SerializedDictionary<int,string> dictionary;
|
||||
public static DictionaryReferenceScriptableObject Singleton
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_singleton == null)
|
||||
{
|
||||
_singleton = ScriptableObjectHelper.Get<DictionaryReferenceScriptableObject>();
|
||||
}
|
||||
return _singleton;
|
||||
}
|
||||
}
|
||||
private static DictionaryReferenceScriptableObject _singleton;
|
||||
public static IDictionary<int,string> Dictionary => Singleton.dictionary;
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.SetDirty(Singleton);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Add(string value)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var random = Random.Range(int.MinValue, int.MaxValue);
|
||||
while (Dictionary.ContainsKey(random))
|
||||
{
|
||||
random = Random.Range(int.MinValue, int.MaxValue);
|
||||
}
|
||||
Singleton.dictionary.AddConflictAllowed(random,value);
|
||||
Save();
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void AddOrUpdate(int key, string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (Singleton.dictionary.TryAdd(key,value) is false)
|
||||
{
|
||||
Singleton.dictionary[key] = value;
|
||||
}
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user