ObjectCollectionMask.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace O3DWB
  6. {
  7. [Serializable]
  8. public class ObjectCollectionMask : ScriptableObject
  9. {
  10. #region Private Variables
  11. [SerializeField]
  12. private SerializableGameObjectHashSet _gameObjects = new SerializableGameObjectHashSet();
  13. [SerializeField]
  14. private ObjectCollectionMaskView _view;
  15. #endregion
  16. #region Public Properties
  17. public ObjectCollectionMaskView View { get { return _view; } }
  18. #endregion
  19. #region Constructors
  20. public ObjectCollectionMask()
  21. {
  22. _view = new ObjectCollectionMaskView(this);
  23. }
  24. #endregion
  25. #region Public Methods
  26. public bool IsMasked(GameObject gameObject)
  27. {
  28. return _gameObjects.Contains(gameObject);
  29. }
  30. public void Mask(GameObject gameObject)
  31. {
  32. if(gameObject != null) _gameObjects.Add(gameObject);
  33. }
  34. public void Mask(List<GameObject> gameObjects)
  35. {
  36. foreach(GameObject gameObject in gameObjects)
  37. {
  38. Mask(gameObject);
  39. }
  40. }
  41. public void Unmask(GameObject gameObject)
  42. {
  43. _gameObjects.Remove(gameObject);
  44. }
  45. public void Unmask(List<GameObject> gameObjects)
  46. {
  47. foreach (GameObject gameObject in gameObjects)
  48. {
  49. Unmask(gameObject);
  50. }
  51. }
  52. public void UnmaskAll()
  53. {
  54. _gameObjects.Clear();
  55. }
  56. public List<GameObject> GetAllMaskedGameObjects()
  57. {
  58. _gameObjects.HashSet.RemoveWhere(item => item == null);
  59. return new List<GameObject>(_gameObjects.HashSet);
  60. }
  61. public void RemoveNullEntries()
  62. {
  63. _gameObjects.RemoveNullEntries();
  64. }
  65. #endregion
  66. }
  67. }
  68. #endif