Added auto-save
This commit is contained in:
parent
09973676e1
commit
8857a11038
8 changed files with 206 additions and 21 deletions
|
@ -47,6 +47,7 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
public void Play(string name) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -60,6 +61,8 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
/// <param name="delay" type="float">The delay in seconds</param>
|
||||
public void Play(string name, float delay) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -73,6 +76,7 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
public void PlayOneShot(string name) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -86,6 +90,8 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="intro" type="string">The name of the intro song</param>
|
||||
/// <param name="song" type="string">The name of the song loop</param>
|
||||
public void PlayWithIntro(string intro, string song) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == intro);
|
||||
if (s == null) {
|
||||
|
@ -102,6 +108,7 @@ namespace SimpleTools.AudioManager {
|
|||
/// <summary>Use this to play one shot of a random sound within a list
|
||||
/// <para>They have to be in the Sound asset referenced in the AudioManager instance</para>
|
||||
/// </summary>
|
||||
/// <param name="names" type="string[]">The names of the sounds</param>
|
||||
public void PlayRandomSound(params string[] names) {
|
||||
int random = UnityEngine.Random.Range(0, names.Length);
|
||||
PlayOneShot(names[random]);
|
||||
|
@ -111,6 +118,7 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
public void Pause(string name) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -124,6 +132,7 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
public void UnPause(string name) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -139,6 +148,7 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
public void Stop(string name) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -163,6 +173,8 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name">The name of the sound</param>
|
||||
/// <returns>The AudioSource in the scene</returns>
|
||||
public AudioSource GetSource(string name) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -175,6 +187,8 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
/// <param name="duration" type="float">The duration of the fade in</param>
|
||||
public void FadeIn(string name, float duration) {
|
||||
StartCoroutine(FadeInCoroutine(name, duration));
|
||||
}
|
||||
|
@ -195,6 +209,8 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
/// <param name="duration" type="float">The duration of the fade out</param>
|
||||
public void FadeOut(string name, float duration) {
|
||||
StartCoroutine(FadeOutCoroutine(name, duration));
|
||||
}
|
||||
|
@ -217,6 +233,7 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
public void PlayMuted(string name) {
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null) {
|
||||
|
@ -231,6 +248,8 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
/// <param name="duration">The duration of the fade in</param>
|
||||
public void FadeMutedIn(string name, float duration) {
|
||||
StartCoroutine(FadeMutedInCoroutine(name, duration));
|
||||
}
|
||||
|
@ -250,6 +269,8 @@ namespace SimpleTools.AudioManager {
|
|||
/// <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>
|
||||
/// <param name="name" type="string">The name of the sound</param>
|
||||
/// <param name="duration">The duration of the fade out</param>
|
||||
public void FadeMutedOut(string name, float duration) {
|
||||
StartCoroutine(FadeMutedOutCoroutine(name, duration));
|
||||
}
|
||||
|
|
8
Tools/AutoSave.meta
Normal file
8
Tools/AutoSave.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2f2d8faa0dc23b34f9f347dc08bd85be
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
124
Tools/AutoSave/AutoSaveConfig.cs
Normal file
124
Tools/AutoSave/AutoSaveConfig.cs
Normal file
|
@ -0,0 +1,124 @@
|
|||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using UnityEditor.SceneManagement;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SimpleTools.AutoSave {
|
||||
public class AutoSaveConfig : EditorWindow {
|
||||
|
||||
[MenuItem("Simple Tools/Auto Save Configuration")]
|
||||
public static void ShowWindow(){
|
||||
EditorWindow w = GetWindow<AutoSaveConfig>("Auto-save Configuration");
|
||||
w.position = new Rect(w.position.position, new Vector2(400, 150));
|
||||
var data = EditorPrefs.GetString("AutoSave", JsonUtility.ToJson(w, false));
|
||||
JsonUtility.FromJsonOverwrite(data, w);
|
||||
}
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
static void OnInitialize(){
|
||||
int _index = EditorPrefs.GetInt("Index", 0);
|
||||
bool _logging = EditorPrefs.GetBool("Logging", false);
|
||||
ChangeAutoSaveMode(_index, _logging);
|
||||
}
|
||||
|
||||
protected void OnEnable() {
|
||||
OnInitialize();
|
||||
}
|
||||
|
||||
protected void OnDisable() {
|
||||
var data = JsonUtility.ToJson(this, false);
|
||||
EditorPrefs.SetString("AutoSave", data);
|
||||
EditorPrefs.SetInt("Index", index);
|
||||
EditorPrefs.SetBool("Logging", logging);
|
||||
}
|
||||
|
||||
readonly static string[] options = new string[] { "Disabled", "On Play", "1 Minute", "10 Minutes", "1 Hour" };
|
||||
public static int index;
|
||||
public static bool enabled;
|
||||
public static bool logging;
|
||||
|
||||
void OnGUI() {
|
||||
GUILayout.Label("Select auto-save mode:", EditorStyles.boldLabel);
|
||||
int i = EditorGUILayout.Popup(index, options);
|
||||
if (i != index) ChangeAutoSaveMode(i, logging);
|
||||
|
||||
GUILayout.Label("Log a message every time a the scene gets saved.");
|
||||
if (logging) {
|
||||
if (GUILayout.Button("Disable Logging")){
|
||||
logging ^= true;
|
||||
ChangeAutoSaveMode(i, logging);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (GUILayout.Button("Enable Logging")) {
|
||||
logging ^= true;
|
||||
ChangeAutoSaveMode(i, logging);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static CancellationTokenSource _tokenSource;
|
||||
static Task _task;
|
||||
static int frequency;
|
||||
static void ChangeAutoSaveMode(int mode, bool log){
|
||||
index = mode;
|
||||
logging = log;
|
||||
CancelTask();
|
||||
enabled = true;
|
||||
EditorApplication.playModeStateChanged -= AutoSaveWhenPlayModeStarts;
|
||||
|
||||
switch(index){
|
||||
case 0:
|
||||
enabled = false;
|
||||
return;
|
||||
case 1:
|
||||
EditorApplication.playModeStateChanged += AutoSaveWhenPlayModeStarts;
|
||||
return;
|
||||
case 2:
|
||||
frequency = 1 * 60 * 1000;
|
||||
break;
|
||||
case 3:
|
||||
frequency = 10 * 60 * 1000;
|
||||
break;
|
||||
case 4:
|
||||
frequency = 60 * 60 * 1000;
|
||||
break;
|
||||
}
|
||||
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
_task = SaveInterval(_tokenSource.Token);
|
||||
}
|
||||
|
||||
static void AutoSaveWhenPlayModeStarts(PlayModeStateChange state){
|
||||
if(state == PlayModeStateChange.ExitingEditMode){
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
AssetDatabase.SaveAssets();
|
||||
if (logging) Debug.Log($"Auto-saved at {DateTime.Now:h:mm:ss tt}");
|
||||
}
|
||||
}
|
||||
|
||||
static void CancelTask() {
|
||||
if (_task == null) return;
|
||||
_tokenSource.Cancel();
|
||||
}
|
||||
|
||||
static async Task SaveInterval(CancellationToken token) {
|
||||
while (!token.IsCancellationRequested) {
|
||||
await Task.Delay(frequency, token);
|
||||
|
||||
if (token.IsCancellationRequested) break;
|
||||
|
||||
if (!enabled || Application.isPlaying || BuildPipeline.isBuildingPlayer || EditorApplication.isCompiling) return;
|
||||
if (!UnityEditorInternal.InternalEditorUtility.isApplicationActive) return;
|
||||
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
AssetDatabase.SaveAssets();
|
||||
if (logging) Debug.Log($"Auto-saved at {DateTime.Now:h:mm:ss tt}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Tools/AutoSave/AutoSaveConfig.cs.meta
Normal file
11
Tools/AutoSave/AutoSaveConfig.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e3f4095259fcc1f45991636604af9829
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -5,6 +5,7 @@ namespace SimpleTools.Cinemachine {
|
|||
public class CMCameraTrigger : MonoBehaviour {
|
||||
|
||||
CinemachineVirtualCamera vcam;
|
||||
[SerializeField, Tooltip("Name of the collider's tag that will trigger the camera.")] string triggerTagName;
|
||||
|
||||
void Awake() {
|
||||
vcam = GetComponentInChildren<CinemachineVirtualCamera>(true);
|
||||
|
@ -13,12 +14,12 @@ namespace SimpleTools.Cinemachine {
|
|||
|
||||
#region 3D
|
||||
void OnTriggerEnter(Collider col) {
|
||||
if (col.CompareTag("Player")) {
|
||||
if (col.CompareTag(triggerTagName)) {
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider col) {
|
||||
if (col.CompareTag("Player")) {
|
||||
if (col.CompareTag(triggerTagName)) {
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +27,12 @@ namespace SimpleTools.Cinemachine {
|
|||
|
||||
#region 2D
|
||||
void OnTriggerEnter2D(Collider2D col) {
|
||||
if (col.CompareTag("Player")) {
|
||||
if (col.CompareTag(triggerTagName)) {
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit2D(Collider2D col) {
|
||||
if (col.CompareTag("Player")) {
|
||||
if (col.CompareTag(triggerTagName)) {
|
||||
vcam.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace SimpleTools.DialogueSystem {
|
|||
Queue<Sprite> characterImages;
|
||||
bool talking;
|
||||
|
||||
public DialogueItems dialogueItems;
|
||||
public DialogueManagerItems dialogueItems;
|
||||
|
||||
public static DialogueManager instance;
|
||||
void Awake() {
|
||||
|
@ -27,10 +27,21 @@ namespace SimpleTools.DialogueSystem {
|
|||
dialogueVertexAnimator = new DialogueVertexAnimator(dialogueItems.textBox);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the main function to call to start a dialogue.
|
||||
/// </summary>
|
||||
/// <param name="dialogue">The dialogue to start.</param>
|
||||
/// <returns>A bool that is false if the dialogue has finished and true if it hasn't.</returns>
|
||||
public bool Dialogue(Dialogue dialogue) {
|
||||
return Dialogue(dialogue, string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the main function to call to start a dialogue.
|
||||
/// </summary>
|
||||
/// <param name="dialogue">The dialogue to start.</param>
|
||||
/// <param name="sounds">The sounds from the AudioManager that will be played on character reveal.</param>
|
||||
/// <returns>A bool that is false if the dialogue has finished and true if it hasn't.</returns>
|
||||
public bool Dialogue(Dialogue dialogue, params string[] sounds) {
|
||||
dialogueVertexAnimator.SetAudioSourceGroup(sounds);
|
||||
|
||||
|
@ -49,6 +60,8 @@ namespace SimpleTools.DialogueSystem {
|
|||
talking = true;
|
||||
|
||||
if (sentences.Count == 0) {
|
||||
if (dialogueVertexAnimator.IsMessageAnimating())
|
||||
return true;
|
||||
talking = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -66,6 +79,8 @@ namespace SimpleTools.DialogueSystem {
|
|||
return true;
|
||||
} else {
|
||||
if (sentences.Count == 0) {
|
||||
if (dialogueVertexAnimator.IsMessageAnimating())
|
||||
return true;
|
||||
talking = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -102,7 +117,7 @@ namespace SimpleTools.DialogueSystem {
|
|||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct DialogueItems {
|
||||
public struct DialogueManagerItems {
|
||||
public Image characterImage;
|
||||
public TMP_Text characterName;
|
||||
public TMP_Text textBox;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue