init
This commit is contained in:
commit
341a877b4a
2338 changed files with 1346408 additions and 0 deletions
8
Assets/Scripts/Tools/AudioManager.meta
Normal file
8
Assets/Scripts/Tools/AudioManager.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2693168e92b394e4cafa0931d3b8f901
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
279
Assets/Scripts/Tools/AudioManager/AudioManager.cs
Normal file
279
Assets/Scripts/Tools/AudioManager/AudioManager.cs
Normal file
|
@ -0,0 +1,279 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.Audio;
|
||||
using System.Collections;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
[Tooltip("The music mixer.")]
|
||||
[SerializeField] AudioMixerGroup mainMixer = default;
|
||||
[Tooltip("The SFX mixer.")]
|
||||
[SerializeField] AudioMixerGroup sfxMixer = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Sound[] sounds = default;
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
if (instance == null){
|
||||
instance = this;
|
||||
}else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach (Sound s in sounds){
|
||||
GameObject sound = new GameObject(s.name);
|
||||
sound.transform.parent = transform;
|
||||
s.source = sound.AddComponent<AudioSource>();
|
||||
|
||||
if(s.type == Sound.Type.Music)
|
||||
s.source.outputAudioMixerGroup = mainMixer;
|
||||
else
|
||||
s.source.outputAudioMixerGroup = sfxMixer;
|
||||
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
}
|
||||
}
|
||||
|
||||
#region Play
|
||||
/// <summary> Play a sound with a certain name setted on the inspector. </summary>
|
||||
public void Play(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.Play();
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name setted on the inspector.
|
||||
/// Set the randomPitch to true to make the sound start with a random pitch variation setted on the inspector. </summary>
|
||||
public void Play(string name, bool randomPitch){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (randomPitch){
|
||||
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
|
||||
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
|
||||
}else{
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
}
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name setted on the inspector.
|
||||
/// Make the sound start with a certain delay. </summary>
|
||||
public void Play(string name, float delay){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.PlayDelayed(delay);
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name setted on the inspector.
|
||||
/// Play it with a randomPitch and delay. </summary>
|
||||
public void Play(string name, float delay, bool randomPitch){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (randomPitch){
|
||||
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
|
||||
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
|
||||
}else{
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
}
|
||||
s.source.PlayDelayed(delay);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PlayOneShot
|
||||
/// <summary> Play a sound with a certain name without overlapping. </summary>
|
||||
public void PlayOneShot(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name without overlapping.
|
||||
/// Set the randomPitch to true to make the sound start with a random pitch variation setted on the inspector. </summary>
|
||||
public void PlayOneShot(string name, bool randomPitch){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (randomPitch){
|
||||
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
|
||||
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
|
||||
}else{
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
}
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary> Pause a sound with a certain name setted on the inspector. </summary>
|
||||
public void Pause(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Pause();
|
||||
}
|
||||
|
||||
/// <summary> Unpause a sound with a certain name setted on the inspector. </summary>
|
||||
public void UnPause(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.UnPause();
|
||||
}
|
||||
|
||||
/// <summary> Stop a sound with a certain name setted on the inspector. </summary>
|
||||
public void Stop(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Stop();
|
||||
}
|
||||
|
||||
/// <summary> Stops all the sounds. </summary>
|
||||
public void StopAll(){
|
||||
foreach(Sound s in sounds){
|
||||
if(s.source != null){
|
||||
s.source.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AudioSource GetSource(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if(s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return s.source;
|
||||
}
|
||||
|
||||
/// <summary> Fade out an AudioSource with a specific name and fade duration. </summary>
|
||||
public IEnumerator FadeOut(string name, float fadeTime){
|
||||
AudioSource audioSource = GetSource(name);
|
||||
|
||||
if(audioSource != null && audioSource.isPlaying){
|
||||
float startVolume = audioSource.volume;
|
||||
|
||||
while(audioSource.volume > 0){
|
||||
audioSource.volume -= startVolume * Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
audioSource.Stop();
|
||||
audioSource.volume = startVolume;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Fade in an AudioSource with a specific name and fade duration. </summary>
|
||||
public IEnumerator FadeIn(string name, float fadeTime){
|
||||
AudioSource audioSource = GetSource(name);
|
||||
if(audioSource != null && !audioSource.isPlaying){
|
||||
float volume = audioSource.volume;
|
||||
audioSource.volume = 0;
|
||||
audioSource.Play();
|
||||
while(audioSource.volume < volume){
|
||||
audioSource.volume += Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
audioSource.volume = volume;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMuted(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = 0;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.Play();
|
||||
}
|
||||
|
||||
public void FadeMutedIn(string name, float fadeTime, float percentageToGo){
|
||||
StartCoroutine(MutedIn(name, fadeTime, percentageToGo));
|
||||
}
|
||||
|
||||
IEnumerator MutedIn(string name, float fadeTime, float percentageToGo){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
while(s.source.volume < s.volume * percentageToGo / 100){
|
||||
s.source.volume += Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
s.source.volume = s.volume * percentageToGo / 100;
|
||||
}
|
||||
|
||||
public void FadeMutedOut(string name, float fadeTime, float percentageToGo){
|
||||
StartCoroutine(MutedOut(name, fadeTime, percentageToGo));
|
||||
}
|
||||
|
||||
IEnumerator MutedOut(string name, float fadeTime, float percentageToGo){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
while (s.source.volume > s.volume * percentageToGo / 100){
|
||||
s.source.volume -= Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
s.source.volume = s.volume * percentageToGo / 100;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/AudioManager/AudioManager.cs.meta
Normal file
11
Assets/Scripts/Tools/AudioManager/AudioManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ebdca66b03709e04097142c1a3259b26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/Tools/AudioManager/PlaySounds.cs
Normal file
10
Assets/Scripts/Tools/AudioManager/PlaySounds.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlaySounds : MonoBehaviour{
|
||||
|
||||
public void PlayError(){
|
||||
AudioManager.instance.PlayOneShot("critical_error", true);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/AudioManager/PlaySounds.cs.meta
Normal file
11
Assets/Scripts/Tools/AudioManager/PlaySounds.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3ee95b3a33f682041b2e1e15e0af463a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Scripts/Tools/AudioManager/Sound.cs
Normal file
25
Assets/Scripts/Tools/AudioManager/Sound.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Sound{
|
||||
[Tooltip("Name of the sound. Each name has to be different between each other.")]
|
||||
public string name;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
[System.Serializable] public enum Type {Music, SFX}
|
||||
[Space]
|
||||
[Tooltip("Is it part of the music or the SFX?")] public Type type;
|
||||
|
||||
[Space]
|
||||
[Tooltip("Default volume of the sound.")] [Range(0f, 1f)] public float volume = 1;
|
||||
[Tooltip("Max random volume variation of the sound.")] [Range(0f, 1f)] public float volumeVariance;
|
||||
[Space]
|
||||
[Tooltip("Default pitch of the sound.")] [Range(.1f, 3f)] public float pitch = 1;
|
||||
[Tooltip("Max random pitch variation of the sound.")] [Range(0f, 1f)] public float pitchVariance;
|
||||
|
||||
public bool loop;
|
||||
|
||||
[HideInInspector] public AudioSource source;
|
||||
}
|
||||
|
11
Assets/Scripts/Tools/AudioManager/Sound.cs.meta
Normal file
11
Assets/Scripts/Tools/AudioManager/Sound.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 515e53d16f5b80c4f9bca8a800703033
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/Cinemachine.meta
Normal file
8
Assets/Scripts/Tools/Cinemachine.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b17b95811debd13428871199ec7b91b9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs
Normal file
27
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class CMCameraTrigger : MonoBehaviour{
|
||||
|
||||
CinemachineVirtualCamera vcam;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
vcam = GetComponentInChildren<CinemachineVirtualCamera>();
|
||||
vcam.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs.meta
Normal file
11
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 368758c1440a4cb4c867e140e8934c09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 64770ab13b014f446bb4ad495e0b508c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,105 @@
|
|||
using Cinemachine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CMCameraRail : MonoBehaviour{
|
||||
|
||||
[SerializeField] CinemachineVirtualCamera dollyTrackCamera = default;
|
||||
CinemachineTrackedDolly cameraTrack;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Waypoint[] waypoints = default;
|
||||
int totalCount;
|
||||
int currentCount;
|
||||
|
||||
bool finished;
|
||||
bool paused;
|
||||
|
||||
float easedPercentBetweenWaypoints;
|
||||
float speed;
|
||||
float currentEase;
|
||||
float percentBetweenWaypoints;
|
||||
float nextPos;
|
||||
float lastFieldOfView;
|
||||
|
||||
void Awake(){
|
||||
totalCount = waypoints.Length - 1;
|
||||
if(dollyTrackCamera != null){
|
||||
cameraTrack = dollyTrackCamera.GetCinemachineComponent<CinemachineTrackedDolly>();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(!finished && !paused){
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
|
||||
if(currentCount == 0){
|
||||
speed = Time.deltaTime / waypoint.timeBetweenWaypoints * waypoint.endWaypoint;
|
||||
percentBetweenWaypoints += speed / waypoint.endWaypoint;
|
||||
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
|
||||
easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
|
||||
|
||||
nextPos = easedPercentBetweenWaypoints * waypoint.endWaypoint;
|
||||
}else{
|
||||
speed = Time.deltaTime / waypoint.timeBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
percentBetweenWaypoints += speed / (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
|
||||
easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
|
||||
|
||||
nextPos = waypoints[currentCount - 1].endWaypoint + easedPercentBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
}
|
||||
|
||||
dollyTrackCamera.m_Lens.FieldOfView = Mathf.Lerp(lastFieldOfView, waypoint.fieldOfView, easedPercentBetweenWaypoints);
|
||||
|
||||
if (cameraTrack.m_PathPosition < waypoint.endWaypoint){
|
||||
cameraTrack.m_PathPosition = nextPos;
|
||||
}else{
|
||||
NextWaypoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Ease(float x){
|
||||
if (waypoints[currentCount].ease){
|
||||
float a = currentEase + 1;
|
||||
return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a));
|
||||
}else{
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Starts playing the cutscene. </summary>
|
||||
public void StartRail(){
|
||||
lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView;
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
if (waypoint.startDelay > 0){
|
||||
paused = true;
|
||||
StartCoroutine(DelayMovement(waypoint.startDelay));
|
||||
}
|
||||
currentEase = waypoint.ease ? waypoint.easeAmount : 1;
|
||||
}
|
||||
|
||||
void NextWaypoint(){
|
||||
lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView;
|
||||
if (currentCount >= totalCount){
|
||||
Debug.Log("Finish");
|
||||
finished = true;
|
||||
}else{
|
||||
percentBetweenWaypoints = 0;
|
||||
currentCount++;
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
if(waypoint.startDelay > 0){
|
||||
paused = true;
|
||||
StartCoroutine(DelayMovement(waypoint.startDelay));
|
||||
}
|
||||
currentEase = waypoint.ease ? waypoint.easeAmount : 1;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DelayMovement(float delay){
|
||||
yield return new WaitForSeconds(delay);
|
||||
paused = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e80df5e5cd6b984396c057f7ce9a9c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Waypoint{
|
||||
|
||||
[Min(0)] public float startDelay;
|
||||
|
||||
[Header("Easing")]
|
||||
public bool ease;
|
||||
[Range(0f, 2f)] public float easeAmount;
|
||||
|
||||
[Header("Waypoints")]
|
||||
[Min(0)] public float timeBetweenWaypoints;
|
||||
[Min(0)] public int endWaypoint;
|
||||
|
||||
[Header("Field of View")]
|
||||
[Range(1, 179)] public float fieldOfView = 60;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cbcbf05409a71c34498aea255a6ba921
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
Normal file
39
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class ScreenShakeCall : MonoBehaviour{
|
||||
|
||||
CinemachineVirtualCamera vCam;
|
||||
float shakeTimer;
|
||||
float shakeTimerTotal;
|
||||
float startingIntensity;
|
||||
|
||||
public static ScreenShakeCall instance { get; private set; }
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
vCam = GetComponent<CinemachineVirtualCamera>();
|
||||
}
|
||||
|
||||
/// <summary> Smoothly shakes with a certain intensity and duration </summary>
|
||||
public void ShakeCamera(float intensity, float time){
|
||||
startingIntensity = intensity;
|
||||
shakeTimer = shakeTimerTotal = time;
|
||||
}
|
||||
|
||||
public void StopShaking(){
|
||||
shakeTimer = 0;
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin.m_AmplitudeGain = 0;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (shakeTimer > 0){
|
||||
shakeTimer -= Time.deltaTime;
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs.meta
Normal file
11
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f000cf598e480f345a7feb226d3b026a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/DialogueSystem.meta
Normal file
8
Assets/Scripts/Tools/DialogueSystem.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1b4ebc8cd1722294a80f5265eb6385d0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs
Normal file
10
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Character", menuName = "Character")]
|
||||
public class Dialogue : ScriptableObject{
|
||||
|
||||
public string characterName;
|
||||
[TextArea] public string[] sentences;
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd553cd05b84d614b998afe62e37c17c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
44
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs
Normal file
44
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class DialogueSystem : MonoBehaviour{
|
||||
|
||||
public TextMeshProUGUI nameText;
|
||||
public TextMeshProUGUI dialogueText;
|
||||
public TMP_Animated dialogue;
|
||||
|
||||
public Queue<string> sentences;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
sentences = new Queue<string>();
|
||||
}
|
||||
|
||||
public void StartDialogue(Dialogue dialogue){
|
||||
nameText.text = dialogue.characterName;
|
||||
|
||||
sentences.Clear();
|
||||
|
||||
foreach(string sentence in dialogue.sentences){
|
||||
sentences.Enqueue(sentence);
|
||||
}
|
||||
|
||||
DisplayNextSentence();
|
||||
}
|
||||
|
||||
public void DisplayNextSentence(){
|
||||
if(sentences.Count == 0){
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
|
||||
string sentence = sentences.Dequeue();
|
||||
dialogue.ReadText(sentence);
|
||||
}
|
||||
|
||||
void EndDialogue(){
|
||||
Debug.Log("End of conversation.");
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: caad12703fd5c3349acc637253734ac9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs
Normal file
13
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DialogueTrigger : MonoBehaviour{
|
||||
|
||||
public Dialogue dialogue;
|
||||
|
||||
/// <summary> Start the dialogue specified on the inspector </summary>
|
||||
public void TriggerDialogue(){
|
||||
FindObjectOfType<DialogueSystem>().StartDialogue(dialogue);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f15c572386779eb4aa5d6e8471fba51d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
76
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs
Normal file
76
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace TMPro{
|
||||
[System.Serializable] public class TextRevealEvent : UnityEvent<char> { }
|
||||
[System.Serializable] public class DialogueEvent : UnityEvent { }
|
||||
|
||||
public class TMP_Animated : TextMeshProUGUI{
|
||||
|
||||
float speed;
|
||||
|
||||
public TextRevealEvent onTextReveal;
|
||||
public DialogueEvent onDialogueFinish;
|
||||
|
||||
public void ClearText(){
|
||||
text = string.Empty;
|
||||
}
|
||||
|
||||
public void ReadText(string newText){
|
||||
text = string.Empty;
|
||||
|
||||
string[] subTexts = newText.Split('<', '>');
|
||||
|
||||
string displayText = "";
|
||||
for (int i = 0; i < subTexts.Length; i++){
|
||||
if (i % 2 == 0)
|
||||
displayText += subTexts[i];
|
||||
else if (!isCustomTag(subTexts[i].Replace(" ", "")))
|
||||
displayText += $"<{subTexts[i]}>";
|
||||
}
|
||||
|
||||
bool isCustomTag(string tag){
|
||||
return tag.StartsWith("speed=") || tag.StartsWith("pause=");
|
||||
}
|
||||
|
||||
text = displayText;
|
||||
maxVisibleCharacters = 0;
|
||||
StartCoroutine(Read());
|
||||
|
||||
IEnumerator Read(){
|
||||
int subCounter = 0;
|
||||
int visibleCounter = 0;
|
||||
while(subCounter < subTexts.Length){
|
||||
if(subCounter % 2 == 1){
|
||||
yield return EvaluateTag(subTexts[subCounter].Replace(" ", ""));
|
||||
}else{
|
||||
while(visibleCounter < subTexts[subCounter].Length){
|
||||
onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
|
||||
visibleCounter++;
|
||||
maxVisibleCharacters++;
|
||||
yield return new WaitForSecondsRealtime(1f / speed);
|
||||
}
|
||||
visibleCounter = 0;
|
||||
}
|
||||
subCounter++;
|
||||
}
|
||||
yield return null;
|
||||
|
||||
WaitForSecondsRealtime EvaluateTag(string tag){
|
||||
if (tag.Length > 0){
|
||||
if (tag.StartsWith("speed=")){
|
||||
speed = float.Parse(tag.Split('=')[1]);
|
||||
}else if (tag.StartsWith("pause=")){
|
||||
return new WaitForSecondsRealtime(float.Parse(tag.Split('=')[1]));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
onDialogueFinish.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f713d84a3ae882945800780459e26170
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/Menu.meta
Normal file
8
Assets/Scripts/Tools/Menu.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2e8a959779b966342ae50d05159abb6d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
111
Assets/Scripts/Tools/Menu/MenuController.cs
Normal file
111
Assets/Scripts/Tools/Menu/MenuController.cs
Normal file
|
@ -0,0 +1,111 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[System.Serializable] public class OnPlay : UnityEvent { }
|
||||
|
||||
public class MenuController : MonoBehaviour{
|
||||
|
||||
public OnPlay onPlay;
|
||||
|
||||
[SerializeField] AudioMixer mainMixer = default;
|
||||
[Tooltip("The music volume the first time you start the game")] [SerializeField, Range(0, 1)] float defaultMusicValue = 1f;
|
||||
[Tooltip("The SFX volume the first time you start the game")] [SerializeField, Range(0, 1)] float defaultSfxValue = 1f;
|
||||
[SerializeField] Slider musicSlider = default;
|
||||
[SerializeField] Slider sfxSlider = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField] TMP_Dropdown qualityDropdown = default;
|
||||
int qualitySelected;
|
||||
|
||||
[Space]
|
||||
[SerializeField] TMP_Dropdown resolutionDropdown = default;
|
||||
Resolution[] resolutions;
|
||||
int currentResolutionIndex;
|
||||
|
||||
void Awake(){
|
||||
if (resolutionDropdown != null){
|
||||
resolutions = Screen.resolutions.Select(resolution => new Resolution { width = resolution.width, height = resolution.height }).Distinct().ToArray();
|
||||
resolutionDropdown.ClearOptions();
|
||||
|
||||
List<string> options = new List<string>();
|
||||
for (int i = 0; i < resolutions.Length; i++){
|
||||
string option = resolutions[i].width + "x" + resolutions[i].height;
|
||||
options.Add(option);
|
||||
|
||||
if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height){
|
||||
currentResolutionIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
resolutions.Reverse();
|
||||
|
||||
resolutionDropdown.AddOptions(options);
|
||||
resolutionDropdown.value = currentResolutionIndex;
|
||||
resolutionDropdown.RefreshShownValue();
|
||||
}
|
||||
|
||||
if(qualityDropdown != null){
|
||||
if (PlayerPrefs.HasKey("QualitySelected")){
|
||||
qualitySelected = PlayerPrefs.GetInt("QualitySelected");
|
||||
}else{
|
||||
qualitySelected = qualityDropdown.value;
|
||||
}
|
||||
|
||||
qualityDropdown.value = qualitySelected;
|
||||
QualitySettings.SetQualityLevel(qualitySelected);
|
||||
}
|
||||
}
|
||||
|
||||
void Start(){
|
||||
Time.timeScale = 1;
|
||||
if (musicSlider != null && sfxSlider != null){
|
||||
musicSlider.value = PlayerPrefs.GetFloat("MusicVolume", defaultMusicValue);
|
||||
sfxSlider.value = PlayerPrefs.GetFloat("SFXVolume", defaultSfxValue);
|
||||
mainMixer.SetFloat("SFX", Mathf.Log10(PlayerPrefs.GetFloat("SFXVolume", defaultSfxValue)) * 20);
|
||||
mainMixer.SetFloat("Master", Mathf.Log10(PlayerPrefs.GetFloat("MusicVolume", defaultMusicValue)) * 20);
|
||||
}
|
||||
|
||||
AudioManager.instance.StopAll();
|
||||
AudioManager.instance.Play("MenuIntro");
|
||||
AudioManager.instance.Play("MenuMain", 2.1f);
|
||||
}
|
||||
|
||||
//Needs a slider between 0.0001 and 1
|
||||
public void SetMusicVolume(float sliderValue){
|
||||
mainMixer.SetFloat("Master", Mathf.Log10(sliderValue) * 20);
|
||||
PlayerPrefs.SetFloat("MusicVolume", sliderValue);
|
||||
}
|
||||
|
||||
//Needs a slider between 0.0001 and 1
|
||||
public void SetSfxVolume(float sliderValue){
|
||||
mainMixer.SetFloat("SFX", Mathf.Log10(sliderValue) * 20);
|
||||
PlayerPrefs.SetFloat("SFXVolume", sliderValue);
|
||||
}
|
||||
|
||||
public void SetQuality(int qualityIndex){
|
||||
QualitySettings.SetQualityLevel(qualityIndex);
|
||||
PlayerPrefs.SetInt("QualitySelected", qualityIndex);
|
||||
}
|
||||
|
||||
public void SetResolution(int resolutionIndex){
|
||||
Resolution resolution = resolutions[resolutionIndex];
|
||||
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
|
||||
}
|
||||
|
||||
public void Play(){
|
||||
PlayerPrefs.DeleteKey("HP");
|
||||
PlayerPrefs.DeleteKey("Percentage");
|
||||
PlayerPrefs.DeleteKey("TimeSurvived");
|
||||
onPlay.Invoke();
|
||||
}
|
||||
|
||||
public void Quit(){
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/Menu/MenuController.cs.meta
Normal file
11
Assets/Scripts/Tools/Menu/MenuController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1e26602e8c04bfd488f5d150c29aed57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/ObjectPooler.meta
Normal file
8
Assets/Scripts/Tools/ObjectPooler.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 88d9486b4c021564ea0f3a76d4c0265e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
Assets/Scripts/Tools/ObjectPooler/IPooledObject.cs
Normal file
3
Assets/Scripts/Tools/ObjectPooler/IPooledObject.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
public interface IPooledObject{
|
||||
void OnObjectSpawn();
|
||||
}
|
11
Assets/Scripts/Tools/ObjectPooler/IPooledObject.cs.meta
Normal file
11
Assets/Scripts/Tools/ObjectPooler/IPooledObject.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f901e5ecf80a03c43b4375b93741a3bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
154
Assets/Scripts/Tools/ObjectPooler/ObjectPooler.cs
Normal file
154
Assets/Scripts/Tools/ObjectPooler/ObjectPooler.cs
Normal file
|
@ -0,0 +1,154 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectPooler : MonoBehaviour{
|
||||
|
||||
[System.Serializable]
|
||||
public class Pool{
|
||||
public string tag;
|
||||
public GameObject prefab;
|
||||
public int size;
|
||||
}
|
||||
|
||||
public List<Pool> pools;
|
||||
public Dictionary<string, Queue<GameObject>> poolDictionary;
|
||||
|
||||
public static ObjectPooler instance;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
|
||||
poolDictionary = new Dictionary<string, Queue<GameObject>>();
|
||||
|
||||
foreach (Pool pool in pools){
|
||||
Queue<GameObject> objectPool = new Queue<GameObject>();
|
||||
for (int i = 0; i < pool.size; i++){
|
||||
GameObject obj = Instantiate(pool.prefab);
|
||||
obj.SetActive(false);
|
||||
obj.transform.parent = transform;
|
||||
objectPool.Enqueue(obj);
|
||||
}
|
||||
|
||||
poolDictionary.Add(pool.tag, objectPool);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Spawns a GameObject taken from a pool to a specific position in world space. </summary>
|
||||
public GameObject SpawnFromPool(string tag, Vector3 position){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.LogWarning("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
|
||||
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = Quaternion.identity;
|
||||
if (objectToSpawn.transform.parent != transform){
|
||||
objectToSpawn.transform.SetParent(transform);
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
|
||||
poolDictionary[tag].Enqueue(objectToSpawn);
|
||||
|
||||
return objectToSpawn;
|
||||
}
|
||||
|
||||
/// <summary> Spawns a GameObject taken from a pool to a specific position and rotation in world space. </summary>
|
||||
public GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.LogWarning("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
|
||||
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
if (objectToSpawn.transform.parent != transform){
|
||||
objectToSpawn.transform.SetParent(transform);
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
|
||||
poolDictionary[tag].Enqueue(objectToSpawn);
|
||||
|
||||
return objectToSpawn;
|
||||
}
|
||||
|
||||
/// <summary> Spawns a GameObject taken from a pool to a specific position and rotation in world space and sets it as a child of a transform. </summary>
|
||||
public GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation, Transform parent){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.LogWarning("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
|
||||
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
if (parent != null){
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
|
||||
poolDictionary[tag].Enqueue(objectToSpawn);
|
||||
|
||||
return objectToSpawn;
|
||||
}
|
||||
|
||||
/// <summary> Spawns a GameObject taken from a pool to a specific position and rotation in world or local space and sets it as a child of a transform. </summary>
|
||||
public GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation, Transform parent, bool instantiateInWorldSpace){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.LogWarning("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
|
||||
|
||||
if (instantiateInWorldSpace){
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
if (parent != null){
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
}
|
||||
}else if(parent != null){
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.transform.localPosition = position;
|
||||
objectToSpawn.transform.localRotation = rotation;
|
||||
}else{
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
if (parent != null){
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
}
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
|
||||
poolDictionary[tag].Enqueue(objectToSpawn);
|
||||
|
||||
return objectToSpawn;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/ObjectPooler/ObjectPooler.cs.meta
Normal file
11
Assets/Scripts/Tools/ObjectPooler/ObjectPooler.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 30043b312af8e504e8702664c7037295
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/SceneManager.meta
Normal file
8
Assets/Scripts/Tools/SceneManager.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1d611482d31b2d1429b583c81d7b7d65
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Assets/Scripts/Tools/SceneManager/SceneLoader.cs
Normal file
43
Assets/Scripts/Tools/SceneManager/SceneLoader.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SceneLoader : MonoBehaviour{
|
||||
|
||||
Animator anim;
|
||||
[SerializeField, Range(0f, 3f)] float fadeDuration = 1f;
|
||||
|
||||
public static SceneLoader instance;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
/// <summary> Loads the scene. </summary>
|
||||
public void LoadScene(int scene){
|
||||
StartCoroutine(LoadLevel(scene));
|
||||
}
|
||||
|
||||
IEnumerator LoadLevel(int scene){
|
||||
if(anim != null)
|
||||
anim.SetTrigger("Fade");
|
||||
yield return new WaitForSecondsRealtime(fadeDuration);
|
||||
Loader.Load(scene);
|
||||
}
|
||||
|
||||
/// <summary> Loads the scene with a certain delay. </summary>
|
||||
public void LoadScene(int scene, float delay){
|
||||
StartCoroutine(LoadLevel(scene, delay));
|
||||
}
|
||||
|
||||
IEnumerator LoadLevel(int scene, float delay){
|
||||
yield return new WaitForSecondsRealtime(delay);
|
||||
if (anim != null)
|
||||
anim.SetTrigger("Fade");
|
||||
yield return new WaitForSecondsRealtime(fadeDuration);
|
||||
//SceneManager.LoadSceneAsync(scene);
|
||||
Loader.Load(scene);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/SceneManager/SceneLoader.cs.meta
Normal file
11
Assets/Scripts/Tools/SceneManager/SceneLoader.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ede2123fe3b94fd4f812e1d322f2b7f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue