Initialize AI Scripts
This commit is contained in:
parent
a52bbb0849
commit
576a2d3e99
126802
Assets/Scenes/HomeTown.unity
126802
Assets/Scenes/HomeTown.unity
File diff suppressed because it is too large
Load Diff
8
Assets/Scripts/Runtime/AI/Base.meta
Normal file
8
Assets/Scripts/Runtime/AI/Base.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 964a04e7fca6b3143a441e08dadb0579
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/Runtime/AI/Base/AgentController.cs
Normal file
17
Assets/Scripts/Runtime/AI/Base/AgentController.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI.Base {
|
||||
public abstract class AgentController : MonoBehaviour {
|
||||
protected IState currentState;
|
||||
|
||||
protected virtual void Update() {
|
||||
currentState?.Tick();
|
||||
IState next = currentState?.CheckTransitions();
|
||||
if (next != null && next != currentState) {
|
||||
currentState.OnExit();
|
||||
currentState = next;
|
||||
currentState.OnEnter();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Runtime/AI/Base/AgentController.cs.meta
Normal file
2
Assets/Scripts/Runtime/AI/Base/AgentController.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6297ec95b1219e9418a9025265733745
|
||||
8
Assets/Scripts/Runtime/AI/Base/IState.cs
Normal file
8
Assets/Scripts/Runtime/AI/Base/IState.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace AI.Base {
|
||||
public interface IState {
|
||||
void OnEnter();
|
||||
void Tick();
|
||||
void OnExit();
|
||||
IState CheckTransitions();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Runtime/AI/Base/IState.cs.meta
Normal file
2
Assets/Scripts/Runtime/AI/Base/IState.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 967d629cb6eb5914baeef87e8d71f614
|
||||
8
Assets/Scripts/Runtime/AI/BehaviorTrees.meta
Normal file
8
Assets/Scripts/Runtime/AI/BehaviorTrees.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25ebfdde91f6f5d42a04209ffeb5ff50
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6
Assets/Scripts/Runtime/AI/BehaviorTrees/BTNode.cs
Normal file
6
Assets/Scripts/Runtime/AI/BehaviorTrees/BTNode.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace AI.BehaviorTrees {
|
||||
public abstract class BTNode {
|
||||
// Returns true on success, false if failed
|
||||
public abstract bool Tick();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Runtime/AI/BehaviorTrees/BTNode.cs.meta
Normal file
2
Assets/Scripts/Runtime/AI/BehaviorTrees/BTNode.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2488a298ffb7f694c81f4bc8c4556416
|
||||
20
Assets/Scripts/Runtime/AI/BehaviorTrees/CompositeNode.cs
Normal file
20
Assets/Scripts/Runtime/AI/BehaviorTrees/CompositeNode.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AI.BehaviorTrees {
|
||||
public class CompositeNode : BTNode {
|
||||
protected readonly List<BTNode> children = new List<BTNode>();
|
||||
|
||||
public override bool Tick() {
|
||||
foreach (BTNode child in children) {
|
||||
if (!child.Tick())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddChild(BTNode child) {
|
||||
if (child != null)
|
||||
children.Add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d2e6460215009149a2ce3676a5bb827
|
||||
8
Assets/Scripts/Runtime/AI/PathFinding.meta
Normal file
8
Assets/Scripts/Runtime/AI/PathFinding.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d23211d0455243e4bb0eee95a7104962
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/Runtime/AI/PathFinding/AStarPathFinder.cs
Normal file
13
Assets/Scripts/Runtime/AI/PathFinding/AStarPathFinder.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AI.Pathfinding {
|
||||
public class AStarPathfinder {
|
||||
// Example pathfinding method — replace with actual implementation
|
||||
public List<Vector2> FindPath(Vector2 start, Vector2 goal) {
|
||||
var path = new List<Vector2>();
|
||||
// TODO: Implement A* algorithm here.
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cbae134355a5c84392588e5f7904de9
|
||||
8
Assets/Scripts/Runtime/AI/StateMachines.meta
Normal file
8
Assets/Scripts/Runtime/AI/StateMachines.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 266a8f8b490dc6449ad625710b64ef7d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/Runtime/AI/StateMachines/EnemyStateMachine.cs
Normal file
15
Assets/Scripts/Runtime/AI/StateMachines/EnemyStateMachine.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using AI.Base;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI.StateMachines {
|
||||
public class EnemyStateMachine : AgentController {
|
||||
public IState IdleState;
|
||||
public IState ChaseState;
|
||||
|
||||
protected override void Start() {
|
||||
base.Start();
|
||||
currentState = IdleState;
|
||||
currentState?.OnEnter();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71ab834a15cf8184ca8a951d8ea332bb
|
||||
Loading…
Reference in New Issue
Block a user