Base Scene
This commit is contained in:
56
Assets/Scripts/UI/Canvas/CanvasFader.cs
Normal file
56
Assets/Scripts/UI/Canvas/CanvasFader.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Exsersewo.Nydaliv.Extensions;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Exsersewo.UI.Canvas
|
||||
{
|
||||
public class CanvasFader : MonoBehaviour
|
||||
{
|
||||
public MenuType MenuType;
|
||||
public bool Visible => GetComponent<CanvasGroup>().alpha > 0.9f;
|
||||
|
||||
IEnumerator ChangeVisibility(bool lerp, bool show, float TimeToLerp)
|
||||
{
|
||||
float timeLerped = 0;
|
||||
|
||||
var group = GetComponent<CanvasGroup>();
|
||||
|
||||
group.interactable = group.blocksRaycasts = show;
|
||||
|
||||
if (lerp)
|
||||
{
|
||||
while (timeLerped < TimeToLerp)
|
||||
{
|
||||
var lerped = Mathf.Lerp(0, 1, timeLerped / TimeToLerp);
|
||||
|
||||
if (lerped > 0.9)
|
||||
lerped = 1;
|
||||
else if (lerped < 0.1)
|
||||
lerped = 0;
|
||||
|
||||
group.alpha = show ? lerped : 1 - lerped;
|
||||
|
||||
timeLerped += Time.unscaledDeltaTime;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
group.alpha = show ? 1 : 0;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void HidePanel(bool lerp, float TimeToLerp)
|
||||
{
|
||||
StartCoroutine(ChangeVisibility(lerp, false, TimeToLerp));
|
||||
}
|
||||
|
||||
public void ShowPanel(bool lerp, float TimeToLerp)
|
||||
{
|
||||
StartCoroutine(ChangeVisibility(lerp, true, TimeToLerp));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Canvas/CanvasFader.cs.meta
Normal file
11
Assets/Scripts/UI/Canvas/CanvasFader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c58fff238daa16943b4b0f160a89238d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
Assets/Scripts/UI/Canvas/CanvasManager.cs
Normal file
49
Assets/Scripts/UI/Canvas/CanvasManager.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Exsersewo.UI.Canvas
|
||||
{
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class CanvasManager : MonoBehaviour
|
||||
{
|
||||
public CanvasFader[] Canvases;
|
||||
public float TimeToLerp;
|
||||
|
||||
void ChangeCanvas(MenuType menu, bool lerp)
|
||||
{
|
||||
var toZero = Canvases.Where(x => x.MenuType != menu).ToList();
|
||||
var toOne = Canvases.FirstOrDefault(x => x.MenuType == menu);
|
||||
|
||||
toZero.ForEach(x =>
|
||||
{
|
||||
var fader = x.GetComponent<CanvasFader>();
|
||||
if (fader.Visible)
|
||||
{
|
||||
fader.HidePanel(lerp, TimeToLerp);
|
||||
}
|
||||
});
|
||||
|
||||
toOne.GetComponent<CanvasFader>().ShowPanel(lerp, TimeToLerp);
|
||||
}
|
||||
|
||||
public void ChangeToCanvas(CanvasFader menu)
|
||||
=> ChangeToCanvas(menu.MenuType);
|
||||
|
||||
public void ChangeToCanvas(MenuType menu)
|
||||
=> ChangeCanvas(menu, false);
|
||||
|
||||
public void LerpToCanvas(CanvasFader menu)
|
||||
=> LerpToCanvas(menu.MenuType);
|
||||
|
||||
public void LerpToCanvas(MenuType menu)
|
||||
=> ChangeCanvas(menu, true);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public enum MenuType
|
||||
{
|
||||
Game = 0,
|
||||
Stats = 1,
|
||||
Codex = 2
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Canvas/CanvasManager.cs.meta
Normal file
11
Assets/Scripts/UI/Canvas/CanvasManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfcae502041575f409e1334fcaa80eb1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user