Init
This commit is contained in:
57
Assets/Scripts/UI/FitContentHeight.cs
Normal file
57
Assets/Scripts/UI/FitContentHeight.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[ExecuteAlways]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
public class FitContentHeight : MonoBehaviour
|
||||
{
|
||||
[SerializeField] float updatePeriod = 1;
|
||||
float lastCheck = 0;
|
||||
RectTransform RectTransform;
|
||||
VerticalLayoutGroup LayoutManager;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
RectTransform = GetComponent<RectTransform>();
|
||||
LayoutManager = GetComponent<VerticalLayoutGroup>();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (!Application.isPlaying && Application.isEditor) Check();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (Application.isPlaying && !Application.isEditor) Check();
|
||||
}
|
||||
|
||||
void Check()
|
||||
{
|
||||
if (lastCheck >= updatePeriod)
|
||||
{
|
||||
float height = 0;
|
||||
foreach (RectTransform child in RectTransform)
|
||||
{
|
||||
height += child.rect.height;
|
||||
}
|
||||
|
||||
if(LayoutManager != null)
|
||||
{
|
||||
height += (LayoutManager.spacing * RectTransform.childCount);
|
||||
}
|
||||
|
||||
RectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
|
||||
RectTransform.anchorMin.Set(RectTransform.anchorMin.x, 1);
|
||||
RectTransform.anchorMax.Set(RectTransform.anchorMax.x, 1);
|
||||
|
||||
lastCheck = 0;
|
||||
}
|
||||
|
||||
lastCheck += Time.deltaTime;
|
||||
|
||||
Debug.Log(lastCheck);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/FitContentHeight.cs.meta
Normal file
11
Assets/Scripts/UI/FitContentHeight.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62acdf8b338d7ac4f93b267922482071
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Scripts/UI/PageController.cs
Normal file
43
Assets/Scripts/UI/PageController.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class PageController : MonoBehaviour
|
||||
{
|
||||
private CanvasGroup canvasManager;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
canvasManager = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
private IEnumerator Lerp(bool display, float time)
|
||||
{
|
||||
float t = 0;
|
||||
while (t <= time)
|
||||
{
|
||||
if (display)
|
||||
{
|
||||
canvasManager.alpha = Mathf.Lerp(0, 1, t / time);
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasManager.alpha = Mathf.Lerp(1, 0, t / time);
|
||||
}
|
||||
|
||||
t += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
StopCoroutine(Lerp(display, time));
|
||||
}
|
||||
|
||||
public void Display()
|
||||
{
|
||||
StartCoroutine(Lerp(true, 5));
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
StartCoroutine(Lerp(false, 5));
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/PageController.cs.meta
Normal file
11
Assets/Scripts/UI/PageController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c724a4090b5a883428e0383a3163f731
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/UI/PageManager.cs
Normal file
35
Assets/Scripts/UI/PageManager.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class PageManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<PageController> Pages;
|
||||
[SerializeField] private RectTransform Sidebar;
|
||||
private RectTransform RectTransform;
|
||||
|
||||
public static PageManager Instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
RectTransform = GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
float previous = 0;
|
||||
private void LateUpdate()
|
||||
{
|
||||
if(previous != Sidebar.rect.width)
|
||||
{
|
||||
RectTransform.offsetMin = new Vector2(Sidebar.rect.width, RectTransform.offsetMin.y);
|
||||
previous = Sidebar.rect.width;
|
||||
}
|
||||
}
|
||||
|
||||
public void DisplayPage(Transform page)
|
||||
{
|
||||
Pages.FirstOrDefault(z => z.transform == page).Display();
|
||||
Pages.Where(z => z.transform != page).ToList().ForEach(z => z.Hide());
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/PageManager.cs.meta
Normal file
11
Assets/Scripts/UI/PageManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 969bfa2e510124742addc5bc026a08ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
85
Assets/Scripts/UI/Resizable.cs
Normal file
85
Assets/Scripts/UI/Resizable.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum AnimationType
|
||||
{
|
||||
EaseInOut,
|
||||
Ease,
|
||||
Lerp,
|
||||
SlowThenFast
|
||||
}
|
||||
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
public class Resizable : MonoBehaviour
|
||||
{
|
||||
RectTransform RectTransform;
|
||||
[SerializeField] private Vector2 Minimum;
|
||||
[SerializeField] private Vector2 Maximum;
|
||||
private bool IsStretched;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
RectTransform = GetComponent<RectTransform>();
|
||||
IsStretched = RectTransform.rect.width > Minimum.x;
|
||||
}
|
||||
|
||||
IEnumerator Lerp(bool toMaximum, AnimationType animation, float time)
|
||||
{
|
||||
float t = 0;
|
||||
float originalWidth = RectTransform.rect.width;
|
||||
float originalHeight = RectTransform.rect.height;
|
||||
while (t <= time)
|
||||
{
|
||||
switch(animation)
|
||||
{
|
||||
case AnimationType.Lerp:
|
||||
{
|
||||
if(toMaximum)
|
||||
{
|
||||
RectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Lerp(originalWidth, Maximum.x, t));
|
||||
if(Maximum.y != -1)
|
||||
{
|
||||
RectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Mathf.Lerp(originalHeight, Maximum.y, t));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Lerp(originalWidth, Minimum.x, t));
|
||||
if (Minimum.y != -1)
|
||||
{
|
||||
RectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Mathf.Lerp(originalHeight, Minimum.y, t));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
t += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
StopCoroutine(Lerp(toMaximum, animation, time));
|
||||
}
|
||||
|
||||
public void Stretch(AnimationType animation = AnimationType.Lerp, float time = 5)
|
||||
=> StartCoroutine(Lerp(true, animation, time));
|
||||
|
||||
public void Shrink(AnimationType animation = AnimationType.Lerp, float time = 5)
|
||||
=> StartCoroutine(Lerp(false, animation, time));
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
if(IsStretched)
|
||||
{
|
||||
Shrink();
|
||||
|
||||
IsStretched = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Stretch();
|
||||
|
||||
IsStretched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Resizable.cs.meta
Normal file
11
Assets/Scripts/UI/Resizable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa8f29377ab1ace49b3a492968d512e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/UI/SidebarEntryManager.cs
Normal file
19
Assets/Scripts/UI/SidebarEntryManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SidebarEntryManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Color Selected;
|
||||
[SerializeField] private Color Unselected;
|
||||
[SerializeField] private Image background;
|
||||
|
||||
public void MarkSelected()
|
||||
{
|
||||
background.color = Selected;
|
||||
}
|
||||
|
||||
public void MarkUnselected()
|
||||
{
|
||||
background.color = Unselected;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/SidebarEntryManager.cs.meta
Normal file
11
Assets/Scripts/UI/SidebarEntryManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7340b4e66d131e478dd11574f9690e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/UI/SidebarManager.cs
Normal file
14
Assets/Scripts/UI/SidebarManager.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class SidebarManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<SidebarEntryManager> Entries;
|
||||
|
||||
public void SelectEntry(Transform obj)
|
||||
{
|
||||
Entries.FirstOrDefault(z => z.transform == obj).MarkSelected();
|
||||
Entries.Where(z => z.transform != obj).ToList().ForEach(z => z.MarkUnselected());
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/SidebarManager.cs.meta
Normal file
11
Assets/Scripts/UI/SidebarManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0478b032106651d46a7c8d5563dccc9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user