This commit is contained in:
Alex38Lyon
2025-06-03 12:00:47 +02:00
parent ed8041abcd
commit 878ea46cac
1300 changed files with 527178 additions and 0 deletions
@@ -0,0 +1,79 @@
using Unity.FPS.Game;
using UnityEngine;
namespace Unity.FPS.Gameplay
{
public class ObjectiveKillEnemies : Objective
{
[Tooltip("Chose whether you need to kill every enemies or only a minimum amount")]
public bool MustKillAllEnemies = true;
[Tooltip("If MustKillAllEnemies is false, this is the amount of enemy kills required")]
public int KillsToCompleteObjective = 5;
[Tooltip("Start sending notification about remaining enemies when this amount of enemies is left")]
public int NotificationEnemiesRemainingThreshold = 3;
int m_KillTotal;
protected override void Start()
{
base.Start();
EventManager.AddListener<EnemyKillEvent>(OnEnemyKilled);
// set a title and description specific for this type of objective, if it hasn't one
if (string.IsNullOrEmpty(Title))
Title = "Eliminate " + (MustKillAllEnemies ? "all the" : KillsToCompleteObjective.ToString()) +
" enemies";
if (string.IsNullOrEmpty(Description))
Description = GetUpdatedCounterAmount();
}
void OnEnemyKilled(EnemyKillEvent evt)
{
if (IsCompleted)
return;
m_KillTotal++;
if (MustKillAllEnemies)
KillsToCompleteObjective = evt.RemainingEnemyCount + m_KillTotal;
int targetRemaining = MustKillAllEnemies ? evt.RemainingEnemyCount : KillsToCompleteObjective - m_KillTotal;
// update the objective text according to how many enemies remain to kill
if (targetRemaining == 0)
{
CompleteObjective(string.Empty, GetUpdatedCounterAmount(), "Objective complete : " + Title);
}
else if (targetRemaining == 1)
{
string notificationText = NotificationEnemiesRemainingThreshold >= targetRemaining
? "One enemy left"
: string.Empty;
UpdateObjective(string.Empty, GetUpdatedCounterAmount(), notificationText);
}
else
{
// create a notification text if needed, if it stays empty, the notification will not be created
string notificationText = NotificationEnemiesRemainingThreshold >= targetRemaining
? targetRemaining + " enemies to kill left"
: string.Empty;
UpdateObjective(string.Empty, GetUpdatedCounterAmount(), notificationText);
}
}
string GetUpdatedCounterAmount()
{
return m_KillTotal + " / " + KillsToCompleteObjective;
}
void OnDestroy()
{
EventManager.RemoveListener<EnemyKillEvent>(OnEnemyKilled);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3cff9918d8018a44989bf444e3232f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
using Unity.FPS.Game;
using UnityEngine;
namespace Unity.FPS.Gameplay
{
public class ObjectivePickupItem : Objective
{
[Tooltip("Item to pickup to complete the objective")]
public GameObject ItemToPickup;
protected override void Start()
{
base.Start();
EventManager.AddListener<PickupEvent>(OnPickupEvent);
}
void OnPickupEvent(PickupEvent evt)
{
if (IsCompleted || ItemToPickup != evt.Pickup)
return;
// this will trigger the objective completion
// it works even if the player can't pickup the item (i.e. objective pickup healthpack while at full heath)
CompleteObjective(string.Empty, string.Empty, "Objective complete : " + Title);
if (gameObject)
{
Destroy(gameObject);
}
}
void OnDestroy()
{
EventManager.RemoveListener<PickupEvent>(OnPickupEvent);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 33498356859fc2040b30fc2e60beac7f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using Unity.FPS.Game;
using UnityEngine;
namespace Unity.FPS.Gameplay
{
[RequireComponent(typeof(Collider))]
public class ObjectiveReachPoint : Objective
{
[Tooltip("Visible transform that will be destroyed once the objective is completed")]
public Transform DestroyRoot;
void Awake()
{
if (DestroyRoot == null)
DestroyRoot = transform;
}
void OnTriggerEnter(Collider other)
{
if (IsCompleted)
return;
var player = other.GetComponent<PlayerCharacterController>();
// test if the other collider contains a PlayerCharacterController, then complete
if (player != null)
{
CompleteObjective(string.Empty, string.Empty, "Objective complete : " + Title);
// destroy the transform, will remove the compass marker if it has one
Destroy(DestroyRoot.gameObject);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 37fff5bb19450134f9e207f3823811fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: