Add behaviourState + NeutralBehavior

This commit is contained in:
Crizomb 2025-01-13 17:41:17 +01:00
parent 7287be07a9
commit 5bca085548
13 changed files with 123 additions and 11 deletions

View file

@ -30,7 +30,6 @@ public class AttackHandler : MonoBehaviour
void Update()
{
_timer = _timer - Time.deltaTime;
Attack();
}
/// <summary>

View file

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

View file

@ -0,0 +1,47 @@
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(MinecraftUnit))]
[RequireComponent(typeof(MovementHandler))]
public abstract class AbstractBehaviour : MonoBehaviour
{
[SerializeField] private float pathFps = 1.0f;
[SerializeField] private float attackFps = 5.0f;
protected abstract void MoveAction();
protected abstract void AttackAction();
protected MinecraftUnit Unit;
void Start()
{
Unit = GetComponent<MinecraftUnit>();
StartCoroutine(attackUpdate());
StartCoroutine(pathUpdate());
}
// Path update and attack update can be expansive, so we don't do that every frame. We create custom update
// We create custom update at low fps to handle this without performance issues
private IEnumerator attackUpdate()
{
while (true)
{
AttackAction();
yield return new WaitForSeconds(1.0f/attackFps);
}
}
private IEnumerator pathUpdate()
{
while (true)
{
MoveAction();
yield return new WaitForSeconds(1.0f/pathFps);
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bca22bdff905462e49dd5f0d224452c6

View file

@ -0,0 +1,14 @@
using UnityEngine;
public class DefensiveBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
throw new System.NotImplementedException();
}
protected override void AttackAction()
{
throw new System.NotImplementedException();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4d7eb557429d0c73b8e60870d6370ff6

View file

@ -0,0 +1,14 @@
using UnityEngine;
public class NeutralBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
Unit.MovementHandler.MoveTowardsNearest();
}
protected override void AttackAction()
{
Unit.AttackHandler.Attack();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 794f919ac24609c05b9c690aaab19146

View file

@ -0,0 +1,14 @@
using UnityEngine;
public class OffensiveBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
throw new System.NotImplementedException();
}
protected override void AttackAction()
{
throw new System.NotImplementedException();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 02c5dcee842138a4ab3b5db250170c31

View file

@ -6,5 +6,6 @@ public static class GlobalsVariable
{
public static List<MinecraftUnit> AliveUnitsTeamA = new List<MinecraftUnit>();
public static List<MinecraftUnit> AliveUnitsTeamB = new List<MinecraftUnit>();
public static AbstractUnit QueenA;
public static AbstractUnit QueenB;
}

View file

@ -66,15 +66,6 @@ public class MovementHandler : MonoBehaviour
return closestMinecraftUnit;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
//MoveTowards(defaultMoveTarget.position);
MoveTowardsNearest();
}
}
public IEnumerator TakeImpulse(Vector3 impulse)
{