Added Timer
New version featuring a timer
This commit is contained in:
parent
f7c4067db4
commit
750d7f6b88
14 changed files with 186 additions and 23 deletions
|
@ -21,11 +21,11 @@ First install the TextMeshPro and Cinemachine into your Unity project
|
||||||
|
|
||||||
### Git Installation (Best way to get latest version)
|
### 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/GerardGascon/SimpleTools.git](https://github.com/GerardGascon/SimpleTools.git)
|
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/Geri8/SimpleTools.git](https://github.com/Geri8/SimpleTools.git)
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
Open the manifest.json file of your Unity project. Add "com.geri.simpletools": "[https://github.com/GerardGascon/SimpleTools.git](https://github.com/GerardGascon/SimpleTools.git)"
|
Open the manifest.json file of your Unity project. Add "com.geri.simpletools": "[https://github.com/Geri8/SimpleTools.git](https://github.com/Geri8/SimpleTools.git)"
|
||||||
|
|
||||||
### Manual Installation
|
### Manual Installation
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Audio;
|
using UnityEngine.Audio;
|
||||||
|
|
||||||
[CreateAssetMenu(fileName = "Sounds", menuName = "Tools/Sounds", order = 0)]
|
[CreateAssetMenu(fileName = "Sounds", menuName = "Simple Tools/Sounds", order = 11)]
|
||||||
public class Sounds : ScriptableObject{
|
public class Sounds : ScriptableObject{
|
||||||
|
|
||||||
[Tooltip("The music mixer.")]
|
[Tooltip("The music mixer.")]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[CreateAssetMenu(fileName = "New Character", menuName = "Tools/Character", order = 0)]
|
[CreateAssetMenu(fileName = "New Character", menuName = "Simple Tools/Character", order = 11)]
|
||||||
public class Dialogue : ScriptableObject{
|
public class Dialogue : ScriptableObject{
|
||||||
|
|
||||||
public bool displayName;
|
public bool displayName;
|
||||||
|
|
|
@ -8,11 +8,16 @@ namespace TMPro{
|
||||||
|
|
||||||
public class TMP_Animated : TextMeshProUGUI{
|
public class TMP_Animated : TextMeshProUGUI{
|
||||||
|
|
||||||
float speed;
|
float speed = 20;
|
||||||
|
|
||||||
public TextRevealEvent onTextReveal;
|
public TextRevealEvent onTextReveal;
|
||||||
public DialogueEvent onDialogueFinish;
|
public DialogueEvent onDialogueFinish;
|
||||||
|
|
||||||
|
void Update(){
|
||||||
|
/*if(Application.isPlaying)
|
||||||
|
this.Animate();*/
|
||||||
|
}
|
||||||
|
|
||||||
public void ReadText(string newText){
|
public void ReadText(string newText){
|
||||||
text = string.Empty;
|
text = string.Empty;
|
||||||
|
|
||||||
|
@ -27,7 +32,7 @@ namespace TMPro{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCustomTag(string tag){
|
bool isCustomTag(string tag){
|
||||||
return tag.StartsWith("speed=") || tag.StartsWith("pause=");
|
return tag.StartsWith("speed=") || tag.StartsWith("pause=") || tag.StartsWith("wave") || tag.StartsWith("rainbow") || tag.StartsWith("shake");
|
||||||
}
|
}
|
||||||
|
|
||||||
text = displayText;
|
text = displayText;
|
||||||
|
@ -45,7 +50,9 @@ namespace TMPro{
|
||||||
onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
|
onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
|
||||||
visibleCounter++;
|
visibleCounter++;
|
||||||
maxVisibleCharacters++;
|
maxVisibleCharacters++;
|
||||||
yield return new WaitForSeconds(1f / speed);
|
//this.Animate();
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(text[maxVisibleCharacters - 1] == ' ' ? 0 : (1f / speed));
|
||||||
}
|
}
|
||||||
visibleCounter = 0;
|
visibleCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#if UNITY_EDITOR
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
@ -14,13 +13,13 @@ using System;
|
||||||
|
|
||||||
public class ToolsEditor{
|
public class ToolsEditor{
|
||||||
|
|
||||||
[MenuItem("GameObject/Tools/AudioManager", false, 10)]
|
[MenuItem("GameObject/Simple Tools/AudioManager", false, 10)]
|
||||||
static void CreateAudioManager(){
|
static void CreateAudioManager(){
|
||||||
GameObject audioManager = new GameObject("AudioManager");
|
GameObject audioManager = new GameObject("AudioManager");
|
||||||
audioManager.AddComponent<AudioManager>();
|
audioManager.AddComponent<AudioManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/Tools/Dialogue System", false, 10)]
|
[MenuItem("GameObject/Simple Tools/Dialogue System", false, 10)]
|
||||||
static void CreateDialogueSystem(){
|
static void CreateDialogueSystem(){
|
||||||
GameObject dialogueCanvas = new GameObject("DialogueCanvas");
|
GameObject dialogueCanvas = new GameObject("DialogueCanvas");
|
||||||
dialogueCanvas.AddComponent<RectTransform>();
|
dialogueCanvas.AddComponent<RectTransform>();
|
||||||
|
@ -51,7 +50,7 @@ public class ToolsEditor{
|
||||||
dialogueSystem.nameField = name;
|
dialogueSystem.nameField = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/Tools/Camera Trigger/2D", false, 10)]
|
[MenuItem("GameObject/Simple Tools/Camera Trigger/2D", false, 10)]
|
||||||
static void CreateCameraTrigger2D(){
|
static void CreateCameraTrigger2D(){
|
||||||
GameObject cameraTrigger = new GameObject("CameraTrigger2D");
|
GameObject cameraTrigger = new GameObject("CameraTrigger2D");
|
||||||
cameraTrigger.AddComponent<BoxCollider2D>();
|
cameraTrigger.AddComponent<BoxCollider2D>();
|
||||||
|
@ -64,7 +63,7 @@ public class ToolsEditor{
|
||||||
cam.m_Lens.Orthographic = true;
|
cam.m_Lens.Orthographic = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/Tools/Camera Trigger/3D", false, 10)]
|
[MenuItem("GameObject/Simple Tools/Camera Trigger/3D", false, 10)]
|
||||||
static void CreateCameraTrigger3D(){
|
static void CreateCameraTrigger3D(){
|
||||||
GameObject cameraTrigger = new GameObject("CameraTrigger3D");
|
GameObject cameraTrigger = new GameObject("CameraTrigger3D");
|
||||||
cameraTrigger.AddComponent<BoxCollider>();
|
cameraTrigger.AddComponent<BoxCollider>();
|
||||||
|
@ -78,7 +77,7 @@ public class ToolsEditor{
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CINEMACHINE_271_OR_NEWER
|
#if CINEMACHINE_271_OR_NEWER
|
||||||
[MenuItem("GameObject/Tools/ScreenShake Camera/2D", false, 10)]
|
[MenuItem("GameObject/Simple Tools/ScreenShake Camera/2D", false, 10)]
|
||||||
static void CreateScreenShakeCamera2d(){
|
static void CreateScreenShakeCamera2d(){
|
||||||
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
||||||
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
||||||
|
@ -92,7 +91,7 @@ public class ToolsEditor{
|
||||||
shake.m_AmplitudeGain = 0f;
|
shake.m_AmplitudeGain = 0f;
|
||||||
shake.m_FrequencyGain = 1f;
|
shake.m_FrequencyGain = 1f;
|
||||||
}
|
}
|
||||||
[MenuItem("GameObject/Tools/ScreenShake Camera/3D", false, 10)]
|
[MenuItem("GameObject/Simple Tools/ScreenShake Camera/3D", false, 10)]
|
||||||
static void CreateScreenShakeCamera3d(){
|
static void CreateScreenShakeCamera3d(){
|
||||||
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
||||||
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
||||||
|
@ -107,7 +106,7 @@ public class ToolsEditor{
|
||||||
shake.m_FrequencyGain = 1f;
|
shake.m_FrequencyGain = 1f;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
[MenuItem("GameObject/Tools/ScreenShake Camera", false, 10)]
|
[MenuItem("GameObject/Simple Tools/ScreenShake Camera", false, 10)]
|
||||||
static void CreateScreenShakeCamera2d(){
|
static void CreateScreenShakeCamera2d(){
|
||||||
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
GameObject screenShakeCamera = new GameObject("ScreenShakeCamera");
|
||||||
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
CinemachineVirtualCamera vCam = screenShakeCamera.AddComponent<CinemachineVirtualCamera>();
|
||||||
|
@ -122,7 +121,8 @@ public class ToolsEditor{
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[MenuItem("Assets/Create/Tools/Create Loading Scene")]
|
[MenuItem("Assets/Create/Simple Tools/Create Loading Scene")]
|
||||||
|
[MenuItem("Simple Tools/Create Loading Scene")]
|
||||||
static void CreateLoadingScene(){
|
static void CreateLoadingScene(){
|
||||||
EditorSceneManager.SaveOpenScenes();
|
EditorSceneManager.SaveOpenScenes();
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ public class ToolsEditor{
|
||||||
progressBarTransform.anchoredPosition = Vector2.zero;
|
progressBarTransform.anchoredPosition = Vector2.zero;
|
||||||
progressBarTransform.sizeDelta = new Vector2Int(900, 20);
|
progressBarTransform.sizeDelta = new Vector2Int(900, 20);
|
||||||
|
|
||||||
progressBar.sprite = (Sprite)AssetDatabase.LoadAssetAtPath("Packages/com.geri.simpletools/Tools/Editor/Square.png", typeof(Sprite));
|
progressBar.sprite = (Sprite)AssetDatabase.LoadAssetAtPath("Packages/com.geri.simpletools/Simple Tools/Editor/Square.png", typeof(Sprite));
|
||||||
progressBar.type = Image.Type.Filled;
|
progressBar.type = Image.Type.Filled;
|
||||||
progressBar.fillMethod = Image.FillMethod.Horizontal;
|
progressBar.fillMethod = Image.FillMethod.Horizontal;
|
||||||
progressBar.fillOrigin = (int)Image.OriginHorizontal.Left;
|
progressBar.fillOrigin = (int)Image.OriginHorizontal.Left;
|
||||||
|
@ -172,7 +172,8 @@ public class ToolsEditor{
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_2019_3_OR_NEWER
|
#if UNITY_2019_3_OR_NEWER
|
||||||
[MenuItem("Assets/Create/Tools/Create Menu Scene")]
|
[MenuItem("Assets/Create/Simple Tools/Create Menu Scene")]
|
||||||
|
[MenuItem("Simple Tools/Create Menu Scene")]
|
||||||
static void CreateMenuScene(){
|
static void CreateMenuScene(){
|
||||||
EditorSceneManager.SaveOpenScenes();
|
EditorSceneManager.SaveOpenScenes();
|
||||||
|
|
||||||
|
@ -532,4 +533,3 @@ public class ToolsEditor{
|
||||||
#endregion
|
#endregion
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[CreateAssetMenu(fileName = "New Pool", menuName = "Tools/Pool", order = 0)]
|
[CreateAssetMenu(fileName = "New Pool", menuName = "Simple Tools/Pool", order = 11)]
|
||||||
public class Pool : ScriptableObject{
|
public class Pool : ScriptableObject{
|
||||||
|
|
||||||
public List<PoolPrefab> pools;
|
public List<PoolPrefab> pools;
|
||||||
|
|
8
Tools/Timer.meta
Normal file
8
Tools/Timer.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b904c9938b1a3df4e83b1103e3085400
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
79
Tools/Timer/Timer.cs
Normal file
79
Tools/Timer/Timer.cs
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using System;
|
||||||
|
using TMPro;
|
||||||
|
|
||||||
|
namespace SimpleTools.Timer{
|
||||||
|
public class Timer : MonoBehaviour{
|
||||||
|
|
||||||
|
float elapsedTime;
|
||||||
|
public float ElapsedTime { get { return elapsedTime; } }
|
||||||
|
bool isPaused;
|
||||||
|
public bool IsPaused { get { return isPaused; } }
|
||||||
|
TimeSpan timePlaying;
|
||||||
|
public TimeSpan TimePlaying { get { return timePlaying; } }
|
||||||
|
TMP_Text timer;
|
||||||
|
public TMP_Text TimerText { get { return timer; } }
|
||||||
|
TimerType timerType;
|
||||||
|
public TimerType TimerType { get { return timerType; } }
|
||||||
|
|
||||||
|
public void Setup(float elapsedTime, bool isPaused, TimeSpan timePlaying, TMP_Text timer, TimerType timerType, string text){
|
||||||
|
this.elapsedTime = elapsedTime;
|
||||||
|
this.isPaused = isPaused;
|
||||||
|
this.timePlaying = timePlaying;
|
||||||
|
this.timer = timer;
|
||||||
|
this.timerType = timerType;
|
||||||
|
timer.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator UpdateTimer(){
|
||||||
|
while (!isPaused){
|
||||||
|
if(timerType == TimerType.Clock){
|
||||||
|
timer.text = DateTime.Now.ToString("HH:mm:ss");
|
||||||
|
}else{
|
||||||
|
switch (timerType){
|
||||||
|
case TimerType.Countdown:
|
||||||
|
elapsedTime -= Time.deltaTime;
|
||||||
|
if(elapsedTime < 0f){
|
||||||
|
elapsedTime = 0f;
|
||||||
|
isPaused = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TimerType.Stopwatch:
|
||||||
|
elapsedTime += Time.deltaTime;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
timePlaying = TimeSpan.FromSeconds(elapsedTime);
|
||||||
|
timer.text = timePlaying.ToString("m':'ss'.'ff");
|
||||||
|
}
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Play(){
|
||||||
|
isPaused = false;
|
||||||
|
StartCoroutine(UpdateTimer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop(){
|
||||||
|
isPaused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetTimer(){
|
||||||
|
isPaused = true;
|
||||||
|
elapsedTime = 0f;
|
||||||
|
timePlaying = TimeSpan.FromSeconds(elapsedTime);
|
||||||
|
timer.text = timePlaying.ToString("m':'ss'.'ff");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Restart(){
|
||||||
|
isPaused = false;
|
||||||
|
elapsedTime = 0f;
|
||||||
|
timePlaying = TimeSpan.FromSeconds(elapsedTime);
|
||||||
|
timer.text = timePlaying.ToString("m':'ss'.'ff");
|
||||||
|
StopAllCoroutines();
|
||||||
|
StartCoroutine(UpdateTimer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Tools/Timer/Timer.cs.meta
Normal file
11
Tools/Timer/Timer.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6daeed0a6935f484f85fc0ec1871344f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Tools/Timer/TimerType.cs
Normal file
7
Tools/Timer/TimerType.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace SimpleTools.Timer{
|
||||||
|
public enum TimerType{
|
||||||
|
Countdown,
|
||||||
|
Stopwatch,
|
||||||
|
Clock
|
||||||
|
}
|
||||||
|
}
|
11
Tools/Timer/TimerType.cs.meta
Normal file
11
Tools/Timer/TimerType.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f285456223780f946b49c6131d493c01
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
29
Tools/Timer/TimerUtility.cs
Normal file
29
Tools/Timer/TimerUtility.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using System;
|
||||||
|
using TMPro;
|
||||||
|
|
||||||
|
namespace SimpleTools.Timer{
|
||||||
|
public static class TimerUtility {
|
||||||
|
public static Timer SetupTimer(this TMP_Text container, TimerType timerType, float countdownTime = 60f){
|
||||||
|
Timer t = container.gameObject.AddComponent<Timer>();
|
||||||
|
float elapsedTime = 0f;
|
||||||
|
string text = string.Empty;
|
||||||
|
TimeSpan timePlaying = TimeSpan.Zero;
|
||||||
|
switch (timerType){
|
||||||
|
case TimerType.Countdown:
|
||||||
|
elapsedTime = countdownTime;
|
||||||
|
timePlaying = TimeSpan.FromSeconds(elapsedTime);
|
||||||
|
text = timePlaying.ToString("m':'ss'.'ff");
|
||||||
|
break;
|
||||||
|
case TimerType.Clock:
|
||||||
|
text = DateTime.Now.ToString("HH:mm:ss");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
t.Setup(elapsedTime, true, timePlaying, container, timerType, text);
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Tools/Timer/TimerUtility.cs.meta
Normal file
11
Tools/Timer/TimerUtility.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 38076483429281e438cee653b26bb03d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.geri.simpletools",
|
"name": "com.geri.simpletools",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"displayName": "Simple Tools",
|
"displayName": "Simple Tools",
|
||||||
"description": "This package contains simple tools to use in your project.",
|
"description": "This package contains simple tools to use in your project.",
|
||||||
"unity": "2018.4",
|
"unity": "2018.4",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue