#if UNITY_EDITOR using UnityEngine; using System; using System.Collections.Generic; namespace GSpawn { [Serializable] public class IntHashSet : SerializableHashSet {} [Serializable] public class PluginGuidHashSet : SerializableHashSet {} [Serializable] public class GameObjectHashSet : SerializableHashSet {} // Note: Don't inherit from HashSet. Doesn't serialize properly. [Serializable] public class SerializableHashSet : ISerializationCallbackReceiver { private HashSet _hashSet = new HashSet(); [SerializeField] private List _serializedList = new List(); public HashSet hashSet { get { return _hashSet; } } public int Count { get { return _hashSet.Count; } } public void OnBeforeSerialize() { _serializedList.Clear(); foreach (T item in _hashSet) _serializedList.Add(item); } public void OnAfterDeserialize() { _hashSet.Clear(); foreach (T item in _serializedList) _hashSet.Add(item); } public void Add(T item) { _hashSet.Add(item); } public bool Contains(T item) { return _hashSet.Contains(item); } public bool Remove(T item) { return _hashSet.Remove(item); } public void Clear() { _hashSet.Clear(); } public int RemoveWhere(Predicate match) { return _hashSet.RemoveWhere(match); } public IEnumerator GetEnumerator() { return _hashSet.GetEnumerator(); } } } #endif