FlashSupport.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /// <summary>
  6. /// Helper class to support HasSet for Flash export
  7. /// </summary>
  8. /// <typeparam name="T"></typeparam>
  9. #if UNITY_FLASH
  10. public class HashSet_Flash<T> : IEnumerable
  11. {
  12. Dictionary< T, T> _dict = new Dictionary<T,T>();
  13. public bool Add( T obj )
  14. {
  15. try
  16. {
  17. _dict.Add( obj, obj );
  18. } catch( SystemException )
  19. {
  20. return false;
  21. }
  22. return true;
  23. }
  24. public bool Remove( T obj )
  25. {
  26. return _dict.Remove( obj );
  27. }
  28. public int Count
  29. {
  30. get
  31. {
  32. return _dict.Count;
  33. }
  34. }
  35. public bool Contains( T obj )
  36. {
  37. return _dict.ContainsKey( obj );
  38. }
  39. public IEnumerator GetEnumerator()
  40. {
  41. return new Enumerator( _dict.GetEnumerator() );
  42. }
  43. class Enumerator : IEnumerator
  44. {
  45. IEnumerator _dictEnumerator;
  46. public Enumerator( IEnumerator dictEnumerator )
  47. {
  48. _dictEnumerator = dictEnumerator;
  49. }
  50. public object Current
  51. {
  52. get { return ((KeyValuePair<T,T>)_dictEnumerator.Current).Value; }
  53. }
  54. public bool MoveNext()
  55. {
  56. return _dictEnumerator.MoveNext();
  57. }
  58. public void Reset()
  59. {
  60. _dictEnumerator.Reset();
  61. }
  62. }
  63. }
  64. #else
  65. public class HashSet_Flash<T> : HashSet<T>
  66. {
  67. }
  68. #endif