보스 몬스터 Ai 관련 코드 틀 추가
This commit is contained in:
@@ -646,6 +646,7 @@ GameObject:
|
||||
- component: {fileID: 114042778}
|
||||
- component: {fileID: 114042777}
|
||||
- component: {fileID: 114042780}
|
||||
- component: {fileID: 114042781}
|
||||
m_Layer: 9
|
||||
m_Name: False Knight
|
||||
m_TagString: Enemy
|
||||
@@ -746,6 +747,18 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
nextMove: 0
|
||||
--- !u!114 &114042781
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 114042775}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 39a88fe79855e244ea5a0692e248e48e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &119726257
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
8
Assets/Scripts/AI.meta
Normal file
8
Assets/Scripts/AI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19a8dafa2c009e14bb05f829de83171e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/AI/EnemyStateManager.cs
Normal file
24
Assets/Scripts/AI/EnemyStateManager.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyStateManager : MonoBehaviour
|
||||
{
|
||||
public IEnemyState CurrentState;
|
||||
|
||||
void Start()
|
||||
{
|
||||
TransitionToState(new EIdleState());
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
CurrentState?.UpdateState(this); // ? = CurrentState가 null이 아닐때만 실행되는 null 조건 연산자
|
||||
}
|
||||
|
||||
public void TransitionToState(IEnemyState newState)
|
||||
{
|
||||
CurrentState?.ExitState(this);
|
||||
CurrentState = newState;
|
||||
CurrentState.EnterState(this);
|
||||
print($"[TransitionToState]에서 상태 변경 -> {newState}");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AI/EnemyStateManager.cs.meta
Normal file
2
Assets/Scripts/AI/EnemyStateManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39a88fe79855e244ea5a0692e248e48e
|
||||
9
Assets/Scripts/AI/IEnemyuState.cs
Normal file
9
Assets/Scripts/AI/IEnemyuState.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
public interface IEnemyState
|
||||
{
|
||||
// 상태에 들어갈때 실행할 함수
|
||||
void EnterState(EnemyStateManager enemy);
|
||||
// 상태가 유지될때 실행되는 함수
|
||||
void UpdateState(EnemyStateManager enemy);
|
||||
// 상태에서 나올때 실행되는 함수
|
||||
void ExitState(EnemyStateManager enemy);
|
||||
}
|
||||
2
Assets/Scripts/AI/IEnemyuState.cs.meta
Normal file
2
Assets/Scripts/AI/IEnemyuState.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0911e8eea571dfa4fa92f80429dbf6df
|
||||
8
Assets/Scripts/AI/State.meta
Normal file
8
Assets/Scripts/AI/State.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2c6d5b1456feb84098929adaa216fdd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Scripts/AI/State/EAttackState.cs
Normal file
22
Assets/Scripts/AI/State/EAttackState.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EAttackState : IEnemyState
|
||||
{
|
||||
public void EnterState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EAttackState에서 EnterState 실행");
|
||||
}
|
||||
|
||||
public void UpdateState(EnemyStateManager enemy)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab))
|
||||
{
|
||||
enemy.TransitionToState(new EIdleState());
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EAttackState에서 ExitState 실행");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AI/State/EAttackState.cs.meta
Normal file
2
Assets/Scripts/AI/State/EAttackState.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8e7338261caaf747acc655ddc6600c0
|
||||
22
Assets/Scripts/AI/State/EChaseState.cs
Normal file
22
Assets/Scripts/AI/State/EChaseState.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EChaseState : IEnemyState
|
||||
{
|
||||
public void EnterState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EChaseState에서 EnterState 실행");
|
||||
}
|
||||
|
||||
public void UpdateState(EnemyStateManager enemy)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab))
|
||||
{
|
||||
enemy.TransitionToState(new EAttackState());
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EChaseState에서 ExitState 실행");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AI/State/EChaseState.cs.meta
Normal file
2
Assets/Scripts/AI/State/EChaseState.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cf86eba8a247ce44aab23fb33a3c799
|
||||
22
Assets/Scripts/AI/State/EIdleState.cs
Normal file
22
Assets/Scripts/AI/State/EIdleState.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EIdleState : IEnemyState
|
||||
{
|
||||
public void EnterState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EIdleState에서 EnterState 실행");
|
||||
}
|
||||
|
||||
public void UpdateState(EnemyStateManager enemy)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab))
|
||||
{
|
||||
enemy.TransitionToState(new EPatrolState());
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EIdleState에서 ExitState 실행");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AI/State/EIdleState.cs.meta
Normal file
2
Assets/Scripts/AI/State/EIdleState.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf2076e239e13174599ab45c0c843ecb
|
||||
22
Assets/Scripts/AI/State/EPatrolState.cs
Normal file
22
Assets/Scripts/AI/State/EPatrolState.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EPatrolState : IEnemyState
|
||||
{
|
||||
public void EnterState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EPatrolState에서 EnterState 실행");
|
||||
}
|
||||
|
||||
public void UpdateState(EnemyStateManager enemy)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab))
|
||||
{
|
||||
enemy.TransitionToState(new EChaseState());
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitState(EnemyStateManager enemy)
|
||||
{
|
||||
Debug.Log("EPatrolState에서 ExitState 실행");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AI/State/EPatrolState.cs.meta
Normal file
2
Assets/Scripts/AI/State/EPatrolState.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1999129bffd0d544bba613cfcc014cdd
|
||||
Reference in New Issue
Block a user