Merge remote-tracking branch 'origin/Syntriax' into Over
This commit is contained in:
8
Assets/Scripts/AI.meta
Normal file
8
Assets/Scripts/AI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4e4f06743dc1be42806947cd62fb68e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Assets/Scripts/AI/BasicPatrollingEnemyAI.cs
Normal file
45
Assets/Scripts/AI/BasicPatrollingEnemyAI.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Movement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public class BasicPatrollingEnemyAI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] protected bool isMovingRight = false;
|
||||
|
||||
protected IMovement movement = null;
|
||||
|
||||
protected CollissionChecker leftWallChecker = null;
|
||||
protected CollissionChecker rightWallChecker = null;
|
||||
protected CollissionChecker leftGroundChecker = null;
|
||||
protected CollissionChecker rightGroundChecker = null;
|
||||
|
||||
|
||||
// If moving Right, and either there's no more ground to move into or there is a wall at the Right side of the enemy OR
|
||||
// If moving Left, and either there's no more ground to move into or there is a wall at the Left side of the enemy
|
||||
// We should change directions
|
||||
protected bool ShouldChangeDirection
|
||||
=> (isMovingRight && (rightWallChecker.IsCollided || !rightGroundChecker.IsCollided)) ||
|
||||
(!isMovingRight && (leftWallChecker.IsCollided || !leftGroundChecker.IsCollided));
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
movement = gameObject.AddComponent<EnemyMovement>();
|
||||
leftWallChecker = GetCollissionCheckerOnChild("Collission Checkers/Left Wall");
|
||||
rightWallChecker = GetCollissionCheckerOnChild("Collission Checkers/Right Wall");
|
||||
leftGroundChecker = GetCollissionCheckerOnChild("Collission Checkers/Left Ground");
|
||||
rightGroundChecker = GetCollissionCheckerOnChild("Collission Checkers/Right Ground");
|
||||
}
|
||||
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
if (ShouldChangeDirection)
|
||||
isMovingRight = !isMovingRight;
|
||||
|
||||
movement.Move(isMovingRight ? 1f : -1f);
|
||||
}
|
||||
|
||||
protected CollissionChecker GetCollissionCheckerOnChild(string childName)
|
||||
=> transform.Find(childName).GetComponent<CollissionChecker>();
|
||||
}
|
||||
}
|
11
Assets/Scripts/AI/BasicPatrollingEnemyAI.cs.meta
Normal file
11
Assets/Scripts/AI/BasicPatrollingEnemyAI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 321c5495f0d597749bf29c3a2966aa4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Movement.meta
Normal file
8
Assets/Scripts/Movement.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc70279699861044bb90fcb1700e5eaf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
Assets/Scripts/Movement/CollissionChecker.cs
Normal file
18
Assets/Scripts/Movement/CollissionChecker.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Movement
|
||||
{
|
||||
public class CollissionChecker : MonoBehaviour
|
||||
{
|
||||
private Collider2D[] nonAllocColliderArray = new Collider2D[5];
|
||||
|
||||
public LayerMask LayerMask = ~((1 << 6) | (1 << 7)); // Everything except the "Player" and "Enemy" layer
|
||||
public bool IsCollided => Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, nonAllocColliderArray, LayerMask) != 0;
|
||||
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = IsCollided ? Color.green : Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, transform.localScale);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Movement/CollissionChecker.cs.meta
Normal file
11
Assets/Scripts/Movement/CollissionChecker.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02e036b6321fff34cbd154fd665a8b23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
46
Assets/Scripts/Movement/EnemyMovement.cs
Normal file
46
Assets/Scripts/Movement/EnemyMovement.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Movement
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class EnemyMovement : MonoBehaviour, IMovement
|
||||
{
|
||||
private Rigidbody2D _rigidbody2D = null;
|
||||
private bool _isPaused = false;
|
||||
private float moveValue = 0f;
|
||||
|
||||
public float BaseSpeed { get; set; } = 1f;
|
||||
public bool IsPaused => _isPaused;
|
||||
|
||||
private void Awake()
|
||||
=> _rigidbody2D = GetComponent<Rigidbody2D>();
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (IsPaused)
|
||||
return;
|
||||
|
||||
Vector2 velocity = _rigidbody2D.velocity;
|
||||
velocity.x = moveValue;
|
||||
_rigidbody2D.velocity = velocity;
|
||||
}
|
||||
|
||||
public void Move(float value)
|
||||
=> moveValue = value * BaseSpeed;
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
_isPaused = true;
|
||||
UpdateRigidbody();
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
_isPaused = false;
|
||||
UpdateRigidbody();
|
||||
}
|
||||
|
||||
private void UpdateRigidbody()
|
||||
=> _rigidbody2D.simulated = !_isPaused;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Movement/EnemyMovement.cs.meta
Normal file
11
Assets/Scripts/Movement/EnemyMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ae10931055aaa44d8c518e9efa3d034
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/Movement/IMovement.cs
Normal file
10
Assets/Scripts/Movement/IMovement.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Pausable;
|
||||
|
||||
namespace Movement
|
||||
{
|
||||
public interface IMovement : IPausable
|
||||
{
|
||||
float BaseSpeed { get; set; }
|
||||
void Move(float value);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Movement/IMovement.cs.meta
Normal file
11
Assets/Scripts/Movement/IMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7372c0f42c210d04f98b21e15803e940
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Pausable.meta
Normal file
8
Assets/Scripts/Pausable.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a98c359db26a84941b48a708071cf618
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
Assets/Scripts/Pausable/IPausable.cs
Normal file
9
Assets/Scripts/Pausable/IPausable.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Pausable
|
||||
{
|
||||
public interface IPausable
|
||||
{
|
||||
bool IsPaused { get; }
|
||||
void Pause();
|
||||
void Resume();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Pausable/IPausable.cs.meta
Normal file
11
Assets/Scripts/Pausable/IPausable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: beb0150e245e8cc4cad614670be50ac8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user