23 Commits

Author SHA1 Message Date
gav
3090e248c2 Merge branch 'main' into krazerleo/core/1 2022-05-05 23:54:12 +07:00
b8e8e74ab4 Fixes in Map Manager 2022-05-05 20:45:26 +07:00
2caf658d19 "update unresolved conflicts" 2022-05-05 18:11:57 +07:00
ba1b350c62 resolved merge conflicts 2022-05-05 16:49:21 +07:00
6514599f22 Merge branch 'krazerleo/core/1' of https://gitea.gavt45.ru/gav/real-shooter into krazerleo/core/1 2022-05-05 16:30:27 +07:00
f3fe5ea4cd commit 665 2022-05-05 16:26:23 +07:00
1cf5776a1b Merge branch 'krazerleo/core/1' of https://gitea.gavt45.ru/gav/real-shooter into krazerleo/core/1 2022-05-05 11:48:32 +07:00
351fa8ee12 test 1 2022-05-05 01:10:04 +07:00
690f1e2536 test 2022-05-05 01:08:58 +07:00
e689927b73 dadwa 2022-05-05 00:55:51 +07:00
3420d14cdc merge 2022-05-04 23:57:38 +07:00
c8af0e5284 to new git 2022-05-04 23:50:07 +07:00
290f5515b7 update scripts 2022-04-25 16:23:25 +07:00
1e4f90c0ed Removed useless temporary files 2022-04-19 19:31:15 +07:00
28863de9df Merge branch 'krazerleo/core/1' 2022-04-19 19:29:10 +07:00
39d29da2be Merge branch 'main' into krazerleo/core/1 2022-04-19 19:28:44 +07:00
dfdd018a5f added mlagent jsons to gitignore 2022-04-19 19:25:45 +07:00
aae98595d3 Small fizes 2022-04-19 19:24:53 +07:00
4bd1e0644a latest 2022-04-18 19:01:06 +07:00
e1d0bbc1eb kirill loh 2022-04-18 10:53:21 +07:00
d911dce62a Merge pull request #5 from gavt45/karavan/nav/1
Merging model and player#1
2022-04-17 13:57:19 +07:00
79f27125b6 Merge branch 'main' into karavan/nav/1 2022-04-17 13:57:12 +07:00
e8d75b627c Merging model and player#1 2022-04-12 17:04:03 +07:00
56 changed files with 9156 additions and 1062 deletions

5
.gitignore vendored
View File

@ -2,6 +2,11 @@
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
# MLagents
Assets/ML-Agents/Timers/*
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/

1
1 Normal file
View File

@ -0,0 +1 @@

View File

@ -1 +0,0 @@
{"count":1,"self":249.99626239999998,"total":250.70272609999998,"children":{"InitializeActuators":{"count":1,"self":0.0005131,"total":0.0005131,"children":null},"AgentSendState":{"count":8389,"self":0.1187579,"total":0.1187579,"children":null},"DecideAction":{"count":8389,"self":0.5871921,"total":0.5871921,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1649259643","unity_version":"2019.4.36f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2019.4.36f1\\Editor\\Unity.exe -projectpath D:\\real_shooter -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-user -hubSessionId 91406950-b5ad-11ec-a63c-e7b76cbae13d -accessToken EBt97pMhHqClFDnjD_uh-3vplxP-uI2yS0WK-hSxfuM012f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"DemoScene01","end_time_seconds":"1649259893"}}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 1b328c4e26e7a994e8a42f269ca7419b
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1 +0,0 @@
{"count":1,"self":16.677081599999998,"total":16.6850819,"children":{"InitializeActuators":{"count":1,"self":0.0020011,"total":0.0020011,"children":null},"InitializeSensors":{"count":1,"self":0.0019998,"total":0.0019998,"children":null},"AgentSendState":{"count":1,"self":0.0020001,"total":0.0030001,"children":{"CollectObservations":{"count":1,"self":0.001,"total":0.001,"children":null}}}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1650121997","unity_version":"2019.4.35f1","command_line_arguments":"C:\\Program Files\\unityeditorfolder\\2019.4.35f1\\Editor\\Unity.exe -projectpath F:\\SigmaRiskManagment\\real shooter Git Version -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-BipJTP5Uk-fN-2Lss2TUJ -hubSessionId a1fe6f50-bcbd-11ec-b648-df8ff5c97a4c -accessToken K_G64_ace_5LgpX3riGrgGS92ESag4RH04Ti1lswMX8009f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Greatest_map_ever","end_time_seconds":"1650122013"}}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 80ef0d75029e25243857877facd14d75
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1 +0,0 @@
{"count":1,"self":14.5494256,"total":14.5766034,"children":{"InitializeActuators":{"count":1,"self":0,"total":0,"children":null},"AgentSendState":{"count":497,"self":0.0020012999999999997,"total":0.0020012999999999997,"children":null},"DecideAction":{"count":497,"self":0.0241768,"total":0.0241768,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1649741696","unity_version":"2019.4.35f1","command_line_arguments":"D:\\Unity\\2019.4.35f1\\Editor\\Unity.exe -projectpath C:\\Users\\kiril\\real-shooter -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-kiril -hubSessionId 21e9de90-ba14-11ec-9398-079edccf5e34 -accessToken oIpf_7gKWQQRilVTeJehUsFhrxasdzsG_K3j5Swtgx0009f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"dont touch me plz","end_time_seconds":"1649741711"}}

View File

@ -17,6 +17,7 @@ GameObject:
- component: {fileID: 2676446634235362783}
- component: {fileID: 8656710265340117963}
- component: {fileID: 778652956973742106}
- component: {fileID: 1208561866453126566}
m_Layer: 0
m_Name: Bot
m_TagString: Untagged
@ -115,7 +116,6 @@ MonoBehaviour:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 100
moveController: {fileID: 778652956973742106}
--- !u!114 &7805954453358028498
MonoBehaviour:
m_ObjectHideFlags: 0
@ -143,19 +143,23 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
VectorObservationSize: 1
<<<<<<< HEAD
VectorObservationSize: 9
=======
VectorObservationSize: 4
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes: 01000000
VectorActionSize: 01000000
BranchSizes: 0200000002000000
VectorActionSize: 0200000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 0}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: My Behavior
m_BehaviorName: npc
TeamId: 0
m_UseChildSensors: 1
m_UseChildActuators: 1
@ -195,3 +199,19 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
navMeshAgent: {fileID: 8656710265340117963}
flag: {fileID: 6818223691859422291, guid: 1685c1d9ce4ab174f95c646b1826010b, type: 3}
--- !u!114 &1208561866453126566
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2988578997639256874}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dd8012d5925524537b27131fef517017, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SensorName: BufferSensor
m_ObservableSize: 5
m_MaxNumObservables: 5

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 99bb17a23a489624baeaf337f91a4f84
guid: 80f6c1c85e5daed4c96c70205ed5503d
PrefabImporter:
externalObjects: {}
userData:

View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.57481617, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -259,6 +259,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name:
m_EditorClassIdentifier:
<<<<<<< HEAD
navType: 1
=======
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
PointId: 0
DeathAttr: 0
EnemiesSeen: []
--- !u!23 &140697607
@ -353,6 +358,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name:
m_EditorClassIdentifier:
<<<<<<< HEAD
navType: 1
=======
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
PointId: 0
DeathAttr: 0
EnemiesSeen: []
--- !u!23 &293522541
@ -1120,7 +1130,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 77.5, y: 55.2, z: -5.9}
m_LocalPosition: {x: 81.2, y: 64.1, z: -12.4}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -1251,6 +1261,12 @@ Transform:
m_Father: {fileID: 671439045}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!4 &868386701 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
m_PrefabInstance: {fileID: 1809549197}
m_PrefabAsset: {fileID: 0}
--- !u!1 &884498019
GameObject:
m_ObjectHideFlags: 0
@ -1284,6 +1300,80 @@ Transform:
m_Father: {fileID: 782729761}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1061293905
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 868386701}
m_Modifications:
- target: {fileID: 2836004473841745626, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_Controller
value:
objectReference: {fileID: 9100000, guid: 95a44e56d04c7d248ba723eda9611c51, type: 2}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalPosition.y
value: -1
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591197023, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2836004475591695743, guid: f432554f564e69242897607d34218939,
type: 3}
propertyPath: m_Name
value: DragonFucker
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f432554f564e69242897607d34218939, type: 3}
--- !u!1 &1116745543
GameObject:
m_ObjectHideFlags: 0
@ -1315,6 +1405,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name:
m_EditorClassIdentifier:
<<<<<<< HEAD
navType: 1
=======
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
PointId: 0
DeathAttr: 0
EnemiesSeen: []
--- !u!23 &1116745545
@ -1477,7 +1572,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh17416
m_Name: pb_Mesh16900
serializedVersion: 10
m_SubMeshes:
- serializedVersion: 2
@ -1745,7 +1840,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1345085340}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 47.446796, y: -5.782543, z: -25.400002}
m_LocalPosition: {x: 21.51, y: -5.782543, z: -10.46}
m_LocalScale: {x: 1.4367, y: 1.4367, z: 1.4367}
m_Children: []
m_Father: {fileID: 2060099472}
@ -1763,6 +1858,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name:
m_EditorClassIdentifier:
<<<<<<< HEAD
navType: 1
=======
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
PointId: 0
DeathAttr: 0
EnemiesSeen: []
--- !u!23 &1345085343
@ -1857,6 +1957,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name:
m_EditorClassIdentifier:
<<<<<<< HEAD
navType: 1
=======
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
PointId: 0
DeathAttr: 0
EnemiesSeen: []
--- !u!23 &1488699524
@ -2077,6 +2182,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name:
m_EditorClassIdentifier:
<<<<<<< HEAD
navType: 1
=======
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
PointId: 0
DeathAttr: 0
EnemiesSeen: []
--- !u!23 &1663305224
@ -2126,6 +2236,105 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1663305221}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &1809549197
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -4942972567661207728, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_RootOrder
value: 6
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalPosition.x
value: 42.23
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalPosition.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalPosition.z
value: -15.91
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763689, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763699, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763700, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: playerStance
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763700, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: playerCrouchStance.CameraHeight
value: 0.3
objectReference: {fileID: 0}
- target: {fileID: 4528203470625763703, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4528203471293941515, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4528203471293941515, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
propertyPath: m_LocalPosition.z
value: -2.417
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 99bb17a23a489624baeaf337f91a4f84, type: 3}
--- !u!1 &1858987083
GameObject:
m_ObjectHideFlags: 0
@ -2141,6 +2350,7 @@ GameObject:
- component: {fileID: 1858987090}
- component: {fileID: 1858987088}
- component: {fileID: 1858987085}
- component: {fileID: 1858987091}
m_Layer: 0
m_Name: Game
m_TagString: Untagged
@ -2251,8 +2461,20 @@ MonoBehaviour:
- {fileID: 2004854094}
AIPrefab: {fileID: 2988578997639256874, guid: b016874eb34cc084aa4359f0bbec50e1,
type: 3}
PlayerPrefab: {fileID: 5245491127989480125, guid: 80f6c1c85e5daed4c96c70205ed5503d,
PlayerPrefab: {fileID: 5245491127989480125, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3}
--- !u!114 &1858987091
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1858987083}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bf3fe86787bfb0c4b8751fe495148ede, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1871257865
GameObject:
m_ObjectHideFlags: 0
@ -2506,6 +2728,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name:
m_EditorClassIdentifier:
<<<<<<< HEAD
navType: 1
=======
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467
PointId: 0
DeathAttr: 0
EnemiesSeen: []
--- !u!23 &2004854095
@ -2593,7 +2820,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2060099471}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 19.553204, y: 7.782543, z: -15}
m_LocalPosition: {x: 27.79, y: 7.782543, z: -15}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1345085341}

View File

@ -1,33 +1,36 @@
using System.Collections.Generic;
using UnityEngine;
using Unity;
public class CharacterFactory : MonoBehaviour
{
private CharacterFactory instance;
public CharacterFactory Instance { get { return instance; } }
private static CharacterFactory instance;
public static CharacterFactory Instance => instance;
[SerializeField] private List<NavPoint> spawnPointsForDefendersTeam;
[SerializeField] private List<NavPoint> spawnPointsForAttackersTeam;
[SerializeField] private GameObject AIPrefab;
[SerializeField] private GameObject PlayerPrefab;
private List<GameObject> Players;
private List<GameObject> bots = new List<GameObject>();
public GameObject player { get; private set; }
private void Awake()
{
if (instance == null)
instance = this;
else
{
Destroy(gameObject);
Debug.LogError("Only 1 Instance");
}
}
private void Start()
{
var attcNum = SettingsReader.Instance.GetSettings.numOfAttackers;
var defNum = SettingsReader.Instance.GetSettings.numOfDefenders;
var humanDef = SettingsReader.Instance.GetSettings.hasHumanDefender == true ? 1 : 0;
var humanAtc = SettingsReader.Instance.GetSettings.hasHumanAttacker == true ? 1 : 0;
var attcNum = SettingsReader.Instance.GetSettings.NumOfAttackers;
var defNum = SettingsReader.Instance.GetSettings.NumOfDefenders;
var humanDef = SettingsReader.Instance.GetSettings.HasHumanDefender == true ? 1 : 0;
var humanAtc = SettingsReader.Instance.GetSettings.HasHumanAttacker == true ? 1 : 0;
if (humanAtc == 1 && humanDef == 1)
throw new System.ArgumentException("Can be only one human player");
@ -44,16 +47,68 @@ public class CharacterFactory : MonoBehaviour
if (humanDef == 1)
InstanciateEntity(Team.Defenders, TypeAI.HumanAI,
spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]);
GameManager.OnResetScene += ResetCharacters;
}
private void InstanciateEntity(Team team, TypeAI typeAi, NavPoint spawnPoint)
{
var gameobject = GameObject.Instantiate(
typeAi == TypeAI.HumanAI ? PlayerPrefab : AIPrefab,
spawnPoint.position,
spawnPoint.Position,
Quaternion.identity);
var character = gameObject.GetComponent<ICharacter>();
character.GetCharacter.Team = team;
gameobject.SetActive(true);
if (team == Team.Attackers)
gameObject.tag = "Attacker";
else
gameObject.tag = "Defender";
if (typeAi == TypeAI.HumanAI)
{
gameobject.GetComponent<Player>().GetCharacter.Team = team;
player = gameobject;
}
else
{
gameobject.GetComponent<NPC>().GetCharacter.Team = team;
gameobject.GetComponent<MovementController>().PointStartID = spawnPoint.PointId;
bots.Add(gameobject);
}
}
public void ReSpawn(ICharacter character, ref Vector3 pos, ref int startPointId)
{
character.ResetCharacter();
var team = character.GetCharacter.Team;
NavPoint navPoint;
if (team == Team.Attackers)
navPoint = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)];
else
navPoint = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)];
pos = navPoint.Position;
startPointId = navPoint.PointId;
}
private void ResetCharacters()
{
foreach (var bot in bots)
{
var npc = bot.GetComponent<NPC>();
npc.ResetCharacter();
if (npc.GetCharacter.Team == Team.Attackers)
bot.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
else
bot.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position;
}
Player player;
if (TryGetComponent<Player>(out player))
{
player.ResetCharacter();
if (player.GetCharacter.Team == Team.Attackers)
this.player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
else
this.player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position;
}
}
}

View File

@ -2,4 +2,15 @@
{
Defenders,
Attackers,
}
public static class TeamExtension
{
public static Team GetOppositeTeam(this Team team)
{
if (team == Team.Attackers)
return Team.Defenders;
else
return Team.Attackers;
}
}

View File

@ -9,14 +9,4 @@ public class Character
{
Condition = new CharacterCondition();
}
public void ResetCharacter()
{
}
}
public interface ICharacter
{
Character GetCharacter { get; }
}

View File

@ -19,7 +19,18 @@ public class CharacterCondition
{
health = value;
OnChangeHealthEvent?.Invoke(value);
}
}
}
public int GetHealthPointsInQuantile()
{
if (health < 25)
return 0;
else if (health < 50)
return 1;
else if (health < 75)
return 2;
else return 3;
}
private int armour;
public int ArmourPoints
@ -34,6 +45,17 @@ public class CharacterCondition
OnChangeArmourEvent?.Invoke(value);
}
}
public int GetArmourPointsInQuantile()
{
if (armour < 25)
return 0;
else if (armour < 50)
return 1;
else if (armour < 75)
return 2;
else return 3;
}
private int ammo;
public int Ammunition
{
@ -49,11 +71,16 @@ public class CharacterCondition
}
public CharacterCondition()
{
this.Reset();
}
public void Reset()
{
var settings = SettingsReader.Instance.GetSettings;
ammo = settings.maxAmmo;
health = settings.maxHealth;
armour = settings.maxArmour;
ammo = settings.MaxAmmo;
health = settings.MaxHealth;
armour = settings.MaxArmour;
}
public void GiveHealth(int health) => HealthPoints = Mathf.Clamp(health + HealthPoints, 0, 100);

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5e73ba257bc6b684c86edf9ecfd475ef
guid: f23b6db3be1e4cd469fd18dfe3e39764
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,5 @@
public interface ICharacter
{
Character GetCharacter { get; }
void ResetCharacter();
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8f76201fe6436164789d10350a0fd6e2
guid: b6dfb78244ae35c4db1326d5f5b73375
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,17 @@
using UnityEngine;
public interface INpcBaseState
{
NpcEnumState State { get; }
bool InCover { get; }
bool IsRunning { get; }
bool InDirectPoint { get; }
float HitChance { get; }
float DoDamageChance { get; }
}
public interface INpcBaseBodyState
{
NpcBodyState State { get; }
Vector3 GetPointToHit(GameObject go);
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 4599c57bc5b1c3945847dead0f9f0ba4
guid: 58b7e1962495ada4c8e6ee6219c99a20
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,32 +1,82 @@
using System.Linq;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class MovementController : MonoBehaviour
{
public NavPoint currentPosition { get; private set; }
public int PointStartID { get; set; }
public int PointEndID { get; private set; }
public float FlagDistance { get; private set; }
private const float updateFlagPositionDelay = 5;
private const float updateReachedDestinationDelay = 5;
[SerializeField] private NavMeshAgent navMeshAgent;
[SerializeField] private GameObject flag;
public float DistanceToGo { get; private set; }
public float RemainingDistance => navMeshAgent.remainingDistance;
private Dictionary<int, NavPoint> idNavPointDict;
private void Start()
private void Awake()
{
navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed;
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
idNavPointDict = MapManager.IDToNavPoint;
InvokeRepeating(nameof(UpdateFlagPosition), 0, updateFlagPositionDelay);
InvokeRepeating(nameof(ReachedDestination), 0, updateReachedDestinationDelay);
}
private void OnDestroy()
{
CancelInvoke(nameof(UpdateFlagPosition));
}
private void UpdateFlagPosition()
{
FlagDistance = (flag.transform.position - gameObject.transform.position).magnitude;
}
public void MoveToRandomPoint()
{
Debug.Log(MapManager.navPoints == null);
goToNextNavPoint(MapManager.navPoints[Random.Range(0, MapManager.navPoints.Count)]);
{
GoToNextNavPoint(MapManager.NavPoints[Random.Range(0, MapManager.NavPoints.Count)]);
}
public List<NavPoint> getPointsCandidate()
public List<NavPoint> GetPointsCandidate()
{
return MapManager.navPoints
.Where(point => (currentPosition.position - point.position).magnitude <= SettingsReader.Instance.GetSettings.movementSpeed)
return MapManager.NavPoints
.Where(point =>
(idNavPointDict[PointStartID].Position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
.ToList();
}
public void goToNextNavPoint(NavPoint destination) =>
navMeshAgent.SetDestination(destination.position);
public void GoToNextNavPoint(NavPoint destination)
{
if (navMeshAgent.isStopped == true) navMeshAgent.isStopped = false;
PointStartID = PointEndID;
PointEndID = destination.PointId;
navMeshAgent.SetDestination(destination.Position);
DistanceToGo = navMeshAgent.remainingDistance;
}
public void ReturnToStartPoint()
{
if (navMeshAgent.isStopped == true) navMeshAgent.isStopped = false;
navMeshAgent.SetDestination(idNavPointDict[PointStartID].Position);
PointEndID = PointStartID;
PointStartID = -1;
}
public void StopOnPath()
{
navMeshAgent.isStopped = true;
PointStartID = -1;
PointEndID = -1;
}
public void ReachedDestination()
{
if ((navMeshAgent.isStopped == false) && (navMeshAgent.velocity.magnitude < 0.1))
PointStartID = PointEndID;
}
}

View File

@ -1,102 +1,170 @@
using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Actuators;
using System.Collections.Generic;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
using UnityEngine;
[RequireComponent(typeof(MovementController))]
[RequireComponent(typeof(MovementController),typeof(BufferSensor))]
public class NPC : Agent, ICharacter
{
[HideInInspector]
public Character AgentCharacter;
private Character AgentCharacter;
public CharacterCondition Condition;
private FlagZone flagZone = null;
public NPC_BaseState NPC_State { get; private set; }
public INpcBaseState NpcState { get; private set; }
public INpcBaseBodyState NpcBodyState { get; private set; }
public Character GetCharacter => AgentCharacter;
private NPC_DirectPointState DirectState;
private NPC_InCoverState CoverState;
private NPC_RunningState RunningState;
private NpcDirectPointState DirectState;
private NpcInCoverState CoverState;
private NpcRunningState RunningState;
private NpcStandingState StandingState;
private NpcCrouchingState CrouchingState;
private MovementController moveController;
private BufferSensorComponent bufferSensor;
private Dictionary<int, NavPoint> navPointIdDict;
#region UnityEvents and ML
private void Awake()
{
DirectState = new NPC_DirectPointState();
CoverState = new NPC_InCoverState();
RunningState = new NPC_RunningState();
NPC_State = DirectState;
DirectState = new NpcDirectPointState();
CoverState = new NpcInCoverState();
RunningState = new NpcRunningState();
NpcState = DirectState;
CrouchingState = new NpcCrouchingState();
StandingState = new NpcStandingState();
NpcBodyState = StandingState;
AgentCharacter = new Character();
Condition = AgentCharacter.Condition;
}
private void Start()
{
AgentCharacter = new Character();
Condition = AgentCharacter.Condition;
moveController = gameObject.GetComponent<MovementController>();
bufferSensor = gameObject.GetComponent<BufferSensorComponent>();
GameManager.OnResetScene += AgentCharacter.ResetCharacter;
flagZone = GameObject.FindObjectOfType<FlagZone>();
if (flagZone == null)
Debug.LogError("Flag Is Not Setted");
navPointIdDict = MapManager.IDToNavPoint;
if (navPointIdDict is null)
Debug.LogError("Cant Find Nav Point Dictionary");
}
private void OnDestroy()
{
Debug.LogWarning("Pooled object was destroyed");
}
public override void OnEpisodeBegin()
{
NpcState = DirectState;
flagZone = GameObject.FindObjectOfType<FlagZone>();
}
public override void CollectObservations(VectorSensor sensor)
{
sensor.AddObservation(Condition.HealthPoints);
sensor.AddObservation(Condition.ArmourPoints);
sensor.AddObservation(Condition.Ammunition);
sensor.AddObservation((int)NPC_State.State);
var candidates = moveController.GetPointsCandidate();
//common sensors
sensor.AddObservation(GameManager.IsHaveSeenByEnemy(AgentCharacter.Team.GetOppositeTeam(),
NpcBodyState.GetPointToHit(gameObject)).ToInt());
sensor.AddObservation(AgentCharacter.LastTimeHit);
sensor.AddObservation((!flagZone.IsNotOccup).ToInt());
sensor.AddObservation(Condition.GetHealthPointsInQuantile());
sensor.AddObservation(Condition.GetArmourPointsInQuantile());
sensor.AddObservation(candidates.Count);
sensor.AddObservation(moveController.PointStartID);
sensor.AddObservation(moveController.PointEndID);
//state sensors
sensor.AddObservation((int)NpcState.State);
sensor.AddObservation((int)NpcBodyState.State);
sensor.AddObservation(GameManager.IsEnemyNearby(gameObject.transform.position, AgentCharacter.Team));
sensor.AddObservation(navPointIdDict[moveController.PointStartID].DeathAttr);
sensor.AddObservation(navPointIdDict[moveController.PointEndID].DeathAttr);
sensor.AddObservation(moveController.FlagDistance);
var candidates = moveController.getPointsCandidate();
//point sensors
foreach (var point in candidates)
{
bufferSensor.AppendObservation(new float[] {
//1 position in navpointId
(float)moveController.currentPosition.PointId,
//2 distance to flag
moveController.currentPosition.FlagDistance,
//3 death count in point
moveController.currentPosition.DeathAttr,
point.DeathAttr,
(int)point.navType,
//4 flagEnemyDistance
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position)==true?1:0,
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position).ToInt(),
//5 EnemyVsNavPointDistance
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team)==true?1:0
});
}
}
public override void Heuristic(in ActionBuffers actionsOut)
{
var discreteActionsOut = actionsOut.DiscreteActions;
if (Input.GetKeyDown(KeyCode.W))
{
discreteActionsOut[0] = 1;
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team.GetOppositeTeam()).ToInt(),
//6 Have been seen by enemy in this point
GameManager.IsHaveSeenByEnemy(AgentCharacter.Team.GetOppositeTeam(),
point.Position).ToInt()
});
}
}
public override void OnActionReceived(ActionBuffers actions)
{
if (actions.DiscreteActions[0] == 1)
var result = actions.DiscreteActions;
if (result[0] == 0)
{
moveController.MoveToRandomPoint();
NPC_State = RunningState;
if (navPointIdDict[moveController.PointStartID].navType != NavPointType.Cover)
return;
NpcState = CoverState;
switch (result[1])
{
case 0: Peek(); break;
case 1: Cover(); break;
case 3: Peek(); moveController.GoToNextNavPoint(navPointIdDict[result[2]]); break;
case 4: NpcState = DirectState; break;
default: throw new ArgumentException("Undefined Action recieved");
}
}
if (result[0] == 1)
{
if (navPointIdDict[moveController.PointStartID].navType != NavPointType.Direction)
return;
switch (result[1])
{
case 0: moveController.GoToNextNavPoint(navPointIdDict[result[2]]);
NpcState = RunningState; break;
case 1: NpcState = DirectState; break;
default: throw new ArgumentException("Undefined Action recieved");
}
}
if (result[0] == 2)
{
if (moveController.PointStartID == moveController.PointEndID && moveController.PointEndID != -1)
return;
switch (result[1])
{
case 0: moveController.StopOnPath(); NpcState = DirectState; break;
case 1: moveController.ReturnToStartPoint(); NpcState = RunningState; break;
default: throw new ArgumentException("Undefined Action recieved");
}
}
}
#endregion
public event Action<object> OnKilledEvent;
public event Action<NpcBodyState> OnChangePosition;
private void Peek()
{
OnChangePosition?.Invoke(global::NpcBodyState.Standing);
NpcBodyState = StandingState;
}
private void Cover()
{
OnChangePosition?.Invoke(global::NpcBodyState.Crouching);
NpcBodyState = CrouchingState;
}
public event Action<int, Team> OnDamageRecieved;
public void GetDamage(float damage)
{
AgentCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
@ -105,13 +173,17 @@ public class NPC : Agent, ICharacter
if (Condition.HealthPoints < 0)
{
OnKilledEvent?.Invoke(this);
moveController.currentPosition.DeathAttr += 1;
MapManager.AddDeathAttributeToPoints(moveController.PointStartID, moveController.PointEndID,
moveController.DistanceToGo, moveController.RemainingDistance);
var pos = gameObject.transform.position;
var id = moveController.PointStartID;
CharacterFactory.Instance.ReSpawn(this, ref pos, ref id);
}
}
private void OnDestroy()
public void ResetCharacter()
{
Debug.LogWarning("Pooled object was destroyed");
Condition.Reset();
EndEpisode();
}
}

View File

@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder: 200
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -1,46 +0,0 @@
public enum NPC_EnumState
{
InCover,
InDirectPoint,
InRunning,
}
public interface NPC_BaseState
{
NPC_EnumState State { get; }
bool InCover { get; }
bool IsRunning { get; }
bool InDirectPoint { get; }
float HitChance { get; }
float DoDamageChance { get; }
}
public class NPC_DirectPointState : NPC_BaseState
{
public bool InCover => false;
public bool IsRunning => false;
public bool InDirectPoint => false;
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInDirectPoint;
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInDirectPoint;
public NPC_EnumState State => NPC_EnumState.InDirectPoint;
}
public class NPC_RunningState : NPC_BaseState
{
public bool InCover => false;
public bool IsRunning => true;
public bool InDirectPoint => false;
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInRunning;
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInRunning;
public NPC_EnumState State => NPC_EnumState.InRunning;
}
public class NPC_InCoverState : NPC_BaseState
{
public bool InCover => true;
public bool IsRunning => false;
public bool InDirectPoint => false;
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInCover;
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInCover;
public NPC_EnumState State => NPC_EnumState.InCover;
}

View File

@ -0,0 +1,68 @@
using UnityEngine;
public enum NpcEnumState
{
InCover,
InDirectPoint,
InRunning,
}
public enum NpcBodyState
{
Crouching,
Standing,
}
public class NpcCrouchingState : INpcBaseBodyState
{
public NpcBodyState State => NpcBodyState.Crouching;
public Vector3 GetPointToHit(GameObject go)
{
MeshRenderer meshRenderer;
go.TryGetComponent<MeshRenderer>(out meshRenderer);
return meshRenderer.bounds.center;
}
}
public class NpcStandingState : INpcBaseBodyState
{
public NpcBodyState State => NpcBodyState.Standing;
public Vector3 GetPointToHit(GameObject go)
{
MeshRenderer meshRenderer;
go.TryGetComponent<MeshRenderer>(out meshRenderer);
return meshRenderer.bounds.center;
}
}
public class NpcDirectPointState : INpcBaseState
{
public bool InCover => false;
public bool IsRunning => false;
public bool InDirectPoint => false;
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInDirectPoint;
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInDirectPoint;
public NpcEnumState State => NpcEnumState.InDirectPoint;
}
public class NpcRunningState : INpcBaseState
{
public bool InCover => false;
public bool IsRunning => true;
public bool InDirectPoint => false;
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInRunning;
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInRunning;
public NpcEnumState State => NpcEnumState.InRunning;
}
public class NpcInCoverState : INpcBaseState
{
public bool InCover => true;
public bool IsRunning => false;
public bool InDirectPoint => false;
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInCover;
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInCover;
public NpcEnumState State => NpcEnumState.InCover;
}

View File

@ -9,11 +9,15 @@ public class Player : MonoBehaviour, ICharacter
public Character GetCharacter => PlayerCharacter;
private void Start()
private void Awake()
{
PlayerCharacter = new Character();
Condition = PlayerCharacter.Condition;
GameManager.OnResetScene += PlayerCharacter.ResetCharacter;
}
private void OnDestroy()
{
Debug.LogWarning("Pooled object was destroyed");
}
public event Action<object> OnKilledEvent;
@ -23,12 +27,12 @@ public class Player : MonoBehaviour, ICharacter
Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f)));
Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5));
if (Condition.HealthPoints < 0)
OnKilledEvent?.Invoke(this);
if (Condition.HealthPoints < 0)
OnKilledEvent?.Invoke(this);
}
private void OnDestroy()
public void ResetCharacter()
{
Debug.LogWarning("Pooled object was destroyed");
Condition = new CharacterCondition();
}
}

View File

@ -1,10 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Barracuda;
using UnityEngine;
using UnityEngine;
using static scr_Models;
using static scr_Models;
public class scr_CharacterController : MonoBehaviour
{
@ -14,7 +10,7 @@ public class scr_CharacterController : MonoBehaviour
private Vector2 input_Movement;
[HideInInspector]
public Vector2 input_View;
private Vector3 newCameraRotation;
private Vector3 newCharacterRotation;
@ -22,14 +18,14 @@ public class scr_CharacterController : MonoBehaviour
public Transform cameraHolder;
public Transform feetTransform;
[Header("Settings")]
[Header("Settings")]
public PlayerSettingsModel playerSettings;
public float ViewClampYMin = -70;
public float ViewClampYMax = 80;
public LayerMask playerMask;
[Header("Gravity")]
[Header("Gravity")]
public float gravityAmount;
public float gravityMin;
private float playerGravity;
@ -37,14 +33,14 @@ public class scr_CharacterController : MonoBehaviour
public Vector3 jumpingForce;
private Vector3 jumpingForceVelocity;
[Header("Stance")]
[Header("Stance")]
public PlayerStance playerStance;
public float playerStanceSmoothing;
public CharacterStance playerStandStance;
public CharacterStance playerCrouchStance;
public CharacterStance playerProneStance;
private float stanceCheckErrorMargin = 0.05f;
private float cameraHeight;
private float cameraHeightVelocity;
@ -61,13 +57,13 @@ public class scr_CharacterController : MonoBehaviour
defaultInput.Character.Movement.performed += e => input_Movement = e.ReadValue<Vector2>();
defaultInput.Character.View.performed += e => input_View = e.ReadValue<Vector2>();
defaultInput.Character.Jump.performed += e => Jump();
defaultInput.Character.Crouch.performed += e => Crouch();
defaultInput.Character.Prone.performed += e => Prone();
defaultInput.Character.Sprint.performed += e => ToggleSprint();
defaultInput.Character.SprintReleased.performed += e => StopSprint();
defaultInput.Enable();
newCameraRotation = cameraHolder.localRotation.eulerAngles;
@ -80,7 +76,7 @@ public class scr_CharacterController : MonoBehaviour
{
currentWeapon.Initialise(this);
}
}
private void Update()
@ -95,10 +91,10 @@ public class scr_CharacterController : MonoBehaviour
{
newCharacterRotation.y += playerSettings.ViewXSensetivity * (playerSettings.ViewXInverted ? -input_View.x : input_View.x) * Time.deltaTime;
transform.localRotation = Quaternion.Euler(newCharacterRotation);
newCameraRotation.x += playerSettings.ViewYSensetivity * (playerSettings.ViewYInverted ? input_View.y : -input_View.y) * Time.deltaTime;
newCameraRotation.x = Mathf.Clamp(newCameraRotation.x, ViewClampYMin, ViewClampYMax);
cameraHolder.localRotation = Quaternion.Euler(newCameraRotation);
}
@ -108,7 +104,7 @@ public class scr_CharacterController : MonoBehaviour
{
isSprinting = false;
}
var verticalSpeed = playerSettings.WalkingForwardSpeed;
var horizontalSpeed = playerSettings.WalkingStrafeSpeed;
@ -117,17 +113,17 @@ public class scr_CharacterController : MonoBehaviour
verticalSpeed = playerSettings.RunningForwardSpeed;
horizontalSpeed = playerSettings.RunningStrafeSpeed;
}
// Effectors
if (!characterController.isGrounded)
{
playerSettings.SpeedEffector = playerSettings.FallingSpeedEffector;
}
else if(playerStance == PlayerStance.Crouch)
else if (playerStance == PlayerStance.Crouch)
{
playerSettings.SpeedEffector = playerSettings.CrouchSpeedEffector;
}
else if(playerStance == PlayerStance.Prone)
}
else if (playerStance == PlayerStance.Prone)
{
playerSettings.SpeedEffector = playerSettings.ProneSpeedEffector;
}
@ -135,15 +131,15 @@ public class scr_CharacterController : MonoBehaviour
{
playerSettings.SpeedEffector = 1;
}
verticalSpeed *= playerSettings.SpeedEffector;
horizontalSpeed *= playerSettings.SpeedEffector;
newMovementSpeed = Vector3.SmoothDamp(newMovementSpeed,
new Vector3(horizontalSpeed * input_Movement.x * Time.deltaTime,
0, verticalSpeed * input_Movement.y * Time.deltaTime),
ref newMovementSpeedVelocity, characterController.isGrounded ? playerSettings.MovementSmoothing : playerSettings.FallingSmoothing);
var MovementSpeed = transform.TransformDirection(newMovementSpeed);
if (playerGravity > gravityMin)
@ -158,7 +154,7 @@ public class scr_CharacterController : MonoBehaviour
MovementSpeed.y += playerGravity;
MovementSpeed += jumpingForce * Time.deltaTime;
characterController.Move(MovementSpeed);
}
@ -179,7 +175,7 @@ public class scr_CharacterController : MonoBehaviour
{
stanceHeight = playerProneStance.CameraHeight;
}
cameraHeight = Mathf.SmoothDamp(cameraHolder.localPosition.y, stanceHeight, ref cameraHeightVelocity, playerStanceSmoothing);
cameraHolder.localPosition = new Vector3(cameraHolder.localPosition.x, cameraHeight, cameraHolder.localPosition.z);
@ -190,7 +186,7 @@ public class scr_CharacterController : MonoBehaviour
{
return;
}
if (playerStance == PlayerStance.Crouch)
{
if (StanceCheck(playerStandStance.StanceCollider.height))
@ -200,7 +196,7 @@ public class scr_CharacterController : MonoBehaviour
playerStance = PlayerStance.Stand;
return;
}
// Jump
jumpingForce = Vector3.up * playerSettings.JumpingHeight;
playerGravity = 0;
@ -233,8 +229,8 @@ public class scr_CharacterController : MonoBehaviour
{
var start = new Vector3(feetTransform.position.x, feetTransform.position.y + characterController.radius + stanceCheckErrorMargin, feetTransform.position.z);
var end = new Vector3(feetTransform.position.x, feetTransform.position.y - characterController.radius - stanceCheckErrorMargin + stanceCheckheight, feetTransform.position.z);
return Physics.CheckCapsule(start, end, characterController.radius, playerMask);
}
@ -247,7 +243,7 @@ public class scr_CharacterController : MonoBehaviour
}
isSprinting = !isSprinting;
}
private void StopSprint()
{
if (playerSettings.SprintingHold)
@ -255,5 +251,5 @@ public class scr_CharacterController : MonoBehaviour
isSprinting = false;
}
}
}

View File

@ -3,73 +3,73 @@ using UnityEngine;
public static class scr_Models
{
#region Player
public enum PlayerStance
{
Stand,
Crouch,
Prone
}
[Serializable]
public class PlayerSettingsModel
{
[Header("View Settings")]
public float ViewXSensetivity;
public float ViewYSensetivity;
#region Player
public bool ViewXInverted;
public bool ViewYInverted;
public enum PlayerStance
{
Stand,
Crouch,
Prone
}
[Header("Movement Settings")]
public bool SprintingHold;
public float MovementSmoothing;
[Header("Movement - Running")]
public float RunningForwardSpeed;
public float RunningStrafeSpeed;
[Header("Movement - Walking")]
public float WalkingForwardSpeed;
public float WalkingBackwardSpeed;
public float WalkingStrafeSpeed;
[Serializable]
public class PlayerSettingsModel
{
[Header("View Settings")]
public float ViewXSensetivity;
public float ViewYSensetivity;
[Header("Jumping")]
public float JumpingHeight;
public float JumpingFalloff;
public float FallingSmoothing;
public bool ViewXInverted;
public bool ViewYInverted;
[Header("Speed Effectors")]
public float SpeedEffector = 1;
public float CrouchSpeedEffector;
public float ProneSpeedEffector;
public float FallingSpeedEffector;
}
[Header("Movement Settings")]
public bool SprintingHold;
public float MovementSmoothing;
[Serializable]
public class CharacterStance
{
public float CameraHeight;
public CapsuleCollider StanceCollider;
}
[Header("Movement - Running")]
public float RunningForwardSpeed;
public float RunningStrafeSpeed;
#endregion
[Header("Movement - Walking")]
public float WalkingForwardSpeed;
public float WalkingBackwardSpeed;
public float WalkingStrafeSpeed;
#region - Weapons -
[Header("Jumping")]
public float JumpingHeight;
public float JumpingFalloff;
public float FallingSmoothing;
[Serializable]
public class WeaponSettingsModel
{
[Header("Sway")]
public float SwayAmount;
public bool SwayYInverted;
public bool SwayXInverted;
public float SwaySmoothing;
public float SwayResetSmoothing;
public float SwayClampX;
public float SwayClampY;
}
[Header("Speed Effectors")]
public float SpeedEffector = 1;
public float CrouchSpeedEffector;
public float ProneSpeedEffector;
public float FallingSpeedEffector;
}
#endregion
[Serializable]
public class CharacterStance
{
public float CameraHeight;
public CapsuleCollider StanceCollider;
}
#endregion
#region - Weapons -
[Serializable]
public class WeaponSettingsModel
{
[Header("Sway")]
public float SwayAmount;
public bool SwayYInverted;
public bool SwayXInverted;
public float SwaySmoothing;
public float SwayResetSmoothing;
public float SwayClampX;
public float SwayClampY;
}
#endregion
}

View File

@ -1,80 +1,151 @@
using Unity.MLAgents;
using System;
using Unity.MLAgents;
using UnityEngine;
public class GameManager : MonoBehaviour
{
private static GameManager instance;
public static GameManager Instance { get { return instance; } }
public static GameManager Instance => instance;
private static SimpleMultiAgentGroup DefendersTeam = new SimpleMultiAgentGroup();
private static SimpleMultiAgentGroup AttackersTeam = new SimpleMultiAgentGroup();
private static SimpleMultiAgentGroup defendersTeam = new SimpleMultiAgentGroup();
private static SimpleMultiAgentGroup attackersTeam = new SimpleMultiAgentGroup();
private void Awake()
{
if (Instance == null)
if (instance is null)
instance = this;
else if (Instance == this)
else
{
Destroy(gameObject);
Debug.LogError("Only 1 Instance");
}
}
private void Start()
{
GlobalEventManager.onCaptureFlag += flagCaptured;
GlobalEventManager.onTimeLeft += timeOut;
Academy.Instance.OnEnvironmentReset += ResetScene;
GlobalEventManager.OnCaptureFlag += FlagCaptured;
GlobalEventManager.OnTimeLeft += TimeOut;
var agents = GameObject.FindObjectsOfType<Agent>();
foreach (var item in agents)
{
var agent = item as NPC;
if (agent.GetCharacter.Team == Team.Attackers)
AttackersTeam.RegisterAgent(agent);
attackersTeam.RegisterAgent(item);
else
DefendersTeam.RegisterAgent(agent);
defendersTeam.RegisterAgent(item);
}
}
public static bool IsCloserToEnemyThanToNextNavPoint(NavPoint navPoint, Vector3 currentTransform, Team team)
private static SimpleMultiAgentGroup getAgentList(Team team)
{
SimpleMultiAgentGroup agentGroup;
if (team == Team.Attackers)
agentGroup = AttackersTeam;
return attackersTeam;
else
agentGroup = DefendersTeam;
return defendersTeam;
}
var distToNavPoint = (currentTransform - navPoint.position).magnitude;
public static bool IsCloserToEnemyThanToNextNavPoint(NavPoint navPoint, Vector3 currentTransform, Team oppositeTeam)
{
var agentGroup = getAgentList(oppositeTeam);
var distToNavPoint = (currentTransform - navPoint.Position).magnitude;
foreach (var agent in agentGroup.GetRegisteredAgents())
if (distToNavPoint > (currentTransform - agent.transform.position).magnitude)
return true;
if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) ||
(SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders))
{
if (distToNavPoint > (currentTransform - CharacterFactory.Instance.player.transform.position).magnitude)
return true;
}
return false;
}
public static bool IsEnemyNearby(Vector3 currentTransform, Team oppositeTeam)
{
var agentGroup = getAgentList(oppositeTeam);
foreach (var agent in agentGroup.GetRegisteredAgents())
if ((currentTransform - agent.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance)
return true;
if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) ||
(SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders))
{
if ((currentTransform - CharacterFactory.Instance.player.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance)
return true;
}
return false;
}
public static bool IsCloserToFlagFromNextNavPoint(NavPoint navPoint, Vector3 currentTransform)
=> navPoint.FlagDistance < (currentTransform - GameObject.FindGameObjectWithTag("Flag").transform.position).magnitude;
private void flagCaptured(Team team)
public static bool IsHaveSeenByEnemy(Team oppositeTeam, Vector3 position)
{
switch(team)
var agentGroup = getAgentList(oppositeTeam);
RaycastHit rayHit = new RaycastHit();
foreach (var agent in agentGroup.GetRegisteredAgents() )
{
var npc = agent as NPC;
if (Physics.Raycast(position,
(npc.NpcBodyState.GetPointToHit(npc.gameObject) - position).normalized,
out rayHit,
SettingsReader.Instance.GetSettings.ViewDistance))
{
if (rayHit.collider.gameObject.GetComponent<ICharacter>() != null)
return true;
}
}
if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) ||
(SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders))
{
var player = CharacterFactory.Instance.player;
if (Physics.Raycast(position,
(player.GetComponent<MeshRenderer>().bounds.center - position).normalized,
out rayHit,
SettingsReader.Instance.GetSettings.ViewDistance))
{
if (rayHit.collider.gameObject.GetComponent<ICharacter>() != null)
return true;
}
}
return false;
}
private void FlagCaptured(Team team)
{
switch (team)
{
case Team.Attackers:
Debug.Log("Attackers Win");
ResetScene();
break;
case Team.Defenders:
Debug.Log("Defenders Win");
break;
default:
Debug.LogError("Unexpected Team");
ResetScene();
break;
}
ResetScene();
}
private void timeOut()
private void TimeOut()
{
Debug.Log("Time is out");
ResetScene();
}
private void OnDestroy()
{
GlobalEventManager.onCaptureFlag -= flagCaptured;
GlobalEventManager.onTimeLeft -= timeOut;
GlobalEventManager.OnCaptureFlag -= FlagCaptured;
GlobalEventManager.OnTimeLeft -= TimeOut;
}
public static event Action OnResetScene;
private void ResetScene()
{
Debug.Log("Scene Reset");
OnResetScene?.Invoke();
}
}

View File

@ -2,18 +2,18 @@
public class GlobalEventManager
{
public static event Action<Team> onCaptureFlag;
public static event Action<Team> OnCaptureFlag;
public static void SendCaptureFlag(Team team)
{
onCaptureFlag?.Invoke(team);
onCaptureFlag = null;
OnCaptureFlag?.Invoke(team);
OnCaptureFlag = null;
}
public static event Action onTimeLeft;
public static event Action OnTimeLeft;
public static void SendTimeout()
{
onTimeLeft?.Invoke();
onTimeLeft = null;
OnTimeLeft?.Invoke();
OnTimeLeft = null;
}
}

View File

@ -3,17 +3,61 @@ using UnityEngine;
public class MapManager : MonoBehaviour
{
public static List<NavPoint> navPoints { get; private set; }
private void Start()
private static MapManager instance;
public static MapManager Instance => instance;
[SerializeField] static List<NavPoint> _navPoints;
public static List<NavPoint> NavPoints { get => _navPoints; private set => _navPoints = value; }
public static Dictionary<int, NavPoint> IDToNavPoint {get; private set; }
private void Awake()
{
var i = 0;
navPoints = new List<NavPoint>();
var navPointsGameObj = GameObject.FindGameObjectsWithTag("Point");
foreach (var gameobj in navPointsGameObj)
if (instance is null)
instance = this;
else
{
var navpoint = gameobj.GetComponent<NavPoint>();
navpoint.PointId = i; i++;
navPoints.Add(navpoint);
Destroy(gameObject);
Debug.LogError("Only 1 Instance");
}
}
private void Start()
{
var navPointSet = GameObject.Find("NavPoint Set");
var count = navPointSet.transform.childCount;
for (int i=0; i < count; i++)
NavPoints.Add(navPointSet.transform.GetChild(i)
.gameObject.GetComponent<NavPoint>());
NavPointSetToID();
}
private void NavPointSetToID()
{
int i = 0;
foreach (var navPoint in NavPoints)
{
IDToNavPoint.Add(i, navPoint);
navPoint.PointId = i;
i++;
}
}
public static void AddDeathAttributeToPoints(int startPoint, int endPoint,
float allDistance, float remainingDistance)
{
var startNavPoint = IDToNavPoint[startPoint];
var endNavPoint = IDToNavPoint[endPoint];
float coef;
try
{
coef = remainingDistance / allDistance;
}
catch (System.ArithmeticException)
{
Debug.LogError("Path Length is zero");
return;
}
startNavPoint.DeathAttr += 1 - coef;
endNavPoint.DeathAttr += coef;
}
}

View File

@ -1,6 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
public class TimeManager : MonoBehaviour
{
@ -17,12 +15,14 @@ public class TimeManager : MonoBehaviour
}
else
{
Debug.LogError("Only one Instance");
Debug.LogError("Only 1 Instance");
Destroy(gameObject);
}
}
void Update()
{
CurrentTime += Time.deltaTime;
if (CurrentTime > SettingsReader.Instance.GetSettings.TimeOut)
GlobalEventManager.SendTimeout();
}
}

View File

@ -1,6 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
public class FlagZone : MonoBehaviour
{
@ -9,14 +7,14 @@ public class FlagZone : MonoBehaviour
public float TimeStayDefenders { get; private set; }
private int occupDefenders;
private int occupAttackers;
private bool isOccupBoth => (occupDefenders>0) && (occupAttackers>0);
private bool isNotOccup => (occupDefenders == 0) && (occupAttackers == 0);
public bool IsOccupBoth => (occupDefenders > 0) && (occupAttackers > 0);
public bool IsNotOccup => (occupDefenders == 0) && (occupAttackers == 0);
private float timeForWin;
private void Start()
{
timeForWin = SettingsReader.Instance.GetSettings.timeToWin;
timeForWin = SettingsReader.Instance.GetSettings.TimeToWin;
TimeStayAttackers = 0;
TimeStayDefenders = 0;
occupAttackers = 0;
@ -24,7 +22,7 @@ public class FlagZone : MonoBehaviour
}
private void OnTriggerEnter(Collider other)
{
switch(other.tag)
switch (other.tag)
{
case "Defender":
occupDefenders++;
@ -54,7 +52,7 @@ public class FlagZone : MonoBehaviour
}
private void Update()
{
if (isOccupBoth || isNotOccup)
if (IsOccupBoth || IsNotOccup)
{
TimeStayAttackers = 0;
TimeStayDefenders = 0;
@ -64,7 +62,7 @@ public class FlagZone : MonoBehaviour
{
TimeStayAttackers += Time.deltaTime;
if (TimeStayAttackers > timeForWin)
GlobalEventManager.SendCaptureFlag(Team.Attackers);
GlobalEventManager.SendCaptureFlag(Team.Attackers);
}
else
{

View File

@ -1,20 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using System;
using UnityEngine;
public enum NavPointType
{
Cover,
Direction,
}
public class NavPoint : MonoBehaviour
{
public Vector3 position => gameObject.transform.position;
public Vector3 Position => gameObject.transform.position;
public float FlagDistance { get; private set; }
public NavPointType navType = NavPointType.Direction;
[HideInInspector]
public int? PointId;
public int PointId = 0;
public float DeathAttr = 0;
public List<Vector3> EnemiesSeen = new List<Vector3>();
//Here other attributes;
private void Start()
{
FlagDistance = (GameObject.FindGameObjectWithTag("Flag").transform.position - position).magnitude;
FlagDistance = (GameObject.FindGameObjectWithTag("Flag").transform.position - Position).magnitude;
}
}

View File

@ -1,32 +1,34 @@
using UnityEngine;
[CreateAssetMenu(fileName ="Game Settings", menuName = "Game/Settings", order = 51)]
[CreateAssetMenu(fileName = "Game Settings", menuName = "Game/Settings", order = 51)]
public class Settings : ScriptableObject
{
public bool isTesting;
public bool IsTesting;
public float timeToWin;
public float timeOut;
public float TimeToWin;
public float TimeOut;
[Header("movement")]
public float movementDistance;
public float movementSpeed;
public float MovementDistance;
public float MovementSpeed;
public TypeAI defTeamAI;
public TypeAI atcTeamAI;
public int numOfDefenders;
public int numOfAttackers;
public bool hasHumanDefender;
public bool hasHumanAttacker;
public TypeAI DefTeamAI;
public TypeAI AtcTeamAI;
public int NumOfDefenders;
public int NumOfAttackers;
public bool HasHumanDefender;
public bool HasHumanAttacker;
public int healthPickupAmount;
public int armourPickupAmount;
public int ammunitionPickupAmount;
public int pickupsAmount;
public int HealthPickupAmount;
public int ArmourPickupAmount;
public int AmmunitionPickupAmount;
public int PickupsAmount;
public int maxHealth;
public int maxArmour;
public int maxAmmo;
public int MaxHealth;
public int MaxArmour;
public int MaxAmmo;
public float ViewDistance;
public float GetHitChanceInDirectPoint;
public float GetHitChanceInRunning;
@ -34,4 +36,6 @@ public class Settings : ScriptableObject
public float DoDamageChanceInDirectPoint;
public float DoDamageChanceInRunning;
public float DoDamageChanceInCover;
public float CrouchingCoefficient;
}

View File

@ -1,17 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
public class SettingsReader : MonoBehaviour
{
private static SettingsReader instance;
public static SettingsReader Instance { get { return instance; } }
public static SettingsReader Instance => instance;
private void Awake()
{
instance = this;
if (instance is null)
instance = this;
else
{
Destroy(gameObject);
Debug.LogError("Only 1 Instance");
}
}
[SerializeField] private Settings gameSettings;
public Settings GetSettings { get { return gameSettings; } }
public Settings GetSettings => gameSettings;
}

View File

@ -1,9 +0,0 @@
using UnityEngine;
public class Statistics : MonoBehaviour
{
private void Start()
{
}
}

View File

@ -1,5 +1,4 @@
using System;
using UnityEngine;
using UnityEngine;
[RequireComponent(typeof(BoxCollider))]
public class AmmoPickUp : MonoBehaviour, IPickable
@ -11,9 +10,14 @@ public class AmmoPickUp : MonoBehaviour, IPickable
PickObject(other.gameObject);
}
private void OnDestroy()
{
Debug.LogWarning("Pooled object was destroyed");
}
public void PickObject(GameObject obj)
{
obj.GetComponent<CharacterCondition>()?.TakeAmmo(SettingsReader.Instance.GetSettings.ammunitionPickupAmount);
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.TakeAmmo(SettingsReader.Instance.GetSettings.AmmunitionPickupAmount);
gameObject.SetActive(false);
}
}

View File

@ -1,5 +1,4 @@
using System;
using UnityEngine;
using UnityEngine;
[RequireComponent(typeof(BoxCollider))]
public class ArmourPickUp : MonoBehaviour, IPickable
@ -11,9 +10,14 @@ public class ArmourPickUp : MonoBehaviour, IPickable
PickObject(other.gameObject);
}
private void OnDestroy()
{
Debug.LogWarning("Pooled object was destroyed");
}
public void PickObject(GameObject obj)
{
obj.GetComponent<CharacterCondition>()?.GiveArmour(SettingsReader.Instance.GetSettings.armourPickupAmount);
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveArmour(SettingsReader.Instance.GetSettings.ArmourPickupAmount);
gameObject.SetActive(false);
}
}

View File

@ -1,5 +1,4 @@
using System;
using UnityEngine;
using UnityEngine;
[RequireComponent(typeof(BoxCollider))]
public class HealthPickUp : MonoBehaviour, IPickable
@ -11,9 +10,14 @@ public class HealthPickUp : MonoBehaviour, IPickable
PickObject(other.gameObject);
}
private void OnDestroy()
{
Debug.LogWarning("Pooled object was destroyed");
}
public void PickObject(GameObject obj)
{
obj.GetComponent<CharacterCondition>()?.GiveHealth(SettingsReader.Instance.GetSettings.healthPickupAmount);
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveHealth(SettingsReader.Instance.GetSettings.HealthPickupAmount);
gameObject.SetActive(false);
}
}

View File

@ -1,7 +1,6 @@
using System;
using UnityEngine;
using UnityEngine;
public interface IPickable
{
PickUpType type { get; }
PickUpType type { get; }
void PickObject(GameObject obj);
}

View File

@ -27,7 +27,7 @@ public class PickUpSpawner : MonoBehaviour
private void Start()
{
pickups = new List<GameObject>();
var amount = SettingsReader.Instance.GetSettings.pickupsAmount;
var amount = SettingsReader.Instance.GetSettings.PickupsAmount;
for (int i = 0; i < amount; i++)
pickups.Add(GameObject.Instantiate(healthPrefab, spawnPoints[Random.Range(0, spawnPoints.Count)].transform.position, Quaternion.identity));
for (int i = 0; i < amount; i++)
@ -44,25 +44,25 @@ public class PickUpSpawner : MonoBehaviour
private IEnumerator SpawnNewPickUps()
{
while(true)
while (true)
{
GameObject item;
if(IsDisableCheck(out item))
if (IsDisableCheck(out item))
{
yield return new WaitForSeconds(3);
if (item != null)
{
item.transform.position = spawnPoints[Random.Range(0, spawnPoints.Count)].position;
item.transform.position = spawnPoints[Random.Range(0, spawnPoints.Count)].Position;
item.SetActive(true);
}
}
yield return new WaitForSeconds(2);
yield return new WaitForSeconds(2);
}
}
private bool IsDisableCheck(out GameObject gameobj)
{
foreach(var pick in pickups)
foreach (var pick in pickups)
{
if (!pick.activeInHierarchy)
{

View File

@ -1,6 +0,0 @@
public enum SensorType
{
Visual,
Sound,
Other
}

View File

@ -1,4 +0,0 @@
using System.Collections.Generic;
using Unity.MLAgents.Sensors;

View File

@ -1,6 +1,7 @@
fileFormatVersion: 2
guid: 249f8a9af2b0bc041a08a0009a6fdf44
TextScriptImporter:
guid: 3a9f7f0a9faf11f49a433480722bffc5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:

View File

@ -0,0 +1,19 @@
using System.IO;
using UnityEngine;
public class Logger
{
private const string Directory = "/Logs/";
private const string BaseName = "Log#";
public static void SaveLog<T>(T objToSerialize)
{
var dir = Application.persistentDataPath + Directory;
if (!System.IO.Directory.Exists(dir))
System.IO.Directory.CreateDirectory(dir);
var logName = BaseName + (System.IO.Directory.GetFiles(dir).Length + 1).ToString();
var json = JsonUtility.ToJson(objToSerialize);
File.WriteAllText(dir + logName, json);
}
}

11
Assets/Scripts/Statistics/Logger.cs.meta generated Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3a1cec894fa98b4bbe20470f1e316c4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,51 @@
using UnityEngine;
internal class Log
{
public int damageTakenByDefs = 0;
public int damageTakenByAtc = 0;
public int AtcWin = 0;
public int DefWin = 0;
public int TimeOuts = 0;
}
public class StatisticManager : MonoBehaviour
{
private Log log = new Log();
private void Awake()
{
foreach (var npc in GameObject.FindObjectsOfType<NPC>())
npc.OnDamageRecieved += RegisterDamage;
GlobalEventManager.OnCaptureFlag += RegisterWin;
GlobalEventManager.OnTimeLeft += RegisterTimeOut;
}
private void RegisterDamage(int damage, Team team)
{
if (team == Team.Attackers)
log.damageTakenByAtc += damage;
else
log.damageTakenByDefs += damage;
}
private void RegisterWin(Team team)
{
if (team == Team.Attackers)
log.AtcWin += 1;
else
log.DefWin += 1;
}
private void RegisterTimeOut()
{
log.TimeOuts += 1;
}
private void OnApplicationQuit()
{
Logger.SaveLog<Log>(log);
}
}

View File

@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder: 300
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,7 @@
public static class BoolExtension
{
public static int ToInt(this bool _bool)
{
return _bool == true ? 1 : 0;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f48fff3c2eda14d4fba923fe8875f651
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,10 +1,10 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityObject = UnityEngine.Object;
[Serializable, DebuggerDisplay("Count = {Count}")]

View File

@ -1,17 +1,16 @@
using System;
using UnityEngine;
using UnityEngine;
using static scr_Models;
public class scr_WeaponController : MonoBehaviour
{
private scr_CharacterController characterController;
[Header("Settings")]
[Header("Settings")]
public WeaponSettingsModel settings;
private bool isInitialised;
Vector3 newWeaponRotation;
Vector3 newWeaponRotationVelocity;
Vector3 targetWeaponRotation;
Vector3 targetWeaponRotationVelocity;
@ -32,17 +31,17 @@ public class scr_WeaponController : MonoBehaviour
{
return;
}
targetWeaponRotation.y += settings.SwayAmount * (settings.SwayXInverted ? -characterController.input_View.x : characterController.input_View.x) * Time.deltaTime;
targetWeaponRotation.x += settings.SwayAmount * (settings.SwayYInverted ? characterController.input_View.y : -characterController.input_View.y) * Time.deltaTime;
targetWeaponRotation.x += settings.SwayAmount * (settings.SwayYInverted ? characterController.input_View.y : -characterController.input_View.y) * Time.deltaTime;
//newWeaponRotation.x = Mathf.Clamp(newWeaponRotation.x, ViewClampYMin, ViewClampYMax);
targetWeaponRotation.x = Mathf.Clamp(targetWeaponRotation.x, -settings.SwayClampX, settings.SwayClampX);
targetWeaponRotation.y = Mathf.Clamp(targetWeaponRotation.y, -settings.SwayClampY, settings.SwayClampY);
targetWeaponRotation = Vector3.SmoothDamp(targetWeaponRotation, Vector3.zero, ref targetWeaponRotationVelocity, settings.SwayResetSmoothing);
newWeaponRotation = Vector3.SmoothDamp(newWeaponRotation, targetWeaponRotation, ref newWeaponRotationVelocity, settings.SwaySmoothing);
transform.localRotation = Quaternion.Euler(newWeaponRotation);
}
}

View File

@ -12,6 +12,34 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e2c47233b9062c84482336b145c6891b, type: 3}
m_Name: Game Settings
m_EditorClassIdentifier:
<<<<<<< HEAD
IsTesting: 0
TimeToWin: 15
TimeOut: 3600
MovementDistance: 50
MovementSpeed: 5
DefTeamAI: 3
AtcTeamAI: 3
NumOfDefenders: 1
NumOfAttackers: 1
HasHumanDefender: 0
HasHumanAttacker: 0
HealthPickupAmount: 50
ArmourPickupAmount: 50
AmmunitionPickupAmount: 60
PickupsAmount: 0
MaxHealth: 100
MaxArmour: 100
MaxAmmo: 360
ViewDistance: 100
GetHitChanceInDirectPoint: 50
GetHitChanceInRunning: 25
GetHitChanceInCover: 20
DoDamageChanceInDirectPoint: 70
DoDamageChanceInRunning: 30
DoDamageChanceInCover: 25
CrouchingCoefficient: 1.4
=======
isTesting: 1
timeToWin: 5
timeOut: 1600
@ -27,12 +55,13 @@ MonoBehaviour:
armourPickupAmount: 50
ammunitionPickupAmount: 120
pickupsAmount: 2
maxHealth: 0
maxArmour: 0
maxAmmo: 0
maxHealth: 100
maxArmour: 100
maxAmmo: 31337
GetHitChanceInDirectPoint: 0
GetHitChanceInRunning: 0
GetHitChanceInCover: 0
DoDamageChanceInDirectPoint: 0
DoDamageChanceInRunning: 0
DoDamageChanceInCover: 0
>>>>>>> 351fa8ee12c499a0374be71a192a5f288611f467

7477
StyleCop.Cache Normal file

File diff suppressed because it is too large Load Diff