Door.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using UnityEngine;
  3. namespace DunGen
  4. {
  5. [Serializable]
  6. public class Door : MonoBehaviour
  7. {
  8. public delegate void DoorStateChangedDelegate(Door door, bool isOpen);
  9. [HideInInspector]
  10. public Dungeon Dungeon;
  11. [HideInInspector]
  12. public Doorway DoorwayA;
  13. [HideInInspector]
  14. public Doorway DoorwayB;
  15. [HideInInspector]
  16. public Tile TileA;
  17. [HideInInspector]
  18. public Tile TileB;
  19. public bool DontCullBehind
  20. {
  21. get { return dontCullBehind; }
  22. set
  23. {
  24. if (dontCullBehind == value)
  25. return;
  26. dontCullBehind = value;
  27. SetDoorState(isOpen);
  28. }
  29. }
  30. public bool ShouldCullBehind
  31. {
  32. get
  33. {
  34. if (DontCullBehind)
  35. return false;
  36. return !isOpen;
  37. }
  38. }
  39. public virtual bool IsOpen
  40. {
  41. get { return isOpen; }
  42. set
  43. {
  44. if (isOpen == value)
  45. return;
  46. SetDoorState(value);
  47. }
  48. }
  49. public event DoorStateChangedDelegate OnDoorStateChanged;
  50. [SerializeField]
  51. private bool dontCullBehind;
  52. [SerializeField]
  53. private bool isOpen = true;
  54. private void OnDestroy()
  55. {
  56. OnDoorStateChanged = null;
  57. }
  58. public void SetDoorState(bool isOpen)
  59. {
  60. this.isOpen = isOpen;
  61. if (OnDoorStateChanged != null)
  62. OnDoorStateChanged(this, isOpen);
  63. }
  64. }
  65. }