Add behaviourState + NeutralBehavior
This commit is contained in:
parent
7287be07a9
commit
5bca085548
13 changed files with 123 additions and 11 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bca22bdff905462e49dd5f0d224452c6
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d7eb557429d0c73b8e60870d6370ff6
|
14
Assets/Scripts/UnitScripts/BehaviorState/NeutralBehaviour.cs
Normal file
14
Assets/Scripts/UnitScripts/BehaviorState/NeutralBehaviour.cs
Normal 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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 794f919ac24609c05b9c690aaab19146
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 02c5dcee842138a4ab3b5db250170c31
|
Loading…
Add table
Add a link
Reference in a new issue