Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game Update : #7

Open
wants to merge 1 commit into
base: Complex-Enemies-Setup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Scripts/Enemy/EnemyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public virtual void Die()
public void ToggleEnemyColor(bool value)=> enemyView.ToggleColor(value);


public void Shoot()
public virtual void Shoot()
{
enemyView.PlayShootingEffect();
GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.ENEMY_SHOOT);
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Enemy/EnemyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public EnemyController CreateEnemy(EnemyScriptableObject enemyScriptableObject)
case EnemyType.PatrolMan:
enemy = new PatrolManController(enemyScriptableObject);
break;
case EnemyType.Hitman:
enemy = new HitmanController(enemyScriptableObject);
break;
default:
enemy = new EnemyController(enemyScriptableObject);
break;
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Enemy/Hitman.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Assets/Scripts/Enemy/Hitman/HitmanController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using StatePattern.Player;
using StatePattern.StateMachine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace StatePattern.Enemy
{
public class HitmanController : EnemyController
{
private HitmanStateMachine stateMachine;

public HitmanController(EnemyScriptableObject enemyScriptableObject) : base(enemyScriptableObject)
{
enemyView.SetController(this);
CreateStateMachine();
stateMachine.ChangeState(States.IDLE);
}

private void CreateStateMachine() => stateMachine = new HitmanStateMachine(this);

public override void UpdateEnemy()
{
if (currentState == EnemyState.DEACTIVE)
return;

stateMachine.Update();
}

public override void Shoot()
{
base.Shoot();
stateMachine.ChangeState(States.TELEPORTING);
}

public override void PlayerEnteredRange(PlayerController targetToSet)
{
base.PlayerEnteredRange(targetToSet);
stateMachine.ChangeState(States.CHASING);
}

public override void PlayerExitedRange() => stateMachine.ChangeState(States.IDLE);
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Enemy/Hitman/HitmanController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Assets/Scripts/Enemy/Hitman/HitmanStateMachine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using StatePattern.StateMachine;
using System;

namespace StatePattern.Enemy
{
public class HitmanStateMachine : GenericStateMachine <HitmanController>
{
public HitmanStateMachine(HitmanController Owner) : base(Owner)
{
this.Owner = Owner;
CreateStates();
SetOwner();
}

private void CreateStates()
{
States.Add(StateMachine.States.IDLE, new IdleState<HitmanController>(this));
States.Add(StateMachine.States.PATROLLING, new PatrollingState<HitmanController>(this));
States.Add(StateMachine.States.CHASING, new ChasingState<HitmanController>(this));
States.Add(StateMachine.States.SHOOTING, new ShootingState<HitmanController>(this));
States.Add(StateMachine.States.TELEPORTING, new TeleportingState<HitmanController>(this));
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Enemy/Hitman/HitmanStateMachine.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions Assets/Scripts/Enemy/States/TeleportingState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using StatePattern.Enemy;
using StatePattern.StateMachine;
using System.Collections;
using UnityEngine;
using UnityEngine.AI;

namespace StatePattern.Enemy
{
public class TeleportingState<T> : IState where T : EnemyController
{
public EnemyController Owner { get; set; }
private GenericStateMachine<T> stateMachine;

public TeleportingState(GenericStateMachine<T> stateMachine) => this.stateMachine = stateMachine;

public void OnStateEnter()
{
TeleportToRandomPosition();

stateMachine.ChangeState(States.CHASING);
}

public void Update()
{

}

public void OnStateExit()
{

}
private void TeleportToRandomPosition() => Owner.Agent.Warp(GetRandomNavMeshPoint());

private Vector3 GetRandomNavMeshPoint()
{
Vector3 randomDirection = Random.insideUnitSphere * 5f + Owner.Position;
NavMeshHit hit;
if (NavMesh.SamplePosition(randomDirection, out hit, 5f, NavMesh.AllAreas))
return hit.position;
else
return Owner.Data.SpawnPosition;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Enemy/States/TeleportingState.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/Scripts/StateMachine/States.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum States
ROTATING,
SHOOTING,
PATROLLING,
CHASING
CHASING,
TELEPORTING
}
}
12 changes: 6 additions & 6 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.ide.visualstudio": "2.0.17",
"com.unity.ide.rider": "3.0.18",
"com.unity.ide.visualstudio": "2.0.16",
"com.unity.ide.rider": "3.0.15",
"com.unity.ide.vscode": "1.2.5",
"com.unity.editorcoroutines": "1.0.0",
"com.unity.performance.profile-analyzer": "1.2.2",
"com.unity.performance.profile-analyzer": "1.1.1",
"com.unity.test-framework": "1.1.31",
"com.unity.testtools.codecoverage": "1.2.2"
"com.unity.testtools.codecoverage": "1.0.1"
}
},
"com.unity.ide.rider": {
Expand Down Expand Up @@ -67,7 +67,7 @@
"url": "https://packages.unity.com"
},
"com.unity.performance.profile-analyzer": {
"version": "1.2.2",
"version": "1.1.1",
"depth": 1,
"source": "registry",
"dependencies": {},
Expand Down Expand Up @@ -101,7 +101,7 @@
"url": "https://packages.unity.com"
},
"com.unity.testtools.codecoverage": {
"version": "1.2.2",
"version": "1.0.1",
"depth": 1,
"source": "registry",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.21f1
m_EditorVersionWithRevision: 2021.3.21f1 (1b156197d683)
m_EditorVersion: 2021.3.10f1
m_EditorVersionWithRevision: 2021.3.10f1 (1c7d0df0160b)