Add files via upload
This commit is contained in:
parent
82aab308f0
commit
310f5c8838
54 changed files with 2357 additions and 0 deletions
19
LICENSE.md
Normal file
19
LICENSE.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2021 Geri
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
7
LICENSE.md.meta
Normal file
7
LICENSE.md.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 535f36a1918d4d2479031f3ca2725323
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
92
README.md
Normal file
92
README.md
Normal file
|
@ -0,0 +1,92 @@
|
|||
# Simple Tools
|
||||
|
||||
## Features
|
||||
|
||||
- **AudioManager** with Play, Pause and most of the other basic things, as well as some effects like FadeIn or FadeOut.
|
||||
- Some Cinemachine tools for making a **camera trigger** and an easy way for creating a **screen shake camera.**
|
||||
- Basic **dialogue system** that works with TextMeshPro.
|
||||
- Basic menu with **music and SFX sliders** as well as **resolution and quality dropdowns.**
|
||||
- An **object pooler** with the ability to create pools with an undetermined size.
|
||||
- A basic **scene manager** with a loading screen with progress bar.
|
||||
|
||||
All of that comes with some editor menu items for creating all of that as fast as possible.
|
||||
|
||||
## How to install
|
||||
|
||||
First install the TextMeshPro and Cinemachine into your Unity project
|
||||
|
||||
### Git Installation (Best way to get latest version)
|
||||
|
||||
If you have git in your computer, you can open Package Manager inside Unity, select "Add package from Git url...", and paste link [https://github.com/IntoTheDev/Save-System-for-Unity.git](https://github.com/IntoTheDev/Save-System-for-Unity.git)
|
||||
|
||||
or
|
||||
|
||||
Open the manifest.json file of your Unity project. Add "com.geri.simpletools": "[https://github.com/IntoTheDev/Save-System-for-Unity.git](https://github.com/IntoTheDev/Save-System-for-Unity.git)"
|
||||
|
||||
### Manual Installation
|
||||
|
||||
Download latest package from the Release section Import SimpleTools.unitypackage to your Unity Project
|
||||
|
||||
## Usage
|
||||
|
||||
### AudioManager
|
||||
|
||||
```csharp
|
||||
AudioManager.instance.Play("Name"); //Plays the sound with that name
|
||||
AudioManager.instance.Play("Name", 1f); //Starts playing the sound "Name" in 1 second
|
||||
AudioManager.instance.PlayOneShot("Name"); //Plays one shot of that sound (Useful for repeated sounds)
|
||||
|
||||
AudioManager.instance.Pause("Name"); //Pauses the sound
|
||||
AudioManager.instance.UnPause("Name"); //Unpauses the sound
|
||||
|
||||
AudioManager.instance.Stop("Name"); //Stops the sound
|
||||
AudioManager.instance.StopAll(); //Stops all the sounds that are being played
|
||||
|
||||
AudioManager.instance.GetSource("Name"); //Gets the AudioSource with that name
|
||||
|
||||
AudioManager.instance.FadeIn("Name", 1f); //Fade In the source with a specific duration
|
||||
AudioManager.instance.FadeOut("Name", 1f); //Fade Out the source with a specific duration
|
||||
|
||||
AudioManager.instance.PlayMuted("Name"); //Play a sound muted
|
||||
AudioManager.instance.FadeMutedIn("Name", 1f); //Fade In a muted sound with a specific duration
|
||||
AudioManager.instance.FadeMutedOut("Name", 1f); //Fade Out a sound without stopping it
|
||||
```
|
||||
|
||||
### ObjectPooler
|
||||
|
||||
The SpawnFromPool function always return a GameObject
|
||||
|
||||
```csharp
|
||||
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.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
|
||||
Pooler.SpawnFromPool("Name", Vector3.zero, Quaternion.identity, transform); //Spawn into a specific position, rotation and parent
|
||||
Pooler.SpawnFromPool("Name", Vector3.zero, transform, true); //Spawn into a specific position, parent and instantiate in worldSpace or not
|
||||
Pooler.SpawnFromPool("Name", Vector3.zero, Quaternion.identity, transform, true); //Spawn into a specific position, rotation, parent and instantiate in worldSpace or not
|
||||
```
|
||||
|
||||
### Dialogue System
|
||||
|
||||
The Dialogue function returns a bool (true if it's talking, false if it has ended)
|
||||
|
||||
```csharp
|
||||
Dialogue dialogue; //The dialogue scriptable object goes here
|
||||
DialogueSystem.instance.Dialogue(dialogue); //Start/Continue the dialogue
|
||||
```
|
||||
|
||||
### SceneManager
|
||||
|
||||
```csharp
|
||||
Loader.Load(0); //Loads a scene with a specific build index
|
||||
Loader.Load("Scene"); //Loads a scene with a specific name
|
||||
```
|
||||
|
||||
### ScreenShake
|
||||
|
||||
```csharp
|
||||
ScreenShake.Shake(1f, .25f); //Shakes the camera with an intensity and duration
|
||||
```
|
7
README.md.meta
Normal file
7
README.md.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9c1d398f3d17184a97bce327ff06621
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tools.meta
Normal file
8
Tools.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 78a1b199ab0716542b34cc9a3dd3a9df
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tools/AudioManager.meta
Normal file
8
Tools/AudioManager.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1d98cf7b5d008ba4a832612b94195e04
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
206
Tools/AudioManager/AudioManager.cs
Normal file
206
Tools/AudioManager/AudioManager.cs
Normal file
|
@ -0,0 +1,206 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
[SerializeField] Sounds soundList = default;
|
||||
|
||||
void Awake(){
|
||||
if(instance == null){
|
||||
instance = this;
|
||||
}else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach(Sounds.List s in soundList.sounds){
|
||||
if(string.IsNullOrEmpty(s.name) || string.IsNullOrWhiteSpace(s.name)){
|
||||
Debug.LogWarning("The name one sound is empty");
|
||||
continue;
|
||||
}
|
||||
|
||||
GameObject sound = new GameObject(s.name);
|
||||
sound.transform.parent = transform;
|
||||
s.source = sound.AddComponent<AudioSource>();
|
||||
|
||||
if(soundList.mainMixer && soundList.sfxMixer){
|
||||
if (s.type == Sounds.List.Type.Music)
|
||||
s.source.outputAudioMixerGroup = soundList.mainMixer;
|
||||
else
|
||||
s.source.outputAudioMixerGroup = soundList.sfxMixer;
|
||||
}
|
||||
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
}
|
||||
}
|
||||
|
||||
#region Play
|
||||
public void Play(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if(s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.Play();
|
||||
}
|
||||
public void Play(string name, float delay){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.PlayDelayed(delay);
|
||||
}
|
||||
public void PlayOneShot(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
#endregion
|
||||
#region Pause
|
||||
public void Pause(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.Pause();
|
||||
}
|
||||
public void UnPause(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.UnPause();
|
||||
}
|
||||
#endregion
|
||||
#region Stop
|
||||
public void Stop(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.Stop();
|
||||
}
|
||||
public void StopAll(){
|
||||
foreach (Sounds.List s in soundList.sounds){
|
||||
if (s.source){
|
||||
s.source.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
public AudioSource GetSource(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return null;
|
||||
}
|
||||
return s.source;
|
||||
}
|
||||
#region Fades
|
||||
public void FadeIn(string name, float duration){
|
||||
StartCoroutine(FadeInCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeInCoroutine(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 FadeOut(string name, float duration){
|
||||
StartCoroutine(FadeOutCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeOutCoroutine(string name, float fadeTime){
|
||||
AudioSource audioSource = GetSource(name);
|
||||
|
||||
if (audioSource && audioSource.isPlaying){
|
||||
float startVolume = audioSource.volume;
|
||||
|
||||
while (audioSource.volume > 0){
|
||||
audioSource.volume -= startVolume * Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
audioSource.Stop();
|
||||
audioSource.volume = startVolume;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMuted(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = 0f;
|
||||
s.source.Play();
|
||||
}
|
||||
public void FadeMutedIn(string name, float duration){
|
||||
StartCoroutine(FadeMutedInCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeMutedInCoroutine(string name, float fadeTime){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
while (s.source.volume < s.volume){
|
||||
s.source.volume += Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
s.source.volume = s.volume;
|
||||
}
|
||||
public void FadeMutedOut(string name, float duration){
|
||||
StartCoroutine(FadeMutedOutCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeMutedOutCoroutine(string name, float fadeTime){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
while (s.source.volume > 0){
|
||||
s.source.volume -= Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
s.source.volume = 0;
|
||||
}
|
||||
#endregion
|
||||
}
|
11
Tools/AudioManager/AudioManager.cs.meta
Normal file
11
Tools/AudioManager/AudioManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d2879f3876727040b4f0cc799ec7ada
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Tools/AudioManager/AudioManager.png
Normal file
BIN
Tools/AudioManager/AudioManager.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
96
Tools/AudioManager/AudioManager.png.meta
Normal file
96
Tools/AudioManager/AudioManager.png.meta
Normal file
|
@ -0,0 +1,96 @@
|
|||
fileFormatVersion: 2
|
||||
guid: af0857324620d1d4b8b6bf41b6cdecfc
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: -1
|
||||
wrapV: -1
|
||||
wrapW: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Tools/AudioManager/Sounds.cs
Normal file
50
Tools/AudioManager/Sounds.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
[CreateAssetMenu(fileName = "Sounds", menuName = "Tools/Sounds", order = 0)]
|
||||
public class Sounds : ScriptableObject{
|
||||
|
||||
[Tooltip("The music mixer.")]
|
||||
public AudioMixerGroup mainMixer = default;
|
||||
[Tooltip("The SFX mixer.")]
|
||||
public AudioMixerGroup sfxMixer = default;
|
||||
|
||||
public List[] sounds;
|
||||
|
||||
[System.Serializable] public class List{
|
||||
[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;
|
||||
[Tooltip("Variance percentage of the volume"), Range(0f, 1f)] public float volumeVariance;
|
||||
[Tooltip("Default pitch of the sound."), Range(.1f, 3f)] public float pitch;
|
||||
[Tooltip("Variance percentage of the pitch"), Range(0f, 1f)] public float pitchVariance;
|
||||
|
||||
public bool loop;
|
||||
|
||||
[HideInInspector] public AudioSource source;
|
||||
|
||||
float randomVolume;
|
||||
public float RandomVolume{
|
||||
get{
|
||||
randomVolume = volume * (1f + Random.Range(-volumeVariance / 2f, volumeVariance / 2f));
|
||||
return randomVolume;
|
||||
}
|
||||
}
|
||||
|
||||
float randomPitch;
|
||||
public float RandomPitch{
|
||||
get{
|
||||
randomPitch = pitch * (1f + Random.Range(-pitchVariance / 2f, pitchVariance / 2f));
|
||||
return randomPitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Tools/AudioManager/Sounds.cs.meta
Normal file
11
Tools/AudioManager/Sounds.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6ded47588579f3047b1c3cd72cd87044
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: af0857324620d1d4b8b6bf41b6cdecfc, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tools/Cinemachine.meta
Normal file
8
Tools/Cinemachine.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5a2ff5ceb779d824d811d139fa608262
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
38
Tools/Cinemachine/CMCameraTrigger.cs
Normal file
38
Tools/Cinemachine/CMCameraTrigger.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class CMCameraTrigger : MonoBehaviour{
|
||||
|
||||
CinemachineVirtualCamera vcam;
|
||||
|
||||
void Awake(){
|
||||
vcam = GetComponentInChildren<CinemachineVirtualCamera>(true);
|
||||
vcam.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
#region 3D
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 2D
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit2D(Collider2D col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
11
Tools/Cinemachine/CMCameraTrigger.cs.meta
Normal file
11
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:
|
31
Tools/Cinemachine/ScreenShake.cs
Normal file
31
Tools/Cinemachine/ScreenShake.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ScreenShake{
|
||||
|
||||
static CinemachineVirtualCamera vCam;
|
||||
static ScreenShakeUpdate shakeUpdate;
|
||||
|
||||
class ScreenShakeUpdate : MonoBehaviour {
|
||||
[HideInInspector] public float shakeTimer;
|
||||
[HideInInspector] public float shakeTimerTotal;
|
||||
[HideInInspector] public float startingIntensity;
|
||||
|
||||
void Update(){
|
||||
if (shakeTimer > 0){
|
||||
shakeTimer -= Time.deltaTime;
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Shake(float intensity, float time){
|
||||
if(vCam == null || shakeUpdate == null){
|
||||
vCam = Camera.main.GetComponent<CinemachineBrain>().ActiveVirtualCamera.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
|
||||
shakeUpdate = new GameObject("ShakeUpdate").AddComponent<ScreenShakeUpdate>();
|
||||
}
|
||||
shakeUpdate.startingIntensity = intensity;
|
||||
shakeUpdate.shakeTimer = shakeUpdate.shakeTimerTotal = time;
|
||||
}
|
||||
}
|
11
Tools/Cinemachine/ScreenShake.cs.meta
Normal file
11
Tools/Cinemachine/ScreenShake.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 181034c7ad5ece241a2737ab35d47c5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tools/DialogueSystem.meta
Normal file
8
Tools/DialogueSystem.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 645cca644899cc74882ea9bc1d9c5aa9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Tools/DialogueSystem/Dialogue.cs
Normal file
12
Tools/DialogueSystem/Dialogue.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Character", menuName = "Tools/Character", order = 0)]
|
||||
public class Dialogue : ScriptableObject{
|
||||
|
||||
public bool displayName;
|
||||
public string characterName;
|
||||
|
||||
[Space]
|
||||
public Sprite characterImage;
|
||||
[TextArea] public string[] sentences;
|
||||
}
|
11
Tools/DialogueSystem/Dialogue.cs.meta
Normal file
11
Tools/DialogueSystem/Dialogue.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd553cd05b84d614b998afe62e37c17c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 4dfc626116fd10c4f972c17720d957ac, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Tools/DialogueSystem/Dialogue.png
Normal file
BIN
Tools/DialogueSystem/Dialogue.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
96
Tools/DialogueSystem/Dialogue.png.meta
Normal file
96
Tools/DialogueSystem/Dialogue.png.meta
Normal file
|
@ -0,0 +1,96 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4dfc626116fd10c4f972c17720d957ac
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: -1
|
||||
wrapV: -1
|
||||
wrapW: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
72
Tools/DialogueSystem/DialogueSystem.cs
Normal file
72
Tools/DialogueSystem/DialogueSystem.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DialogueSystem : MonoBehaviour{
|
||||
|
||||
public static DialogueSystem instance;
|
||||
|
||||
public GameObject nameField = default;
|
||||
public TextMeshProUGUI nameText = default;
|
||||
public TMP_Animated dialogue = default;
|
||||
public Image faceImage = default;
|
||||
|
||||
Queue<string> sentences;
|
||||
bool talking;
|
||||
Animator anim;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
sentences = new Queue<string>();
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public bool Dialogue(Dialogue dialogue){
|
||||
if(!talking){
|
||||
if (dialogue.displayName){
|
||||
nameText.text = dialogue.characterName;
|
||||
nameField.SetActive(true);
|
||||
nameText.gameObject.SetActive(true);
|
||||
}else{
|
||||
nameField.SetActive(false);
|
||||
nameText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (dialogue.characterImage)
|
||||
faceImage.sprite = dialogue.characterImage;
|
||||
else
|
||||
faceImage.sprite = null;
|
||||
|
||||
sentences.Clear();
|
||||
if(dialogue.sentences.Length != 0){
|
||||
foreach (string sentence in dialogue.sentences){
|
||||
sentences.Enqueue(sentence);
|
||||
}
|
||||
}else{
|
||||
sentences.Enqueue("I am error. No text has been added");
|
||||
}
|
||||
talking = true;
|
||||
|
||||
if(sentences.Count == 0){
|
||||
talking = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
string sentenceToShow = sentences.Dequeue();
|
||||
this.dialogue.ReadText(sentenceToShow);
|
||||
anim.SetBool("Talking", true);
|
||||
return true;
|
||||
}else{
|
||||
if (sentences.Count == 0){
|
||||
talking = false;
|
||||
anim.SetBool("Talking", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
string sentenceToShow = sentences.Dequeue();
|
||||
this.dialogue.ReadText(sentenceToShow);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
11
Tools/DialogueSystem/DialogueSystem.cs.meta
Normal file
11
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:
|
71
Tools/DialogueSystem/TMP_Animated.cs
Normal file
71
Tools/DialogueSystem/TMP_Animated.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System.Collections;
|
||||
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 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 WaitForSeconds(1f / speed);
|
||||
}
|
||||
visibleCounter = 0;
|
||||
}
|
||||
subCounter++;
|
||||
}
|
||||
yield return null;
|
||||
|
||||
WaitForSeconds EvaluateTag(string tag){
|
||||
if (tag.Length > 0){
|
||||
if (tag.StartsWith("speed=")){
|
||||
speed = float.Parse(tag.Split('=')[1]);
|
||||
}else if (tag.StartsWith("pause=")){
|
||||
return new WaitForSeconds(float.Parse(tag.Split('=')[1]));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
onDialogueFinish.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Tools/DialogueSystem/TMP_Animated.cs.meta
Normal file
11
Tools/DialogueSystem/TMP_Animated.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f713d84a3ae882945800780459e26170
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 2fd6421f253b4ef1a19526541f9ffc0c, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tools/Editor.meta
Normal file
8
Tools/Editor.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 53d517df853ee5d44b788e900f897c54
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Tools/Editor/Square.png
Normal file
BIN
Tools/Editor/Square.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 B |
104
Tools/Editor/Square.png.meta
Normal file
104
Tools/Editor/Square.png.meta
Normal file
|
@ -0,0 +1,104 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d93624141d1826749b7f50e692cc2a93
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 3
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 4
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 4
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline:
|
||||
- - {x: -2, y: -2}
|
||||
- {x: -2, y: 2}
|
||||
- {x: 2, y: 2}
|
||||
- {x: 2, y: -2}
|
||||
physicsShape:
|
||||
- - {x: -2, y: -2}
|
||||
- {x: -2, y: 2}
|
||||
- {x: 2, y: 2}
|
||||
- {x: 2, y: -2}
|
||||
bones: []
|
||||
spriteID: 5e97eb03825dee720800000000000000
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
531
Tools/Editor/ToolsEditor.cs
Normal file
531
Tools/Editor/ToolsEditor.cs
Normal file
|
@ -0,0 +1,531 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Cinemachine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEditor.Experimental.SceneManagement;
|
||||
using System;
|
||||
|
||||
public class ToolsEditor{
|
||||
|
||||
[MenuItem("GameObject/Tools/AudioManager", false, 10)]
|
||||
static void CreateAudioManager(){
|
||||
GameObject audioManager = new GameObject("AudioManager");
|
||||
audioManager.AddComponent<AudioManager>();
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Tools/Dialogue System", false, 10)]
|
||||
static void CreateDialogueSystem(){
|
||||
GameObject dialogueCanvas = new GameObject("DialogueCanvas");
|
||||
dialogueCanvas.AddComponent<RectTransform>();
|
||||
Canvas canvas = dialogueCanvas.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
dialogueCanvas.AddComponent<CanvasScaler>();
|
||||
dialogueCanvas.AddComponent<GraphicRaycaster>();
|
||||
|
||||
GameObject text = new GameObject("TMP_Animated");
|
||||
text.transform.SetParent(dialogueCanvas.transform);
|
||||
text.AddComponent<TMP_Animated>().text = "New Text";
|
||||
text.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
|
||||
|
||||
GameObject name = new GameObject("NameText");
|
||||
name.transform.SetParent(dialogueCanvas.transform);
|
||||
name.AddComponent<TextMeshProUGUI>().text = "Name";
|
||||
name.GetComponent<RectTransform>().anchoredPosition = Vector2.up * 50f;
|
||||
|
||||
GameObject image = new GameObject("Image");
|
||||
image.transform.SetParent(dialogueCanvas.transform);
|
||||
image.AddComponent<Image>();
|
||||
image.GetComponent<RectTransform>().anchoredPosition = new Vector2(-150f, 25f);
|
||||
|
||||
DialogueSystem dialogueSystem = dialogueCanvas.AddComponent<DialogueSystem>();
|
||||
dialogueSystem.nameText = name.GetComponent<TextMeshProUGUI>();
|
||||
dialogueSystem.dialogue = text.GetComponent<TMP_Animated>();
|
||||
dialogueSystem.faceImage = image.GetComponent<Image>();
|
||||
dialogueSystem.nameField = name;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Tools/Camera Trigger/2D", false, 10)]
|
||||
static void CreateCameraTrigger2D(){
|
||||
GameObject cameraTrigger = new GameObject("CameraTrigger2D");
|
||||
cameraTrigger.AddComponent<BoxCollider2D>();
|
||||
cameraTrigger.AddComponent<CMCameraTrigger>();
|
||||
|
||||
GameObject vCam = new GameObject("CM vcam1");
|
||||
vCam.transform.SetParent(cameraTrigger.transform);
|
||||
vCam.SetActive(false);
|
||||
CinemachineVirtualCamera cam = vCam.AddComponent<CinemachineVirtualCamera>();
|
||||
cam.m_Lens.Orthographic = true;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Tools/Camera Trigger/3D", false, 10)]
|
||||
static void CreateCameraTrigger3D(){
|
||||
GameObject cameraTrigger = new GameObject("CameraTrigger3D");
|
||||
cameraTrigger.AddComponent<BoxCollider>();
|
||||
cameraTrigger.AddComponent<CMCameraTrigger>();
|
||||
|
||||
GameObject vCam = new GameObject("CM vcam1");
|
||||
vCam.transform.SetParent(cameraTrigger.transform);
|
||||
vCam.SetActive(false);
|
||||
CinemachineVirtualCamera cam = vCam.AddComponent<CinemachineVirtualCamera>();
|
||||
cam.m_Lens.FieldOfView = 60f;
|
||||
}
|
||||
|
||||
#if CINEMACHINE_271_OR_NEWER
|
||||
[MenuItem("GameObject/Tools/ScreenShake Camera/2D", false, 10)]
|
||||
static void CreateScreenShakeCamera2d(){
|
||||
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
||||
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
||||
vCam.m_Lens.ModeOverride = LensSettings.OverrideModes.Orthographic;
|
||||
|
||||
CinemachineBasicMultiChannelPerlin shake = vCam.AddCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
|
||||
NoiseSettings noise = (NoiseSettings)AssetDatabase.LoadAssetAtPath("Packages/com.unity.cinemachine/Presets/Noise/6D Shake.asset", typeof(NoiseSettings));
|
||||
|
||||
shake.m_NoiseProfile = noise;
|
||||
shake.m_AmplitudeGain = 0f;
|
||||
shake.m_FrequencyGain = 1f;
|
||||
}
|
||||
[MenuItem("GameObject/Tools/ScreenShake Camera/3D", false, 10)]
|
||||
static void CreateScreenShakeCamera3d(){
|
||||
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
||||
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
||||
vCam.m_Lens.ModeOverride = LensSettings.OverrideModes.Perspective;
|
||||
|
||||
CinemachineBasicMultiChannelPerlin shake = vCam.AddCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
|
||||
NoiseSettings noise = (NoiseSettings)AssetDatabase.LoadAssetAtPath("Packages/com.unity.cinemachine/Presets/Noise/6D Shake.asset", typeof(NoiseSettings));
|
||||
|
||||
shake.m_NoiseProfile = noise;
|
||||
shake.m_AmplitudeGain = 0f;
|
||||
shake.m_FrequencyGain = 1f;
|
||||
}
|
||||
#else
|
||||
[MenuItem("GameObject/Tools/ScreenShake Camera", false, 10)]
|
||||
static void CreateScreenShakeCamera2d(){
|
||||
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
||||
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
||||
|
||||
CinemachineBasicMultiChannelPerlin shake = vCam.AddCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
|
||||
NoiseSettings noise = (NoiseSettings)AssetDatabase.LoadAssetAtPath("Packages/com.unity.cinemachine/Presets/Noise/6D Shake.asset", typeof(NoiseSettings));
|
||||
|
||||
shake.m_NoiseProfile = noise;
|
||||
shake.m_AmplitudeGain = 0f;
|
||||
shake.m_FrequencyGain = 1f;
|
||||
}
|
||||
#endif
|
||||
|
||||
[MenuItem("Assets/Create/Tools/Create Loading Scene")]
|
||||
static void CreateLoadingScene(){
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
|
||||
Scene loadingScene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
|
||||
loadingScene.name = "Loading";
|
||||
|
||||
GameObject loaderCallback = new GameObject("LoaderCallback");
|
||||
loaderCallback.AddComponent<LoaderCallback>();
|
||||
|
||||
GameObject canvasObj = new GameObject("Canvas");
|
||||
Canvas canvas = canvasObj.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
CanvasScaler canvasScaler = canvasObj.AddComponent<CanvasScaler>();
|
||||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasScaler.referenceResolution = new Vector2Int(951, 535);
|
||||
canvasScaler.matchWidthOrHeight = 1f;
|
||||
|
||||
canvasObj.AddComponent<GraphicRaycaster>();
|
||||
|
||||
TextMeshProUGUI loadingText = new GameObject("LoadingText").AddComponent<TextMeshProUGUI>();
|
||||
loadingText.transform.SetParent(canvasObj.transform);
|
||||
RectTransform loadingTextTransform = loadingText.GetComponent<RectTransform>();
|
||||
loadingTextTransform.anchoredPosition = new Vector2Int(-333, -212);
|
||||
loadingTextTransform.sizeDelta = new Vector2Int(237, 52);
|
||||
loadingText.text = "LOADING...";
|
||||
|
||||
Image bg = new GameObject("bg").AddComponent<Image>();
|
||||
bg.transform.SetParent(canvasObj.transform);
|
||||
RectTransform bgTransform = bg.GetComponent<RectTransform>();
|
||||
bgTransform.anchoredPosition = new Vector2Int(0, -235);
|
||||
bgTransform.sizeDelta = new Vector2Int(900, 20);
|
||||
bg.color = new Color(36f / 255f, 36f / 255f, 36f / 255f);
|
||||
|
||||
Image progressBar = new GameObject("ProgressBar").AddComponent<Image>();
|
||||
progressBar.transform.SetParent(bg.transform);
|
||||
RectTransform progressBarTransform = progressBar.GetComponent<RectTransform>();
|
||||
progressBarTransform.anchoredPosition = Vector2.zero;
|
||||
progressBarTransform.sizeDelta = new Vector2Int(900, 20);
|
||||
|
||||
progressBar.sprite = (Sprite)AssetDatabase.LoadAssetAtPath("Packages/com.geri.simpletools/Tools/Editor/Square.png", typeof(Sprite));
|
||||
progressBar.type = Image.Type.Filled;
|
||||
progressBar.fillMethod = Image.FillMethod.Horizontal;
|
||||
progressBar.fillOrigin = (int)Image.OriginHorizontal.Left;
|
||||
progressBar.fillAmount = 1f;
|
||||
progressBar.gameObject.AddComponent<LoadingProgressBar>();
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Tools/Create Menu Scene")]
|
||||
static void CreateMenuScene(){
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
|
||||
Scene menuScene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
|
||||
menuScene.name = "Menu";
|
||||
|
||||
GameObject canvasObj = new GameObject("Canvas");
|
||||
Canvas canvas = canvasObj.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
CreateEventSystem(false, null);
|
||||
|
||||
CanvasScaler canvasScaler = canvasObj.AddComponent<CanvasScaler>();
|
||||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasScaler.referenceResolution = new Vector2Int(951, 535);
|
||||
canvasScaler.matchWidthOrHeight = 1f;
|
||||
|
||||
canvasObj.AddComponent<GraphicRaycaster>();
|
||||
|
||||
GameObject qualityDropdown = TMP_DefaultControls.CreateDropdown(GetStandardResources());
|
||||
qualityDropdown.transform.SetParent(canvasObj.transform);
|
||||
RectTransform qualityRectTransform = qualityDropdown.GetComponent<RectTransform>();
|
||||
qualityRectTransform.anchoredPosition = Vector2.up * 15f;
|
||||
qualityDropdown.name = "QualityDropdown";
|
||||
|
||||
GameObject resolutionDropdown = TMP_DefaultControls.CreateDropdown(GetStandardResources());
|
||||
resolutionDropdown.transform.SetParent(canvasObj.transform);
|
||||
RectTransform resolutionRectTransform = resolutionDropdown.GetComponent<RectTransform>();
|
||||
resolutionRectTransform.anchoredPosition = Vector2.down * 15f;
|
||||
resolutionDropdown.name = "ResolutionDropdown";
|
||||
|
||||
GameObject musicSlider;
|
||||
using (new FactorySwapToEditor())
|
||||
musicSlider = DefaultControls.CreateSlider(GetStandardUIResources());
|
||||
musicSlider.transform.SetParent(canvasObj.transform);
|
||||
RectTransform musicRectTransform = musicSlider.GetComponent<RectTransform>();
|
||||
musicRectTransform.anchoredPosition = Vector2.down * 40f;
|
||||
musicSlider.name = "MusicSlider";
|
||||
|
||||
GameObject sfxSlider;
|
||||
using (new FactorySwapToEditor())
|
||||
sfxSlider = DefaultControls.CreateSlider(GetStandardUIResources());
|
||||
sfxSlider.transform.SetParent(canvasObj.transform);
|
||||
RectTransform sfxRectTransform = sfxSlider.GetComponent<RectTransform>();
|
||||
sfxRectTransform.anchoredPosition = Vector2.down * 60;
|
||||
sfxSlider.name = "MusicSlider";
|
||||
|
||||
GameObject playButton = TMP_DefaultControls.CreateButton(GetStandardResources());
|
||||
playButton.transform.SetParent(canvasObj.transform);
|
||||
TMP_Text playTextComponent = playButton.GetComponentInChildren<TMP_Text>();
|
||||
playTextComponent.fontSize = 24;
|
||||
playTextComponent.text = "PLAY";
|
||||
RectTransform playRectTransform = playButton.GetComponent<RectTransform>();
|
||||
playRectTransform.anchoredPosition = Vector2.up * 45f;
|
||||
playButton.name = "PlayButton";
|
||||
|
||||
GameObject quitButton = TMP_DefaultControls.CreateButton(GetStandardResources());
|
||||
quitButton.transform.SetParent(canvasObj.transform);
|
||||
TMP_Text quitTextComponent = quitButton.GetComponentInChildren<TMP_Text>();
|
||||
quitTextComponent.fontSize = 24;
|
||||
quitTextComponent.text = "QUIT";
|
||||
RectTransform quitRectTransform = quitButton.GetComponent<RectTransform>();
|
||||
quitRectTransform.anchoredPosition = Vector2.down * 85f;
|
||||
quitButton.name = "QuitButton";
|
||||
|
||||
MenuController menuController = canvasObj.AddComponent<MenuController>();
|
||||
Slider sliderMusic = menuController.musicSlider = musicSlider.GetComponent<Slider>();
|
||||
Slider sliderSfx = menuController.sfxSlider = sfxSlider.GetComponent<Slider>();
|
||||
TMP_Dropdown dropdownQuality = menuController.qualityDropdown = qualityDropdown.GetComponent<TMP_Dropdown>();
|
||||
TMP_Dropdown dropdownResolution = menuController.resolutionDropdown = resolutionDropdown.GetComponent<TMP_Dropdown>();
|
||||
|
||||
sliderMusic.onValueChanged.AddListener(menuController.SetMusicVolume);
|
||||
sliderSfx.onValueChanged.AddListener(menuController.SetSfxVolume);
|
||||
dropdownQuality.onValueChanged.AddListener(menuController.SetQuality);
|
||||
dropdownResolution.onValueChanged.AddListener(menuController.SetResolution);
|
||||
|
||||
playButton.GetComponent<Button>().onClick.AddListener(menuController.Play);
|
||||
quitButton.GetComponent<Button>().onClick.AddListener(menuController.Quit);
|
||||
}
|
||||
|
||||
#region CreateUISettings
|
||||
const string kUILayerName = "UI";
|
||||
|
||||
const string kStandardSpritePath = "UI/Skin/UISprite.psd";
|
||||
const string kBackgroundSpritePath = "UI/Skin/Background.psd";
|
||||
const string kInputFieldBackgroundPath = "UI/Skin/InputFieldBackground.psd";
|
||||
const string kKnobPath = "UI/Skin/Knob.psd";
|
||||
const string kCheckmarkPath = "UI/Skin/Checkmark.psd";
|
||||
const string kDropdownArrowPath = "UI/Skin/DropdownArrow.psd";
|
||||
const string kMaskPath = "UI/Skin/UIMask.psd";
|
||||
|
||||
static TMP_DefaultControls.Resources s_StandardResources;
|
||||
|
||||
static TMP_DefaultControls.Resources GetStandardResources(){
|
||||
if (s_StandardResources.standard == null){
|
||||
s_StandardResources.standard = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
|
||||
s_StandardResources.background = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpritePath);
|
||||
s_StandardResources.inputField = AssetDatabase.GetBuiltinExtraResource<Sprite>(kInputFieldBackgroundPath);
|
||||
s_StandardResources.knob = AssetDatabase.GetBuiltinExtraResource<Sprite>(kKnobPath);
|
||||
s_StandardResources.checkmark = AssetDatabase.GetBuiltinExtraResource<Sprite>(kCheckmarkPath);
|
||||
s_StandardResources.dropdown = AssetDatabase.GetBuiltinExtraResource<Sprite>(kDropdownArrowPath);
|
||||
s_StandardResources.mask = AssetDatabase.GetBuiltinExtraResource<Sprite>(kMaskPath);
|
||||
}
|
||||
return s_StandardResources;
|
||||
}
|
||||
static void SetPositionVisibleinSceneView(RectTransform canvasRTransform, RectTransform itemTransform){
|
||||
// Find the best scene view
|
||||
SceneView sceneView = SceneView.lastActiveSceneView;
|
||||
if (sceneView == null && SceneView.sceneViews.Count > 0)
|
||||
sceneView = SceneView.sceneViews[0] as SceneView;
|
||||
|
||||
// Couldn't find a SceneView. Don't set position.
|
||||
if (sceneView == null || sceneView.camera == null)
|
||||
return;
|
||||
|
||||
// Create world space Plane from canvas position.
|
||||
Camera camera = sceneView.camera;
|
||||
Vector3 position = Vector3.zero;
|
||||
Vector2 localPlanePosition;
|
||||
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRTransform, new Vector2(camera.pixelWidth / 2, camera.pixelHeight / 2), camera, out localPlanePosition)){
|
||||
// Adjust for canvas pivot
|
||||
localPlanePosition.x = localPlanePosition.x + canvasRTransform.sizeDelta.x * canvasRTransform.pivot.x;
|
||||
localPlanePosition.y = localPlanePosition.y + canvasRTransform.sizeDelta.y * canvasRTransform.pivot.y;
|
||||
|
||||
localPlanePosition.x = Mathf.Clamp(localPlanePosition.x, 0, canvasRTransform.sizeDelta.x);
|
||||
localPlanePosition.y = Mathf.Clamp(localPlanePosition.y, 0, canvasRTransform.sizeDelta.y);
|
||||
|
||||
// Adjust for anchoring
|
||||
position.x = localPlanePosition.x - canvasRTransform.sizeDelta.x * itemTransform.anchorMin.x;
|
||||
position.y = localPlanePosition.y - canvasRTransform.sizeDelta.y * itemTransform.anchorMin.y;
|
||||
|
||||
Vector3 minLocalPosition;
|
||||
minLocalPosition.x = canvasRTransform.sizeDelta.x * (0 - canvasRTransform.pivot.x) + itemTransform.sizeDelta.x * itemTransform.pivot.x;
|
||||
minLocalPosition.y = canvasRTransform.sizeDelta.y * (0 - canvasRTransform.pivot.y) + itemTransform.sizeDelta.y * itemTransform.pivot.y;
|
||||
|
||||
Vector3 maxLocalPosition;
|
||||
maxLocalPosition.x = canvasRTransform.sizeDelta.x * (1 - canvasRTransform.pivot.x) - itemTransform.sizeDelta.x * itemTransform.pivot.x;
|
||||
maxLocalPosition.y = canvasRTransform.sizeDelta.y * (1 - canvasRTransform.pivot.y) - itemTransform.sizeDelta.y * itemTransform.pivot.y;
|
||||
|
||||
position.x = Mathf.Clamp(position.x, minLocalPosition.x, maxLocalPosition.x);
|
||||
position.y = Mathf.Clamp(position.y, minLocalPosition.y, maxLocalPosition.y);
|
||||
}
|
||||
|
||||
itemTransform.anchoredPosition = position;
|
||||
itemTransform.localRotation = Quaternion.identity;
|
||||
itemTransform.localScale = Vector3.one;
|
||||
}
|
||||
static GameObject CreateNewUI(){
|
||||
// Root for the UI
|
||||
var root = new GameObject("Canvas");
|
||||
root.layer = LayerMask.NameToLayer(kUILayerName);
|
||||
Canvas canvas = root.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
root.AddComponent<CanvasScaler>();
|
||||
root.AddComponent<GraphicRaycaster>();
|
||||
|
||||
// Works for all stages.
|
||||
StageUtility.PlaceGameObjectInCurrentStage(root);
|
||||
bool customScene = false;
|
||||
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
if (prefabStage != null){
|
||||
root.transform.SetParent(prefabStage.prefabContentsRoot.transform, false);
|
||||
customScene = true;
|
||||
}
|
||||
|
||||
Undo.RegisterCreatedObjectUndo(root, "Create " + root.name);
|
||||
|
||||
// If there is no event system add one...
|
||||
// No need to place event system in custom scene as these are temporary anyway.
|
||||
// It can be argued for or against placing it in the user scenes,
|
||||
// but let's not modify scene user is not currently looking at.
|
||||
if (!customScene)
|
||||
CreateEventSystem(false);
|
||||
return root;
|
||||
}
|
||||
static void CreateEventSystem(bool select){
|
||||
CreateEventSystem(select, null);
|
||||
}
|
||||
static void CreateEventSystem(bool select, GameObject parent){
|
||||
var esys = UnityEngine.Object.FindObjectOfType<EventSystem>();
|
||||
if (esys == null){
|
||||
var eventSystem = new GameObject("EventSystem");
|
||||
GameObjectUtility.SetParentAndAlign(eventSystem, parent);
|
||||
esys = eventSystem.AddComponent<EventSystem>();
|
||||
eventSystem.AddComponent<StandaloneInputModule>();
|
||||
|
||||
Undo.RegisterCreatedObjectUndo(eventSystem, "Create " + eventSystem.name);
|
||||
}
|
||||
|
||||
if (select && esys != null){
|
||||
Selection.activeGameObject = esys.gameObject;
|
||||
}
|
||||
}
|
||||
// Helper function that returns a Canvas GameObject; preferably a parent of the selection, or other existing Canvas.
|
||||
static GameObject GetOrCreateCanvasGameObject(){
|
||||
GameObject selectedGo = Selection.activeGameObject;
|
||||
|
||||
// Try to find a gameobject that is the selected GO or one if its parents.
|
||||
Canvas canvas = (selectedGo != null) ? selectedGo.GetComponentInParent<Canvas>() : null;
|
||||
if (IsValidCanvas(canvas))
|
||||
return canvas.gameObject;
|
||||
|
||||
// No canvas in selection or its parents? Then use any valid canvas.
|
||||
// We have to find all loaded Canvases, not just the ones in main scenes.
|
||||
Canvas[] canvasArray = StageUtility.GetCurrentStageHandle().FindComponentsOfType<Canvas>();
|
||||
for (int i = 0; i < canvasArray.Length; i++)
|
||||
if (IsValidCanvas(canvasArray[i]))
|
||||
return canvasArray[i].gameObject;
|
||||
|
||||
// No canvas in the scene at all? Then create a new one.
|
||||
return CreateNewUI();
|
||||
}
|
||||
static bool IsValidCanvas(Canvas canvas){
|
||||
if (canvas == null || !canvas.gameObject.activeInHierarchy)
|
||||
return false;
|
||||
|
||||
// It's important that the non-editable canvas from a prefab scene won't be rejected,
|
||||
// but canvases not visible in the Hierarchy at all do. Don't check for HideAndDontSave.
|
||||
if (EditorUtility.IsPersistent(canvas) || (canvas.hideFlags & HideFlags.HideInHierarchy) != 0)
|
||||
return false;
|
||||
|
||||
if (StageUtility.GetStageHandle(canvas.gameObject) != StageUtility.GetCurrentStageHandle())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class FactorySwapToEditor : IDisposable{
|
||||
DefaultControls.IFactoryControls factory;
|
||||
|
||||
public FactorySwapToEditor(){
|
||||
factory = DefaultControls.factory;
|
||||
DefaultControls.factory = DefaultEditorFactory.Default;
|
||||
}
|
||||
|
||||
public void Dispose(){
|
||||
DefaultControls.factory = factory;
|
||||
}
|
||||
}
|
||||
|
||||
const string kStandardSpritePathDefault = "UI/Skin/UISprite.psd";
|
||||
const string kBackgroundSpritePathDefault = "UI/Skin/Background.psd";
|
||||
const string kInputFieldBackgroundPathDefault = "UI/Skin/InputFieldBackground.psd";
|
||||
const string kKnobPathDefault = "UI/Skin/Knob.psd";
|
||||
const string kCheckmarkPathDefault = "UI/Skin/Checkmark.psd";
|
||||
const string kDropdownArrowPathDefault = "UI/Skin/DropdownArrow.psd";
|
||||
const string kMaskPathDefault = "UI/Skin/UIMask.psd";
|
||||
|
||||
static DefaultControls.Resources s_StandardResourcesDefault;
|
||||
static DefaultControls.Resources GetStandardUIResources(){
|
||||
if (s_StandardResourcesDefault.standard == null){
|
||||
s_StandardResourcesDefault.standard = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePathDefault);
|
||||
s_StandardResourcesDefault.background = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpritePathDefault);
|
||||
s_StandardResourcesDefault.inputField = AssetDatabase.GetBuiltinExtraResource<Sprite>(kInputFieldBackgroundPathDefault);
|
||||
s_StandardResourcesDefault.knob = AssetDatabase.GetBuiltinExtraResource<Sprite>(kKnobPathDefault);
|
||||
s_StandardResourcesDefault.checkmark = AssetDatabase.GetBuiltinExtraResource<Sprite>(kCheckmarkPathDefault);
|
||||
s_StandardResourcesDefault.dropdown = AssetDatabase.GetBuiltinExtraResource<Sprite>(kDropdownArrowPathDefault);
|
||||
s_StandardResourcesDefault.mask = AssetDatabase.GetBuiltinExtraResource<Sprite>(kMaskPathDefault);
|
||||
}
|
||||
return s_StandardResourcesDefault;
|
||||
}
|
||||
static void PlaceUIElementRoot(GameObject element, MenuCommand menuCommand){
|
||||
GameObject parent = menuCommand.context as GameObject;
|
||||
bool explicitParentChoice = true;
|
||||
if (parent == null){
|
||||
parent = GetOrCreateCanvasGameObject();
|
||||
explicitParentChoice = false;
|
||||
|
||||
// If in Prefab Mode, Canvas has to be part of Prefab contents,
|
||||
// otherwise use Prefab root instead.
|
||||
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
if (prefabStage != null && !prefabStage.IsPartOfPrefabContents(parent))
|
||||
parent = prefabStage.prefabContentsRoot;
|
||||
}
|
||||
if (parent.GetComponentsInParent<Canvas>(true).Length == 0){
|
||||
// Create canvas under context GameObject,
|
||||
// and make that be the parent which UI element is added under.
|
||||
GameObject canvas = CreateNewUIDefault();
|
||||
Undo.SetTransformParent(canvas.transform, parent.transform, "");
|
||||
parent = canvas;
|
||||
}
|
||||
|
||||
GameObjectUtility.EnsureUniqueNameForSibling(element);
|
||||
|
||||
SetParentAndAlign(element, parent);
|
||||
if (!explicitParentChoice) // not a context click, so center in sceneview
|
||||
SetPositionVisibleinSceneView(parent.GetComponent<RectTransform>(), element.GetComponent<RectTransform>());
|
||||
|
||||
// This call ensure any change made to created Objects after they where registered will be part of the Undo.
|
||||
Undo.RegisterFullObjectHierarchyUndo(parent == null ? element : parent, "");
|
||||
|
||||
// We have to fix up the undo name since the name of the object was only known after reparenting it.
|
||||
Undo.SetCurrentGroupName("Create " + element.name);
|
||||
|
||||
Selection.activeGameObject = element;
|
||||
}
|
||||
static GameObject CreateNewUIDefault(){
|
||||
// Root for the UI
|
||||
var root = ObjectFactory.CreateGameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
root.layer = LayerMask.NameToLayer(kUILayerName);
|
||||
Canvas canvas = root.GetComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
// Works for all stages.
|
||||
StageUtility.PlaceGameObjectInCurrentStage(root);
|
||||
bool customScene = false;
|
||||
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
if (prefabStage != null){
|
||||
Undo.SetTransformParent(root.transform, prefabStage.prefabContentsRoot.transform, "");
|
||||
customScene = true;
|
||||
}
|
||||
|
||||
Undo.SetCurrentGroupName("Create " + root.name);
|
||||
|
||||
// If there is no event system add one...
|
||||
// No need to place event system in custom scene as these are temporary anyway.
|
||||
// It can be argued for or against placing it in the user scenes,
|
||||
// but let's not modify scene user is not currently looking at.
|
||||
if (!customScene)
|
||||
CreateEventSystem(false);
|
||||
return root;
|
||||
}
|
||||
static void SetParentAndAlign(GameObject child, GameObject parent){
|
||||
if (parent == null)
|
||||
return;
|
||||
|
||||
Undo.SetTransformParent(child.transform, parent.transform, "");
|
||||
|
||||
RectTransform rectTransform = child.transform as RectTransform;
|
||||
if (rectTransform){
|
||||
rectTransform.anchoredPosition = Vector2.zero;
|
||||
Vector3 localPosition = rectTransform.localPosition;
|
||||
localPosition.z = 0;
|
||||
rectTransform.localPosition = localPosition;
|
||||
}else{
|
||||
child.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
child.transform.localRotation = Quaternion.identity;
|
||||
child.transform.localScale = Vector3.one;
|
||||
|
||||
SetLayerRecursively(child, parent.layer);
|
||||
}
|
||||
static void SetLayerRecursively(GameObject go, int layer){
|
||||
go.layer = layer;
|
||||
Transform t = go.transform;
|
||||
for (int i = 0; i < t.childCount; i++)
|
||||
SetLayerRecursively(t.GetChild(i).gameObject, layer);
|
||||
}
|
||||
class DefaultEditorFactory : DefaultControls.IFactoryControls{
|
||||
public static DefaultEditorFactory Default = new DefaultEditorFactory();
|
||||
|
||||
public GameObject CreateGameObject(string name, params Type[] components){
|
||||
return ObjectFactory.CreateGameObject(name, components);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
11
Tools/Editor/ToolsEditor.cs.meta
Normal file
11
Tools/Editor/ToolsEditor.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c0943954f274aa44b030be2d213a763
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tools/Menu.meta
Normal file
8
Tools/Menu.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce31707f0d21dca449c23caec3a42cb5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
109
Tools/Menu/MenuController.cs
Normal file
109
Tools/Menu/MenuController.cs
Normal file
|
@ -0,0 +1,109 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
[System.Serializable] public class OnPlay : UnityEngine.Events.UnityEvent { }
|
||||
public class MenuController : MonoBehaviour{
|
||||
|
||||
[Header("Audio")]
|
||||
[SerializeField] AudioMixer mainMixer = default;
|
||||
[Tooltip("The music volume the first time you start the game")] [SerializeField, Range(0, 1)] float defaultMusicValue = .75f;
|
||||
[Tooltip("The SFX volume the first time you start the game")] [SerializeField, Range(0, 1)] float defaultSfxValue = .75f;
|
||||
public Slider musicSlider = default;
|
||||
public Slider sfxSlider = default;
|
||||
|
||||
[Header("Visual")]
|
||||
public TMP_Dropdown qualityDropdown = default;
|
||||
int qualitySelected;
|
||||
|
||||
public TMP_Dropdown resolutionDropdown = default;
|
||||
Resolution[] resolutions;
|
||||
int currentResolutionIndex;
|
||||
|
||||
[Space]
|
||||
[SerializeField] OnPlay onPlay = default;
|
||||
|
||||
void Awake(){
|
||||
if (mainMixer){
|
||||
float musicVolume = PlayerPrefs.GetFloat("MusicVolume", defaultMusicValue);
|
||||
float sfxVolume = PlayerPrefs.GetFloat("SFXVolume", defaultSfxValue);
|
||||
mainMixer.SetFloat("Master", Mathf.Log10(musicVolume <= .0001f ? .0001f : musicVolume) * 20);
|
||||
mainMixer.SetFloat("SFX", Mathf.Log10(sfxVolume <= .0001f ? .0001f : sfxVolume) * 20);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
qualityDropdown.ClearOptions();
|
||||
List<string> qualityNames = new List<string>();
|
||||
for (int i = 0; i < QualitySettings.names.Length; i++){
|
||||
qualityNames.Add(QualitySettings.names[i]);
|
||||
}
|
||||
qualityDropdown.AddOptions(qualityNames);
|
||||
|
||||
qualitySelected = PlayerPrefs.HasKey("QualitySelected") ? PlayerPrefs.GetInt("QualitySelected") : QualitySettings.GetQualityLevel();
|
||||
qualityDropdown.value = qualitySelected;
|
||||
QualitySettings.SetQualityLevel(qualitySelected);
|
||||
qualityDropdown.RefreshShownValue();
|
||||
}
|
||||
|
||||
void OnValidate(){
|
||||
if (musicSlider) musicSlider.minValue = musicSlider.minValue < .0001f ? .0001f : musicSlider.minValue;
|
||||
if (sfxSlider) sfxSlider.minValue = sfxSlider.minValue < .0001f ? .0001f : sfxSlider.minValue;
|
||||
}
|
||||
|
||||
void Start(){
|
||||
musicSlider.value = PlayerPrefs.GetFloat("MusicVolume", defaultMusicValue);
|
||||
sfxSlider.value = PlayerPrefs.GetFloat("SFXVolume", defaultSfxValue);
|
||||
}
|
||||
|
||||
//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(){
|
||||
onPlay.Invoke();
|
||||
}
|
||||
|
||||
public void Quit(){
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
11
Tools/Menu/MenuController.cs.meta
Normal file
11
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
Tools/ObjectPooler.meta
Normal file
8
Tools/ObjectPooler.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ec26cabd12646bb47bbe875cc4577e25
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
Tools/ObjectPooler/IPooledObject.cs
Normal file
3
Tools/ObjectPooler/IPooledObject.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
public interface IPooledObject{
|
||||
void OnObjectSpawn();
|
||||
}
|
11
Tools/ObjectPooler/IPooledObject.cs.meta
Normal file
11
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:
|
BIN
Tools/ObjectPooler/ObjectPooler.png
Normal file
BIN
Tools/ObjectPooler/ObjectPooler.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
96
Tools/ObjectPooler/ObjectPooler.png.meta
Normal file
96
Tools/ObjectPooler/ObjectPooler.png.meta
Normal file
|
@ -0,0 +1,96 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a0a572e598bbe3439aa4dab4a39293f
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: -1
|
||||
wrapV: -1
|
||||
wrapW: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
Tools/ObjectPooler/Pool.cs
Normal file
18
Tools/ObjectPooler/Pool.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Pool", menuName = "Tools/Pool", order = 0)]
|
||||
public class Pool : ScriptableObject{
|
||||
|
||||
public List<PoolPrefab> pools;
|
||||
[System.Serializable]
|
||||
public class PoolPrefab{
|
||||
public string tag;
|
||||
public GameObject prefab;
|
||||
public bool undetermined;
|
||||
public int size;
|
||||
|
||||
[HideInInspector] public Queue<GameObject> determinedPool;
|
||||
[HideInInspector] public List<GameObject> undeterminedPool;
|
||||
}
|
||||
}
|
11
Tools/ObjectPooler/Pool.cs.meta
Normal file
11
Tools/ObjectPooler/Pool.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b5ff40c8bb5e75d4fabf7bd1d6a59c68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 8a0a572e598bbe3439aa4dab4a39293f, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
317
Tools/ObjectPooler/Pooler.cs
Normal file
317
Tools/ObjectPooler/Pooler.cs
Normal file
|
@ -0,0 +1,317 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public static class Pooler{
|
||||
|
||||
class PoolChecker : MonoBehaviour {
|
||||
public string poolTag;
|
||||
}
|
||||
|
||||
static Dictionary<string, Pool.PoolPrefab> poolDictionary;
|
||||
static Scene poolScene;
|
||||
|
||||
public static void CreatePools(Pool pool){
|
||||
poolDictionary = new Dictionary<string, Pool.PoolPrefab>();
|
||||
poolScene = SceneManager.CreateScene("PoolScene");
|
||||
|
||||
foreach(Pool.PoolPrefab p in pool.pools){
|
||||
if (!p.undetermined){
|
||||
p.determinedPool = new Queue<GameObject>();
|
||||
for (int i = 0; i < p.size; i++){
|
||||
GameObject obj = Object.Instantiate(p.prefab);
|
||||
obj.SetActive(false);
|
||||
obj.AddComponent<PoolChecker>().poolTag = p.tag;
|
||||
SceneManager.MoveGameObjectToScene(obj, poolScene);
|
||||
p.determinedPool.Enqueue(obj);
|
||||
}
|
||||
}else{
|
||||
p.undeterminedPool = new List<GameObject>();
|
||||
}
|
||||
poolDictionary.Add(p.tag, p);
|
||||
}
|
||||
}
|
||||
public static void CreatePools(Pool[] pools){
|
||||
poolDictionary = new Dictionary<string, Pool.PoolPrefab>();
|
||||
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>();
|
||||
for (int j = 0; j < p.size; j++){
|
||||
GameObject obj = Object.Instantiate(p.prefab);
|
||||
obj.SetActive(false);
|
||||
obj.AddComponent<PoolChecker>().poolTag = p.tag;
|
||||
SceneManager.MoveGameObjectToScene(obj, poolScene);
|
||||
p.determinedPool.Enqueue(obj);
|
||||
}
|
||||
}else{
|
||||
p.undeterminedPool = new List<GameObject>();
|
||||
}
|
||||
poolDictionary.Add(p.tag, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Destroy(GameObject gameObject){
|
||||
PoolChecker poolChecker = gameObject.GetComponent<PoolChecker>();
|
||||
if (poolChecker == null){
|
||||
Debug.LogWarning("GameObject: " + gameObject + " isn't from a pool", gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
gameObject.transform.SetParent(null);
|
||||
SceneManager.MoveGameObjectToScene(gameObject, poolScene);
|
||||
|
||||
if (poolDictionary.ContainsKey(poolChecker.poolTag)){
|
||||
Pool.PoolPrefab pool = poolDictionary[poolChecker.poolTag];
|
||||
if (pool.undetermined){
|
||||
gameObject.SetActive(false);
|
||||
pool.undeterminedPool.Remove(gameObject);
|
||||
}else{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GameObject SpawnFromPool(string tag, Vector3 position){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.Log("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Pool.PoolPrefab pool = poolDictionary[tag];
|
||||
GameObject objectToSpawn;
|
||||
if (!pool.undetermined){
|
||||
objectToSpawn = pool.determinedPool.Dequeue();
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = Quaternion.identity;
|
||||
objectToSpawn.SetActive(true);
|
||||
|
||||
pool.determinedPool.Enqueue(objectToSpawn);
|
||||
}else{
|
||||
if(pool.undeterminedPool.Count != 0){
|
||||
int lastIndex = pool.undeterminedPool.Count - 1;
|
||||
objectToSpawn = pool.undeterminedPool[lastIndex];
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = Quaternion.identity;
|
||||
objectToSpawn.SetActive(true);
|
||||
}else{
|
||||
objectToSpawn = Object.Instantiate(pool.prefab, position, Quaternion.identity);
|
||||
SceneManager.MoveGameObjectToScene(objectToSpawn, poolScene);
|
||||
objectToSpawn.AddComponent<PoolChecker>().poolTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if(pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
return objectToSpawn;
|
||||
}
|
||||
public static GameObject SpawnFromPool(string tag, Vector3 position, Transform parent){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.Log("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Pool.PoolPrefab pool = poolDictionary[tag];
|
||||
GameObject objectToSpawn;
|
||||
if (!pool.undetermined){
|
||||
objectToSpawn = pool.determinedPool.Dequeue();
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = Quaternion.identity;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
|
||||
pool.determinedPool.Enqueue(objectToSpawn);
|
||||
}else{
|
||||
if (pool.undeterminedPool.Count != 0){
|
||||
int lastIndex = pool.undeterminedPool.Count - 1;
|
||||
objectToSpawn = pool.undeterminedPool[lastIndex];
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = Quaternion.identity;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
}else{
|
||||
objectToSpawn = Object.Instantiate(pool.prefab, position, Quaternion.identity, parent);
|
||||
objectToSpawn.AddComponent<PoolChecker>().poolTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
return objectToSpawn;
|
||||
}
|
||||
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.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!instantiateInWorldSpace){
|
||||
SpawnFromPool(tag, position, parent);
|
||||
}
|
||||
|
||||
Pool.PoolPrefab pool = poolDictionary[tag];
|
||||
GameObject objectToSpawn;
|
||||
if (!pool.undetermined){
|
||||
objectToSpawn = pool.determinedPool.Dequeue();
|
||||
|
||||
objectToSpawn.transform.localPosition = position;
|
||||
objectToSpawn.transform.localRotation = Quaternion.identity;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
|
||||
pool.determinedPool.Enqueue(objectToSpawn);
|
||||
}else{
|
||||
if (pool.undeterminedPool.Count != 0){
|
||||
int lastIndex = pool.undeterminedPool.Count - 1;
|
||||
objectToSpawn = pool.undeterminedPool[lastIndex];
|
||||
|
||||
objectToSpawn.transform.localPosition = position;
|
||||
objectToSpawn.transform.localRotation = Quaternion.identity;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
}else{
|
||||
objectToSpawn = Object.Instantiate(pool.prefab);
|
||||
objectToSpawn.transform.localPosition = position;
|
||||
objectToSpawn.transform.localRotation = Quaternion.identity;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.AddComponent<PoolChecker>().poolTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
return objectToSpawn;
|
||||
}
|
||||
public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.Log("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Pool.PoolPrefab pool = poolDictionary[tag];
|
||||
GameObject objectToSpawn;
|
||||
if (!pool.undetermined){
|
||||
objectToSpawn = pool.determinedPool.Dequeue();
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
objectToSpawn.SetActive(true);
|
||||
|
||||
pool.determinedPool.Enqueue(objectToSpawn);
|
||||
}else{
|
||||
if (pool.undeterminedPool.Count != 0){
|
||||
int lastIndex = pool.undeterminedPool.Count - 1;
|
||||
objectToSpawn = pool.undeterminedPool[lastIndex];
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
objectToSpawn.SetActive(true);
|
||||
}else{
|
||||
objectToSpawn = Object.Instantiate(pool.prefab, position, rotation);
|
||||
SceneManager.MoveGameObjectToScene(objectToSpawn, poolScene);
|
||||
objectToSpawn.AddComponent<PoolChecker>().poolTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
return objectToSpawn;
|
||||
}
|
||||
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.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Pool.PoolPrefab pool = poolDictionary[tag];
|
||||
GameObject objectToSpawn;
|
||||
if (!pool.undetermined){
|
||||
objectToSpawn = pool.determinedPool.Dequeue();
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
|
||||
pool.determinedPool.Enqueue(objectToSpawn);
|
||||
}else{
|
||||
if (pool.undeterminedPool.Count != 0){
|
||||
int lastIndex = pool.undeterminedPool.Count - 1;
|
||||
objectToSpawn = pool.undeterminedPool[lastIndex];
|
||||
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
}else{
|
||||
objectToSpawn = Object.Instantiate(pool.prefab, position, rotation, parent);
|
||||
objectToSpawn.AddComponent<PoolChecker>().poolTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
return objectToSpawn;
|
||||
}
|
||||
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.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!instantiateInWorldSpace){
|
||||
SpawnFromPool(tag, position, rotation, parent);
|
||||
}
|
||||
|
||||
Pool.PoolPrefab pool = poolDictionary[tag];
|
||||
GameObject objectToSpawn;
|
||||
if (!pool.undetermined){
|
||||
objectToSpawn = pool.determinedPool.Dequeue();
|
||||
|
||||
objectToSpawn.transform.localPosition = position;
|
||||
objectToSpawn.transform.localRotation = rotation;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
|
||||
pool.determinedPool.Enqueue(objectToSpawn);
|
||||
}else{
|
||||
if (pool.undeterminedPool.Count != 0){
|
||||
int lastIndex = pool.undeterminedPool.Count - 1;
|
||||
objectToSpawn = pool.undeterminedPool[lastIndex];
|
||||
|
||||
objectToSpawn.transform.localPosition = position;
|
||||
objectToSpawn.transform.localRotation = rotation;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.SetActive(true);
|
||||
}else{
|
||||
objectToSpawn = Object.Instantiate(pool.prefab);
|
||||
objectToSpawn.transform.localPosition = position;
|
||||
objectToSpawn.transform.localRotation = rotation;
|
||||
objectToSpawn.transform.SetParent(parent);
|
||||
objectToSpawn.AddComponent<PoolChecker>().poolTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
return objectToSpawn;
|
||||
}
|
||||
}
|
11
Tools/ObjectPooler/Pooler.cs.meta
Normal file
11
Tools/ObjectPooler/Pooler.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 05981bd6149198c4594304b79460229f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tools/SceneManager.meta
Normal file
8
Tools/SceneManager.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7fab4cee4244fe944894c2ed51272d02
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
61
Tools/SceneManager/Loader.cs
Normal file
61
Tools/SceneManager/Loader.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public static class Loader{
|
||||
|
||||
class LoadingMonoBehaviour : MonoBehaviour { }
|
||||
|
||||
static Action onLoaderCallback;
|
||||
static AsyncOperation loadingAsyncOperation;
|
||||
|
||||
public static void Load(int scene){
|
||||
onLoaderCallback = () => {
|
||||
GameObject loadingGameObject = new GameObject("LoadingGameObject");
|
||||
loadingGameObject.AddComponent<LoadingMonoBehaviour>().StartCoroutine(LoadSceneAsync(scene));
|
||||
};
|
||||
|
||||
SceneManager.LoadScene("Loading");
|
||||
}
|
||||
public static void Load(string scene){
|
||||
onLoaderCallback = () => {
|
||||
GameObject loadingGameObject = new GameObject("LoadingGameObject");
|
||||
loadingGameObject.AddComponent<LoadingMonoBehaviour>().StartCoroutine(LoadSceneAsync(scene));
|
||||
};
|
||||
|
||||
SceneManager.LoadScene("Loading");
|
||||
}
|
||||
|
||||
static IEnumerator LoadSceneAsync(int scene){
|
||||
yield return null;
|
||||
loadingAsyncOperation = SceneManager.LoadSceneAsync(scene);
|
||||
|
||||
while (!loadingAsyncOperation.isDone){
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
static IEnumerator LoadSceneAsync(string scene){
|
||||
yield return null;
|
||||
loadingAsyncOperation = SceneManager.LoadSceneAsync(scene);
|
||||
|
||||
while (!loadingAsyncOperation.isDone){
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetLoadingProgress(){
|
||||
if(loadingAsyncOperation != null){
|
||||
return loadingAsyncOperation.progress;
|
||||
}else{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoaderCallback(){
|
||||
if(onLoaderCallback != null){
|
||||
onLoaderCallback();
|
||||
onLoaderCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
11
Tools/SceneManager/Loader.cs.meta
Normal file
11
Tools/SceneManager/Loader.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f063a9d603510c141ab14838d5426a9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Tools/SceneManager/LoaderCallback.cs
Normal file
14
Tools/SceneManager/LoaderCallback.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class LoaderCallback : MonoBehaviour{
|
||||
|
||||
bool isFirstUpdate = true;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (isFirstUpdate){
|
||||
isFirstUpdate = false;
|
||||
Loader.LoaderCallback();
|
||||
}
|
||||
}
|
||||
}
|
11
Tools/SceneManager/LoaderCallback.cs.meta
Normal file
11
Tools/SceneManager/LoaderCallback.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 26cb7a3b5197df940891506a87636cf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Tools/SceneManager/LoadingProgressBar.cs
Normal file
17
Tools/SceneManager/LoadingProgressBar.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LoadingProgressBar : MonoBehaviour{
|
||||
|
||||
Image image;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
image = transform.GetComponent<Image>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
image.fillAmount = Loader.GetLoadingProgress();
|
||||
}
|
||||
}
|
11
Tools/SceneManager/LoadingProgressBar.cs.meta
Normal file
11
Tools/SceneManager/LoadingProgressBar.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 79bedd11df41bee44a527b2e4e718d17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
24
Tools/geri.simpletools.editor.asmdef
Normal file
24
Tools/geri.simpletools.editor.asmdef
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "SimpleTools",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"Cinemachine",
|
||||
"TMP_Runtime-CSharp",
|
||||
"Unity.TextMeshPro"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.cinemachine",
|
||||
"expression": "2.7.1",
|
||||
"define": "CINEMACHINE_271_OR_NEWER"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
7
Tools/geri.simpletools.editor.asmdef.meta
Normal file
7
Tools/geri.simpletools.editor.asmdef.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee6e31376ad94a04aa42bdea5f22b2ab
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
23
package.json
Normal file
23
package.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "com.geri.simpletools",
|
||||
"version": "1.0.0",
|
||||
"displayName": "Simple Tools",
|
||||
"description": "This package contains simple tools to use in your project.",
|
||||
"unity": "2018.4",
|
||||
"unityRelease": "30f1",
|
||||
"dependencies": {
|
||||
"com.unity.cinemachine": "2.2.0",
|
||||
"com.unity.textmeshpro": "1.0.21"
|
||||
},
|
||||
"keywords": [
|
||||
"gamejam",
|
||||
"simple",
|
||||
"easy"
|
||||
],
|
||||
"author": {
|
||||
"name": "Geri",
|
||||
"email": "ggasconmoline@gmail.com",
|
||||
"url": "https://geri8.itch.io/"
|
||||
},
|
||||
"type": "commonjs"
|
||||
}
|
7
package.json.meta
Normal file
7
package.json.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d9e8f428943ed2045a746644f61eb664
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue