Created base for FSM.

This commit is contained in:
Ashby Issac 2026-01-07 12:00:57 +05:30
parent fbeac39eb3
commit 90172daae5
22 changed files with 396 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0082726b257d94b50be8e6ddfe50611a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class AIController : MonoBehaviour
{
private BaseState currentState;
private void Start()
{
currentState = new IdleState();
}
private void Update()
{
currentState = currentState.ProcessStates();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a6b3b930b0df4c68b9ddc3c91955866
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,24 @@
public enum AIState
{
Idle,
Roam,
AcquireTarget,
Charge,
Impact,
Recover,
// Idle / Spawn
// ↓
// Roam
// ↓
// Targeting
// ↓
// Charge
// ↓
// Impact
// ↓
// Recover
// ↓
// Roam (loop)
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 33bcaf2c66bb74d0fbbdea47322b33aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,6 @@
public enum STAGE
{
Enter,
Update,
Exit
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67552ab251082417691eae453527d89e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c0a6f1dfd8c8d48dcae8cb76eb994be0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
using UnityEngine;
public class AcquireTargetState : BaseState
{
public AcquireTargetState() : base()
{
Debug.Log($"### {this} constructor");
}
protected override void Enter()
{
base.Enter();
Debug.Log($"### {this} Enter STAGE");
}
protected override void Update()
{
base.Update();
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 61a251a5ccfb640c48cc604c7ea3fd23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
public class BaseState
{
protected STAGE stage;
protected BaseState nextState;
public BaseState()
{
stage = STAGE.Enter;
}
protected virtual void Enter() => stage = STAGE.Update;
protected virtual void Update() => stage = STAGE.Update;
protected virtual void Exit() => stage = STAGE.Exit;
public BaseState ProcessStates()
{
if (stage == STAGE.Enter) Enter();
if (stage == STAGE.Update) Update();
if (stage == STAGE.Exit)
{
Exit();
return nextState;
}
return this;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d8715db69bce948539b926b2c28eb005
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
using UnityEngine;
public class ChargeState : BaseState
{
public ChargeState() : base()
{
Debug.Log($"### {this} constructor");
}
protected override void Enter()
{
base.Enter();
Debug.Log($"### {this} Enter STAGE");
}
protected override void Update()
{
base.Update();
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08843ca91c2a54b6faed7c52c3d62f9f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,33 @@
using UnityEngine;
public class IdleState : BaseState
{
public IdleState() : base()
{
Debug.Log($"### {this} constructor");
}
protected override void Enter()
{
base.Enter();
Debug.Log($"### {this} Enter STAGE");
}
protected override void Update()
{
base.Update();
// use a mod timer system and when timer completes then move onto the next state (RoamState)
nextState = new RoamState();
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dc42ece7f3a2e4de2a929f821c43ac67
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
using UnityEngine;
public class ImpactState : BaseState
{
public ImpactState() : base()
{
Debug.Log($"### {this} constructor");
}
protected override void Enter()
{
base.Enter();
Debug.Log($"### {this} Enter STAGE");
}
protected override void Update()
{
base.Update();
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b377ea7860c26439691096a2f8924177
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
using UnityEngine;
public class RecoverState : BaseState
{
public RecoverState() : base()
{
Debug.Log($"### {this} constructor");
}
protected override void Enter()
{
base.Enter();
Debug.Log($"### {this} Enter STAGE");
}
protected override void Update()
{
base.Update();
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aa57a200f3f314c0e9b66293926e7b4d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,40 @@
using UnityEngine;
public class RoamState : BaseState
{
public RoamState() : base()
{
Debug.Log($"### {this} constructor");
}
protected override void Enter()
{
base.Enter();
Debug.Log($"### {this} Enter STAGE");
// get the target point
}
protected override void Update()
{
base.Update();
// keeping roaming for a specific duration
// use a set of target points which would be placed on the arena,
// get one of the target point and then start roaming towards that point.
// if an enemy/player is found within a specific radius and in front of-
// -the player then go to the next state after acquiring the target-
// -(next state could be ChargeState)
Debug.Log($"### {this} Update STAGE");
}
protected override void Exit()
{
base.Exit();
Debug.Log($"### {this} Exit STAGE");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2b520dcd5d374b71b0fed8e64923e5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: