Add basic ui controller
parent
66dd0a6206
commit
1316dbb553
@ -0,0 +1,11 @@
|
||||
#ifndef HSL_INCLUDED
|
||||
#define HSL_INCLUDED
|
||||
|
||||
inline float3 HSL2RGB(float3 hsl) {
|
||||
int3 n = int3(0, 8, 4);
|
||||
float3 k = (n + hsl.x * 12) % 12;
|
||||
float a = hsl.y * min(hsl.z, 1 - hsl.z);
|
||||
return hsl.z - a * max(-1, min(k - 3, min(9 - k, 1)));
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,99 @@
|
||||
Shader "ConformalDecals/UI/HSLSlider"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_StencilComp ("Stencil Comparison", Float) = 8
|
||||
_Stencil ("Stencil ID", Float) = 0
|
||||
_StencilOp ("Stencil Operation", Float) = 0
|
||||
_StencilWriteMask ("Stencil Write Mask", Float) = 255
|
||||
_StencilReadMask ("Stencil Read Mask", Float) = 255
|
||||
|
||||
_ColorMask ("Color Mask", Float) = 15
|
||||
|
||||
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma require integers
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
#include "HSL.cginc"
|
||||
|
||||
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
|
||||
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
|
||||
|
||||
float4 _ClipRect;
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 worldPosition : TEXCOORD1;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.worldPosition = v.vertex;
|
||||
o.uv = v.uv;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 color = 1;
|
||||
color.rgb = HSL2RGB(float3(i.uv.y, 1, 0.5));
|
||||
|
||||
#ifdef UNITY_UI_CLIP_RECT
|
||||
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_UI_ALPHACLIP
|
||||
clip (color.a - 0.001);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
Shader "ConformalDecals/UI/HSLSquare"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Hue("Hue", Range(0,1)) = 0
|
||||
|
||||
_StencilComp ("Stencil Comparison", Float) = 8
|
||||
_Stencil ("Stencil ID", Float) = 0
|
||||
_StencilOp ("Stencil Operation", Float) = 0
|
||||
_StencilWriteMask ("Stencil Write Mask", Float) = 255
|
||||
_StencilReadMask ("Stencil Read Mask", Float) = 255
|
||||
|
||||
_ColorMask ("Color Mask", Float) = 15
|
||||
|
||||
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma require integers
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
#include "HSL.cginc"
|
||||
|
||||
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
|
||||
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
|
||||
|
||||
float _Hue;
|
||||
float4 _ClipRect;
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 worldPosition : TEXCOORD1;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.worldPosition = v.vertex;
|
||||
o.uv = v.uv;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 color = 1;
|
||||
color.rgb = HSL2RGB(float3(_Hue, i.uv.x, i.uv.y));
|
||||
|
||||
#ifdef UNITY_UI_CLIP_RECT
|
||||
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_UI_ALPHACLIP
|
||||
clip (color.a - 0.001);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 8.4 KiB |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,15 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ConformalDecals.Text {
|
||||
public struct FormattedText {
|
||||
public string text;
|
||||
public TMP_FontAsset font;
|
||||
public FontStyles style;
|
||||
public bool vertical;
|
||||
|
||||
public Color32 color;
|
||||
public Color32 outlineColor;
|
||||
public float outlineWidth;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
namespace ConformalDecals.Text {
|
||||
public struct TextSettings {
|
||||
|
||||
}
|
||||
}
|
@ -1,9 +1,108 @@
|
||||
using System;
|
||||
using ConformalDecals.Text;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ConformalDecals.UI {
|
||||
public class TextEntryController : MonoBehaviour {
|
||||
public void OnClose() {
|
||||
Debug.Log("Close!");
|
||||
private FormattedText _text;
|
||||
|
||||
[SerializeField] private Selectable _textBox;
|
||||
[SerializeField] private Toggle _fontColorButton;
|
||||
[SerializeField] private Toggle _fontButton;
|
||||
[SerializeField] private Toggle _outlineColorButton;
|
||||
[SerializeField] private Slider _outlineWidthSlider;
|
||||
|
||||
[SerializeField] private Toggle _boldButton;
|
||||
[SerializeField] private Toggle _italicButton;
|
||||
[SerializeField] private Toggle _underlineButton;
|
||||
[SerializeField] private Toggle _smallCapsButton;
|
||||
[SerializeField] private Toggle _verticalButton;
|
||||
|
||||
public delegate void TextUpdateReceiver(FormattedText text);
|
||||
|
||||
public delegate void TextCancelReceiver();
|
||||
|
||||
public TextUpdateReceiver textUpdateCallback;
|
||||
public TextCancelReceiver textCancelCallback;
|
||||
|
||||
private void Start() {
|
||||
(_textBox as TMP_InputField).text = _text.text;
|
||||
|
||||
_boldButton.isOn = (_text.style | FontStyles.Bold) != 0;
|
||||
_italicButton.isOn = (_text.style | FontStyles.Italic) != 0;
|
||||
_underlineButton.isOn = (_text.style | FontStyles.Underline) != 0;
|
||||
_smallCapsButton.isOn = (_text.style | FontStyles.SmallCaps) != 0;
|
||||
_verticalButton.isOn = _text.vertical;
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void OnCancel() {
|
||||
textCancelCallback();
|
||||
Close();
|
||||
}
|
||||
|
||||
public void OnApply() {
|
||||
textUpdateCallback(_text);
|
||||
Close();
|
||||
}
|
||||
|
||||
public void OnTextUpdate(string text) {
|
||||
_text.text = text;
|
||||
textUpdateCallback(_text);
|
||||
|
||||
}
|
||||
|
||||
public void OnFontMenu(bool state) { }
|
||||
public void OnColorMenu(bool state) { }
|
||||
|
||||
public void OnOutlineColorMenu(bool state) { }
|
||||
|
||||
public void OnOutlineUpdate(float value) {
|
||||
_text.outlineWidth = value;
|
||||
textUpdateCallback(_text);
|
||||
|
||||
}
|
||||
|
||||
public void OnBoldUpdate(bool state) {
|
||||
if (state) _text.style |= FontStyles.Bold;
|
||||
else _text.style &= ~FontStyles.Bold;
|
||||
|
||||
textUpdateCallback(_text);
|
||||
|
||||
}
|
||||
|
||||
public void OnItalicUpdate(bool state) {
|
||||
if (state) _text.style |= FontStyles.Italic;
|
||||
else _text.style &= ~FontStyles.Italic;
|
||||
|
||||
textUpdateCallback(_text);
|
||||
|
||||
}
|
||||
|
||||
public void OnUnderlineUpdate(bool state) {
|
||||
if (state) _text.style |= FontStyles.Underline;
|
||||
else _text.style &= ~FontStyles.Underline;
|
||||
|
||||
textUpdateCallback(_text);
|
||||
|
||||
}
|
||||
|
||||
public void OnSmallCapsUpdate(bool state) {
|
||||
if (state) _text.style |= FontStyles.SmallCaps;
|
||||
else _text.style &= ~FontStyles.SmallCaps;
|
||||
|
||||
textUpdateCallback(_text);
|
||||
|
||||
}
|
||||
|
||||
public void OnVerticalUpdate(bool state) {
|
||||
_text.vertical = state;
|
||||
textUpdateCallback(_text);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue