Init
This commit is contained in:
79
Assets/Scripts/GameManager.cs
Normal file
79
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Q42.HueApi;
|
||||
using Q42.HueApi.Interfaces;
|
||||
using Q42.HueApi.Models.Bridge;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance;
|
||||
private IBridgeLocator bridgeLocator;
|
||||
private List<LocatedBridge> bridges;
|
||||
private LocatedBridge currentBridge;
|
||||
private bool canRunBridgeCheck = true;
|
||||
|
||||
public IReadOnlyList<LocatedBridge> FoundBridges
|
||||
{
|
||||
get
|
||||
{
|
||||
if(bridges == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return bridges.AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
public LocatedBridge CurrentBridge
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentBridge;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
if (bridgeLocator == null)
|
||||
{
|
||||
bridgeLocator = new LocalNetworkScanBridgeLocator();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var locatedBridges = await bridgeLocator.LocateBridgesAsync(TimeSpan.FromSeconds(5));
|
||||
|
||||
bridges = locatedBridges.ToList();
|
||||
});
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (Time.frameCount % 100 == 0)
|
||||
{
|
||||
if(canRunBridgeCheck)
|
||||
{
|
||||
if (bridges != null && bridges.Any())
|
||||
{
|
||||
Debug.Log($"I have found {bridges.Count} hue bridge{(bridges.Count > 1 ? "s" : "")}");
|
||||
canRunBridgeCheck = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCurrentBridge(LocatedBridge bridge)
|
||||
{
|
||||
currentBridge = bridge;
|
||||
Debug.Log($"Set the current selected bridge to: {currentBridge.IpAddress}: {currentBridge.BridgeId}");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameManager.cs.meta
Normal file
11
Assets/Scripts/GameManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bf16aff98769d942a2a5ffea9eb1146
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Scripts/HueBridgeShower.cs
Normal file
33
Assets/Scripts/HueBridgeShower.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class HueBridgeShower : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Dropdown dropdown;
|
||||
private void Awake()
|
||||
{
|
||||
if(dropdown == null)
|
||||
{
|
||||
dropdown = GetComponent<TMP_Dropdown>();
|
||||
}
|
||||
dropdown.ClearOptions();
|
||||
dropdown.AddOptions(new List<string> { "" });
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if(GameManager.Instance.FoundBridges != null && GameManager.Instance.FoundBridges.Any())
|
||||
{
|
||||
dropdown.AddOptions(GameManager.Instance.FoundBridges.Select(x=>$"{x.IpAddress}: {x.BridgeId}").ToList());
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DropdownChanged(int index)
|
||||
{
|
||||
GameManager.Instance.SetCurrentBridge(GameManager.Instance.FoundBridges[index - 1]);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HueBridgeShower.cs.meta
Normal file
11
Assets/Scripts/HueBridgeShower.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cd9bab26a7096f4cad17e7de37d1bdc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Materials.meta
Normal file
8
Assets/Scripts/Materials.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c83b00a4e08c3c24882cdb123ff5f3c6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
110
Assets/Scripts/Materials/Blur.mat
Normal file
110
Assets/Scripts/Materials/Blur.mat
Normal file
@@ -0,0 +1,110 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Blur
|
||||
m_Shader: {fileID: 4800000, guid: 9d87777e2ffaa1049ad4cbeef5b44173, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BGTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailBump:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainBump:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _Mask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpAmt: 66.8
|
||||
- _BumpScale: 1
|
||||
- _ColorMask: 15
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _Focus: -100
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _Radius: 21
|
||||
- _Shininess: 0.2
|
||||
- _Size: 11.9
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UVSec: 0
|
||||
- _UseUIAlphaClip: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _Specular: {r: 0, g: 0, b: 0, a: 0}
|
||||
8
Assets/Scripts/Materials/Blur.mat.meta
Normal file
8
Assets/Scripts/Materials/Blur.mat.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a57182796c5444f44a9ab520d1cfc76c
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/RequireBridgeSet.cs
Normal file
19
Assets/Scripts/RequireBridgeSet.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class RequireBridgeSet : MonoBehaviour
|
||||
{
|
||||
CanvasGroup canvasManager;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
canvasManager = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
canvasManager.alpha = GameManager.Instance.CurrentBridge == null ? 0 : 1;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RequireBridgeSet.cs.meta
Normal file
11
Assets/Scripts/RequireBridgeSet.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 048689eba1fed8043845daebca2ff389
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Shaders.meta
Normal file
8
Assets/Scripts/Shaders.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e62016bd7fdb3b546bc1e9eb80ca41a5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
154
Assets/Scripts/Shaders/SimpleGrabPassBlur.shader
Normal file
154
Assets/Scripts/Shaders/SimpleGrabPassBlur.shader
Normal file
@@ -0,0 +1,154 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Unlit/FrostedGlass"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Radius("Radius", Range(1, 255)) = 1
|
||||
}
|
||||
|
||||
Category
|
||||
{
|
||||
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Opaque" }
|
||||
|
||||
SubShader
|
||||
{
|
||||
GrabPass
|
||||
{
|
||||
Tags{ "LightMode" = "Always" }
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Tags{ "LightMode" = "Always" }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 texcoord: TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 uvgrab : TEXCOORD0;
|
||||
};
|
||||
|
||||
v2f vert(appdata_t v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
float scale = -1.0;
|
||||
#else
|
||||
float scale = 1.0;
|
||||
#endif
|
||||
o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y * scale) + o.vertex.w) * 0.5;
|
||||
o.uvgrab.zw = o.vertex.zw;
|
||||
return o;
|
||||
}
|
||||
|
||||
sampler2D _GrabTexture;
|
||||
float4 _GrabTexture_TexelSize;
|
||||
float _Radius;
|
||||
|
||||
half4 frag(v2f i) : COLOR
|
||||
{
|
||||
half4 sum = half4(0,0,0,0);
|
||||
|
||||
#define GRABXYPIXEL(kernelx, kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely, i.uvgrab.z, i.uvgrab.w)))
|
||||
|
||||
sum += GRABXYPIXEL(0.0, 0.0);
|
||||
int measurments = 1;
|
||||
|
||||
for (float range = 0.1f; range <= _Radius; range += 0.1f)
|
||||
{
|
||||
sum += GRABXYPIXEL(range, range);
|
||||
sum += GRABXYPIXEL(range, -range);
|
||||
sum += GRABXYPIXEL(-range, range);
|
||||
sum += GRABXYPIXEL(-range, -range);
|
||||
measurments += 4;
|
||||
}
|
||||
|
||||
return sum / measurments;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
GrabPass
|
||||
{
|
||||
Tags{ "LightMode" = "Always" }
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Tags{ "LightMode" = "Always" }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 texcoord: TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 uvgrab : TEXCOORD0;
|
||||
};
|
||||
|
||||
v2f vert(appdata_t v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
float scale = -1.0;
|
||||
#else
|
||||
float scale = 1.0;
|
||||
#endif
|
||||
o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y * scale) + o.vertex.w) * 0.5;
|
||||
o.uvgrab.zw = o.vertex.zw;
|
||||
return o;
|
||||
}
|
||||
|
||||
sampler2D _GrabTexture;
|
||||
float4 _GrabTexture_TexelSize;
|
||||
float _Radius;
|
||||
|
||||
half4 frag(v2f i) : COLOR
|
||||
{
|
||||
|
||||
half4 sum = half4(0,0,0,0);
|
||||
float radius = 1.41421356237 * _Radius;
|
||||
|
||||
#define GRABXYPIXEL(kernelx, kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely, i.uvgrab.z, i.uvgrab.w)))
|
||||
|
||||
sum += GRABXYPIXEL(0.0, 0.0);
|
||||
int measurments = 1;
|
||||
|
||||
for (float range = 1.41421356237f; range <= radius * 1.41; range += 1.41421356237f)
|
||||
{
|
||||
sum += GRABXYPIXEL(range, 0);
|
||||
sum += GRABXYPIXEL(-range, 0);
|
||||
sum += GRABXYPIXEL(0, range);
|
||||
sum += GRABXYPIXEL(0, -range);
|
||||
measurments += 4;
|
||||
}
|
||||
|
||||
return sum / measurments;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Assets/Scripts/Shaders/SimpleGrabPassBlur.shader.meta
Normal file
9
Assets/Scripts/Shaders/SimpleGrabPassBlur.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d87777e2ffaa1049ad4cbeef5b44173
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/UI.meta
Normal file
8
Assets/Scripts/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b6ed6b12c96e8949bc58fae19723d81
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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