Fancy Background Shader

This commit is contained in:
hyperion51 2020-03-25 02:22:44 +00:00
commit 4221f304f1
18 changed files with 698 additions and 398 deletions

View file

@ -0,0 +1,31 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackgroundRenderer : MonoBehaviour
{
public Transform Background;
// public float RotationSpeed1 = 1;
// public float RotationSpeed2 = 1;
private Camera _camera;
private float _ratio;
//private Material _material;
private float _depth;
private void Start()
{
_camera = GetComponent<Camera>();
_depth = Background.position.z;
//_material = Background.GetComponent<MeshRenderer>().material;
}
private void OnPreRender()
{
//_material.SetVector("Rot1", );
_ratio = (float) Screen.height / Screen.width;
Background.position = new Vector3(transform.position.x, transform.position.y, _depth);
var size = _camera.orthographicSize;
Background.localScale = new Vector3(size * 4, size * 4 * _ratio, 1);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60335bb143d92fd4eac7a5ed8b12494c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -19,25 +19,7 @@
// https://github.com/ashima/webgl-noise
//
float3 mod289(float3 x)
{
return x - floor(x / 289.0) * 289.0;
}
float2 mod289(float2 x)
{
return x - floor(x / 289.0) * 289.0;
}
float3 permute(float3 x)
{
return mod289((x * 34.0 + 1.0) * x);
}
float3 taylorInvSqrt(float3 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
#include "SimplexNoise2D.cginc"
float2 snoise_grad(float2 v)
{

View file

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TabActivator : MonoBehaviour
{
public TabGroup TabGroup;
public TabButton TabButton;
void Start()
{
TabGroup.OnTabChange += button => gameObject.SetActive(button == TabButton);
gameObject.SetActive(false);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f60c7818169f95468915fbca3ef4773
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: -50
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

101
Assets/Scripts/TabButton.cs Normal file
View file

@ -0,0 +1,101 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class TabButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
public event Action<TabButton> OnClick;
public float StateDamping;
public RectTransform Tab;
public Image Fill;
public Image Outline;
public TextMeshProUGUI Label;
public VerticalLayoutGroup LabelLayout;
public TabButtonState CurrentState = TabButtonState.Unselected;
public TabButtonAppearance UnselectedAppearance;
public TabButtonAppearance SelectedAppearance;
public TabButtonAppearance HoverAppearance;
public TabButtonAppearance ClickAppearance;
private RectOffset _defaultPadding;
private float _currentPadding;
private void Start()
{
_defaultPadding = LabelLayout.padding;
_currentPadding = _defaultPadding.left;
}
public void OnPointerEnter(PointerEventData eventData)
{
if (CurrentState == TabButtonState.Unselected)
CurrentState = TabButtonState.Hover;
}
public void OnPointerExit(PointerEventData eventData)
{
if (CurrentState == TabButtonState.Hover)
CurrentState = TabButtonState.Unselected;
}
public void OnPointerClick(PointerEventData eventData)
{
if (CurrentState != TabButtonState.Selected)
{
Fill.color = ClickAppearance.FillColor;
Outline.color = ClickAppearance.OutlineColor;
OnClick?.Invoke(this);
}
}
private void Update()
{
TabButtonAppearance appearance;
switch (CurrentState)
{
case TabButtonState.Unselected:
appearance = UnselectedAppearance;
break;
case TabButtonState.Selected:
appearance = SelectedAppearance;
break;
case TabButtonState.Hover:
appearance = HoverAppearance;
break;
default:
appearance = new TabButtonAppearance();
break;
}
Fill.color = Color.Lerp(Fill.color, appearance.FillColor, StateDamping * Time.deltaTime);
Outline.color = Color.Lerp(Outline.color, appearance.OutlineColor, StateDamping * Time.deltaTime);
_currentPadding = Mathf.Lerp(_currentPadding, appearance.LayoutPadding, StateDamping * Time.deltaTime);
LabelLayout.padding = new RectOffset
{
bottom = _defaultPadding.bottom,
top = _defaultPadding.top,
left = (int) _currentPadding,
right = (int) _currentPadding
};
}
}
public enum TabButtonState
{
Unselected,
Selected,
Hover
}
[Serializable]
public struct TabButtonAppearance
{
public Color FillColor;
public Color OutlineColor;
public int LayoutPadding;
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ec4ae0999e1b814cbb86e167df3c039
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class TabGroup : MonoBehaviour
{
public event Action<TabButton> OnTabChange;
private TabButton[] _tabButtons;
private TabButton _currentButton;
private void Start()
{
_tabButtons = GetComponentsInChildren<TabButton>();
foreach (var thisButton in _tabButtons)
{
thisButton.OnClick += button =>
{
if (_currentButton != null)
{
_currentButton.CurrentState = TabButtonState.Unselected;
_currentButton.Tab.gameObject.SetActive(false);
}
_currentButton = thisButton;
_currentButton.CurrentState = TabButtonState.Selected;
_currentButton.Tab.gameObject.SetActive(true);
OnTabChange?.Invoke(_currentButton);
};
thisButton.Tab.gameObject.SetActive(false);
}
_tabButtons.First().OnPointerClick(null);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 828461d20e2142546814879a0a0f44b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: