Avoid FindObjectsOfType
This commit is contained in:
parent
cc5507a2a5
commit
c19966a4d2
@ -134,17 +134,36 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3}
|
m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
--- !u!114 &344214379 stripped
|
--- !u!1 &615088692
|
||||||
MonoBehaviour:
|
GameObject:
|
||||||
m_CorrespondingSourceObject: {fileID: 344214379, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
m_ObjectHideFlags: 0
|
||||||
m_PrefabInstance: {fileID: 1551362086}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 0}
|
serializedVersion: 6
|
||||||
m_Enabled: 1
|
m_Component:
|
||||||
m_EditorHideFlags: 0
|
- component: {fileID: 615088693}
|
||||||
m_Script: {fileID: 11500000, guid: a53670f9cd399ea4a8ae3ed81b923aa8, type: 3}
|
m_Layer: 0
|
||||||
m_Name:
|
m_Name: Gladiators
|
||||||
m_EditorClassIdentifier:
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &615088693
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 615088692}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 4
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1001 &647315810
|
--- !u!1001 &647315810
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -215,11 +234,47 @@ Transform:
|
|||||||
m_CorrespondingSourceObject: {fileID: 1214567908930553594, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
m_CorrespondingSourceObject: {fileID: 1214567908930553594, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
m_PrefabInstance: {fileID: 1942557562}
|
m_PrefabInstance: {fileID: 1942557562}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
--- !u!1 &1186739821 stripped
|
--- !u!114 &836972483 stripped
|
||||||
GameObject:
|
MonoBehaviour:
|
||||||
m_CorrespondingSourceObject: {fileID: 1844274959428875625, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
m_CorrespondingSourceObject: {fileID: 344214379, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
||||||
m_PrefabInstance: {fileID: 1551362086}
|
m_PrefabInstance: {fileID: 1551362086}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: a53670f9cd399ea4a8ae3ed81b923aa8, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!1 &851716833
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 851716834}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Minions
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &851716834
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 851716833}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 5
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1001 &1359990804
|
--- !u!1001 &1359990804
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -227,18 +282,26 @@ PrefabInstance:
|
|||||||
m_Modification:
|
m_Modification:
|
||||||
m_TransformParent: {fileID: 0}
|
m_TransformParent: {fileID: 0}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
|
propertyPath: <graveyard>k__BackingField
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1621960505}
|
||||||
|
- target: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
|
propertyPath: <minionParent>k__BackingField
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 851716834}
|
||||||
|
- target: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
|
propertyPath: <gladiatorParent>k__BackingField
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 615088693}
|
||||||
- target: {fileID: 1359990806, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
- target: {fileID: 1359990806, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
propertyPath: gameTimer
|
propertyPath: gameTimer
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 344214379}
|
objectReference: {fileID: 836972483}
|
||||||
- target: {fileID: 1359990806, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
- target: {fileID: 1359990806, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
propertyPath: startPrompt
|
propertyPath: startPrompt
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1186739821}
|
objectReference: {fileID: 1551362088}
|
||||||
- target: {fileID: 4164153230343464235, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
|
||||||
propertyPath: globalCamera
|
|
||||||
value:
|
|
||||||
objectReference: {fileID: 1557338110}
|
|
||||||
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 1
|
value: 1
|
||||||
@ -289,7 +352,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
--- !u!114 &1359990809 stripped
|
--- !u!114 &1359990806 stripped
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_CorrespondingSourceObject: {fileID: 1359990806, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
m_CorrespondingSourceObject: {fileID: 1359990806, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
m_PrefabInstance: {fileID: 1359990804}
|
m_PrefabInstance: {fileID: 1359990804}
|
||||||
@ -427,16 +490,62 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 81a29b049c6380f4abb3c18ed121efcd, type: 3}
|
m_Script: {fileID: 11500000, guid: 81a29b049c6380f4abb3c18ed121efcd, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!1 &1551362088 stripped
|
||||||
|
GameObject:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 1844274959428875625, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1551362086}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!1 &1551362089 stripped
|
||||||
|
GameObject:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 763564871199756608, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1551362086}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
--- !u!1 &1557338110 stripped
|
--- !u!1 &1557338110 stripped
|
||||||
GameObject:
|
GameObject:
|
||||||
m_CorrespondingSourceObject: {fileID: 3328484984159178892, guid: f7f5d2b1228d13f4d9015073aced3e81, type: 3}
|
m_CorrespondingSourceObject: {fileID: 3328484984159178892, guid: f7f5d2b1228d13f4d9015073aced3e81, type: 3}
|
||||||
m_PrefabInstance: {fileID: 647315810}
|
m_PrefabInstance: {fileID: 647315810}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
--- !u!1 &1596616199 stripped
|
--- !u!1 &1621960504
|
||||||
GameObject:
|
GameObject:
|
||||||
m_CorrespondingSourceObject: {fileID: 763564871199756608, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
m_ObjectHideFlags: 0
|
||||||
m_PrefabInstance: {fileID: 1551362086}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1621960505}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Graveyard
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1621960505
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1621960504}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 6
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &1692771147 stripped
|
||||||
|
MonoBehaviour:
|
||||||
|
m_CorrespondingSourceObject: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1359990804}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 72794012913ccd840a73788b90573212, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1001 &1942557562
|
--- !u!1001 &1942557562
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -519,11 +628,11 @@ PrefabInstance:
|
|||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1359990809}
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[15].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
propertyPath: m_ActionEvents.Array.data[15].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1359990809}
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[16].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
propertyPath: m_ActionEvents.Array.data[16].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
||||||
value:
|
value:
|
||||||
@ -599,11 +708,11 @@ PrefabInstance:
|
|||||||
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: safeZonePrompt
|
propertyPath: safeZonePrompt
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1596616199}
|
objectReference: {fileID: 1551362089}
|
||||||
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: gameFlowManager
|
propertyPath: gameFlowManager
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1359990809}
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 1214567908930553593, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553593, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_Name
|
propertyPath: m_Name
|
||||||
value: Vampire
|
value: Vampire
|
||||||
@ -652,10 +761,22 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553595, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_SortingOrder
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1967503440015794769, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: arena
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1692771147}
|
||||||
|
- target: {fileID: 1967503440015794769, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: minionParent
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 851716834}
|
||||||
- target: {fileID: 1967503440015794769, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1967503440015794769, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: gameFlowManager
|
propertyPath: gameFlowManager
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1359990809}
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: healthBar
|
propertyPath: healthBar
|
||||||
value:
|
value:
|
||||||
@ -667,7 +788,7 @@ PrefabInstance:
|
|||||||
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: gameFlowManager
|
propertyPath: gameFlowManager
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1359990809}
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: <Health>k__BackingField
|
propertyPath: <Health>k__BackingField
|
||||||
value: 100
|
value: 100
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 6a79b85d54b2044408b5b5a2ad3ae57d
|
guid: f81c8dca006ae164792c46bced318c31
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
|
|||||||
@ -1,17 +1,16 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
public class AIEntity : Entity
|
public class AIEntity : Entity
|
||||||
{
|
{
|
||||||
[FormerlySerializedAs("stats")] [SerializeField]
|
[FormerlySerializedAs("stats")] [SerializeField]
|
||||||
public AIStats AIStats = null!;
|
public AIStats AIStats = null!;
|
||||||
BaseState currentState = null!;
|
BaseState currentState = null!;
|
||||||
public string[] enemies {get; protected set; }
|
|
||||||
|
|
||||||
override protected void Start(){
|
public EntityFlag enemies {get; protected set; }
|
||||||
|
|
||||||
|
override protected void Start(){
|
||||||
base.Start();
|
base.Start();
|
||||||
currentState = CreateInitialState();
|
currentState = CreateInitialState();
|
||||||
currentState.EnterState();
|
currentState.EnterState();
|
||||||
@ -31,7 +30,12 @@ public class AIEntity : Entity
|
|||||||
|
|
||||||
void OnDrawGizmos() => currentState?.OnDrawGizmos();
|
void OnDrawGizmos() => currentState?.OnDrawGizmos();
|
||||||
|
|
||||||
void SwitchState(BaseState newState) {
|
protected override void OnDied() {
|
||||||
|
base.OnDied();
|
||||||
|
transform.SetParent(arena.graveyard);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitchState(BaseState newState) {
|
||||||
currentState.LeaveState();
|
currentState.LeaveState();
|
||||||
currentState = newState;
|
currentState = newState;
|
||||||
newState.EnterState();
|
newState.EnterState();
|
||||||
@ -40,22 +44,15 @@ public class AIEntity : Entity
|
|||||||
protected virtual BaseState CreateInitialState() => new FindTargetState(this);
|
protected virtual BaseState CreateInitialState() => new FindTargetState(this);
|
||||||
|
|
||||||
//Looks into enemy name list to see if the other is targetable
|
//Looks into enemy name list to see if the other is targetable
|
||||||
virtual protected bool IsTargetable(Entity other){
|
virtual protected bool IsTargetable(Entity other) {
|
||||||
foreach (string name in enemies){
|
return enemies.HasFlag(other.entityType) && other.IsAlive();
|
||||||
if(other.entityName == name && other.IsAlive()){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public bool TakeDamage(float amount, Entity other){
|
override public bool TakeDamage(float amount, Entity other){
|
||||||
Entity currTargetEntity = GetTarget().GetComponent<Entity>();
|
//TODO Should we warn if target is null here?
|
||||||
if(!(currTargetEntity is null)){
|
if (target != null && target.GetComponent<VampireEntity>() is {})
|
||||||
if(currTargetEntity.entityName == "Vampire")
|
target = other.transform;
|
||||||
SetTarget(other.transform);
|
|
||||||
}
|
|
||||||
return base.TakeDamage(amount, other);
|
return base.TakeDamage(amount, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +72,7 @@ public class AIEntity : Entity
|
|||||||
if(!entity.IsAlive()){
|
if(!entity.IsAlive()){
|
||||||
return new DeadState(entity);
|
return new DeadState(entity);
|
||||||
}
|
}
|
||||||
Entity targetEntity = entity.GetTarget().GetComponent<Entity>();
|
Entity targetEntity = entity.target.GetComponent<Entity>();
|
||||||
if(targetEntity != null){
|
if(targetEntity != null){
|
||||||
if(targetEntity.IsAlive()){//target is alive, keep chasing it
|
if(targetEntity.IsAlive()){//target is alive, keep chasing it
|
||||||
return null;
|
return null;
|
||||||
@ -87,9 +84,8 @@ public class AIEntity : Entity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override BaseState? FixedUpdateState(){
|
public override BaseState? FixedUpdateState(){
|
||||||
Transform target = entity.GetTarget();
|
entity.direction = Vector3.RotateTowards(entity.direction, (entity.target.position - entity.transform.position), entity.rotSpeed*Time.fixedDeltaTime, 0.0f);
|
||||||
entity.direction = Vector3.RotateTowards(entity.direction, (target.position - entity.transform.position), entity.rotSpeed*Time.fixedDeltaTime, 0.0f);
|
if(entity.IsTargetable(entity.target.GetComponent<Entity>())){
|
||||||
if(entity.IsTargetable(entity.GetTarget().GetComponent<Entity>())){
|
|
||||||
if(!entity.IsInAttackRange()){
|
if(!entity.IsInAttackRange()){
|
||||||
entity.rb.MovePosition(entity.transform.position + entity.direction * entity.movementSpeed * Time.fixedDeltaTime);
|
entity.rb.MovePosition(entity.transform.position + entity.direction * entity.movementSpeed * Time.fixedDeltaTime);
|
||||||
}else{
|
}else{
|
||||||
@ -112,21 +108,21 @@ public class AIEntity : Entity
|
|||||||
if(!entity.IsAlive()){
|
if(!entity.IsAlive()){
|
||||||
return new DeadState(entity);
|
return new DeadState(entity);
|
||||||
}
|
}
|
||||||
Entity[] entities = FindObjectsOfType<Entity>();
|
|
||||||
|
Transform entityParent = entity.entityType == EntityFlag.Gladiator ? entity.arena.minionParent : entity.arena.gladiatorParent;
|
||||||
float lastDist = float.MaxValue;
|
float lastDist = float.MaxValue;
|
||||||
Entity chosenEntity = null!;
|
Transform chosenEntity = null!;
|
||||||
foreach (Entity other in entities){// Find the closest entity
|
foreach (Transform other in entityParent){// Find the closest entity
|
||||||
if(entity.IsTargetable(other)){
|
float distance = Vector2.Distance(other.position, entity.transform.position);
|
||||||
float distance = Vector2.Distance(other.transform.position, entity.transform.position);
|
if(distance < lastDist){
|
||||||
if(distance < lastDist){
|
lastDist = distance;
|
||||||
lastDist = distance;
|
chosenEntity = other;
|
||||||
chosenEntity = other;
|
if(lastDist <= entity.AIStats.closeEnough)break;
|
||||||
if(lastDist <= entity.AIStats.closeEnough)break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chosenEntity != null){
|
if(chosenEntity != null){
|
||||||
entity.SetTarget(chosenEntity.transform);
|
entity.target = chosenEntity;
|
||||||
return new SeekState(entity);
|
return new SeekState(entity);
|
||||||
}else{
|
}else{
|
||||||
if(roamPosition == new Vector3()) roamPosition = entity.AIStats.getRandomRoamPositon();
|
if(roamPosition == new Vector3()) roamPosition = entity.AIStats.getRandomRoamPositon();
|
||||||
@ -172,7 +168,7 @@ public class AIEntity : Entity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private BaseState? Attack(){
|
private BaseState? Attack(){
|
||||||
Entity targetEntity = entity.GetTarget().GetComponent<Entity>();
|
Entity targetEntity = entity.target.GetComponent<Entity>();
|
||||||
if(targetEntity != null){
|
if(targetEntity != null){
|
||||||
targetEntity.TakeDamage(entity.attackDmg, entity);
|
targetEntity.TakeDamage(entity.attackDmg, entity);
|
||||||
bool isTargetAlive = targetEntity.IsAlive();
|
bool isTargetAlive = targetEntity.IsAlive();
|
||||||
|
|||||||
@ -15,7 +15,6 @@ public class Arena : MonoBehaviour {
|
|||||||
[SerializeField] [Required]
|
[SerializeField] [Required]
|
||||||
GameFlowManager gameFlowManager = null!;
|
GameFlowManager gameFlowManager = null!;
|
||||||
|
|
||||||
//TODO probably add initial direction too
|
|
||||||
//TODO Add some kind of "MinLength(1)" attribute
|
//TODO Add some kind of "MinLength(1)" attribute
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GladiatorEntrance[] spawners = null!;
|
GladiatorEntrance[] spawners = null!;
|
||||||
@ -24,6 +23,15 @@ public class Arena : MonoBehaviour {
|
|||||||
[SerializeField] [Required]
|
[SerializeField] [Required]
|
||||||
GameObject entityPrefab = null!;
|
GameObject entityPrefab = null!;
|
||||||
|
|
||||||
|
[field: SerializeField] [field: Required]
|
||||||
|
public Transform gladiatorParent { get; private set; } = null!;
|
||||||
|
|
||||||
|
[field: SerializeField] [field: Required]
|
||||||
|
public Transform minionParent { get; private set; } = null!;
|
||||||
|
|
||||||
|
[field: SerializeField] [field: Required]
|
||||||
|
public Transform graveyard { get; private set; } = null!;
|
||||||
|
|
||||||
SafeZone safeZone = null!;
|
SafeZone safeZone = null!;
|
||||||
|
|
||||||
void Awake() => safeZone = GetComponentInChildren<SafeZone>();
|
void Awake() => safeZone = GetComponentInChildren<SafeZone>();
|
||||||
@ -34,9 +42,11 @@ public class Arena : MonoBehaviour {
|
|||||||
if (!gameFlowManager.CanDoAction)
|
if (!gameFlowManager.CanDoAction)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var entity = Instantiate(entityPrefab, spawners[spawnerIndex].position, Quaternion.identity).GetComponent<Entity>();
|
var gladiator = Instantiate(entityPrefab, gladiatorParent).GetComponent<Gladiator>();
|
||||||
entity.direction = spawners[spawnerIndex].direction;
|
gladiator.arena = this;
|
||||||
entity.gameFlowManager = gameFlowManager;
|
gladiator.transform.position = spawners[spawnerIndex].position;
|
||||||
|
gladiator.direction = spawners[spawnerIndex].direction;
|
||||||
|
gladiator.gameFlowManager = gameFlowManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator SpawnEnemies() {
|
IEnumerator SpawnEnemies() {
|
||||||
|
|||||||
@ -1,10 +1,21 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using NaughtyAttributes;
|
using NaughtyAttributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[RequireComponent(typeof(Rigidbody2D))]
|
[RequireComponent(typeof(Rigidbody2D))]
|
||||||
public class Entity : MonoBehaviour {
|
public class Entity : MonoBehaviour {
|
||||||
|
[Flags]
|
||||||
|
public enum EntityFlag {
|
||||||
|
Vampire = 0,
|
||||||
|
Monster = 1,
|
||||||
|
Gladiator = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena arena = null!;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Required]
|
[Required]
|
||||||
public GameFlowManager gameFlowManager = null!;
|
public GameFlowManager gameFlowManager = null!;
|
||||||
@ -22,13 +33,12 @@ public class Entity : MonoBehaviour {
|
|||||||
[field: SerializeField] public float attackDmg { get; private set; }
|
[field: SerializeField] public float attackDmg { get; private set; }
|
||||||
[SerializeField] protected float attackCooldown;
|
[SerializeField] protected float attackCooldown;
|
||||||
protected float attackTimer;
|
protected float attackTimer;
|
||||||
[SerializeField] private Transform target;
|
public Transform target;
|
||||||
public string entityName { get; protected set; }
|
public EntityFlag entityType { get; protected set; }
|
||||||
public Vector3 direction { get; set; }
|
public Vector3 direction { get; set; }
|
||||||
public Rigidbody2D rb { get; private set; }
|
public Rigidbody2D rb { get; private set; }
|
||||||
public Collider2D collider { get; private set; }
|
public Collider2D collider { get; private set; }
|
||||||
public SpriteRenderer renderer { get; private set; }
|
public SpriteRenderer renderer { get; private set; }
|
||||||
bool beingPushed;
|
|
||||||
[SerializeField] GameObject halo;
|
[SerializeField] GameObject halo;
|
||||||
[SerializeField] Color deadColor = Color.red;
|
[SerializeField] Color deadColor = Color.red;
|
||||||
[SerializeField] Color emptyColor = Color.grey;
|
[SerializeField] Color emptyColor = Color.grey;
|
||||||
@ -71,21 +81,12 @@ public class Entity : MonoBehaviour {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTarget(Transform newTarget) {
|
|
||||||
target = newTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Transform GetTarget() {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Apply damage to the entity, returns true if it is still alive
|
//Apply damage to the entity, returns true if it is still alive
|
||||||
public virtual bool TakeDamage(float amount, Entity other) {
|
public virtual bool TakeDamage(float amount, Entity other) {
|
||||||
Health -= amount;
|
Health -= amount;
|
||||||
healthBar.SetHealthFraction(Health / initialHealth);
|
healthBar.SetHealthFraction(Health / initialHealth);
|
||||||
|
|
||||||
if (Health <= 0) {
|
if (Health <= 0) {
|
||||||
isAlive = false;
|
|
||||||
OnDied();
|
OnDied();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -115,12 +116,8 @@ public class Entity : MonoBehaviour {
|
|||||||
return isAlive;
|
return isAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void AddImpulse(Vector3 impulse) {
|
|
||||||
beingPushed = true;
|
|
||||||
rb.AddForce(impulse, ForceMode2D.Impulse);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnDied() {
|
protected virtual void OnDied() {
|
||||||
|
isAlive = false;
|
||||||
if(!(collider is null)){
|
if(!(collider is null)){
|
||||||
collider.isTrigger = true;
|
collider.isTrigger = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,13 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class Gladiator : AIEntity
|
public class Gladiator : AIEntity
|
||||||
{
|
{
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
override protected void Start()
|
override protected void Start()
|
||||||
{
|
{
|
||||||
base.Start();
|
base.Start();
|
||||||
base.entityName = "Gladiator";
|
base.entityType = EntityFlag.Gladiator;
|
||||||
base.enemies = new string[]{"Monster", "Vampire"};
|
base.enemies = EntityFlag.Monster | EntityFlag.Vampire;
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected void Update(){
|
override protected void Update(){
|
||||||
@ -20,23 +21,14 @@ public class Gladiator : AIEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
override protected bool IsTargetable(Entity other){
|
override protected bool IsTargetable(Entity other){
|
||||||
foreach (string name in enemies){
|
if (!other.IsAlive() || other is Gladiator)
|
||||||
if(other.entityName == name && other.IsAlive()){
|
return false;
|
||||||
//If it is the vampire: check if it is in safezone
|
|
||||||
if(other.entityName == "Vampire"){
|
|
||||||
VampireEntity vampireEntity = other.GetComponent<VampireEntity>();
|
|
||||||
if(vampireEntity is null){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(vampireEntity.IsInSafeZone()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//Is targetable if it's the vampire but not in safe zone
|
||||||
|
if (other is VampireEntity vampireEntity)
|
||||||
|
return !vampireEntity.IsInSafeZone();
|
||||||
|
|
||||||
|
//If monster
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,14 @@ using UnityEngine;
|
|||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
public class MinionThrower : MonoBehaviour {
|
public class MinionThrower : MonoBehaviour {
|
||||||
|
[SerializeField] [Required]
|
||||||
|
Arena arena = null!;
|
||||||
[SerializeField] [Required]
|
[SerializeField] [Required]
|
||||||
GameFlowManager gameFlowManager = null!;
|
GameFlowManager gameFlowManager = null!;
|
||||||
|
|
||||||
|
[SerializeField] [Required]
|
||||||
|
Transform minionParent = null!;
|
||||||
|
|
||||||
public Entity[] minionPrefabs;
|
public Entity[] minionPrefabs;
|
||||||
public GameObject aimArrow;
|
public GameObject aimArrow;
|
||||||
|
|
||||||
@ -74,15 +79,17 @@ public class MinionThrower : MonoBehaviour {
|
|||||||
currentCooldownTimer = currentInitialCooldown;
|
currentCooldownTimer = currentInitialCooldown;
|
||||||
minionBar.UpdateReload(currentCooldownTimer / currentInitialCooldown);
|
minionBar.UpdateReload(currentCooldownTimer / currentInitialCooldown);
|
||||||
|
|
||||||
var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f, Quaternion.identity)
|
var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, minionParent)
|
||||||
.GetComponent<Monster>();
|
.GetComponent<Monster>();
|
||||||
|
newMinion.arena = arena;
|
||||||
|
newMinion.transform.position = transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f;
|
||||||
|
newMinion.direction = throwDirection;
|
||||||
|
newMinion.gameFlowManager = vampireEntity.gameFlowManager;
|
||||||
|
|
||||||
if (movement.GetSafeZoneIfImmobile() is {} safeZone) {
|
if (movement.GetSafeZoneIfImmobile() is {} safeZone) {
|
||||||
newMinion.thrownFromSafeZone = true;
|
newMinion.thrownFromSafeZone = true;
|
||||||
newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(throwDirection);
|
newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(throwDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
newMinion.direction = throwDirection;
|
|
||||||
newMinion.gameFlowManager = vampireEntity.gameFlowManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,8 @@ public class Monster : AIEntity {
|
|||||||
override protected void Start()
|
override protected void Start()
|
||||||
{
|
{
|
||||||
base.Start();
|
base.Start();
|
||||||
base.entityName = "Monster";
|
base.entityType = EntityFlag.Monster;
|
||||||
base.enemies = new string[]{"Gladiator"};
|
base.enemies = EntityFlag.Gladiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override BaseState CreateInitialState()
|
protected override BaseState CreateInitialState()
|
||||||
@ -18,6 +18,8 @@ public class Monster : AIEntity {
|
|||||||
? (BaseStateAI)new NonPhysicThrownState(this, thrownTargetPosition)
|
? (BaseStateAI)new NonPhysicThrownState(this, thrownTargetPosition)
|
||||||
: new ThrownState(this);
|
: new ThrownState(this);
|
||||||
|
|
||||||
|
protected override bool IsTargetable(Entity other) => other.IsAlive() && other is Gladiator;
|
||||||
|
|
||||||
//Basically a copy of JumpingMovementState
|
//Basically a copy of JumpingMovementState
|
||||||
protected class NonPhysicThrownState : BaseStateAI {
|
protected class NonPhysicThrownState : BaseStateAI {
|
||||||
readonly Vector3 target;
|
readonly Vector3 target;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ public class VampireEntity : Entity {
|
|||||||
|
|
||||||
protected override void Start() {
|
protected override void Start() {
|
||||||
base.Start();
|
base.Start();
|
||||||
base.entityName = "Vampire";
|
base.entityType = EntityFlag.Vampire;
|
||||||
playerMovement = GetComponent<PlayerMovement>();
|
playerMovement = GetComponent<PlayerMovement>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user