update
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.FPS.Game
|
||||
{
|
||||
public class ActorsManager : MonoBehaviour
|
||||
{
|
||||
public List<Actor> Actors { get; private set; }
|
||||
public GameObject Player { get; private set; }
|
||||
|
||||
public void SetPlayer(GameObject player) => Player = player;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Actors = new List<Actor>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf10145f6bd13744c8fd10972a92ac61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace Unity.FPS.Game
|
||||
{
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public AudioMixer[] AudioMixers;
|
||||
|
||||
public AudioMixerGroup[] FindMatchingGroups(string subPath)
|
||||
{
|
||||
for (int i = 0; i < AudioMixers.Length; i++)
|
||||
{
|
||||
AudioMixerGroup[] results = AudioMixers[i].FindMatchingGroups(subPath);
|
||||
if (results != null && results.Length != 0)
|
||||
{
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetFloat(string name, float value)
|
||||
{
|
||||
for (int i = 0; i < AudioMixers.Length; i++)
|
||||
{
|
||||
if (AudioMixers[i] != null)
|
||||
{
|
||||
AudioMixers[i].SetFloat(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GetFloat(string name, out float value)
|
||||
{
|
||||
value = 0f;
|
||||
for (int i = 0; i < AudioMixers.Length; i++)
|
||||
{
|
||||
if (AudioMixers[i] != null)
|
||||
{
|
||||
AudioMixers[i].GetFloat(name, out value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d54177cab788734b8ecb4674c6e5328
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Unity.FPS.Game
|
||||
{
|
||||
public class GameEvent
|
||||
{
|
||||
}
|
||||
|
||||
// A simple Event System that can be used for remote systems communication
|
||||
public static class EventManager
|
||||
{
|
||||
static readonly Dictionary<Type, Action<GameEvent>> s_Events = new Dictionary<Type, Action<GameEvent>>();
|
||||
|
||||
static readonly Dictionary<Delegate, Action<GameEvent>> s_EventLookups =
|
||||
new Dictionary<Delegate, Action<GameEvent>>();
|
||||
|
||||
public static void AddListener<T>(Action<T> evt) where T : GameEvent
|
||||
{
|
||||
if (!s_EventLookups.ContainsKey(evt))
|
||||
{
|
||||
Action<GameEvent> newAction = (e) => evt((T) e);
|
||||
s_EventLookups[evt] = newAction;
|
||||
|
||||
if (s_Events.TryGetValue(typeof(T), out Action<GameEvent> internalAction))
|
||||
s_Events[typeof(T)] = internalAction += newAction;
|
||||
else
|
||||
s_Events[typeof(T)] = newAction;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveListener<T>(Action<T> evt) where T : GameEvent
|
||||
{
|
||||
if (s_EventLookups.TryGetValue(evt, out var action))
|
||||
{
|
||||
if (s_Events.TryGetValue(typeof(T), out var tempAction))
|
||||
{
|
||||
tempAction -= action;
|
||||
if (tempAction == null)
|
||||
s_Events.Remove(typeof(T));
|
||||
else
|
||||
s_Events[typeof(T)] = tempAction;
|
||||
}
|
||||
|
||||
s_EventLookups.Remove(evt);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Broadcast(GameEvent evt)
|
||||
{
|
||||
if (s_Events.TryGetValue(evt.GetType(), out var action))
|
||||
action.Invoke(evt);
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
s_Events.Clear();
|
||||
s_EventLookups.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30e5751c33b241646926d24ab481e1f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,115 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Unity.FPS.Game
|
||||
{
|
||||
public class GameFlowManager : MonoBehaviour
|
||||
{
|
||||
[Header("Parameters")] [Tooltip("Duration of the fade-to-black at the end of the game")]
|
||||
public float EndSceneLoadDelay = 3f;
|
||||
|
||||
[Tooltip("The canvas group of the fade-to-black screen")]
|
||||
public CanvasGroup EndGameFadeCanvasGroup;
|
||||
|
||||
[Header("Win")] [Tooltip("This string has to be the name of the scene you want to load when winning")]
|
||||
public string WinSceneName = "WinScene";
|
||||
|
||||
[Tooltip("Duration of delay before the fade-to-black, if winning")]
|
||||
public float DelayBeforeFadeToBlack = 4f;
|
||||
|
||||
[Tooltip("Win game message")]
|
||||
public string WinGameMessage;
|
||||
[Tooltip("Duration of delay before the win message")]
|
||||
public float DelayBeforeWinMessage = 2f;
|
||||
|
||||
[Tooltip("Sound played on win")] public AudioClip VictorySound;
|
||||
|
||||
[Header("Lose")] [Tooltip("This string has to be the name of the scene you want to load when losing")]
|
||||
public string LoseSceneName = "LoseScene";
|
||||
|
||||
|
||||
public bool GameIsEnding { get; private set; }
|
||||
|
||||
float m_TimeLoadEndGameScene;
|
||||
string m_SceneToLoad;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
EventManager.AddListener<AllObjectivesCompletedEvent>(OnAllObjectivesCompleted);
|
||||
EventManager.AddListener<PlayerDeathEvent>(OnPlayerDeath);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
AudioUtility.SetMasterVolume(1);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (GameIsEnding)
|
||||
{
|
||||
float timeRatio = 1 - (m_TimeLoadEndGameScene - Time.time) / EndSceneLoadDelay;
|
||||
EndGameFadeCanvasGroup.alpha = timeRatio;
|
||||
|
||||
AudioUtility.SetMasterVolume(1 - timeRatio);
|
||||
|
||||
// See if it's time to load the end scene (after the delay)
|
||||
if (Time.time >= m_TimeLoadEndGameScene)
|
||||
{
|
||||
SceneManager.LoadScene(m_SceneToLoad);
|
||||
GameIsEnding = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnAllObjectivesCompleted(AllObjectivesCompletedEvent evt) => EndGame(true);
|
||||
void OnPlayerDeath(PlayerDeathEvent evt) => EndGame(false);
|
||||
|
||||
void EndGame(bool win)
|
||||
{
|
||||
// unlocks the cursor before leaving the scene, to be able to click buttons
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
|
||||
// Remember that we need to load the appropriate end scene after a delay
|
||||
GameIsEnding = true;
|
||||
EndGameFadeCanvasGroup.gameObject.SetActive(true);
|
||||
if (win)
|
||||
{
|
||||
m_SceneToLoad = WinSceneName;
|
||||
m_TimeLoadEndGameScene = Time.time + EndSceneLoadDelay + DelayBeforeFadeToBlack;
|
||||
|
||||
// play a sound on win
|
||||
var audioSource = gameObject.AddComponent<AudioSource>();
|
||||
audioSource.clip = VictorySound;
|
||||
audioSource.playOnAwake = false;
|
||||
audioSource.outputAudioMixerGroup = AudioUtility.GetAudioGroup(AudioUtility.AudioGroups.HUDVictory);
|
||||
audioSource.PlayScheduled(AudioSettings.dspTime + DelayBeforeWinMessage);
|
||||
|
||||
// create a game message
|
||||
//var message = Instantiate(WinGameMessagePrefab).GetComponent<DisplayMessage>();
|
||||
//if (message)
|
||||
//{
|
||||
// message.delayBeforeShowing = delayBeforeWinMessage;
|
||||
// message.GetComponent<Transform>().SetAsLastSibling();
|
||||
//}
|
||||
|
||||
DisplayMessageEvent displayMessage = Events.DisplayMessageEvent;
|
||||
displayMessage.Message = WinGameMessage;
|
||||
displayMessage.DelayBeforeDisplay = DelayBeforeWinMessage;
|
||||
EventManager.Broadcast(displayMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_SceneToLoad = LoseSceneName;
|
||||
m_TimeLoadEndGameScene = Time.time + EndSceneLoadDelay;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
EventManager.RemoveListener<AllObjectivesCompletedEvent>(OnAllObjectivesCompleted);
|
||||
EventManager.RemoveListener<PlayerDeathEvent>(OnPlayerDeath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e1fea5cb3ddbc249bd0181e6766db68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.FPS.Game
|
||||
{
|
||||
public class ObjectiveManager : MonoBehaviour
|
||||
{
|
||||
List<Objective> m_Objectives = new List<Objective>();
|
||||
bool m_ObjectivesCompleted = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Objective.OnObjectiveCreated += RegisterObjective;
|
||||
}
|
||||
|
||||
void RegisterObjective(Objective objective) => m_Objectives.Add(objective);
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (m_Objectives.Count == 0 || m_ObjectivesCompleted)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < m_Objectives.Count; i++)
|
||||
{
|
||||
// pass every objectives to check if they have been completed
|
||||
if (m_Objectives[i].IsBlocking())
|
||||
{
|
||||
// break the loop as soon as we find one uncompleted objective
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_ObjectivesCompleted = true;
|
||||
EventManager.Broadcast(Events.AllObjectivesCompletedEvent);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Objective.OnObjectiveCreated -= RegisterObjective;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5174b5e414847cf4a9dca6e207326c8d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user