From a29bc6aba4b7368d4b0cc0accf83be1ebf8ad843 Mon Sep 17 00:00:00 2001 From: Geri <52170489+Geri8@users.noreply.github.com> Date: Sat, 9 Jan 2021 01:57:59 +0100 Subject: [PATCH] Add files via upload Some first day fug fixes. --- README.md | 2 + Tools/AudioManager/AudioManager.cs | 43 +++++++++++++++++ Tools/Cinemachine/ScreenShake.cs | 7 ++- Tools/DialogueSystem/DialogueSystem.cs | 3 ++ Tools/ObjectPooler/Pooler.cs | 66 +++++++++++++++++++++++--- Tools/SceneManager/Loader.cs | 8 ++++ package.json | 2 +- 7 files changed, 122 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e69e2dd..854060e 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ Pool pool; //The pool scriptable object goes here Pooler.CreatePools(pool); //Create the pool, without creating it you cannot spawn it Pool[] pools; Pooler.CreatePools(pools); //Create multiple pools +Pooler.Destroy(gameObject); //Destroys a GameObject and returns it into the pool scene + Pooler.SpawnFromPool("Name", Vector3.zero); //Spawns an object into a specific position Pooler.SpawnFromPool("Name", Vector3.zero, Quaternion.identity); //Spawn into a specific position and rotation Pooler.SpawnFromPool("Name", Vector3.zero, transform); //Spawn into a specific position and parent diff --git a/Tools/AudioManager/AudioManager.cs b/Tools/AudioManager/AudioManager.cs index 6edfa34..4b6c3f5 100644 --- a/Tools/AudioManager/AudioManager.cs +++ b/Tools/AudioManager/AudioManager.cs @@ -43,6 +43,9 @@ void Awake(){ } #region Play + /// Use this to play a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void Play(string name){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if(s == null){ @@ -53,6 +56,9 @@ public void Play(string name){ s.source.volume = s.RandomVolume; s.source.Play(); } + /// Use this to play a sound with a specific name and with a certain delay + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void Play(string name, float delay){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null){ @@ -63,6 +69,9 @@ public void Play(string name, float delay){ s.source.volume = s.RandomVolume; s.source.PlayDelayed(delay); } + /// Use this to play one shot of a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void PlayOneShot(string name){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null){ @@ -73,6 +82,9 @@ public void PlayOneShot(string name){ s.source.volume = s.RandomVolume; s.source.PlayOneShot(s.clip); } + /// Use this to play an intro song and then start playing the song loop + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void PlayWithIntro(string intro, string song){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == intro); if (s == null){ @@ -88,6 +100,9 @@ public void PlayWithIntro(string intro, string song){ } #endregion #region Pause + /// Use this to pause a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void Pause(string name){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null){ @@ -98,6 +113,9 @@ public void Pause(string name){ s.source.volume = s.RandomVolume; s.source.Pause(); } + /// Use this to unpause a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void UnPause(string name){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null){ @@ -110,6 +128,9 @@ public void UnPause(string name){ } #endregion #region Stop + /// Use this to stop a sound with a specific name + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void Stop(string name){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null){ @@ -120,6 +141,9 @@ public void Stop(string name){ s.source.volume = s.RandomVolume; s.source.Stop(); } + /// Use this to stop all the sounds + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void StopAll(){ foreach (Sounds.List s in soundList.sounds){ if (s.source){ @@ -128,6 +152,9 @@ public void StopAll(){ } } #endregion + /// This function returns the AudioSource that contains a specific sound + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public AudioSource GetSource(string name){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null){ @@ -137,6 +164,9 @@ public AudioSource GetSource(string name){ return s.source; } #region Fades + /// Use this to start playing a sound with a fade in + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void FadeIn(string name, float duration){ StartCoroutine(FadeInCoroutine(name, duration)); } @@ -154,6 +184,9 @@ IEnumerator FadeInCoroutine(string name, float fadeTime){ audioSource.volume = volume; } } + /// Use this to stop playing a sound with a fade out + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void FadeOut(string name, float duration){ StartCoroutine(FadeOutCoroutine(name, duration)); } @@ -173,6 +206,9 @@ IEnumerator FadeOutCoroutine(string name, float fadeTime){ } } + /// Use this to start playing a sound muted + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void PlayMuted(string name){ Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name); if (s == null){ @@ -183,6 +219,10 @@ public void PlayMuted(string name){ s.source.volume = 0f; s.source.Play(); } + /// Use this to fade in a sound that is currently muted + /// It has to be in the Sound asset referenced in the AudioManager instance + /// WARNING: If the PlayMuted hasn't been called before, this function won't work + /// public void FadeMutedIn(string name, float duration){ StartCoroutine(FadeMutedInCoroutine(name, duration)); } @@ -199,6 +239,9 @@ IEnumerator FadeMutedInCoroutine(string name, float fadeTime){ } s.source.volume = s.volume; } + /// Use this to fade out a sound and keep playing that muted + /// It has to be in the Sound asset referenced in the AudioManager instance + /// public void FadeMutedOut(string name, float duration){ StartCoroutine(FadeMutedOutCoroutine(name, duration)); } diff --git a/Tools/Cinemachine/ScreenShake.cs b/Tools/Cinemachine/ScreenShake.cs index e2a1eaf..a9d8143 100644 --- a/Tools/Cinemachine/ScreenShake.cs +++ b/Tools/Cinemachine/ScreenShake.cs @@ -20,9 +20,14 @@ void Update(){ } } + /// Shake the camera + /// It needs a cinemachine camera with a noise profile in it. + /// public static void Shake(float intensity, float time){ - if(vCam == null || shakeUpdate == null){ + if(vCam == null){ vCam = Camera.main.GetComponent().ActiveVirtualCamera.VirtualCameraGameObject.GetComponent(); + } + if(shakeUpdate == null){ shakeUpdate = new GameObject("ShakeUpdate").AddComponent(); } shakeUpdate.startingIntensity = intensity; diff --git a/Tools/DialogueSystem/DialogueSystem.cs b/Tools/DialogueSystem/DialogueSystem.cs index 234cad5..5e35cc3 100644 --- a/Tools/DialogueSystem/DialogueSystem.cs +++ b/Tools/DialogueSystem/DialogueSystem.cs @@ -22,6 +22,9 @@ void Awake(){ anim = GetComponent(); } + /// Start or continue the dialogue + /// This function returns false if the dialogue has ended. + /// public bool Dialogue(Dialogue dialogue){ if(!talking){ if (dialogue.displayName){ diff --git a/Tools/ObjectPooler/Pooler.cs b/Tools/ObjectPooler/Pooler.cs index 9ded6f7..bb1a6d3 100644 --- a/Tools/ObjectPooler/Pooler.cs +++ b/Tools/ObjectPooler/Pooler.cs @@ -11,13 +11,27 @@ class PoolChecker : MonoBehaviour { static Dictionary poolDictionary; static Scene poolScene; + /// Generate a scene with the objects of the pools in it + /// If this isn't called, the pooler won't work + /// public static void CreatePools(Pool pool){ + if(pool == null){ + Debug.LogWarning("You have to provide a pool."); + return; + } + poolDictionary = new Dictionary(); - poolScene = SceneManager.CreateScene("PoolScene"); + if (SceneManager.GetSceneByName("PoolScene").IsValid()){ + poolScene = SceneManager.GetSceneByName("PoolScene"); + }else{ + poolScene = SceneManager.CreateScene("PoolScene"); + } - foreach(Pool.PoolPrefab p in pool.pools){ + foreach (Pool.PoolPrefab p in pool.pools){ if (!p.undetermined){ - p.determinedPool = new Queue(); + if(p.determinedPool == null){ + p.determinedPool = new Queue(); + } for (int i = 0; i < p.size; i++){ GameObject obj = Object.Instantiate(p.prefab); obj.SetActive(false); @@ -26,19 +40,35 @@ public static void CreatePools(Pool pool){ p.determinedPool.Enqueue(obj); } }else{ - p.undeterminedPool = new List(); + if(p.undeterminedPool == null){ + p.undeterminedPool = new List(); + } } poolDictionary.Add(p.tag, p); } } + /// Generate a scene with the objects of the pools in it + /// If this isn't called, the pooler won't work + /// public static void CreatePools(Pool[] pools){ + if (pools == null){ + Debug.LogWarning("You have to provide a pool."); + return; + } + poolDictionary = new Dictionary(); - poolScene = SceneManager.CreateScene("PoolScene"); + if (SceneManager.GetSceneByName("PoolScene").IsValid()){ + poolScene = SceneManager.GetSceneByName("PoolScene"); + }else{ + poolScene = SceneManager.CreateScene("PoolScene"); + } for (int i = 0; i < pools.Length; i++){ foreach (Pool.PoolPrefab p in pools[i].pools){ if (!p.undetermined){ - p.determinedPool = new Queue(); + if (p.determinedPool == null){ + p.determinedPool = new Queue(); + } for (int j = 0; j < p.size; j++){ GameObject obj = Object.Instantiate(p.prefab); obj.SetActive(false); @@ -47,12 +77,16 @@ public static void CreatePools(Pool[] pools){ p.determinedPool.Enqueue(obj); } }else{ - p.undeterminedPool = new List(); + if (p.undeterminedPool == null){ + p.undeterminedPool = new List(); + } } poolDictionary.Add(p.tag, p); } } } + /// Destroy an object and return it to the pool scene + /// public static void Destroy(GameObject gameObject){ PoolChecker poolChecker = gameObject.GetComponent(); if (poolChecker == null){ @@ -74,6 +108,9 @@ public static void Destroy(GameObject gameObject){ } } + /// Spawn an object into a specific position + /// The CreatePools function must have been called before. + /// public static GameObject SpawnFromPool(string tag, Vector3 position){ if (!poolDictionary.ContainsKey(tag)){ Debug.Log("Pool with tag " + tag + " doesn't exist."); @@ -111,6 +148,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position){ } return objectToSpawn; } + /// Spawn an object into a specific position and parent + /// The CreatePools function must have been called before. + /// public static GameObject SpawnFromPool(string tag, Vector3 position, Transform parent){ if (!poolDictionary.ContainsKey(tag)){ Debug.Log("Pool with tag " + tag + " doesn't exist."); @@ -149,6 +189,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Transform p } return objectToSpawn; } + /// Spawn an object into a specific position, parent and set if it's in world space or not + /// The CreatePools function must have been called before. + /// public static GameObject SpawnFromPool(string tag, Vector3 position, Transform parent, bool instantiateInWorldSpace){ if (!poolDictionary.ContainsKey(tag)){ Debug.Log("Pool with tag " + tag + " doesn't exist."); @@ -194,6 +237,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Transform p } return objectToSpawn; } + /// Spawn an object into a specific position and rotation + /// The CreatePools function must have been called before. + /// public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation){ if (!poolDictionary.ContainsKey(tag)){ Debug.Log("Pool with tag " + tag + " doesn't exist."); @@ -231,6 +277,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion } return objectToSpawn; } + /// Spawn an object into a specific position, rotation and parent + /// The CreatePools function must have been called before. + /// public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation, Transform parent){ if (!poolDictionary.ContainsKey(tag)){ Debug.Log("Pool with tag " + tag + " doesn't exist."); @@ -269,6 +318,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion } return objectToSpawn; } + /// Spawn an object into a specific position, rotation, parent and set if it's in world space or not + /// The CreatePools function must have been called before. + /// public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation, Transform parent, bool instantiateInWorldSpace){ if (!poolDictionary.ContainsKey(tag)){ Debug.Log("Pool with tag " + tag + " doesn't exist."); diff --git a/Tools/SceneManager/Loader.cs b/Tools/SceneManager/Loader.cs index ee6a1f6..559df20 100644 --- a/Tools/SceneManager/Loader.cs +++ b/Tools/SceneManager/Loader.cs @@ -10,6 +10,9 @@ class LoadingMonoBehaviour : MonoBehaviour { } static Action onLoaderCallback; static AsyncOperation loadingAsyncOperation; + /// Load a scene with a loading scene + /// It requires a scene called "Loading" where the loading screen is located. + /// public static void Load(int scene){ onLoaderCallback = () => { GameObject loadingGameObject = new GameObject("LoadingGameObject"); @@ -18,6 +21,9 @@ public static void Load(int scene){ SceneManager.LoadScene("Loading"); } + /// Load a scene with a loading scene + /// It requires a scene called "Loading" where the loading screen is located. + /// public static void Load(string scene){ onLoaderCallback = () => { GameObject loadingGameObject = new GameObject("LoadingGameObject"); @@ -44,6 +50,8 @@ static IEnumerator LoadSceneAsync(string scene){ } } + /// Returns the loading progress + /// public static float GetLoadingProgress(){ if(loadingAsyncOperation != null){ return loadingAsyncOperation.progress; diff --git a/package.json b/package.json index c429f59..5f3823b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.geri.simpletools", - "version": "1.0.0", + "version": "1.0.1", "displayName": "Simple Tools", "description": "This package contains simple tools to use in your project.", "unity": "2018.4",