diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/Walls/XWall.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/Walls/XWall.cs')
-rw-r--r-- | Client/Assets/Scripts/Walls/XWall.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/Walls/XWall.cs b/Client/Assets/Scripts/Walls/XWall.cs new file mode 100644 index 00000000..ab1cfea0 --- /dev/null +++ b/Client/Assets/Scripts/Walls/XWall.cs @@ -0,0 +1,54 @@ +using UnityEngine;
+using XUtliPoolLib;
+
+public abstract class XWall : MonoBehaviour
+{
+ protected bool _forward_collision;
+ protected IXPlayerAction _interface;
+
+ private BoxCollider _box = null;
+
+ private Vector3 _left;
+ private Vector3 _right;
+
+ // Use this for initialization
+ void Awake ()
+ {
+ _box = GetComponent<BoxCollider>();
+ _box.enabled = false;
+
+ Vector3 half = Vector3.Cross(Vector3.up, transform.forward) * _box.size.x * _box.transform.localScale.x * 0.5f;
+
+ _left = _box.center + _box.transform.position - half;
+ _right = _box.center + _box.transform.position + half;
+ }
+
+ void Update()
+ {
+ if (_interface == null || _interface.Deprecated) _interface = XInterfaceMgr.singleton.GetInterface<IXPlayerAction>(1);
+
+ if (_interface != null && _interface.IsValid)
+ {
+ Vector3 pos = _interface.PlayerPosition(!(this is XCameraWall));
+ Vector3 last_pos = _interface.PlayerLastPosition(!(this is XCameraWall));
+
+ if ((last_pos - pos).sqrMagnitude > 0)
+ {
+ CollisionDetected(pos, last_pos);
+ }
+ }
+ }
+
+ private void CollisionDetected(Vector3 pos, Vector3 last)
+ {
+ if (XCommon.singleton.IsLineSegmentCross(last, pos, _left, _right))
+ {
+ Vector3 dir = pos - last;
+
+ _forward_collision = Vector3.Dot(dir, transform.forward) > 0;
+ OnTriggered();
+ }
+ }
+
+ protected abstract void OnTriggered();
+}
|