Revamp behaviours and add Crab.cs
This commit is contained in:
parent
6576747756
commit
acee983f6d
@ -9,23 +9,20 @@ GameObject:
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 592487110401094196}
|
||||
- component: {fileID: 592487110401094200}
|
||||
- component: {fileID: 592487110401094195}
|
||||
- component: {fileID: 592487110401094194}
|
||||
- component: {fileID: 592487110401094200}
|
||||
- component: {fileID: 3068808787720623988}
|
||||
- component: {fileID: 4248768674552437703}
|
||||
- component: {fileID: 592487110401094193}
|
||||
- component: {fileID: 3362493323285318061}
|
||||
- component: {fileID: 592487110401094199}
|
||||
- component: {fileID: 592487110401094198}
|
||||
- component: {fileID: 592487110401094204}
|
||||
- component: {fileID: 592487110401094197}
|
||||
- component: {fileID: 592487110401094203}
|
||||
- component: {fileID: 592487110401094201}
|
||||
- component: {fileID: 592487110401094202}
|
||||
- component: {fileID: 592487110401094205}
|
||||
- component: {fileID: 4248768674552437703}
|
||||
- component: {fileID: 3068808787720623988}
|
||||
- component: {fileID: 5951030530186631518}
|
||||
- component: {fileID: 2001250142692207685}
|
||||
- component: {fileID: 3845295542453471664}
|
||||
- component: {fileID: 8799261875116284856}
|
||||
- component: {fileID: 384731428535676825}
|
||||
m_Layer: 0
|
||||
m_Name: Enemy (Default Melee)
|
||||
m_Name: Enemy (Crab)
|
||||
m_TagString: Enemy
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -43,27 +40,10 @@ Transform:
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 1801310824674407730}
|
||||
- {fileID: 7620644064869685210}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &592487110401094200
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 978bec54408eb8f42a36fd68d7447f5a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CurrentBehavior: Nothing
|
||||
Anim: {fileID: 5375970501711434365}
|
||||
MoveSpeed: 1
|
||||
BehaviourTree: {fileID: 592487110401094199}
|
||||
Movement: {fileID: 4248768674552437703}
|
||||
Attacking: 0
|
||||
--- !u!50 &592487110401094195
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
@ -111,6 +91,58 @@ BoxCollider2D:
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &592487110401094200
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 978bec54408eb8f42a36fd68d7447f5a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
MoveSpeed: 1
|
||||
Movement: {fileID: 4248768674552437703}
|
||||
BehaviourDisplay: {fileID: 8912829886182716132}
|
||||
CurrentBehaviour: Nothing
|
||||
Attacking: 0
|
||||
--- !u!114 &3068808787720623988
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e796ba4c6f7efc449a10ed13ee42e34f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
BobbedTransform: {fileID: 1801310824674407730}
|
||||
BobbingMultiplier: 1
|
||||
BobbingGravity: 0.8
|
||||
BobbingLaunchSpeed: 0.12
|
||||
BobbingFrequency: 0
|
||||
BobbingDirection: {x: 0, y: 1}
|
||||
--- !u!114 &4248768674552437703
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Body: {fileID: 592487110401094195}
|
||||
Bobbing: {fileID: 3068808787720623988}
|
||||
Direction: {x: 0, y: 0}
|
||||
MaxSpeed: 2.5
|
||||
AccelerationSpeed: 10
|
||||
--- !u!114 &592487110401094193
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -143,7 +175,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
MaxHealth: 30
|
||||
CurrentHealth: 30
|
||||
--- !u!114 &592487110401094199
|
||||
--- !u!114 &5951030530186631518
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -152,15 +184,11 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: bbf2158cd27572e4599b4c813f555fd8, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 173be6658a5fcba49b9b1f1c91fa5f33, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Trigger: {fileID: 592487110401094201}
|
||||
TriggeredNodes:
|
||||
- {fileID: 592487110401094204}
|
||||
NotTriggeredNodes:
|
||||
- {fileID: 592487110401094198}
|
||||
--- !u!114 &592487110401094198
|
||||
Radius: 5
|
||||
--- !u!114 &2001250142692207685
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -169,12 +197,14 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 163f55033e69e2e4282c151e1a806bc6, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: f7e23822f429fcc46a8fd9163e68f332, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Behaviours:
|
||||
- {fileID: 592487110401094197}
|
||||
--- !u!114 &592487110401094204
|
||||
CurrentStatus:
|
||||
Target: {fileID: 0}
|
||||
CloseEnoughRadius: 1
|
||||
TargetPositionUpdateFrequency: 2
|
||||
--- !u!114 &3845295542453471664
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -183,13 +213,16 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 163f55033e69e2e4282c151e1a806bc6, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 3195d7385bc331f4296251042082af39, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Behaviours:
|
||||
- {fileID: 592487110401094205}
|
||||
- {fileID: 592487110401094202}
|
||||
--- !u!114 &592487110401094197
|
||||
CurrentStatus:
|
||||
AnimatableTransform: {fileID: 592487111173795460}
|
||||
MeleeRange: 1.3
|
||||
AttackAnimationLength: 0.1
|
||||
ReleaseAnimationLength: 0.25
|
||||
CooldownLength: 0.7
|
||||
--- !u!114 &8799261875116284856
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -206,7 +239,7 @@ MonoBehaviour:
|
||||
MinWalkingDistance: 1
|
||||
SubjectRadius: 0.7
|
||||
StopLength: 2
|
||||
--- !u!114 &592487110401094203
|
||||
--- !u!114 &384731428535676825
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -215,94 +248,10 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6e805202a073c5541acd3aa2bde26513, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: bb6b593ac1a60794d9a01585861cb6a1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Follow: {fileID: 592487110401094202}
|
||||
PlayerSighted: {fileID: 592487110401094201}
|
||||
--- !u!114 &592487110401094201
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 173be6658a5fcba49b9b1f1c91fa5f33, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Radius: 5
|
||||
--- !u!114 &592487110401094202
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f7e23822f429fcc46a8fd9163e68f332, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CurrentStatus:
|
||||
Target: {fileID: 0}
|
||||
CloseEnoughRadius: 1
|
||||
TargetPositionUpdateFrequency: 2
|
||||
--- !u!114 &592487110401094205
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3195d7385bc331f4296251042082af39, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CurrentStatus:
|
||||
Follow: {fileID: 592487110401094202}
|
||||
AnimatableTransform: {fileID: 592487111173795460}
|
||||
MeleeRange: 1.3
|
||||
AttackAnimationLength: 0.1
|
||||
ReleaseAnimationLength: 0.25
|
||||
CooldownLength: 0.7
|
||||
--- !u!114 &4248768674552437703
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Body: {fileID: 592487110401094195}
|
||||
Bobbing: {fileID: 3068808787720623988}
|
||||
Direction: {x: 0, y: 0}
|
||||
MaxSpeed: 2.5
|
||||
AccelerationSpeed: 10
|
||||
--- !u!114 &3068808787720623988
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 592487110401094192}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e796ba4c6f7efc449a10ed13ee42e34f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
BobbedTransform: {fileID: 1801310824674407730}
|
||||
BobbingMultiplier: 1
|
||||
BobbingGravity: 0.8
|
||||
BobbingLaunchSpeed: 0.12
|
||||
BobbingFrequency: 0
|
||||
BobbingDirection: {x: 0, y: 1}
|
||||
Anim: {fileID: 5375970501711434365}
|
||||
--- !u!1 &592487111066334293
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -435,6 +384,98 @@ Transform:
|
||||
m_Father: {fileID: 1801310824674407730}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &5800104731865852645
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7620644064869685210}
|
||||
- component: {fileID: 1046432343665673627}
|
||||
- component: {fileID: 8912829886182716132}
|
||||
m_Layer: 0
|
||||
m_Name: Behaviour Display
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
--- !u!4 &7620644064869685210
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5800104731865852645}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0.5, z: 0}
|
||||
m_LocalScale: {x: 0.15, y: 0.15, z: 0.15}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 592487110401094196}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!23 &1046432343665673627
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5800104731865852645}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10100, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
--- !u!102 &8912829886182716132
|
||||
TextMesh:
|
||||
serializedVersion: 3
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5800104731865852645}
|
||||
m_Text: Hello World
|
||||
m_OffsetZ: 0
|
||||
m_CharacterSize: 1
|
||||
m_LineSpacing: 1
|
||||
m_Anchor: 7
|
||||
m_Alignment: 0
|
||||
m_TabSize: 4
|
||||
m_FontSize: 0
|
||||
m_FontStyle: 0
|
||||
m_RichText: 1
|
||||
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_Color:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
--- !u!1 &7558423332818417733
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
@ -13959,6 +13959,11 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5800104731865852645, guid: 1a0e05447c8cf2a4fa9b9dc697884a66,
|
||||
type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 1a0e05447c8cf2a4fa9b9dc697884a66, type: 3}
|
||||
--- !u!4 &458203838 stripped
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35f2aaa7cb89b4142bf7d3fe64bbc9eb
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -3,11 +3,21 @@ using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI {
|
||||
public abstract class AIBehaviour : MonoBehaviour {
|
||||
[HideInInspector]
|
||||
public string CurrentStatus = "";
|
||||
|
||||
/* Returns whether or not Execute() should be called this frame */
|
||||
public abstract bool CanBehave(Enemy subject);
|
||||
/* Returns whether or not this was a blocking behaviour, ie. should the behaviour processing be stopped here */
|
||||
public abstract bool Execute(Enemy subject);
|
||||
public abstract bool CanBehave();
|
||||
|
||||
public abstract void Execute();
|
||||
|
||||
/* Calls Execute() if CanBehave() returns true, and then returns the resultof CanBehave() */
|
||||
public bool TryExecute() {
|
||||
bool Result = CanBehave();
|
||||
if (Result) {
|
||||
Execute();
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
using System;
|
||||
using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI {
|
||||
[Serializable]
|
||||
[Obsolete]
|
||||
public class BehaviourBranch : BehaviourNode {
|
||||
public Trigger Trigger;
|
||||
// FIXME: Change these from arrays to just single ones
|
||||
// BehaviourLeaf already has the capability to have multiple behaviours
|
||||
public BehaviourNode[] TriggeredNodes;
|
||||
public BehaviourNode[] NotTriggeredNodes;
|
||||
|
||||
private String MostRecentExecution;
|
||||
|
||||
/* Returns true if any action was taken. */
|
||||
public override bool Execute(Enemy subject) {
|
||||
if (Trigger != null && Trigger.IsTriggered(subject)) {
|
||||
foreach (BehaviourNode Node in TriggeredNodes) {
|
||||
if (Node.Execute(subject)) {
|
||||
MostRecentExecution = Node.GetExecutedName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (BehaviourNode Node in NotTriggeredNodes) {
|
||||
if (Node.Execute(subject)) {
|
||||
MostRecentExecution = Node.GetExecutedName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GetExecutedName() {
|
||||
return MostRecentExecution;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI {
|
||||
[Serializable]
|
||||
[Obsolete]
|
||||
public class BehaviourLeaf : BehaviourNode {
|
||||
public AIBehaviour[] Behaviours;
|
||||
public bool IsLeaf { get { return Behaviours.Length > 0; } }
|
||||
|
||||
private string ExecutedBehaviours = "";
|
||||
|
||||
/* Returns true if any action was taken. */
|
||||
public override bool Execute(Enemy subject) {
|
||||
bool Acted = false;
|
||||
ExecutedBehaviours = "";
|
||||
foreach (AIBehaviour Behaviour in Behaviours) {
|
||||
if (Behaviour.CanBehave(subject)) {
|
||||
ExecutedBehaviours += Behaviour.GetType().Name + ":" + Behaviour.CurrentStatus + ", ";
|
||||
if (Behaviour.Execute(subject)) {
|
||||
return true;
|
||||
} else {
|
||||
Acted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Acted;
|
||||
}
|
||||
|
||||
public override string GetExecutedName() {
|
||||
return ExecutedBehaviours;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 163f55033e69e2e4282c151e1a806bc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI {
|
||||
[Serializable]
|
||||
[Obsolete]
|
||||
public abstract class BehaviourNode : MonoBehaviour {
|
||||
/* Returns true if any action was taken. */
|
||||
public abstract bool Execute(Enemy subject);
|
||||
|
||||
public abstract string GetExecutedName();
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29a12e34882786345a46452c9e98e2a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -2,16 +2,21 @@
|
||||
using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
[RequireComponent(typeof(Enemy))]
|
||||
public class Follow : AIBehaviour {
|
||||
public Transform Target;
|
||||
public float CloseEnoughRadius;
|
||||
public float TargetPositionUpdateFrequency = 5f;
|
||||
|
||||
private Enemy Enemy;
|
||||
private Vector2 TargetPosition;
|
||||
private float TargetPositionUpdateCooldown;
|
||||
|
||||
private void Update() {
|
||||
private void Start() {
|
||||
Enemy = GetComponent<Enemy>();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if (Target != null && TargetPositionUpdateCooldown <= 0) {
|
||||
TargetPositionUpdateCooldown = 1.0f / TargetPositionUpdateFrequency;
|
||||
TargetPosition = Target.position;
|
||||
@ -22,23 +27,26 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanBehave(Enemy subject) {
|
||||
public override bool CanBehave() {
|
||||
return Target != null;
|
||||
}
|
||||
|
||||
public override bool Execute(Enemy subject) {
|
||||
public override void Execute() {
|
||||
if (Target != null) {
|
||||
Vector2 position = subject.transform.position;
|
||||
Vector2 position = Enemy.transform.position;
|
||||
Vector2 delta = TargetPosition - position;
|
||||
if (delta.magnitude > CloseEnoughRadius) {
|
||||
delta -= delta.normalized * CloseEnoughRadius;
|
||||
subject.StartMovingTo(position + delta);
|
||||
return true;
|
||||
Enemy.StartMovingTo(position + delta);
|
||||
CurrentStatus = "Approach";
|
||||
} else {
|
||||
Enemy.StopMoving();
|
||||
CurrentStatus = "CloseEnough";
|
||||
}
|
||||
} else {
|
||||
Enemy.StopMoving();
|
||||
CurrentStatus = "NoTarget";
|
||||
}
|
||||
|
||||
subject.StopMoving();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ using Saltosion.OneWeapon.Player;
|
||||
using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
[RequireComponent(typeof(Follow), typeof(Enemy))]
|
||||
public class MeleeAttackFollowed : AIBehaviour {
|
||||
public Follow Follow;
|
||||
[Tooltip("This should be at 0,0,0 locally by default.")]
|
||||
public Transform AnimatableTransform;
|
||||
public float MeleeRange;
|
||||
@ -12,12 +12,17 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
public float ReleaseAnimationLength;
|
||||
public float CooldownLength;
|
||||
|
||||
private Enemy Enemy;
|
||||
private Follow Follow;
|
||||
private bool AttackHit;
|
||||
private float AnimationProgress;
|
||||
private float CooldownProgress;
|
||||
private Vector3 LocalOrigin;
|
||||
|
||||
private void Start() {
|
||||
Enemy = GetComponent<Enemy>();
|
||||
Follow = GetComponent<Follow>();
|
||||
|
||||
if (AnimatableTransform.localPosition.magnitude != 0) {
|
||||
Debug.LogWarning($"{name} has an animated melee attack, and AnimatableTransform is not at local origin!");
|
||||
}
|
||||
@ -39,20 +44,20 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanBehave(Enemy subject) {
|
||||
bool CanBehave = Follow.Target != null && (Follow.Target.position - subject.transform.position).magnitude <= MeleeRange;
|
||||
public override bool CanBehave() {
|
||||
bool CanBehave = Follow.Target != null && (Follow.Target.position - Enemy.transform.position).magnitude <= MeleeRange;
|
||||
if (!CanBehave) {
|
||||
subject.Attacking = false;
|
||||
Enemy.Attacking = false;
|
||||
}
|
||||
return CanBehave;
|
||||
}
|
||||
|
||||
public override bool Execute(Enemy subject) {
|
||||
public override void Execute() {
|
||||
if (CooldownProgress > 0) {
|
||||
subject.Attacking = false;
|
||||
return false;
|
||||
Enemy.Attacking = false;
|
||||
return;
|
||||
} else {
|
||||
subject.Attacking = true;
|
||||
Enemy.Attacking = true;
|
||||
}
|
||||
|
||||
Vector2 Root = AnimatableTransform.parent.position + LocalOrigin;
|
||||
@ -76,8 +81,6 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void TakeFunDamage() {
|
||||
|
@ -2,31 +2,34 @@
|
||||
using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
[RequireComponent(typeof(Enemy))]
|
||||
public class Wander : AIBehaviour {
|
||||
public float WalkingDistance;
|
||||
public float MinWalkingDistance;
|
||||
public float SubjectRadius;
|
||||
public float StopLength;
|
||||
|
||||
private Enemy Enemy;
|
||||
private Vector2 Target;
|
||||
private float StopTime;
|
||||
private bool Stopped = true;
|
||||
|
||||
private void Start() {
|
||||
Enemy = GetComponent<Enemy>();
|
||||
StopTime = Time.time;
|
||||
}
|
||||
|
||||
public override bool CanBehave(Enemy subject) {
|
||||
public override bool CanBehave() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Execute(Enemy subject) {
|
||||
Vector2 SubjectPosition = (Vector2)subject.transform.position;
|
||||
public override void Execute() {
|
||||
Vector2 SubjectPosition = (Vector2)Enemy.transform.position;
|
||||
if ((Target - SubjectPosition).magnitude > SubjectRadius) {
|
||||
subject.StartMovingTo(Target);
|
||||
Enemy.StartMovingTo(Target);
|
||||
CurrentStatus = "Move";
|
||||
Stopped = false;
|
||||
return true;
|
||||
return;
|
||||
} else if (!Stopped) {
|
||||
Stopped = true;
|
||||
StopTime = Time.time;
|
||||
@ -39,7 +42,7 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
while ((Target - SubjectPosition).magnitude <= SubjectRadius) {
|
||||
i++;
|
||||
if (i > 100) {
|
||||
Debug.LogWarning($"Wander behaviour took over 100 tries to find a wander position, '{subject.name}' is stuck!");
|
||||
Debug.LogWarning($"Wander behaviour took over 100 tries to find a wander position, '{Enemy.name}' is stuck!");
|
||||
break;
|
||||
}
|
||||
float Distance = MinWalkingDistance + (WalkingDistance - MinWalkingDistance) * Random.value;
|
||||
@ -54,8 +57,7 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
|
||||
CurrentStatus = "Stop";
|
||||
}
|
||||
|
||||
subject.StopMoving();
|
||||
return false;
|
||||
Enemy.StopMoving();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI {
|
||||
[Obsolete]
|
||||
[RequireComponent(typeof(AI.Behaviours.Follow), typeof(AI.Triggers.EnemySighted))]
|
||||
public class EnemyFollower : MonoBehaviour {
|
||||
public AI.Behaviours.Follow Follow;
|
||||
public AI.Triggers.EnemySighted EnemySighted;
|
||||
|
||||
private void Update() {
|
||||
if (EnemySighted.ClosestEnemy == null) {
|
||||
Follow.Target = null;
|
||||
} else {
|
||||
Follow.Target = EnemySighted.ClosestEnemy.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c119fe08cf5d2da43a8d58e6439195b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI {
|
||||
[RequireComponent(typeof(AI.Behaviours.Follow), typeof(AI.Triggers.PlayerSighted))]
|
||||
[Obsolete]
|
||||
public class PlayerFollower : MonoBehaviour {
|
||||
public AI.Behaviours.Follow Follow;
|
||||
public AI.Triggers.PlayerSighted PlayerSighted;
|
||||
|
||||
private void Update() {
|
||||
if (PlayerSighted.Player == null) {
|
||||
Follow.Target = null;
|
||||
} else {
|
||||
Follow.Target = PlayerSighted.Player.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e805202a073c5541acd3aa2bde26513
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -3,6 +3,6 @@ using Saltosion.OneWeapon.Enemies;
|
||||
|
||||
namespace Saltosion.OneWeapon.AI {
|
||||
public abstract class Trigger : MonoBehaviour {
|
||||
public abstract bool IsTriggered(Enemy subject);
|
||||
public abstract bool IsTriggered();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace Saltosion.OneWeapon.AI.Triggers {
|
||||
public float Radius;
|
||||
public Enemy ClosestEnemy { get; private set; }
|
||||
|
||||
public override bool IsTriggered(Enemy subject) {
|
||||
public override bool IsTriggered() {
|
||||
ClosestEnemy = Util.GetClosestTo<Enemy>(transform, Radius);
|
||||
return ClosestEnemy != null;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Saltosion.OneWeapon.AI.Triggers {
|
||||
public float Radius;
|
||||
public PlayerController Player { get; private set; }
|
||||
|
||||
public override bool IsTriggered(Enemy subject) {
|
||||
public override bool IsTriggered() {
|
||||
Player = Util.GetClosestTo<PlayerController>(transform, Radius, true);
|
||||
return Player != null;
|
||||
}
|
||||
|
51
Assets/Scripts/Enemies/Crab.cs
Normal file
51
Assets/Scripts/Enemies/Crab.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Saltosion.OneWeapon.AI.Behaviours;
|
||||
using Saltosion.OneWeapon.AI.Triggers;
|
||||
|
||||
namespace Saltosion.OneWeapon.Enemies {
|
||||
[RequireComponent(typeof(Enemy))]
|
||||
[RequireComponent(typeof(PlayerSighted))]
|
||||
[RequireComponent(typeof(Wander))]
|
||||
[RequireComponent(typeof(Follow))]
|
||||
[RequireComponent(typeof(MeleeAttackFollowed))]
|
||||
public class Crab : MonoBehaviour {
|
||||
public Animator Anim;
|
||||
|
||||
private Enemy Enemy;
|
||||
private PlayerSighted FollowTrigger;
|
||||
private Wander WanderBehaviour;
|
||||
private Follow FollowBehaviour;
|
||||
private MeleeAttackFollowed MeleeBehaviour;
|
||||
|
||||
private void Start() {
|
||||
Enemy = GetComponent<Enemy>();
|
||||
FollowTrigger = GetComponent<PlayerSighted>();
|
||||
WanderBehaviour = GetComponent<Wander>();
|
||||
FollowBehaviour = GetComponent<Follow>();
|
||||
MeleeBehaviour = GetComponent<MeleeAttackFollowed>();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
Enemy.CurrentBehaviour = "Nothing";
|
||||
if (FollowTrigger.IsTriggered()) {
|
||||
FollowBehaviour.Target = FollowTrigger.Player.transform;
|
||||
if (MeleeBehaviour.TryExecute()) {
|
||||
Enemy.CurrentBehaviour = "Melee:" + MeleeBehaviour.CurrentStatus;
|
||||
} else if (FollowBehaviour.TryExecute()) {
|
||||
Enemy.CurrentBehaviour = "Follow:" + FollowBehaviour.CurrentStatus;
|
||||
}
|
||||
} else if (WanderBehaviour.TryExecute()) {
|
||||
Enemy.CurrentBehaviour = "Wander:" + WanderBehaviour.CurrentStatus;
|
||||
}
|
||||
|
||||
if (Enemy.Attacking) {
|
||||
Anim.Play("Attack");
|
||||
} else {
|
||||
Anim.Play("Walk");
|
||||
}
|
||||
Anim.SetFloat("Speed", Enemy.Movement.SpeedPercentage);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbf2158cd27572e4599b4c813f555fd8
|
||||
guid: bb6b593ac1a60794d9a01585861cb6a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -6,15 +6,11 @@ using Saltosion.OneWeapon.Utils;
|
||||
namespace Saltosion.OneWeapon.Enemies {
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class Enemy : MonoBehaviour {
|
||||
[Header("Debug Info")]
|
||||
public string CurrentBehavior = "Nothing";
|
||||
[Header("Graphics")]
|
||||
public Animator Anim;
|
||||
[Header("Stats")]
|
||||
public float MoveSpeed;
|
||||
[Header("Behaviour")]
|
||||
public BehaviourNode BehaviourTree;
|
||||
public AcceleratedMovement Movement;
|
||||
[Header("Debug Info")]
|
||||
public TextMesh BehaviourDisplay;
|
||||
public string CurrentBehaviour = "Nothing";
|
||||
|
||||
[HideInInspector]
|
||||
public bool Attacking;
|
||||
@ -25,20 +21,21 @@ namespace Saltosion.OneWeapon.Enemies {
|
||||
|
||||
private void Start() {
|
||||
Body = GetComponent<Rigidbody2D>();
|
||||
BehaviourDisplay.GetComponent<MeshRenderer>().sortingLayerName = "Debug Text";
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
BehaviourTree.Execute(this);
|
||||
CurrentBehavior = BehaviourTree.GetExecutedName();
|
||||
|
||||
if (Attacking) {
|
||||
Anim.Play("Attack");
|
||||
} else if (Body.velocity.magnitude > 0.1) {
|
||||
Anim.Play("Walk");
|
||||
} else {
|
||||
Anim.Play("Walk");
|
||||
bool DisplayDebugInfo = false;
|
||||
if (Application.isEditor) {
|
||||
Collider2D Hit = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
|
||||
if (Hit != null && Hit.attachedRigidbody == Body) {
|
||||
DisplayDebugInfo = true;
|
||||
}
|
||||
}
|
||||
BehaviourDisplay.gameObject.SetActive(DisplayDebugInfo);
|
||||
if (DisplayDebugInfo) {
|
||||
BehaviourDisplay.text = CurrentBehaviour;
|
||||
}
|
||||
Anim.SetFloat("Speed", Movement.SpeedPercentage);
|
||||
}
|
||||
|
||||
private void FixedUpdate() {
|
||||
|
@ -7,7 +7,8 @@ namespace Saltosion.OneWeapon.Utils {
|
||||
float LowestDistance = float.PositiveInfinity;
|
||||
T FoundTarget = null;
|
||||
foreach (Collider2D Collider in NearbyColliders) {
|
||||
if (Collider.gameObject == Searcher.gameObject) {
|
||||
if (Collider.gameObject == Searcher.gameObject ||
|
||||
(Collider.attachedRigidbody != null && Collider.attachedRigidbody.gameObject == Searcher.gameObject)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -64,3 +64,6 @@ TagManager:
|
||||
- name: Blood Particles (On characters)
|
||||
uniqueID: 3258686711
|
||||
locked: 0
|
||||
- name: Debug Text
|
||||
uniqueID: 1627382605
|
||||
locked: 0
|
||||
|
Loading…
Reference in New Issue
Block a user