Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Some first day fug fixes.
  • Loading branch information
GerardGascon authored Jan 9, 2021
1 parent 7046716 commit a29bc6a
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions Tools/AudioManager/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void Awake(){
}

#region Play
/// <summary>Use this to play a sound with a specific name
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void Play(string name){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if(s == null){
Expand All @@ -53,6 +56,9 @@ public void Play(string name){
s.source.volume = s.RandomVolume;
s.source.Play();
}
/// <summary>Use this to play a sound with a specific name and with a certain delay
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void Play(string name, float delay){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if (s == null){
Expand All @@ -63,6 +69,9 @@ public void Play(string name, float delay){
s.source.volume = s.RandomVolume;
s.source.PlayDelayed(delay);
}
/// <summary>Use this to play one shot of a sound with a specific name
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void PlayOneShot(string name){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if (s == null){
Expand All @@ -73,6 +82,9 @@ public void PlayOneShot(string name){
s.source.volume = s.RandomVolume;
s.source.PlayOneShot(s.clip);
}
/// <summary>Use this to play an intro song and then start playing the song loop
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void PlayWithIntro(string intro, string song){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == intro);
if (s == null){
Expand All @@ -88,6 +100,9 @@ public void PlayWithIntro(string intro, string song){
}
#endregion
#region Pause
/// <summary>Use this to pause a sound with a specific name
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void Pause(string name){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if (s == null){
Expand All @@ -98,6 +113,9 @@ public void Pause(string name){
s.source.volume = s.RandomVolume;
s.source.Pause();
}
/// <summary>Use this to unpause a sound with a specific name
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void UnPause(string name){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if (s == null){
Expand All @@ -110,6 +128,9 @@ public void UnPause(string name){
}
#endregion
#region Stop
/// <summary>Use this to stop a sound with a specific name
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void Stop(string name){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if (s == null){
Expand All @@ -120,6 +141,9 @@ public void Stop(string name){
s.source.volume = s.RandomVolume;
s.source.Stop();
}
/// <summary>Use this to stop all the sounds
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void StopAll(){
foreach (Sounds.List s in soundList.sounds){
if (s.source){
Expand All @@ -128,6 +152,9 @@ public void StopAll(){
}
}
#endregion
/// <summary>This function returns the AudioSource that contains a specific sound
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public AudioSource GetSource(string name){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if (s == null){
Expand All @@ -137,6 +164,9 @@ public AudioSource GetSource(string name){
return s.source;
}
#region Fades
/// <summary>Use this to start playing a sound with a fade in
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void FadeIn(string name, float duration){
StartCoroutine(FadeInCoroutine(name, duration));
}
Expand All @@ -154,6 +184,9 @@ IEnumerator FadeInCoroutine(string name, float fadeTime){
audioSource.volume = volume;
}
}
/// <summary>Use this to stop playing a sound with a fade out
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void FadeOut(string name, float duration){
StartCoroutine(FadeOutCoroutine(name, duration));
}
Expand All @@ -173,6 +206,9 @@ IEnumerator FadeOutCoroutine(string name, float fadeTime){
}
}

/// <summary>Use this to start playing a sound muted
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void PlayMuted(string name){
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
if (s == null){
Expand All @@ -183,6 +219,10 @@ public void PlayMuted(string name){
s.source.volume = 0f;
s.source.Play();
}
/// <summary>Use this to fade in a sound that is currently muted
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// <para>WARNING: If the PlayMuted hasn't been called before, this function won't work</para>
/// </summary>
public void FadeMutedIn(string name, float duration){
StartCoroutine(FadeMutedInCoroutine(name, duration));
}
Expand All @@ -199,6 +239,9 @@ IEnumerator FadeMutedInCoroutine(string name, float fadeTime){
}
s.source.volume = s.volume;
}
/// <summary>Use this to fade out a sound and keep playing that muted
/// <para>It has to be in the Sound asset referenced in the AudioManager instance</para>
/// </summary>
public void FadeMutedOut(string name, float duration){
StartCoroutine(FadeMutedOutCoroutine(name, duration));
}
Expand Down
7 changes: 6 additions & 1 deletion Tools/Cinemachine/ScreenShake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ void Update(){
}
}

/// <summary>Shake the camera
/// <para>It needs a cinemachine camera with a noise profile in it.</para>
/// </summary>
public static void Shake(float intensity, float time){
if(vCam == null || shakeUpdate == null){
if(vCam == null){
vCam = Camera.main.GetComponent<CinemachineBrain>().ActiveVirtualCamera.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
}
if(shakeUpdate == null){
shakeUpdate = new GameObject("ShakeUpdate").AddComponent<ScreenShakeUpdate>();
}
shakeUpdate.startingIntensity = intensity;
Expand Down
3 changes: 3 additions & 0 deletions Tools/DialogueSystem/DialogueSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ void Awake(){
anim = GetComponent<Animator>();
}

/// <summary>Start or continue the dialogue
/// <para>This function returns false if the dialogue has ended.</para>
/// </summary>
public bool Dialogue(Dialogue dialogue){
if(!talking){
if (dialogue.displayName){
Expand Down
66 changes: 59 additions & 7 deletions Tools/ObjectPooler/Pooler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@ class PoolChecker : MonoBehaviour {
static Dictionary<string, Pool.PoolPrefab> poolDictionary;
static Scene poolScene;

/// <summary>Generate a scene with the objects of the pools in it
/// <para>If this isn't called, the pooler won't work</para>
/// </summary>
public static void CreatePools(Pool pool){
if(pool == null){
Debug.LogWarning("You have to provide a pool.");
return;
}

poolDictionary = new Dictionary<string, Pool.PoolPrefab>();
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<GameObject>();
if(p.determinedPool == null){
p.determinedPool = new Queue<GameObject>();
}
for (int i = 0; i < p.size; i++){
GameObject obj = Object.Instantiate(p.prefab);
obj.SetActive(false);
Expand All @@ -26,19 +40,35 @@ public static void CreatePools(Pool pool){
p.determinedPool.Enqueue(obj);
}
}else{
p.undeterminedPool = new List<GameObject>();
if(p.undeterminedPool == null){
p.undeterminedPool = new List<GameObject>();
}
}
poolDictionary.Add(p.tag, p);
}
}
/// <summary>Generate a scene with the objects of the pools in it
/// <para>If this isn't called, the pooler won't work</para>
/// </summary>
public static void CreatePools(Pool[] pools){
if (pools == null){
Debug.LogWarning("You have to provide a pool.");
return;
}

poolDictionary = new Dictionary<string, Pool.PoolPrefab>();
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<GameObject>();
if (p.determinedPool == null){
p.determinedPool = new Queue<GameObject>();
}
for (int j = 0; j < p.size; j++){
GameObject obj = Object.Instantiate(p.prefab);
obj.SetActive(false);
Expand All @@ -47,12 +77,16 @@ public static void CreatePools(Pool[] pools){
p.determinedPool.Enqueue(obj);
}
}else{
p.undeterminedPool = new List<GameObject>();
if (p.undeterminedPool == null){
p.undeterminedPool = new List<GameObject>();
}
}
poolDictionary.Add(p.tag, p);
}
}
}
/// <summary>Destroy an object and return it to the pool scene
/// </summary>
public static void Destroy(GameObject gameObject){
PoolChecker poolChecker = gameObject.GetComponent<PoolChecker>();
if (poolChecker == null){
Expand All @@ -74,6 +108,9 @@ public static void Destroy(GameObject gameObject){
}
}

/// <summary>Spawn an object into a specific position
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
Expand Down Expand Up @@ -111,6 +148,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position){
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position and parent
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position, Transform parent){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
Expand Down Expand Up @@ -149,6 +189,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Transform p
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position, parent and set if it's in world space or not
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
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.");
Expand Down Expand Up @@ -194,6 +237,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Transform p
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position and rotation
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
Expand Down Expand Up @@ -231,6 +277,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position, rotation and parent
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
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.");
Expand Down Expand Up @@ -269,6 +318,9 @@ public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position, rotation, parent and set if it's in world space or not
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
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.");
Expand Down
8 changes: 8 additions & 0 deletions Tools/SceneManager/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class LoadingMonoBehaviour : MonoBehaviour { }
static Action onLoaderCallback;
static AsyncOperation loadingAsyncOperation;

/// <summary>Load a scene with a loading scene
/// <para>It requires a scene called "Loading" where the loading screen is located.</para>
/// </summary>
public static void Load(int scene){
onLoaderCallback = () => {
GameObject loadingGameObject = new GameObject("LoadingGameObject");
Expand All @@ -18,6 +21,9 @@ public static void Load(int scene){

SceneManager.LoadScene("Loading");
}
/// <summary>Load a scene with a loading scene
/// <para>It requires a scene called "Loading" where the loading screen is located.</para>
/// </summary>
public static void Load(string scene){
onLoaderCallback = () => {
GameObject loadingGameObject = new GameObject("LoadingGameObject");
Expand All @@ -44,6 +50,8 @@ static IEnumerator LoadSceneAsync(string scene){
}
}

/// <summary>Returns the loading progress
/// </summary>
public static float GetLoadingProgress(){
if(loadingAsyncOperation != null){
return loadingAsyncOperation.progress;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit a29bc6a

Please sign in to comment.