SceneGate.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using Core;
  3. using UnityEngine;
  4. [RequireComponent(typeof(Collider2D))]
  5. public class SceneGate : BaseBehaviour
  6. {
  7. private void Awake()
  8. {
  9. this._trigger = base.GetComponent<BoxCollider2D>();
  10. if (this._trigger == null)
  11. {
  12. Log.Error("No Collider2D in Scene " + LevelManager.SceneName + " Gate " + base.name);
  13. }
  14. else
  15. {
  16. this.data.TriggerSize = Vector2.Scale(this._trigger.size, base.transform.localScale);
  17. }
  18. this.data.SelfPosition = base.transform.position;
  19. this.data.OpenType = this.openType;
  20. this.data.InAir = this.InAir;
  21. }
  22. public void OnEnable()
  23. {
  24. R.SceneGate.GatesInCurrentScene.Add(this);
  25. }
  26. public void OnDisable()
  27. {
  28. if (!SingletonMono<SceneGateManager>.ApplicationIsQuitting)
  29. {
  30. R.SceneGate.GatesInCurrentScene.Remove(this);
  31. }
  32. }
  33. private void OnTriggerStay2D(Collider2D collision)
  34. {
  35. if (this.AllowEnterGate(collision))
  36. {
  37. Vector3 position = R.Player.Transform.position;
  38. float num = 0.5f;
  39. bool flag = this.openType == SceneGate.OpenType.All;
  40. bool flag2 = this.openType == SceneGate.OpenType.Left && position.x < base.transform.position.x + num && R.Player.Attribute.faceDir == 1;
  41. bool flag3 = this.openType == SceneGate.OpenType.Right && position.x > base.transform.position.x - num && R.Player.Attribute.faceDir == -1;
  42. bool flag4 = this.openType == SceneGate.OpenType.Top && position.y > base.transform.position.y - num;
  43. bool flag5 = this.openType == SceneGate.OpenType.Bottom && position.y < base.transform.position.y + num;
  44. if (flag || flag2 || flag3 || flag4 || flag5)
  45. {
  46. R.SceneGate.Enter(this.data, false);
  47. }
  48. if (this.openType == SceneGate.OpenType.PressKey && Core.Input.Game.Search.OnClick)
  49. {
  50. R.SceneGate.Enter(this.data, false);
  51. }
  52. }
  53. }
  54. private bool AllowEnterGate(Collider2D collision)
  55. {
  56. bool flag = R.SceneGate.IsLocked || R.Player == null || !collision.CompareTag("Player") || this.openType == SceneGate.OpenType.None || R.Mode.IsInBattleMode() || R.Player.Action.NotAllowPassSceneGate || !InputSetting.IsWorking() || (!string.IsNullOrEmpty(this._checkIdInSaveStorage) && SaveStorage.Get(this._checkIdInSaveStorage, false));
  57. return !flag;
  58. }
  59. public Coroutine Enter(bool needProgressBar = false)
  60. {
  61. return R.SceneGate.Enter(this.data, needProgressBar);
  62. }
  63. public Coroutine Exit(float groundDis = 0f, SceneGate.OpenType lastGateOpenType = SceneGate.OpenType.None)
  64. {
  65. return R.SceneGate.Exit(this.data, groundDis, lastGateOpenType);
  66. }
  67. public SwitchLevelGateData data;
  68. [Header("允许进入的方式与方向")]
  69. [SerializeField]
  70. public SceneGate.OpenType openType = SceneGate.OpenType.All;
  71. [SerializeField]
  72. [Header("允许出现在空中")]
  73. private bool InAir;
  74. [SerializeField]
  75. private string _checkIdInSaveStorage;
  76. private BoxCollider2D _trigger;
  77. public enum OpenType
  78. {
  79. None = 1,
  80. All,
  81. Left,
  82. Right,
  83. Top,
  84. Bottom,
  85. PressKey
  86. }
  87. }