Add behaviourState + NeutralBehavior
This commit is contained in:
parent
7287be07a9
commit
5bca085548
13 changed files with 123 additions and 11 deletions
|
@ -12,6 +12,7 @@ GameObject:
|
|||
- component: {fileID: 1284886913308718791}
|
||||
- component: {fileID: 7841837150169133400}
|
||||
- component: {fileID: 3280843376750909586}
|
||||
- component: {fileID: 1854268353119403178}
|
||||
- component: {fileID: 5811210244409818000}
|
||||
- component: {fileID: 1085507300097694875}
|
||||
- component: {fileID: 2572766376840025726}
|
||||
|
@ -122,6 +123,20 @@ Rigidbody:
|
|||
m_Interpolate: 0
|
||||
m_Constraints: 80
|
||||
m_CollisionDetection: 1
|
||||
--- !u!114 &1854268353119403178
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2076979688870881298}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 794f919ac24609c05b9c690aaab19146, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
pathFps: 1
|
||||
attackFps: 5
|
||||
--- !u!195 &5811210244409818000
|
||||
NavMeshAgent:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -181,6 +196,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
price: 0
|
||||
<IsTeamA>k__BackingField: 1
|
||||
<IsQueen>k__BackingField: 0
|
||||
<Body>k__BackingField: {fileID: 3280843376750909586}
|
||||
<HealthHandler>k__BackingField: {fileID: 8213395333053285225}
|
||||
<AttackHandler>k__BackingField: {fileID: 8908285060348773052}
|
||||
|
|
|
@ -30,7 +30,6 @@ public class AttackHandler : MonoBehaviour
|
|||
void Update()
|
||||
{
|
||||
_timer = _timer - Time.deltaTime;
|
||||
Attack();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
8
Assets/Scripts/UnitScripts/BehaviorState.meta
Normal file
8
Assets/Scripts/UnitScripts/BehaviorState.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9d27c54e796078de08e2819b80f8cbcd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue