First UI Timer
This commit is contained in:
parent
cd5b96d5b5
commit
7123c54b1e
11 changed files with 765 additions and 7 deletions
|
@ -10,6 +10,7 @@ public sealed class GameSystem : MonoBehaviour
|
|||
bool serviceOpen = false;
|
||||
float serviceTime = 30.0f;
|
||||
float serviceTimer = 0.0f;
|
||||
UITimer UIServiceTimer;
|
||||
float slowScale = 0.5f; //Default scale for slow mode
|
||||
private float fixedDeltaTime;
|
||||
|
||||
|
@ -54,6 +55,16 @@ public sealed class GameSystem : MonoBehaviour
|
|||
{
|
||||
// Make a copy of the fixedDeltaTime, it defaults to 0.02f, but it can be changed in the editor
|
||||
this.fixedDeltaTime = Time.fixedDeltaTime;
|
||||
GameObject timerObj = GameObject.Find("/UI/Canvas/ServiceTimer");
|
||||
if(timerObj is null)
|
||||
{
|
||||
Debug.LogWarning("No service timer found");
|
||||
UIServiceTimer=null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UIServiceTimer=timerObj.GetComponent<UITimer>();
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
@ -67,12 +78,17 @@ public sealed class GameSystem : MonoBehaviour
|
|||
{
|
||||
if(serviceOpen)
|
||||
{
|
||||
//Update service timer
|
||||
serviceTimer-= Time.deltaTime;
|
||||
if(UIServiceTimer != null)
|
||||
UIServiceTimer.SetValue(serviceTimer/serviceTime);
|
||||
if (serviceTimer < 0)
|
||||
{
|
||||
serviceOpen = false;
|
||||
Debug.Log("Service closed");
|
||||
}
|
||||
|
||||
//Request new clients
|
||||
ClientManager.Instance.clientRequest();
|
||||
}
|
||||
|
||||
|
@ -85,6 +101,9 @@ public sealed class GameSystem : MonoBehaviour
|
|||
// Debug.Log("Service timer : "+(int)serviceTimer);
|
||||
}
|
||||
|
||||
// simple Singleton implementation
|
||||
//public static GameSystem instance { get; private set; } //Give public access to the instance. But only set from this class
|
||||
|
||||
//// Singleton Implementation (https://jlambert.developpez.com/tutoriels/dotnet/implementation-pattern-singleton-csharp/#LIII) ////
|
||||
private GameSystem()
|
||||
{
|
||||
|
|
36
Assets/Scripts/UI/UITimer.cs
Normal file
36
Assets/Scripts/UI/UITimer.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UITimer : MonoBehaviour
|
||||
{
|
||||
// public Image mask;
|
||||
public Image time;
|
||||
// float originalSize;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// originalSize = mask.rectTransform.rect.height;
|
||||
time.color = Color.green;
|
||||
}
|
||||
|
||||
//Value : [0,1]
|
||||
public void SetValue(float value)
|
||||
{
|
||||
if(value>1||value<0)
|
||||
Debug.LogWarning(gameObject.name+" - Timer value out of range [0,1]: "+value);
|
||||
//Change time color
|
||||
if(value>0.66)
|
||||
time.color = Color.green;
|
||||
else if(value>0.33)
|
||||
time.color = Color.yellow;
|
||||
else
|
||||
time.color = Color.red;
|
||||
|
||||
time.fillAmount = value;
|
||||
|
||||
//Change mask size
|
||||
// mask.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, originalSize * value);
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/UITimer.cs.meta
Normal file
11
Assets/Scripts/UI/UITimer.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: da748f5c6c44f274786e0947a0c6bbf8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue