This commit is contained in:
SoulliesOfficial
2025-06-06 10:14:55 -04:00
parent d4e860fa16
commit db4d131192
1088 changed files with 45704 additions and 2260 deletions

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a7296bad073428c4796089b44a48cab9
folderAsset: yes
timeCreated: 1521742084
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 0873351fdb3a65f43901b3ec088375b0
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,150 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UI Extensions/SoftMaskShader"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Color("Tint", Color) = (1,1,1,1)
_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
_AlphaMask("AlphaMask - Must be Wrapped",2D) = "white"{}
_CutOff("CutOff",Float) = 0
[MaterialToggle]
_HardBlend("HardBlend",Float) = 0
_FlipAlphaMask("Flip Alpha Mask",int) = 0
_NoOuterClip("Outer Clip",int) = 0
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Stencil
{
Ref[_Stencil]
Comp[_StencilComp]
Pass[_StencilOp]
ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask]
}
LOD 0
Cull Off
Lighting Off
ZWrite Off
ZTest[unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask[_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
float2 maskTexcoord : TEXCOORD1;
};
inline float UnityGet2DClipping (in float2 position, in float4 clipRect)
{
float2 inside = step(clipRect.xy, position.xy) * step(position.xy, clipRect.zw);
return inside.x * inside.y;
}
fixed4 _Color;
fixed4 _TextureSampleAdd;
sampler2D _MainTex;
bool _UseAlphaClip;
int _FlipAlphaMask = 0;
float4 _AlphaMask_ST;
sampler2D _AlphaMask;
v2f vert(appdata_t IN)
{
v2f OUT;
float4 wolrdPos = IN.vertex;
OUT.maskTexcoord = TRANSFORM_TEX(wolrdPos.xy, _AlphaMask);
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1,1);
#endif
OUT.color = IN.color * _Color;
return OUT;
}
float _CutOff;
bool _HardBlend = false;
bool _NoOuterClip = false;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
float4 inMask = float4(
step(float2(0.0f, 0.0f), IN.maskTexcoord),
step(IN.maskTexcoord, float2(1.0f, 1.0f)) );
// Do we want to clip the image to the Mask Rectangle?
if (_NoOuterClip == false && all(inMask) == false )
{
color.a = 0;
}
else // It's in the mask rectangle, so apply the alpha of the mask provided.
{
float a = tex2D(_AlphaMask, IN.maskTexcoord).a;
if (a <= _CutOff)
a = 0;
else
{
if(_HardBlend)
a = 1;
}
if (_FlipAlphaMask == 1)
a = 1 - a;
color.a *= a;
}
if (_UseAlphaClip)
clip(color.a - 0.001);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 947afae4d36f1274ea2e4098262ceef6
timeCreated: 1444851202
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,105 @@
Shader "UI Extensions/Particles/Additive" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend SrcAlpha One
ColorMask RGB
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
UNITY_TRANSFER_FOG(v,v.vertex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f IN) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.projPos)));
float partZ = IN.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
IN.color.a *= fade;
#endif
fixed4 col = 2.0f * IN.color * _TintColor * tex2D(_MainTex, IN.texcoord);
UNITY_APPLY_FOG_COLOR(IN.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
return col;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e064104788d94b349ab13141a30b5660
timeCreated: 1502443970
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,109 @@
Shader "UI Extensions/Particles/~Additive-Multiply" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend One OneMinusSrcAlpha
ColorMask RGB
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
UNITY_TRANSFER_FOG(v,v.vertex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color *= fade;
#endif
fixed4 tex = tex2D(_MainTex, i.texcoord);
fixed4 col;
col.rgb = _TintColor.rgb * tex.rgb * i.color.rgb * 2.0f;
col.a = (1 - tex.a) * (_TintColor.a * i.color.a * 2.0f);
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
return col;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 088bbfd9222ee044cb4e4699336e9ff1
timeCreated: 1502443969
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
Shader "UI Extensions/Particles/Additive (Soft)" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend One OneMinusSrcColor
ColorMask RGB
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
UNITY_TRANSFER_FOG(v,v.vertex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color.a *= fade;
#endif
half4 col = i.color * tex2D(_MainTex, i.texcoord);
col.rgb *= col.a;
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
return col;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4c2211b120168e44db4a3a8417013615
timeCreated: 1502443969
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
Shader "UI Extensions/Particles/Alpha Blended" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
UNITY_TRANSFER_FOG(v,v.vertex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color.a *= fade;
#endif
fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c3d7d8d71a91071469ad7019e77864d6
timeCreated: 1502443970
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
Shader "UI Extensions/Particles/Blend" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend DstColor One
ColorMask RGB
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
UNITY_TRANSFER_FOG(v,v.vertex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color *= fade;
#endif
fixed4 col = i.color * tex2D(_MainTex, i.texcoord);
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
return col;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 98fed5ba500a9a04a80325266b9911bb
timeCreated: 1502443970
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
Shader "UI Extensions/Particles/Multiply" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend Zero SrcColor
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
UNITY_TRANSFER_FOG(v,v.vertex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color.a *= fade;
#endif
half4 prev = i.color * tex2D(_MainTex, i.texcoord);
fixed4 col = lerp(half4(1,1,1,1), prev, prev.a);
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(1,1,1,1)); // fog towards white due to our blend mode
return col;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 320f6bb7bde369b4a85c9d89a9ba5268
timeCreated: 1502443969
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,107 @@
Shader "UI Extensions/Particles/Multiply (Double)" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend DstColor SrcColor
ColorMask RGB
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
UNITY_TRANSFER_FOG(v,v.vertex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color.a *= fade;
#endif
fixed4 col;
fixed4 tex = tex2D(_MainTex, i.texcoord);
col.rgb = tex.rgb * i.color.rgb * 2;
col.a = i.color.a * tex.a;
col = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), col, col.a);
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0.5,0.5,0.5,0.5)); // fog towards gray due to our blend mode
return col;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0765ecef58833c3429346a1fee45e4e0
timeCreated: 1502443969
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
Shader "UI Extensions/Particles/Alpha Blended Premultiply" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.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
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
Blend One OneMinusSrcAlpha
ColorMask RGB
Cull Off Lighting Off ZWrite Off
ZTest [unity_GUIZTestMode]
SubShader {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD1;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t IN)
{
v2f v;
v.vertex = UnityObjectToClipPos(IN.vertex);
#ifdef SOFTPARTICLES_ON
v.projPos = ComputeScreenPos (v.vertex);
COMPUTE_EYEDEPTH(v.projPos.z);
#endif
v.color = IN.color;
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
return v;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _InvFade;
fixed4 frag (v2f IN) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.projPos)));
float partZ = IN.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
IN.color.a *= fade;
#endif
return IN.color * tex2D(_MainTex, IN.texcoord) * IN.color.a;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0596a6838d78f624397b642817cf20bc
timeCreated: 1502443969
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
Shader "UI Extensions/Particles/VertexLit Blended" {
Properties {
_EmisColor ("Emissive Color", Color) = (.2,.2,.2,0)
_MainTex ("Particle Texture", 2D) = "white" {}
_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" }
Tags { "LightMode" = "Vertex" }
Cull Off
Lighting On
Material { Emission [_EmisColor] }
ColorMaterial AmbientAndDiffuse
ZWrite Off
ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Pass {
SetTexture [_MainTex] { combine primary * texture }
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 65bbb789ada58ab44aaedbe09687f089
timeCreated: 1502443969
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,94 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UI Extensions/UIAdditive"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_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
}
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]
Fog { Mode Off }
Blend One One
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
OUT.color = IN.color * _Color;
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
color.rgb *= color.a;
clip (color.a - 0.01);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 20fb5fa09d4675a4e94314a228763c23
timeCreated: 1464629199
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
/// Credit 00christian00
/// Sourced from - http://forum.unity3d.com/threads/any-way-to-show-part-of-an-image-without-using-mask.360085/#post-2332030
Shader "UI Extensions/UI Image Crop" {
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_XCrop ("X Crop", Range(0.0,1.0)) = 1
_YCrop ("Y Crop", Range(0.0,1.0)) = 1
}
SubShader {
ZWrite Off
Tags
{
"Queue" = "Transparent"
"RenderType" = "Transparent"
"IgnoreProjector" = "True"
}
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : POSITION;
fixed4 color : COLOR;
float2 uv : TEXCOORD0; //UV1 coord
};
uniform sampler2D _MainTex;
float4 _MainTex_ST;
uniform float _XCrop;
uniform float _YCrop;
v2f vert (v2f v)
{
v2f o;
o.color=v.color;
o.color.a=0.1;
o.pos = UnityObjectToClipPos (v.pos);
o.uv=TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : COLOR
{
//return fixed4(0.25,0,0,1);
i.color.a=step(i.uv.x,_XCrop);
//I don't like the bottom up ordering,so I reverse it
i.color.a=i.color.a*step(1-i.uv.y,_YCrop);
return i.color * tex2D (_MainTex, i.uv);
}
ENDCG
}
}
}

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: ccf5a0c8f87d3c547aff3daecb3164a4
ShaderImporter:
defaultTextures: []
userData:

View File

@@ -0,0 +1,95 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UI Extensions/UILinearDodge"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_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
}
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]
Fog { Mode Off }
BlendOp Add
Blend SrcAlpha One, One Zero
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
OUT.color = IN.color * _Color;
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
color.rgb *= color.a;
clip (color.a - 0.01);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c3c3af59790cf3749ba49fe1c838c94e
timeCreated: 1464629199
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UI Extensions/UIMultiply"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_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
}
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]
Fog { Mode Off }
Blend DstColor Zero
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
OUT.color = IN.color * _Color;
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
clip (color.a - 0.01);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d287872ca8fd776418c28d332df585c3
timeCreated: 1464629200
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
Shader "UI/Particles/Hidden"
{
Properties
{
}
SubShader
{
Tags { "Queue"="Geometry" "RenderType"="Opaque" }
Cull Off Lighting Off ZWrite Off Fog { Mode Off }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct v2f
{
float4 vertex : SV_POSITION;
};
v2f vert ()
{
v2f o;
o.vertex = fixed4(0, 0, 0, 0);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
discard;
return fixed4(0, 0, 0, 0);
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: cf73a0a4b5ea8994f916cd18a97c564b
timeCreated: 1464476220
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UI Extensions/UIScreen"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_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
}
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]
Fog { Mode Off }
BlendOp Add
Blend OneMinusDstColor One, One Zero
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
OUT.color = IN.color * _Color;
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
color.rgb *= color.a;
clip (color.a - 0.01);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 227ac21f7763c00489cc458e3938e326
timeCreated: 1464629199
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,94 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UI Extensions/UISoftAdditive"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_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
}
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]
Fog { Mode Off }
Blend OneMinusDstColor One
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
OUT.color = IN.color * _Color;
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
color.rgb *= color.a;
clip (color.a - 0.01);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fb2e16a3d1280334a9e05394e1890f09
timeCreated: 1464629200
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9d40233b1c5add641bb2f4f7f12af05e
folderAsset: yes
timeCreated: 1438724032
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fab8c1b6e538fad489513f03e0418451
folderAsset: yes
timeCreated: 1468775610
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 82ea50ac9a6ea8940a71f86ea8d13bf0
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,61 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(HorizontalOrVerticalLayoutGroup), typeof(ContentSizeFitter), typeof(ToggleGroup))]
[AddComponentMenu("UI/Extensions/Accordion/Accordion Group")]
public class Accordion : MonoBehaviour
{
private bool m_expandVertical = true;
[HideInInspector]
public bool ExpandVerticval => m_expandVertical;
public enum Transition
{
Instant,
Tween
}
[SerializeField] private Transition m_Transition = Transition.Instant;
[SerializeField] private float m_TransitionDuration = 0.3f;
/// <summary>
/// Gets or sets the transition.
/// </summary>
/// <value>The transition.</value>
public Transition transition
{
get { return this.m_Transition; }
set { this.m_Transition = value; }
}
/// <summary>
/// Gets or sets the duration of the transition.
/// </summary>
/// <value>The duration of the transition.</value>
public float transitionDuration
{
get { return this.m_TransitionDuration; }
set { this.m_TransitionDuration = value; }
}
private void Awake()
{
m_expandVertical = GetComponent<HorizontalLayoutGroup>() ? false : true;
var group = GetComponent<ToggleGroup>();
}
#if UNITY_EDITOR
private void OnValidate()
{
if (!GetComponent<HorizontalLayoutGroup>() && !GetComponent<VerticalLayoutGroup>())
{
Debug.LogError("Accordion requires either a Horizontal or Vertical Layout group to place children");
}
}
#endif
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4387cc9950f37044c92f9d144a2b1002
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,226 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System;
using System.Collections;
using UnityEngine.UI.Extensions.Tweens;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
[AddComponentMenu("UI/Extensions/Accordion/Accordion Element")]
public class AccordionElement : Toggle
{
[SerializeField] private float m_MinHeight = 18f;
public float MinHeight => m_MinHeight;
[SerializeField] private float m_MinWidth = 40f;
public float MinWidth => m_MinWidth;
private Accordion m_Accordion;
private RectTransform m_RectTransform;
private LayoutElement m_LayoutElement;
[NonSerialized]
private readonly TweenRunner<FloatTween> m_FloatTweenRunner;
protected AccordionElement()
{
if (this.m_FloatTweenRunner == null)
this.m_FloatTweenRunner = new TweenRunner<FloatTween>();
this.m_FloatTweenRunner.Init(this);
}
protected override void Awake()
{
base.Awake();
base.transition = Transition.None;
base.toggleTransition = ToggleTransition.None;
this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>();
this.m_RectTransform = this.transform as RectTransform;
this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>();
this.onValueChanged.AddListener(OnValueChanged);
}
private new IEnumerator Start()
{
base.Start();
yield return new WaitForEndOfFrame(); // Wait for the first frame
OnValueChanged(this.isOn);
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>();
if (this.group == null)
{
ToggleGroup tg = this.GetComponentInParent<ToggleGroup>();
if (tg != null)
{
this.group = tg;
}
}
LayoutElement le = this.gameObject.GetComponent<LayoutElement>();
if (le != null && m_Accordion != null)
{
if (this.isOn)
{
if (m_Accordion.ExpandVerticval)
{
le.preferredHeight = -1f;
}
else
{
le.preferredWidth = -1f;
}
}
else
{
if (m_Accordion.ExpandVerticval)
{
le.preferredHeight = this.m_MinHeight;
}
else
{
le.preferredWidth = this.m_MinWidth;
}
}
}
}
#endif
public void OnValueChanged(bool state)
{
if (this.m_LayoutElement == null)
return;
Accordion.Transition transition = (this.m_Accordion != null) ? this.m_Accordion.transition : Accordion.Transition.Instant;
if (transition == Accordion.Transition.Instant && m_Accordion != null)
{
if (state)
{
if (m_Accordion.ExpandVerticval)
{
this.m_LayoutElement.preferredHeight = -1f;
}
else
{
this.m_LayoutElement.preferredWidth = -1f;
}
}
else
{
if (m_Accordion.ExpandVerticval)
{
this.m_LayoutElement.preferredHeight = this.m_MinHeight;
}
else
{
this.m_LayoutElement.preferredWidth = this.m_MinWidth;
}
}
}
else if (transition == Accordion.Transition.Tween)
{
if (state)
{
if (m_Accordion.ExpandVerticval)
{
this.StartTween(this.m_MinHeight, this.GetExpandedHeight());
}
else
{
this.StartTween(this.m_MinWidth, this.GetExpandedWidth());
}
}
else
{
if (m_Accordion.ExpandVerticval)
{
this.StartTween(this.m_RectTransform.rect.height, this.m_MinHeight);
}
else
{
this.StartTween(this.m_RectTransform.rect.width, this.m_MinWidth);
}
}
}
}
protected float GetExpandedHeight()
{
if (this.m_LayoutElement == null)
return this.m_MinHeight;
float originalPrefH = this.m_LayoutElement.preferredHeight;
this.m_LayoutElement.preferredHeight = -1f;
float h = LayoutUtility.GetPreferredHeight(this.m_RectTransform);
this.m_LayoutElement.preferredHeight = originalPrefH;
return h;
}
protected float GetExpandedWidth()
{
if (this.m_LayoutElement == null)
return this.m_MinWidth;
float originalPrefW = this.m_LayoutElement.preferredWidth;
this.m_LayoutElement.preferredWidth = -1f;
float w = LayoutUtility.GetPreferredWidth(this.m_RectTransform);
this.m_LayoutElement.preferredWidth = originalPrefW;
return w;
}
protected void StartTween(float startFloat, float targetFloat)
{
float duration = (this.m_Accordion != null) ? this.m_Accordion.transitionDuration : 0.3f;
FloatTween info = new FloatTween
{
duration = duration,
startFloat = startFloat,
targetFloat = targetFloat
};
if (m_Accordion.ExpandVerticval)
{
info.AddOnChangedCallback(SetHeight);
}
else
{
info.AddOnChangedCallback(SetWidth);
}
info.ignoreTimeScale = true;
this.m_FloatTweenRunner.StartTween(info);
}
protected void SetHeight(float height)
{
if (this.m_LayoutElement == null)
return;
this.m_LayoutElement.preferredHeight = height;
}
protected void SetWidth(float width)
{
if (this.m_LayoutElement == null)
return;
this.m_LayoutElement.preferredWidth = width;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3c9d341c4bc7de548937508e6f837144
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: b9115417252d4cd42a5e167bdc1c2d3b
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,120 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using UnityEngine.Events;
namespace UnityEngine.UI.Extensions.Tweens
{
public struct FloatTween : ITweenValue
{
public class FloatTweenCallback : UnityEvent<float> {}
public class FloatFinishCallback : UnityEvent {}
private float m_StartFloat;
private float m_TargetFloat;
private float m_Duration;
private bool m_IgnoreTimeScale;
private FloatTweenCallback m_Target;
private FloatFinishCallback m_Finish;
/// <summary>
/// Gets or sets the starting float.
/// </summary>
/// <value>The start float.</value>
public float startFloat
{
get { return m_StartFloat; }
set { m_StartFloat = value; }
}
/// <summary>
/// Gets or sets the target float.
/// </summary>
/// <value>The target float.</value>
public float targetFloat
{
get { return m_TargetFloat; }
set { m_TargetFloat = value; }
}
/// <summary>
/// Gets or sets the duration of the tween.
/// </summary>
/// <value>The duration.</value>
public float duration
{
get { return m_Duration; }
set { m_Duration = value; }
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="UnityEngine.UI.Tweens.ColorTween"/> should ignore time scale.
/// </summary>
/// <value><c>true</c> if ignore time scale; otherwise, <c>false</c>.</value>
public bool ignoreTimeScale
{
get { return m_IgnoreTimeScale; }
set { m_IgnoreTimeScale = value; }
}
/// <summary>
/// Tweens the float based on percentage.
/// </summary>
/// <param name="floatPercentage">Float percentage.</param>
public void TweenValue(float floatPercentage)
{
if (!ValidTarget())
return;
m_Target.Invoke( Mathf.Lerp (m_StartFloat, m_TargetFloat, floatPercentage) );
}
/// <summary>
/// Adds a on changed callback.
/// </summary>
/// <param name="callback">Callback.</param>
public void AddOnChangedCallback(UnityAction<float> callback)
{
if (m_Target == null)
m_Target = new FloatTweenCallback();
m_Target.AddListener(callback);
}
/// <summary>
/// Adds a on finish callback.
/// </summary>
/// <param name="callback">Callback.</param>
public void AddOnFinishCallback(UnityAction callback)
{
if (m_Finish == null)
m_Finish = new FloatFinishCallback();
m_Finish.AddListener(callback);
}
public bool GetIgnoreTimescale()
{
return m_IgnoreTimeScale;
}
public float GetDuration()
{
return m_Duration;
}
public bool ValidTarget()
{
return m_Target != null;
}
/// <summary>
/// Invokes the on finish callback.
/// </summary>
public void Finished()
{
if (m_Finish != null)
m_Finish.Invoke();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e28e1e9e18f7daa4db5d1ac279d6ce66
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,15 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
namespace UnityEngine.UI.Extensions.Tweens
{
internal interface ITweenValue
{
void TweenValue(float floatPercentage);
bool ignoreTimeScale { get; }
float duration { get; }
bool ValidTarget();
void Finished();
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9edf9da4c14ad2843879a2331b00f738
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,63 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System.Collections;
namespace UnityEngine.UI.Extensions.Tweens
{
// Tween runner, executes the given tween.
// The coroutine will live within the given
// behaviour container.
internal class TweenRunner<T> where T : struct, ITweenValue
{
protected MonoBehaviour m_CoroutineContainer;
protected IEnumerator m_Tween;
// utility function for starting the tween
private static IEnumerator Start(T tweenInfo)
{
if (!tweenInfo.ValidTarget())
yield break;
float elapsedTime = 0.0f;
while (elapsedTime < tweenInfo.duration)
{
elapsedTime += tweenInfo.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
var percentage = Mathf.Clamp01 (elapsedTime / tweenInfo.duration);
tweenInfo.TweenValue (percentage);
yield return null;
}
tweenInfo.TweenValue (1.0f);
tweenInfo.Finished();
}
public void Init(MonoBehaviour coroutineContainer)
{
m_CoroutineContainer = coroutineContainer;
}
public void StartTween(T info)
{
if (m_CoroutineContainer == null)
{
Debug.LogWarning ("Coroutine container not configured... did you forget to call Init?");
return;
}
if (m_Tween != null)
{
m_CoroutineContainer.StopCoroutine (m_Tween);
m_Tween = null;
}
if (!m_CoroutineContainer.gameObject.activeInHierarchy)
{
info.TweenValue(1.0f);
return;
}
m_Tween = Start (info);
m_CoroutineContainer.StartCoroutine (m_Tween);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d00ab96853b24074cb837ee70f07dddc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7ab63fe1b000c254ebed3937038bb01b
folderAsset: yes
timeCreated: 1480011199
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(Image))]
public class ColorImage : MonoBehaviour
{
public ColorPickerControl picker;
private Image image;
private void Awake()
{
image = GetComponent<Image>();
picker.onValueChanged.AddListener(ColorChanged);
}
private void OnDestroy()
{
picker.onValueChanged.RemoveListener(ColorChanged);
}
private void ColorChanged(Color newColor)
{
image.color = newColor;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4210a64d2ce72e9488cf2ad174e9df5b
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
#if UNITY_2022_1_OR_NEWER
[RequireComponent(typeof(TMPro.TMP_Text))]
#else
[RequireComponent(typeof(Text))]
#endif
public class ColorLabel : MonoBehaviour
{
public ColorPickerControl picker;
public ColorValues type;
public string prefix = "R: ";
public float minValue = 0;
public float maxValue = 255;
public int precision = 0;
#if UNITY_2022_1_OR_NEWER
private TMPro.TMP_Text label;
#else
private Text label;
#endif
private void Awake()
{
#if UNITY_2022_1_OR_NEWER
label = GetComponent<TMPro.TMP_Text>();
#else
label = GetComponent<Text>();
#endif
if (!label)
{
Debug.LogError($"{gameObject.name} does not have a Text component assigned for the {nameof(ColorLabel)}");
}
}
private void OnEnable()
{
if (Application.isPlaying && picker != null)
{
picker.onValueChanged.AddListener(ColorChanged);
picker.onHSVChanged.AddListener(HSVChanged);
}
}
private void OnDestroy()
{
if (picker != null)
{
picker.onValueChanged.RemoveListener(ColorChanged);
picker.onHSVChanged.RemoveListener(HSVChanged);
}
}
private void ColorChanged(Color color)
{
UpdateValue();
}
private void HSVChanged(float hue, float sateration, float value)
{
UpdateValue();
}
private void UpdateValue()
{
if (picker == null)
{
label.text = prefix + "-";
}
else
{
float value = minValue + (picker.GetValue(type) * (maxValue - minValue));
label.text = prefix + ConvertToDisplayString(value);
}
}
private string ConvertToDisplayString(float value)
{
if (precision > 0)
return value.ToString("f " + precision);
else
return Mathf.FloorToInt(value).ToString();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b32edf53f1ae84f479c9439b4b5f5b91
timeCreated: 1480011174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,303 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions.ColorPicker
{
[ExecuteInEditMode]
public class ColorPickerControl : MonoBehaviour
{
private float _hue = 0;
private float _saturation = 0;
private float _brightness = 0;
private float _red = 0;
private float _green = 0;
private float _blue = 0;
private float _alpha = 1;
public ColorChangedEvent onValueChanged = new ColorChangedEvent();
public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
[SerializeField]
bool hsvSlidersOn = true;
[SerializeField]
List<GameObject> hsvSliders = new List<GameObject>();
[SerializeField]
bool rgbSlidersOn = true;
[SerializeField]
List<GameObject> rgbSliders = new List<GameObject>();
[SerializeField]
GameObject alphaSlider = null;
public void SetHSVSlidersOn(bool value)
{
hsvSlidersOn = value;
foreach (var item in hsvSliders)
item.SetActive(value);
if (alphaSlider)
alphaSlider.SetActive(hsvSlidersOn || rgbSlidersOn);
}
public void SetRGBSlidersOn(bool value)
{
rgbSlidersOn = value;
foreach (var item in rgbSliders)
item.SetActive(value);
if (alphaSlider)
alphaSlider.SetActive(hsvSlidersOn || rgbSlidersOn);
}
void Update()
{
#if UNITY_EDITOR
SetHSVSlidersOn(hsvSlidersOn);
SetRGBSlidersOn(rgbSlidersOn);
#endif
}
public Color CurrentColor
{
get
{
return new Color(_red, _green, _blue, _alpha);
}
set
{
if (CurrentColor == value)
return;
_red = value.r;
_green = value.g;
_blue = value.b;
_alpha = value.a;
RGBChanged();
SendChangedEvent();
}
}
private void Start()
{
SendChangedEvent();
}
public float H
{
get
{
return _hue;
}
set
{
if (_hue == value)
return;
_hue = value;
HSVChanged();
SendChangedEvent();
}
}
public float S
{
get
{
return _saturation;
}
set
{
if (_saturation == value)
return;
_saturation = value;
HSVChanged();
SendChangedEvent();
}
}
public float V
{
get
{
return _brightness;
}
set
{
if (_brightness == value)
return;
_brightness = value;
HSVChanged();
SendChangedEvent();
}
}
public float R
{
get
{
return _red;
}
set
{
if (_red == value)
return;
_red = value;
RGBChanged();
SendChangedEvent();
}
}
public float G
{
get
{
return _green;
}
set
{
if (_green == value)
return;
_green = value;
RGBChanged();
SendChangedEvent();
}
}
public float B
{
get
{
return _blue;
}
set
{
if (_blue == value)
return;
_blue = value;
RGBChanged();
SendChangedEvent();
}
}
private float A
{
get
{
return _alpha;
}
set
{
if (_alpha == value)
return;
_alpha = value;
SendChangedEvent();
}
}
private void RGBChanged()
{
HsvColor color = HSVUtil.ConvertRgbToHsv(CurrentColor);
_hue = color.NormalizedH;
_saturation = color.NormalizedS;
_brightness = color.NormalizedV;
}
private void HSVChanged()
{
Color color = HSVUtil.ConvertHsvToRgb(_hue * 360, _saturation, _brightness, _alpha);
_red = color.r;
_green = color.g;
_blue = color.b;
}
private void SendChangedEvent()
{
onValueChanged.Invoke(CurrentColor);
onHSVChanged.Invoke(_hue, _saturation, _brightness);
}
public void AssignColor(ColorValues type, float value)
{
switch (type)
{
case ColorValues.R:
R = value;
break;
case ColorValues.G:
G = value;
break;
case ColorValues.B:
B = value;
break;
case ColorValues.A:
A = value;
break;
case ColorValues.Hue:
H = value;
break;
case ColorValues.Saturation:
S = value;
break;
case ColorValues.Value:
V = value;
break;
default:
break;
}
}
public float GetValue(ColorValues type)
{
switch (type)
{
case ColorValues.R:
return R;
case ColorValues.G:
return G;
case ColorValues.B:
return B;
case ColorValues.A:
return A;
case ColorValues.Hue:
return H;
case ColorValues.Saturation:
return S;
case ColorValues.Value:
return V;
default:
throw new System.NotImplementedException("");
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7e448480810b55843aefa91c1ab74cd2
timeCreated: 1483197306
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,194 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions.ColorPicker
{
public class ColorPickerPresets : MonoBehaviour
{
public ColorPickerControl picker;
[SerializeField]
protected GameObject presetPrefab;
[SerializeField]
protected int maxPresets = 16;
[SerializeField]
protected Color[] predefinedPresets;
protected List<Color> presets = new List<Color>();
public Image createPresetImage;
public Transform createButton;
public enum SaveType { None, PlayerPrefs, JsonFile }
[SerializeField]
public SaveType saveMode = SaveType.None;
[SerializeField]
protected string playerPrefsKey;
public virtual string JsonFilePath
{
get { return Application.persistentDataPath + "/" + playerPrefsKey + ".json"; }
}
protected virtual void Reset()
{
playerPrefsKey = "colorpicker_" + GetInstanceID().ToString();
}
protected virtual void Awake()
{
picker.onHSVChanged.AddListener(HSVChanged);
picker.onValueChanged.AddListener(ColorChanged);
picker.CurrentColor = Color.white;
presetPrefab.SetActive(false);
presets.AddRange(predefinedPresets);
LoadPresets(saveMode);
}
public virtual void CreatePresetButton()
{
CreatePreset(picker.CurrentColor);
}
public virtual void LoadPresets(SaveType saveType)
{
string jsonData = "";
switch (saveType)
{
case SaveType.None:
break;
case SaveType.PlayerPrefs:
if (PlayerPrefs.HasKey(playerPrefsKey))
{
jsonData = PlayerPrefs.GetString(playerPrefsKey);
}
break;
case SaveType.JsonFile:
if (System.IO.File.Exists(JsonFilePath))
{
jsonData = System.IO.File.ReadAllText(JsonFilePath);
}
break;
default:
throw new System.NotImplementedException(saveType.ToString());
}
if (!string.IsNullOrEmpty(jsonData))
{
try
{
var jsonColors = JsonUtility.FromJson<JsonColor>(jsonData);
presets.AddRange(jsonColors.GetColors());
}
catch (System.Exception e)
{
Debug.LogException(e);
}
}
foreach (var item in presets)
{
CreatePreset(item, true);
}
}
public virtual void SavePresets(SaveType saveType)
{
if (presets == null || presets.Count <= 0)
{
Debug.LogError(
"presets cannot be null or empty: " + (presets == null ? "NULL" : "EMPTY"));
return;
}
var jsonColor = new JsonColor();
jsonColor.SetColors(presets.ToArray());
string jsonData = JsonUtility.ToJson(jsonColor);
switch (saveType)
{
case SaveType.None:
Debug.LogWarning("Called SavePresets with SaveType = None...");
break;
case SaveType.PlayerPrefs:
PlayerPrefs.SetString(playerPrefsKey, jsonData);
break;
case SaveType.JsonFile:
System.IO.File.WriteAllText(JsonFilePath, jsonData);
//Application.OpenURL(JsonFilePath);
break;
default:
throw new System.NotImplementedException(saveType.ToString());
}
}
protected class JsonColor
{
public Color32[] colors;
public void SetColors(Color[] colorsIn)
{
this.colors = new Color32[colorsIn.Length];
for (int i = 0; i < colorsIn.Length; i++)
{
this.colors[i] = colorsIn[i];
}
}
public Color[] GetColors()
{
Color[] colorsOut = new Color[colors.Length];
for (int i = 0; i < colors.Length; i++)
{
colorsOut[i] = colors[i];
}
return colorsOut;
}
}
public virtual void CreatePreset(Color color, bool loading)
{
createButton.gameObject.SetActive(presets.Count < maxPresets);
var newPresetButton = Instantiate(presetPrefab, presetPrefab.transform.parent);
newPresetButton.transform.SetAsLastSibling();
newPresetButton.SetActive(true);
newPresetButton.GetComponent<Image>().color = color;
createPresetImage.color = Color.white;
if (!loading)
{
presets.Add(color);
SavePresets(saveMode);
}
}
public virtual void CreatePreset(Color color)
{
CreatePreset(color, false);
}
public virtual void PresetSelect(Image sender)
{
picker.CurrentColor = sender.color;
}
protected virtual void HSVChanged(float h, float s, float v)
{
createPresetImage.color = HSVUtil.ConvertHsvToRgb(h * 360, s, v, 1);
//Debug.Log("hsv util color: " + createPresetImage.color);
}
protected virtual void ColorChanged(Color color)
{
createPresetImage.color = color;
//Debug.Log("color changed: " + color);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 502205da447ca7a479ce5ae45e5c19d2
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
public class ColorPickerTester : MonoBehaviour
{
public Renderer pickerRenderer;
public ColorPickerControl picker;
void Awake()
{
pickerRenderer = GetComponent<Renderer>();
}
// Use this for initialization
void Start()
{
picker.onValueChanged.AddListener(color =>
{
pickerRenderer.material.color = color;
});
}
}
}

View File

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

View File

@@ -0,0 +1,95 @@
/// Credit judah4
/// Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
/// Updated by SimonDarksideJ - Updated to use touch position rather than mouse for multi-touch
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions.ColorPicker
{
/// <summary>
/// Samples colors from a screen capture.
/// Warning! In the editor if you're not in Free aspect mode then
/// the captured area includes the grey areas to the left and right of the game view window.
/// In a build this will not be an issue.
///
/// This does not work well with a world space UI as positioning is working with screen space.
/// </summary>
public class ColorSampler : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
{
private Vector2 m_screenPos;
[SerializeField]
protected Button sampler;
private RectTransform sampleRectTransform;
[SerializeField]
protected Outline samplerOutline;
protected Texture2D screenCapture;
public ColorChangedEvent oncolorSelected = new ColorChangedEvent();
protected Color color;
protected virtual void OnEnable()
{
screenCapture = ScreenCapture.CaptureScreenshotAsTexture();
sampleRectTransform = sampler.GetComponent<RectTransform>();
sampler.gameObject.SetActive(true);
sampler.onClick.AddListener(SelectColor);
}
protected virtual void OnDisable()
{
Destroy(screenCapture);
sampler.gameObject.SetActive(false);
sampler.onClick.RemoveListener(SelectColor);
}
protected virtual void Update()
{
if (screenCapture == null)
return;
sampleRectTransform.position = m_screenPos;
color = screenCapture.GetPixel((int)m_screenPos.x, (int)m_screenPos.y);
HandleSamplerColoring();
}
protected virtual void HandleSamplerColoring()
{
sampler.image.color = color;
if (samplerOutline)
{
var c = Color.Lerp(Color.white, Color.black, color.grayscale > 0.5f ? 1 : 0);
c.a = samplerOutline.effectColor.a;
samplerOutline.effectColor = c;
}
}
protected virtual void SelectColor()
{
if (oncolorSelected != null)
oncolorSelected.Invoke(color);
enabled = false;
}
public void OnPointerDown(PointerEventData eventData)
{
m_screenPos = eventData.position;
}
public void OnPointerUp(PointerEventData eventData)
{
m_screenPos = Vector2.zero;
}
public void OnDrag(PointerEventData eventData)
{
m_screenPos = eventData.position;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 01c80b26fb6519c4ea3f410dc08f5814
timeCreated: 1519007668
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
/// <summary>
/// Displays one of the color values of aColorPicker
/// </summary>
[RequireComponent(typeof(Slider))]
public class ColorSlider : MonoBehaviour
{
public ColorPickerControl ColorPicker;
/// <summary>
/// Which value this slider can edit.
/// </summary>
public ColorValues type;
private Slider slider;
private bool listen = true;
private void Awake()
{
slider = GetComponent<Slider>();
ColorPicker.onValueChanged.AddListener(ColorChanged);
ColorPicker.onHSVChanged.AddListener(HSVChanged);
slider.onValueChanged.AddListener(SliderChanged);
}
private void OnDestroy()
{
ColorPicker.onValueChanged.RemoveListener(ColorChanged);
ColorPicker.onHSVChanged.RemoveListener(HSVChanged);
slider.onValueChanged.RemoveListener(SliderChanged);
}
private void ColorChanged(Color newColor)
{
listen = false;
switch (type)
{
case ColorValues.R:
slider.normalizedValue = newColor.r;
break;
case ColorValues.G:
slider.normalizedValue = newColor.g;
break;
case ColorValues.B:
slider.normalizedValue = newColor.b;
break;
case ColorValues.A:
slider.normalizedValue = newColor.a;
break;
default:
break;
}
}
private void HSVChanged(float hue, float saturation, float value)
{
listen = false;
switch (type)
{
case ColorValues.Hue:
slider.normalizedValue = hue; //1 - hue;
break;
case ColorValues.Saturation:
slider.normalizedValue = saturation;
break;
case ColorValues.Value:
slider.normalizedValue = value;
break;
default:
break;
}
}
private void SliderChanged(float newValue)
{
if (listen)
{
newValue = slider.normalizedValue;
//if (type == ColorValues.Hue)
// newValue = 1 - newValue;
ColorPicker.AssignColor(type, newValue);
}
listen = true;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 91558da930270ac4a960ba03b81c836a
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,233 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(RawImage)), ExecuteInEditMode()]
public class ColorSliderImage : MonoBehaviour
{
public ColorPickerControl picker;
/// <summary>
/// Which value this slider can edit.
/// </summary>
public ColorValues type;
public Slider.Direction direction;
private RawImage image;
private RectTransform RectTransform
{
get
{
return transform as RectTransform;
}
}
private void Awake()
{
image = GetComponent<RawImage>();
if (image)
{
RegenerateTexture();
}
else
{
Debug.LogWarning("Missing RawImage on object [" + name + "]");
}
}
private void OnEnable()
{
if (picker != null && Application.isPlaying)
{
picker.onValueChanged.AddListener(ColorChanged);
picker.onHSVChanged.AddListener(ColorChanged);
}
}
private void OnDisable()
{
if (picker != null)
{
picker.onValueChanged.RemoveListener(ColorChanged);
picker.onHSVChanged.RemoveListener(ColorChanged);
}
}
private void OnDestroy()
{
if (image.texture != null)
{
DestroyImmediate(image.texture);
}
}
#if UNITY_EDITOR
private void OnValidate()
{
image = GetComponent<RawImage>();
if (image)
{
RegenerateTexture();
}
else
{
Debug.LogWarning("Missing RawImage on object [" + name + "]");
}
}
#endif
private void ColorChanged(Color newColor)
{
switch (type)
{
case ColorValues.R:
case ColorValues.G:
case ColorValues.B:
case ColorValues.Saturation:
case ColorValues.Value:
RegenerateTexture();
break;
case ColorValues.A:
case ColorValues.Hue:
default:
break;
}
}
private void ColorChanged(float hue, float saturation, float value)
{
switch (type)
{
case ColorValues.R:
case ColorValues.G:
case ColorValues.B:
case ColorValues.Saturation:
case ColorValues.Value:
RegenerateTexture();
break;
case ColorValues.A:
case ColorValues.Hue:
default:
break;
}
}
private void RegenerateTexture()
{
if (!picker)
{
Debug.LogWarning("Missing Picker on object [" + name + "]");
}
Color32 baseColor = picker != null ? picker.CurrentColor : Color.black;
float h = picker != null ? picker.H : 0;
float s = picker != null ? picker.S : 0;
float v = picker != null ? picker.V : 0;
Texture2D texture;
Color32[] colors;
bool vertical = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom;
bool inverted = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft;
int size;
switch (type)
{
case ColorValues.R:
case ColorValues.G:
case ColorValues.B:
case ColorValues.A:
size = 255;
break;
case ColorValues.Hue:
size = 360;
break;
case ColorValues.Saturation:
case ColorValues.Value:
size = 100;
break;
default:
throw new System.NotImplementedException("");
}
if (vertical)
texture = new Texture2D(1, size);
else
texture = new Texture2D(size, 1);
texture.hideFlags = HideFlags.DontSave;
colors = new Color32[size];
switch (type)
{
case ColorValues.R:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255);
}
break;
case ColorValues.G:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255);
}
break;
case ColorValues.B:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255);
}
break;
case ColorValues.A:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255);
}
break;
case ColorValues.Hue:
for (int i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(i, 1, 1, 1);
}
break;
case ColorValues.Saturation:
for (int i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, (float)i / size, v, 1);
}
break;
case ColorValues.Value:
for (int i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, s, (float)i / size, 1);
}
break;
default:
throw new System.NotImplementedException("");
}
texture.SetPixels32(colors);
texture.Apply();
if (image.texture != null)
DestroyImmediate(image.texture);
image.texture = texture;
switch (direction)
{
case Slider.Direction.BottomToTop:
case Slider.Direction.TopToBottom:
image.uvRect = new Rect(0, 0, 2, 1);
break;
case Slider.Direction.LeftToRight:
case Slider.Direction.RightToLeft:
image.uvRect = new Rect(0, 0, 1, 2);
break;
default:
break;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cd3cce5a27f2db94fa394c4719bddecd
timeCreated: 1480011174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
public enum ColorValues
{
R,
G,
B,
A,
Hue,
Saturation,
Value
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0f473590aed5e3f4ab5a0157b2a53dbd
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: cbbc689694061e6439664eda55449513
folderAsset: yes
timeCreated: 1480011173
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System;
using UnityEngine.Events;
namespace UnityEngine.UI.Extensions.ColorPicker
{
[Serializable]
public class ColorChangedEvent : UnityEvent<Color>
{
}
}

View File

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

View File

@@ -0,0 +1,9 @@
using UnityEngine.Events;
namespace UnityEngine.UI.Extensions.ColorPicker
{
public class HSVChangedEvent : UnityEvent<float, float, float>
{
}
}

View File

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

View File

@@ -0,0 +1,206 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System;
namespace UnityEngine.UI.Extensions.ColorPicker
{
#region ColorUtilities
public static class HSVUtil
{
public static HsvColor ConvertRgbToHsv(Color color)
{
return ConvertRgbToHsv((int)(color.r * 255), (int)(color.g * 255), (int)(color.b * 255));
}
//Converts an RGB color to an HSV color.
public static HsvColor ConvertRgbToHsv(double r, double b, double g)
{
double delta, min;
double h = 0, s, v;
min = Math.Min(Math.Min(r, g), b);
v = Math.Max(Math.Max(r, g), b);
delta = v - min;
if (v == 0.0)
s = 0;
else
s = delta / v;
if (s == 0)
h = 360;
else
{
if (r == v)
h = (g - b) / delta;
else if (g == v)
h = 2 + (b - r) / delta;
else if (b == v)
h = 4 + (r - g) / delta;
h *= 60;
if (h <= 0.0)
h += 360;
}
HsvColor hsvColor = new HsvColor()
{
H = 360 - h,
S = s,
V = v / 255
};
return hsvColor;
}
// Converts an HSV color to an RGB color.
public static Color ConvertHsvToRgb(double h, double s, double v, float alpha)
{
double r = 0, g = 0, b = 0;
if (s == 0)
{
r = v;
g = v;
b = v;
}
else
{
int i;
double f, p, q, t;
if (h == 360)
h = 0;
else
h = h / 60;
i = (int)(h);
f = h - i;
p = v * (1.0 - s);
q = v * (1.0 - (s * f));
t = v * (1.0 - (s * (1.0f - f)));
switch (i)
{
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
default:
r = v;
g = p;
b = q;
break;
}
}
return new Color((float)r, (float)g, (float)b, alpha);
}
}
#endregion ColorUtilities
// Describes a color in terms of
// Hue, Saturation, and Value (brightness)
#region HsvColor
public struct HsvColor
{
/// <summary>
/// The Hue, ranges between 0 and 360
/// </summary>
public double H;
/// <summary>
/// The saturation, ranges between 0 and 1
/// </summary>
public double S;
// The value (brightness), ranges between 0 and 1
public double V;
public float NormalizedH
{
get
{
return (float)H / 360f;
}
set
{
H = (double)value * 360;
}
}
public float NormalizedS
{
get
{
return (float)S;
}
set
{
S = value;
}
}
public float NormalizedV
{
get
{
return (float)V;
}
set
{
V = (double)value;
}
}
public HsvColor(double h, double s, double v)
{
this.H = h;
this.S = s;
this.V = v;
}
public override string ToString()
{
return "{" + H.ToString("f2") + "," + S.ToString("f2") + "," + V.ToString("f2") + "}";
}
}
#endregion HsvColor
}

View File

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

View File

@@ -0,0 +1,101 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Globalization;
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(InputField))]
public class HexColorField : MonoBehaviour
{
public ColorPickerControl ColorPicker;
public bool displayAlpha;
private InputField hexInputField;
private const string hexRegex = "^#?(?:[0-9a-fA-F]{3,4}){1,2}$";
private void Awake()
{
hexInputField = GetComponent<InputField>();
// Add listeners to keep text (and color) up to date
hexInputField.onEndEdit.AddListener(UpdateColor);
ColorPicker.onValueChanged.AddListener(UpdateHex);
}
private void OnDestroy()
{
hexInputField.onValueChanged.RemoveListener(UpdateColor);
ColorPicker.onValueChanged.RemoveListener(UpdateHex);
}
private void UpdateHex(Color newColor)
{
hexInputField.text = ColorToHex(newColor);
}
private void UpdateColor(string newHex)
{
Color32 color;
if (HexToColor(newHex, out color))
ColorPicker.CurrentColor = color;
else
Debug.Log("hex value is in the wrong format, valid formats are: #RGB, #RGBA, #RRGGBB and #RRGGBBAA (# is optional)");
}
private string ColorToHex(Color32 color)
{
if (displayAlpha)
return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.r, color.g, color.b, color.a);
else
return string.Format("#{0:X2}{1:X2}{2:X2}", color.r, color.g, color.b);
}
public static bool HexToColor(string hex, out Color32 color)
{
// Check if this is a valid hex string (# is optional)
if (System.Text.RegularExpressions.Regex.IsMatch(hex, hexRegex))
{
int startIndex = hex.StartsWith("#") ? 1 : 0;
if (hex.Length == startIndex + 8) //#RRGGBBAA
{
color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 6, 2), NumberStyles.AllowHexSpecifier));
}
else if (hex.Length == startIndex + 6) //#RRGGBB
{
color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier),
255);
}
else if (hex.Length == startIndex + 4) //#RGBA
{
color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 3] + hex[startIndex + 3], NumberStyles.AllowHexSpecifier));
}
else //#RGB
{
color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier),
255);
}
return true;
}
else
{
color = new Color32();
return false;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7343402602909bd4f928d58433c5c87f
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,124 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(BoxSlider), typeof(RawImage)), ExecuteInEditMode()]
public class SVBoxSlider : MonoBehaviour
{
public ColorPickerControl picker;
private BoxSlider slider;
private RawImage image;
private float lastH = -1;
private bool listen = true;
public RectTransform RectTransform
{
get
{
return transform as RectTransform;
}
}
private void Awake()
{
slider = GetComponent<BoxSlider>();
image = GetComponent<RawImage>();
RegenerateSVTexture();
}
private void OnEnable()
{
if (Application.isPlaying && picker != null)
{
slider.OnValueChanged.AddListener(SliderChanged);
picker.onHSVChanged.AddListener(HSVChanged);
}
}
private void OnDisable()
{
if (picker != null)
{
slider.OnValueChanged.RemoveListener(SliderChanged);
picker.onHSVChanged.RemoveListener(HSVChanged);
}
}
private void OnDestroy()
{
if (image.texture != null)
{
DestroyImmediate(image.texture);
}
}
#if UNITY_EDITOR
private void OnValidate()
{
image = GetComponent<RawImage>();
RegenerateSVTexture();
}
#endif
private void SliderChanged(float saturation, float value)
{
if (listen)
{
picker.AssignColor(ColorValues.Saturation, saturation);
picker.AssignColor(ColorValues.Value, value);
}
listen = true;
}
private void HSVChanged(float h, float s, float v)
{
if (lastH != h)
{
lastH = h;
RegenerateSVTexture();
}
if (s != slider.NormalizedValueX)
{
listen = false;
slider.NormalizedValueX = s;
}
if (v != slider.NormalizedValueY)
{
listen = false;
slider.NormalizedValueY = v;
}
}
private void RegenerateSVTexture()
{
double h = picker != null ? picker.H * 360 : 0;
if (image.texture != null)
DestroyImmediate(image.texture);
Texture2D texture = new Texture2D(100, 100)
{
hideFlags = HideFlags.DontSave
};
for (int s = 0; s < 100; s++)
{
Color32[] colors = new Color32[100];
for (int v = 0; v < 100; v++)
{
colors[v] = HSVUtil.ConvertHsvToRgb(h, (float)s / 100, (float)v / 100, 1);
}
texture.SetPixels32(s, 0, 1, 100, colors);
}
texture.Apply();
image.texture = texture;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7a0647785ed421e449239dbd6512e156
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
public class TiltWindow : MonoBehaviour, IDragHandler
{
public Vector2 range = new Vector2(5f, 3f);
private Transform mTrans;
private Quaternion mStart;
private Vector2 mRot = Vector2.zero;
private Vector2 m_screenPos;
void Start()
{
mTrans = transform;
mStart = mTrans.localRotation;
}
void Update()
{
Vector3 pos = m_screenPos;
float halfWidth = Screen.width * 0.5f;
float halfHeight = Screen.height * 0.5f;
float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f);
float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f);
mRot = Vector2.Lerp(mRot, new Vector2(x, y), Time.deltaTime * 5f);
mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y * range.y, mRot.x * range.x, 0f);
}
public void OnDrag(PointerEventData eventData)
{
m_screenPos = eventData.position;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c7be5109ea5b91e4b856621023b15168
timeCreated: 1480011174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 726a11b8d64fa0143b34f417f5453f80
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,560 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.UI.Extensions
{
public enum AutoCompleteSearchType
{
ArraySort,
Linq
}
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/ComboBox/AutoComplete ComboBox")]
public class AutoCompleteComboBox : MonoBehaviour
{
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
/// <summary>
/// Contains the included items. To add and remove items to/from this list, use the <see cref="AddItem(string)"/>,
/// <see cref="RemoveItem(string)"/> and <see cref="SetAvailableOptions(List{string})"/> methods as these also execute
/// the required methods to update to the current collection.
/// </summary>
[Header("AutoComplete Box Items")]
public List<string> AvailableOptions;
private bool _isPanelActive = false;
private bool _hasDrawnOnce = false;
private InputField _mainInput;
private RectTransform _inputRT;
private RectTransform _rectTransform;
private RectTransform _overlayRT;
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
private ScrollRect _scrollRect;
private List<string> _panelItems; //items that will get shown in the drop-down
private List<string> _prunedPanelItems; //items that used to show in the drop-down
private Dictionary<string, GameObject> panelObjects;
private GameObject itemTemplate;
private bool _initialized;
public string Text { get; private set; }
[Header("Properties")]
[SerializeField]
private bool isActive = true;
[SerializeField]
private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth
{
get { return _scrollBarWidth; }
set
{
_scrollBarWidth = value;
RedrawPanel();
}
}
[SerializeField]
private int _itemsToDisplay;
public int ItemsToDisplay
{
get { return _itemsToDisplay; }
set
{
_itemsToDisplay = value;
RedrawPanel();
}
}
[SerializeField]
[Tooltip("Change input text color based on matching items")]
private bool _ChangeInputTextColorBasedOnMatchingItems = false;
public bool InputColorMatching
{
get { return _ChangeInputTextColorBasedOnMatchingItems; }
set
{
_ChangeInputTextColorBasedOnMatchingItems = value;
if (_ChangeInputTextColorBasedOnMatchingItems)
{
SetInputTextColor();
}
}
}
public float DropdownOffset = 10f;
public Color ValidSelectionTextColor = Color.green;
public Color MatchingItemsRemainingTextColor = Color.black;
public Color NoItemsRemainingTextColor = Color.red;
public AutoCompleteSearchType autocompleteSearchType = AutoCompleteSearchType.Linq;
[SerializeField]
private float dropdownOffset;
[SerializeField]
private bool _displayPanelAbove = false;
public bool SelectFirstItemOnStart = false;
[SerializeField]
private int selectItemIndexOnStart = 0;
private bool shouldSelectItemOnStart => SelectFirstItemOnStart || selectItemIndexOnStart > 0;
private bool _selectionIsValid = false;
[System.Serializable]
public class SelectionChangedEvent : Events.UnityEvent<string, bool> { }
[System.Serializable]
public class SelectionTextChangedEvent : Events.UnityEvent<string> { }
[System.Serializable]
public class SelectionValidityChangedEvent : Events.UnityEvent<bool> { }
[System.Serializable]
public class ItemSelectedEvent : Events.UnityEvent<string> { }
[System.Serializable]
public class ControlDisabledEvent : Events.UnityEvent<bool> { }
// fires when input text is changed;
[Header("Events")]
public SelectionTextChangedEvent OnSelectionTextChanged;
// fires when an Item gets selected / deselected (including when items are added/removed once this is possible)
public SelectionValidityChangedEvent OnSelectionValidityChanged;
// fires in both cases
public SelectionChangedEvent OnSelectionChanged;
// fires when an item is clicked
public ItemSelectedEvent OnItemSelected;
// fires when item is changed;
public ControlDisabledEvent OnControlDisabled;
public void Awake()
{
Initialize();
}
public void Start()
{
if (shouldSelectItemOnStart && AvailableOptions.Count > 0)
{
SelectItemIndex(SelectFirstItemOnStart ? 0 : selectItemIndexOnStart);
}
RedrawPanel();
}
private bool Initialize()
{
if (_initialized) return true;
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_inputRT = _rectTransform.Find("InputField").GetComponent<RectTransform>();
_mainInput = _inputRT.GetComponent<InputField>();
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
itemTemplate = _rectTransform.Find("ItemTemplate").gameObject;
itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Reference Exception");
success = false;
}
panelObjects = new Dictionary<string, GameObject>();
_prunedPanelItems = new List<string>();
_panelItems = new List<string>();
_initialized = true;
RebuildPanel();
return success;
}
/// <summary>
/// Adds the item to <see cref="this.AvailableOptions"/> if it is not a duplicate and rebuilds the panel.
/// </summary>
/// <param name="item">Item to add.</param>
public void AddItem(string item)
{
if (!this.AvailableOptions.Contains(item))
{
this.AvailableOptions.Add(item);
this.RebuildPanel();
}
else
{
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(AddItem)}: items may only exists once. '{item}' can not be added.");
}
}
/// <summary>
/// Removes the item from <see cref="this.AvailableOptions"/> and rebuilds the panel.
/// </summary>
/// <param name="item">Item to remove.</param>
public void RemoveItem(string item)
{
if (this.AvailableOptions.Contains(item))
{
this.AvailableOptions.Remove(item);
this.RebuildPanel();
}
}
/// <summary>
/// Update the drop down selection to a specific index
/// </summary>
/// <param name="index"></param>
public void SelectItemIndex(int index)
{
ToggleDropdownPanel(false);
OnItemClicked(AvailableOptions[index]);
}
/// <summary>
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
/// </summary>
/// <param name="newOptions">New entries.</param>
public void SetAvailableOptions(List<string> newOptions)
{
var uniqueOptions = newOptions.Distinct().ToArray();
SetAvailableOptions(uniqueOptions);
}
/// <summary>
/// Sets the given items as new content for the comboBox. Previous entries will be cleared.
/// </summary>
/// <param name="newOptions">New entries.</param>
public void SetAvailableOptions(string[] newOptions)
{
var uniqueOptions = newOptions.Distinct().ToList();
if (newOptions.Length != uniqueOptions.Count)
{
Debug.LogWarning($"{nameof(AutoCompleteComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Length - uniqueOptions.Count} duplicates.");
}
this.AvailableOptions.Clear();
for (int i = 0; i < newOptions.Length; i++)
{
this.AvailableOptions.Add(newOptions[i]);
}
this.RebuildPanel();
this.RedrawPanel();
}
public void ResetItems()
{
AvailableOptions.Clear();
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Rebuilds the contents of the panel in response to items being added.
/// </summary>
private void RebuildPanel()
{
if (!_initialized)
{
Start();
}
if (_isPanelActive) ToggleDropdownPanel();
//panel starts with all options
_panelItems.Clear();
_prunedPanelItems.Clear();
panelObjects.Clear();
//clear Autocomplete children in scene
foreach (Transform child in _itemsPanelRT.transform)
{
Destroy(child.gameObject);
}
foreach (string option in AvailableOptions)
{
_panelItems.Add(option.ToLower());
}
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
int indx = 0;
while (itemObjs.Count < AvailableOptions.Count)
{
GameObject newItem = Instantiate(itemTemplate) as GameObject;
newItem.name = "Item " + indx;
newItem.transform.SetParent(_itemsPanelRT, false);
itemObjs.Add(newItem);
indx++;
}
for (int i = 0; i < itemObjs.Count; i++)
{
itemObjs[i].SetActive(i <= AvailableOptions.Count);
if (i < AvailableOptions.Count)
{
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
#if UNITY_2022_1_OR_NEWER
itemObjs[i].transform.Find("Text").GetComponent<TMPro.TMP_Text>().text = AvailableOptions[i]; //set the text value
#else
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
#endif
Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners();
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
itemBtn.onClick.AddListener(() =>
{
OnItemClicked(textOfItem);
});
panelObjects[_panelItems[i]] = itemObjs[i];
}
}
SetInputTextColor();
}
/// <summary>
/// what happens when an item in the list is selected
/// </summary>
/// <param name="item"></param>
private void OnItemClicked(string item)
{
Text = item;
_mainInput.text = Text;
ToggleDropdownPanel(true);
OnItemSelected?.Invoke(Text);
}
private void RedrawPanel()
{
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
dropdownHeight += dropdownOffset;
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
{
_hasDrawnOnce = true;
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
var itemsRemaining = _panelItems.Count - ItemsToDisplay;
itemsRemaining = itemsRemaining < 0 ? 0 : itemsRemaining;
_scrollPanelRT.SetParent(transform, true);
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, dropdownOffset + dropdownHeight) :
new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
_overlayRT.SetParent(transform, true);
_scrollPanelRT.SetParent(_overlayRT, true);
}
if (_panelItems.Count < 1) return;
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
_itemsPanelRT.anchoredPosition = new Vector2(5, 0);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);
}
public void OnValueChanged(string currText)
{
Text = currText;
PruneItems(currText);
RedrawPanel();
if (_panelItems.Count == 0)
{
_isPanelActive = true;//this makes it get turned off
ToggleDropdownPanel(false);
}
else if (!_isPanelActive)
{
ToggleDropdownPanel(false);
}
bool validity_changed = (_panelItems.Contains(Text) != _selectionIsValid);
_selectionIsValid = _panelItems.Contains(Text);
OnSelectionChanged.Invoke(Text, _selectionIsValid);
OnSelectionTextChanged.Invoke(Text);
if (validity_changed)
{
OnSelectionValidityChanged.Invoke(_selectionIsValid);
}
SetInputTextColor();
}
private void SetInputTextColor()
{
if (InputColorMatching)
{
if (_selectionIsValid)
{
_mainInput.textComponent.color = ValidSelectionTextColor;
}
else if (_panelItems.Count > 0)
{
_mainInput.textComponent.color = MatchingItemsRemainingTextColor;
}
else
{
_mainInput.textComponent.color = NoItemsRemainingTextColor;
}
}
}
/// <summary>
/// Toggle the drop down list
/// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param>
public void ToggleDropdownPanel(bool directClick = false)
{
if (!isActive) return;
_isPanelActive = !_isPanelActive;
_overlayRT.gameObject.SetActive(_isPanelActive);
if (_isPanelActive)
{
transform.SetAsLastSibling();
}
else if (directClick)
{
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
}
}
/// <summary>
/// Updates the control and sets its active status, determines whether the dropdown will open ot not
/// </summary>
/// <param name="status"></param>
public void SetActive(bool status)
{
if (status != isActive)
{
OnControlDisabled?.Invoke(status);
}
isActive = status;
}
private void PruneItems(string currText)
{
if (autocompleteSearchType == AutoCompleteSearchType.Linq)
{
PruneItemsLinq(currText);
}
else
{
PruneItemsArray(currText);
}
}
private void PruneItemsLinq(string currText)
{
currText = currText.ToLower();
var toPrune = _panelItems.Where(x => !x.Contains(currText)).ToArray();
foreach (string key in toPrune)
{
panelObjects[key].SetActive(false);
_panelItems.Remove(key);
_prunedPanelItems.Add(key);
}
var toAddBack = _prunedPanelItems.Where(x => x.Contains(currText)).ToArray();
foreach (string key in toAddBack)
{
panelObjects[key].SetActive(true);
_panelItems.Add(key);
_prunedPanelItems.Remove(key);
}
}
//Updated to not use Linq
private void PruneItemsArray(string currText)
{
string _currText = currText.ToLower();
for (int i = _panelItems.Count - 1; i >= 0; i--)
{
string _item = _panelItems[i];
if (!_item.Contains(_currText))
{
panelObjects[_panelItems[i]].SetActive(false);
_panelItems.RemoveAt(i);
_prunedPanelItems.Add(_item);
}
}
for (int i = _prunedPanelItems.Count - 1; i >= 0; i--)
{
string _item = _prunedPanelItems[i];
if (_item.Contains(_currText))
{
panelObjects[_prunedPanelItems[i]].SetActive(true);
_prunedPanelItems.RemoveAt(i);
_panelItems.Add(_item);
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ef22b091ebae52c47aa3e86ad9040c05
timeCreated: 1492278993
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,376 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/ComboBox/ComboBox")]
public class ComboBox : MonoBehaviour
{
public DropDownListItem SelectedItem { get; private set; }
[Header("Combo Box Items")]
public List<string> AvailableOptions;
[Header("Properties")]
[SerializeField]
private bool isActive = true;
[SerializeField]
private float _scrollBarWidth = 20.0f;
[SerializeField]
private int _itemsToDisplay;
[SerializeField]
private float dropdownOffset;
[SerializeField]
private bool _displayPanelAbove = false;
public bool SelectFirstItemOnStart = false;
[SerializeField]
private int selectItemIndexOnStart = 0;
private bool shouldSelectItemOnStart => SelectFirstItemOnStart || selectItemIndexOnStart > 0;
[System.Serializable]
public class SelectionChangedEvent : Events.UnityEvent<string> { }
[Header("Events")]
// fires when item is changed;
public SelectionChangedEvent OnSelectionChanged;
[System.Serializable]
public class ControlDisabledEvent : Events.UnityEvent<bool> { }
// fires when item is changed;
public ControlDisabledEvent OnControlDisabled;
//private bool isInitialized = false;
private bool _isPanelActive = false;
private bool _hasDrawnOnce = false;
private InputField _mainInput;
private RectTransform _inputRT;
private RectTransform _rectTransform;
private RectTransform _overlayRT;
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
private ScrollRect _scrollRect;
private List<string> _panelItems; //items that will get shown in the drop-down
private Dictionary<string, GameObject> panelObjects;
private GameObject itemTemplate;
private bool _initialized;
public string Text { get; private set; }
public float ScrollBarWidth
{
get { return _scrollBarWidth; }
set
{
_scrollBarWidth = value;
RedrawPanel();
}
}
public int ItemsToDisplay
{
get { return _itemsToDisplay; }
set
{
_itemsToDisplay = value;
RedrawPanel();
}
}
public void Awake()
{
Initialize();
}
public void Start()
{
if (shouldSelectItemOnStart && AvailableOptions.Count > 0)
{
SelectItemIndex(SelectFirstItemOnStart ? 0 : selectItemIndexOnStart);
}
RedrawPanel();
}
private bool Initialize()
{
if (_initialized) return true;
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_inputRT = _rectTransform.Find("InputField").GetComponent<RectTransform>();
_mainInput = _inputRT.GetComponent<InputField>();
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
itemTemplate = _rectTransform.Find("ItemTemplate").gameObject;
itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Reference Exception");
success = false;
}
panelObjects = new Dictionary<string, GameObject>();
_panelItems = AvailableOptions.ToList();
_initialized = true;
RebuildPanel();
return success;
}
/// <summary>
/// Update the drop down selection to a specific index
/// </summary>
/// <param name="index"></param>
public void SelectItemIndex(int index)
{
ToggleDropdownPanel(false);
OnItemClicked(AvailableOptions[index]);
}
public void AddItem(string item)
{
AvailableOptions.Add(item);
RebuildPanel();
}
public void RemoveItem(string item)
{
AvailableOptions.Remove(item);
RebuildPanel();
}
public void SetAvailableOptions(List<string> newOptions)
{
var uniqueOptions = newOptions.Distinct().ToArray();
SetAvailableOptions(uniqueOptions);
}
public void SetAvailableOptions(string[] newOptions)
{
var uniqueOptions = newOptions.Distinct().ToList();
if (newOptions.Length != uniqueOptions.Count)
{
Debug.LogWarning($"{nameof(ComboBox)}.{nameof(SetAvailableOptions)}: items may only exists once. {newOptions.Length - uniqueOptions.Count} duplicates.");
}
this.AvailableOptions.Clear();
for (int i = 0; i < newOptions.Length; i++)
{
this.AvailableOptions.Add(newOptions[i]);
}
this.RebuildPanel();
this.RedrawPanel();
}
public void ResetItems()
{
AvailableOptions.Clear();
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Rebuilds the contents of the panel in response to items being added.
/// </summary>
private void RebuildPanel()
{
if (!_initialized)
{
Start();
}
//panel starts with all options
_panelItems.Clear();
foreach (string option in AvailableOptions)
{
_panelItems.Add(option.ToLower());
}
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
panelObjects.Clear();
int indx = 0;
while (itemObjs.Count < AvailableOptions.Count)
{
GameObject newItem = Instantiate(itemTemplate) as GameObject;
newItem.name = "Item " + indx;
newItem.transform.SetParent(_itemsPanelRT, false);
itemObjs.Add(newItem);
indx++;
}
for (int i = 0; i < itemObjs.Count; i++)
{
itemObjs[i].SetActive(i <= AvailableOptions.Count);
if (i < AvailableOptions.Count)
{
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
#if UNITY_2022_1_OR_NEWER
itemObjs[i].transform.Find("Text").GetComponent<TMPro.TMP_Text>().text = AvailableOptions[i]; //set the text value
#else
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = AvailableOptions[i]; //set the text value
#endif
Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners();
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
itemBtn.onClick.AddListener(() =>
{
OnItemClicked(textOfItem);
});
panelObjects[_panelItems[i]] = itemObjs[i];
}
}
}
/// <summary>
/// what happens when an item in the list is selected
/// </summary>
/// <param name="item"></param>
private void OnItemClicked(string item)
{
//Debug.Log("item " + item + " clicked");
Text = item;
_mainInput.text = Text;
ToggleDropdownPanel(true);
}
private void RedrawPanel()
{
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
dropdownHeight += dropdownOffset;
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
{
_hasDrawnOnce = true;
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
var itemsRemaining = _panelItems.Count - ItemsToDisplay;
itemsRemaining = itemsRemaining < 0 ? 0 : itemsRemaining;
_scrollPanelRT.SetParent(transform, true);
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, dropdownOffset + dropdownHeight) :
new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
_overlayRT.SetParent(transform, true);
_scrollPanelRT.SetParent(_overlayRT, true);
}
if (_panelItems.Count < 1) return;
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
_itemsPanelRT.anchoredPosition = new Vector2(5, 0);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);
}
public void OnValueChanged(string currText)
{
Text = currText;
RedrawPanel();
if (_panelItems.Count == 0)
{
_isPanelActive = true;//this makes it get turned off
ToggleDropdownPanel(false);
}
else if (!_isPanelActive)
{
ToggleDropdownPanel(false);
}
OnSelectionChanged.Invoke(Text);
}
/// <summary>
/// Toggle the drop down list
/// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param>
public void ToggleDropdownPanel(bool directClick)
{
if (!isActive) return;
_isPanelActive = !_isPanelActive;
_overlayRT.gameObject.SetActive(_isPanelActive);
if (_isPanelActive)
{
transform.SetAsLastSibling();
}
else if (directClick)
{
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
}
}
/// <summary>
/// Updates the control and sets its active status, determines whether the dropdown will open ot not
/// </summary>
/// <param name="status"></param>
public void SetActive(bool status)
{
if (status != isActive)
{
OnControlDisabled?.Invoke(status);
}
isActive = status;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cd26acd32e1be2747b9e5f3587b2b1d5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,493 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System;
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
/// <summary>
/// Extension to the UI class which creates a dropdown list
/// </summary>
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/ComboBox/Dropdown List")]
public class DropDownList : MonoBehaviour
{
public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
[Header("Dropdown List Items")]
public List<DropDownListItem> Items;
[Header("Properties")]
[SerializeField]
private bool isActive = true;
public bool OverrideHighlighted = true;
//private bool isInitialized = false;
private bool _isPanelActive = false;
private bool _hasDrawnOnce = false;
private DropDownListButton _mainButton;
private RectTransform _rectTransform;
private RectTransform _overlayRT;
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
private RectTransform _scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
private ScrollRect _scrollRect;
private List<DropDownListButton> _panelItems = new List<DropDownListButton>();
private GameObject _itemTemplate;
private bool _initialized;
private string _defaultMainButtonCaption = null;
private Color _defaultNormalColor;
[SerializeField]
private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth
{
get { return _scrollBarWidth; }
set
{
_scrollBarWidth = value;
RedrawPanel();
}
}
private int _selectedIndex = -1;
[SerializeField]
private int _itemsToDisplay;
public int ItemsToDisplay
{
get { return _itemsToDisplay; }
set
{
_itemsToDisplay = value;
RedrawPanel();
}
}
[SerializeField]
private float dropdownOffset;
[SerializeField]
private bool _displayPanelAbove = false;
public bool SelectFirstItemOnStart = false;
[SerializeField]
private int selectItemIndexOnStart = 0;
private bool shouldSelectItemOnStart => SelectFirstItemOnStart || selectItemIndexOnStart > 0;
[System.Serializable]
public class SelectionChangedEvent : Events.UnityEvent<int> { }
// fires when item is changed;
[Header("Events")]
public SelectionChangedEvent OnSelectionChanged;
[System.Serializable]
public class ControlDisabledEvent : Events.UnityEvent<bool> { }
// fires when item changes between enabled and disabled;
public ControlDisabledEvent OnControlDisabled;
public void Start()
{
Initialize();
if (shouldSelectItemOnStart && Items.Count > 0)
{
SelectItemIndex(SelectFirstItemOnStart ? 0 : selectItemIndexOnStart);
}
RedrawPanel();
}
private bool Initialize()
{
if (_initialized) return true;
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_mainButton = new DropDownListButton(_rectTransform.Find("MainButton").gameObject);
_defaultMainButtonCaption = _mainButton.txt.text;
_defaultNormalColor = _mainButton.btn.colors.normalColor;
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
_scrollHandleRT = _slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
_itemTemplate = _rectTransform.Find("ItemTemplate").gameObject;
_itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Reference Exception");
success = false;
}
_initialized = true;
RebuildPanel();
RedrawPanel();
return success;
}
/// <summary>
/// Update the drop down selection to a specific index
/// </summary>
/// <param name="index"></param>
public void SelectItemIndex(int index)
{
ToggleDropdownPanel();
OnItemClicked(index);
}
// currently just using items in the list instead of being able to add to it.
/// <summary>
/// Rebuilds the list from a new collection.
/// </summary>
/// <remarks>
/// NOTE, this will clear all existing items
/// </remarks>
/// <param name="list"></param>
public void RefreshItems(params object[] list)
{
Items.Clear();
List<DropDownListItem> ddItems = new List<DropDownListItem>();
foreach (var obj in list)
{
if (obj is DropDownListItem)
{
ddItems.Add((DropDownListItem)obj);
}
else if (obj is string)
{
ddItems.Add(new DropDownListItem(caption: (string)obj));
}
else if (obj is Sprite)
{
ddItems.Add(new DropDownListItem(image: (Sprite)obj));
}
else
{
throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed");
}
}
Items.AddRange(ddItems);
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Adds an additional item to the drop down list (recommended)
/// </summary>
/// <param name="item">Item of type DropDownListItem</param>
public void AddItem(DropDownListItem item)
{
Items.Add(item);
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Adds an additional drop down list item using a string name
/// </summary>
/// <param name="item">Item of type String</param>
public void AddItem(string item)
{
Items.Add(new DropDownListItem(caption: (string)item));
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Adds an additional drop down list item using a sprite image
/// </summary>
/// <param name="item">Item of type UI Sprite</param>
public void AddItem(Sprite item)
{
Items.Add(new DropDownListItem(image: (Sprite)item));
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Removes an item from the drop down list (recommended)
/// </summary>
/// <param name="item">Item of type DropDownListItem</param>
public void RemoveItem(DropDownListItem item)
{
Items.Remove(item);
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Removes an item from the drop down list item using a string name
/// </summary>
/// <param name="item">Item of type String</param>
public void RemoveItem(string item)
{
Items.Remove(new DropDownListItem(caption: (string)item));
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Removes an item from the drop down list item using a sprite image
/// </summary>
/// <param name="item">Item of type UI Sprite</param>
public void RemoveItem(Sprite item)
{
Items.Remove(new DropDownListItem(image: (Sprite)item));
RebuildPanel();
RedrawPanel();
}
public void ResetDropDown()
{
if (!_initialized)
{
return;
}
_mainButton.txt.text = _defaultMainButtonCaption;
for (int i = 0; i < _itemsPanelRT.childCount; i++)
{
_panelItems[i].btnImg.color = _defaultNormalColor;
}
_selectedIndex = -1;
_initialized = false;
Initialize();
}
public void ResetItems()
{
Items.Clear();
RebuildPanel();
RedrawPanel();
}
/// <summary>
/// Rebuilds the contents of the panel in response to items being added.
/// </summary>
private void RebuildPanel()
{
if (Items.Count == 0) return;
if (!_initialized)
{
Start();
}
int indx = _panelItems.Count;
while (_panelItems.Count < Items.Count)
{
GameObject newItem = Instantiate(_itemTemplate) as GameObject;
newItem.name = "Item " + indx;
newItem.transform.SetParent(_itemsPanelRT, false);
_panelItems.Add(new DropDownListButton(newItem));
indx++;
}
for (int i = 0; i < _panelItems.Count; i++)
{
if (i < Items.Count)
{
DropDownListItem item = Items[i];
_panelItems[i].txt.text = item.Caption;
if (item.IsDisabled) _panelItems[i].txt.color = disabledTextColor;
if (_panelItems[i].btnImg != null) _panelItems[i].btnImg.sprite = null;//hide the button image
_panelItems[i].img.sprite = item.Image;
_panelItems[i].img.color = (item.Image == null) ? new Color(1, 1, 1, 0)
: item.IsDisabled ? new Color(1, 1, 1, .5f)
: Color.white;
int ii = i; //have to copy the variable for use in anonymous function
_panelItems[i].btn.onClick.RemoveAllListeners();
_panelItems[i].btn.onClick.AddListener(() =>
{
OnItemClicked(ii);
if (item.OnSelect != null) item.OnSelect();
});
}
_panelItems[i].gameobject.SetActive(i < Items.Count);// if we have more thanks in the panel than Items in the list hide them
}
}
private void OnItemClicked(int indx)
{
//Debug.Log("item " + indx + " clicked");
if (indx != _selectedIndex && OnSelectionChanged != null) OnSelectionChanged.Invoke(indx);
_selectedIndex = indx;
ToggleDropdownPanel();
UpdateSelected();
}
private void UpdateSelected()
{
SelectedItem = (_selectedIndex > -1 && _selectedIndex < Items.Count) ? Items[_selectedIndex] : null;
if (SelectedItem == null) return;
bool hasImage = SelectedItem.Image != null;
if (hasImage)
{
_mainButton.img.sprite = SelectedItem.Image;
_mainButton.img.color = Color.white;
}
else
{
_mainButton.img.sprite = null;
}
_mainButton.txt.text = SelectedItem.Caption;
//update selected index color
if (OverrideHighlighted)
{
for (int i = 0; i < _itemsPanelRT.childCount; i++)
{
_panelItems[i].btnImg.color = (_selectedIndex == i) ? _mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
}
}
}
private void RedrawPanel()
{
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
dropdownHeight += dropdownOffset;
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta)
{
_hasDrawnOnce = true;
_mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
var itemsRemaining = _panelItems.Count - ItemsToDisplay;
itemsRemaining = itemsRemaining < 0 ? 0 : itemsRemaining;
_scrollPanelRT.SetParent(transform, true);
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
new Vector2(0, dropdownOffset + dropdownHeight) :
new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
_overlayRT.SetParent(transform, true);
_scrollPanelRT.SetParent(_overlayRT, true);
}
if (_panelItems.Count < 1) return;
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
_itemsPanelRT.anchoredPosition = new Vector2(5, 0);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
if (scrollbarWidth == 0) _scrollHandleRT.gameObject.SetActive(false); else _scrollHandleRT.gameObject.SetActive(true);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);
}
/// <summary>
/// Toggle the drop down list if it is active
/// </summary>
/// <param name="directClick">Retained for backwards compatibility only.</param>
[Obsolete("DirectClick Parameter is no longer required")]
public void ToggleDropdownPanel(bool directClick = false)
{
ToggleDropdownPanel();
}
/// <summary>
/// Toggle the drop down list if it is active
/// </summary>
public void ToggleDropdownPanel()
{
if (!isActive)
{
return;
}
_overlayRT.transform.localScale = new Vector3(1, 1, 1);
_scrollBarRT.transform.localScale = new Vector3(1, 1, 1);
_isPanelActive = !_isPanelActive;
_overlayRT.gameObject.SetActive(_isPanelActive);
if (_isPanelActive)
{
transform.SetAsLastSibling();
}
}
/// <summary>
/// Hides the drop down panel if its visible at the moment
/// </summary>
public void HideDropDownPanel()
{
if (!_isPanelActive)
{
return;
}
ToggleDropdownPanel();
}
/// <summary>
/// Updates the control and sets its active status, determines whether the dropdown will open ot not
/// and takes care of the underlying button to follow the status.
/// </summary>
/// <param name="status"></param>
public void SetActive(bool status)
{
if (status == isActive)
{
return;
}
isActive = status;
OnControlDisabled?.Invoke(isActive);
_mainButton.btn.enabled = isActive;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7a00cad80d8a47b438b394bebe77d0d2
timeCreated: 1492278993
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform), typeof(Button))]
public class DropDownListButton
{
public RectTransform rectTransform;
public Button btn;
#if UNITY_2022_1_OR_NEWER
public TMPro.TMP_Text txt;
#else
public Text txt;
#endif
public Image btnImg;
public Image img;
public GameObject gameobject;
public DropDownListButton(GameObject btnObj)
{
gameobject = btnObj;
rectTransform = btnObj.GetComponent<RectTransform>();
btnImg = btnObj.GetComponent<Image>();
btn = btnObj.GetComponent<Button>();
#if UNITY_2022_1_OR_NEWER
txt = rectTransform.Find("Text").GetComponent<TMPro.TMP_Text>();
#else
txt = rectTransform.Find("Text").GetComponent<Text>();
#endif
img = rectTransform.Find("Image").GetComponent<Image>();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 491c635e1f309294187ff24b5c71e8cb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,101 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System;
using UnityEngine.Events;
namespace UnityEngine.UI.Extensions
{
[Serializable]
public class DropDownListItem
{
[SerializeField]
private string _caption;
/// <summary>
/// Caption of the Item
/// </summary>
public string Caption
{
get
{
return _caption;
}
set
{
_caption = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private Sprite _image;
/// <summary>
/// Image component of the Item
/// </summary>
public Sprite Image
{
get
{
return _image;
}
set
{
_image = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private bool _isDisabled;
/// <summary>
/// Is the Item currently enabled?
/// </summary>
public bool IsDisabled
{
get
{
return _isDisabled;
}
set
{
_isDisabled = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private string _id;
///<summary>
///ID exists so that an item can have a caption and a value like in traditional windows forms. IE. an item may be a student's name, and the ID can be the student's ID number
///</summary>
public string ID
{
get { return _id; }
set { _id = value; }
}
public UnityAction OnSelect = null; //action to be called when this item is selected
internal UnityAction OnUpdate = null; //action to be called when something changes.
/// <summary>
/// Constructor for Drop Down List panelItems
/// </summary>
/// <param name="caption">Caption for the item </param>
/// <param name="val">ID of the item </param>
/// <param name="image"></param>
/// <param name="disabled">Should the item start disabled</param>
/// <param name="onSelect">UnityAction to be called when this item is selected</param>
public DropDownListItem(string caption = "", string inId = "", Sprite image = null, bool disabled = false, UnityAction onSelect = null)
{
_caption = caption;
_image = image;
_id = inId;
_isDisabled = disabled;
OnSelect = onSelect;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e1dd512d0ed874740902b01df530b2dc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,206 @@
/// Credit SimonDarksideJ
/// Sourced from my head
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/Cooldown Button")]
public class CooldownButton : MonoBehaviour, IPointerDownHandler, ISubmitHandler
{
#region Sub-Classes
[System.Serializable]
public class CooldownButtonEvent : UnityEvent<GameObject> { }
#endregion
#region Private variables
[SerializeField]
private float cooldownTimeout;
[SerializeField]
private float cooldownSpeed = 1;
[SerializeField][ReadOnly]
private bool cooldownActive;
[SerializeField][ReadOnly]
private bool cooldownInEffect;
[SerializeField][ReadOnly]
private float cooldownTimeElapsed;
[SerializeField][ReadOnly]
private float cooldownTimeRemaining;
[SerializeField][ReadOnly]
private int cooldownPercentRemaining;
[SerializeField][ReadOnly]
private int cooldownPercentComplete;
BaseEventData buttonSource;
#endregion
#region Public Properties
public float CooldownTimeout
{
get { return cooldownTimeout; }
set { cooldownTimeout = value; }
}
public float CooldownSpeed
{
get { return cooldownSpeed; }
set { cooldownSpeed = value; }
}
public bool CooldownInEffect
{
get { return cooldownInEffect; }
}
public bool CooldownActive
{
get { return cooldownActive; }
set { cooldownActive = value; }
}
public float CooldownTimeElapsed
{
get { return cooldownTimeElapsed; }
set { cooldownTimeElapsed = value; }
}
public float CooldownTimeRemaining
{
get { return cooldownTimeRemaining; }
}
public int CooldownPercentRemaining
{
get { return cooldownPercentRemaining; }
}
public int CooldownPercentComplete
{
get { return cooldownPercentComplete; }
}
#endregion
#region Events
[Tooltip("Event that fires when a button is initially pressed down")]
public CooldownButtonEvent OnCooldownStart;
[Tooltip("Event that fires when a button is released")]
public CooldownButtonEvent OnButtonClickDuringCooldown;
[Tooltip("Event that continually fires while a button is held down")]
public CooldownButtonEvent OnCoolDownFinish;
#endregion
#region Update
// Update is called once per frame
void Update()
{
if (CooldownActive)
{
cooldownTimeRemaining -= Time.deltaTime * cooldownSpeed;
cooldownTimeElapsed = CooldownTimeout - CooldownTimeRemaining;
if (cooldownTimeRemaining < 0)
{
StopCooldown();
}
else
{
cooldownPercentRemaining = (int)(100 * cooldownTimeRemaining * CooldownTimeout / 100);
cooldownPercentComplete = (int)((CooldownTimeout - cooldownTimeRemaining) / CooldownTimeout * 100);
}
}
}
#endregion
#region Public Methods
/// <summary>
/// Pause Cooldown without resetting values, allows Restarting of cooldown
/// </summary>
public void PauseCooldown()
{
if (CooldownInEffect)
{
CooldownActive = false;
}
}
/// <summary>
/// Restart a paused cooldown
/// </summary>
public void RestartCooldown()
{
if (CooldownInEffect)
{
CooldownActive = true;
}
}
/// <summary>
/// Start a cooldown from outside
/// </summary>
public void StartCooldown()
{
BaseEventData emptySource = new BaseEventData(EventSystem.current);
buttonSource = emptySource;
OnCooldownStart.Invoke(emptySource.selectedObject);
cooldownTimeRemaining = cooldownTimeout;
CooldownActive = cooldownInEffect = true;
}
/// <summary>
/// Stop a running Cooldown and reset all values
/// </summary>
public void StopCooldown()
{
cooldownTimeElapsed = CooldownTimeout;
cooldownTimeRemaining = 0;
cooldownPercentRemaining = 0;
cooldownPercentComplete = 100;
cooldownActive = cooldownInEffect = false;
OnCoolDownFinish?.Invoke(buttonSource.selectedObject);
}
/// <summary>
/// Stop a running Cooldown and retain current values
/// </summary>
public void CancelCooldown()
{
cooldownActive = cooldownInEffect = false;
}
#endregion
#region IPointerDownHandler
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
{
HandleButtonClick(eventData);
}
#endregion
#region ISubmitHandler
public void OnSubmit(BaseEventData eventData)
{
HandleButtonClick(eventData);
}
#endregion ISubmitHandler
#region Private Methods
public void HandleButtonClick(BaseEventData eventData)
{
buttonSource = eventData;
if (CooldownInEffect)
{
OnButtonClickDuringCooldown?.Invoke(buttonSource.selectedObject);
}
if (!CooldownInEffect)
{
OnCooldownStart?.Invoke(buttonSource.selectedObject);
cooldownTimeRemaining = cooldownTimeout;
cooldownActive = cooldownInEffect = true;
}
}
#endregion Private Methods
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 74a62d95b3be0fe47871dd48fca58b7d
timeCreated: 1498387990
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
/// Credit Zelek
/// Sourced from - http://forum.unity3d.com/threads/inputfield-focus-and-unfocus.306634/
/// Usage, assign component to Input field, set OnEndEdit function to the one in this script and the Click for the submit button to the buttonPressed function.
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(InputField))]
[AddComponentMenu("UI/Extensions/InputFocus")]
public class InputFocus : MonoBehaviour
{
#region Private Variables
// The input field we use for chat
protected InputField _inputField;
// When set to true, we will ignore the next time the "Enter" key is released
public bool _ignoreNextActivation = false;
#endregion
void Start()
{
_inputField = GetComponent<InputField>();
}
void Update()
{
// Check if the "Enter" key was just released with the chat input not focused
if (UIExtensionsInputManager.GetKeyUp(KeyCode.Return) && !_inputField.isFocused)
{
// If we need to ignore the keypress, do nothing - otherwise activate the input field
if (_ignoreNextActivation)
{
_ignoreNextActivation = false;
}
else
{
_inputField.Select();
_inputField.ActivateInputField();
}
}
}
public void buttonPressed()
{
// Do whatever you want with the input field text here
// Make note of whether the input string was empty, and then clear it out
bool wasEmpty = _inputField.text == "";
_inputField.text = "";
// If the string was not empty, we should reactivate the input field
if (!wasEmpty)
{
_inputField.Select();
_inputField.ActivateInputField();
}
}
public void OnEndEdit(string textString)
{
// If the edit ended because we clicked away, don't do anything extra
if (!UIExtensionsInputManager.GetKeyDown(KeyCode.Return))
{
return;
}
// Do whatever you want with the input field text here
// Make note of whether the input string was empty, and then clear it out
bool wasEmpty = _inputField.text == "";
_inputField.text = "";
// if the input string was empty, then allow the field to deactivate
if (wasEmpty)
{
_ignoreNextActivation = true;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a18c7c81729dadf40aee407a0cff0462
timeCreated: 1440843410
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
/// Credit Erdener Gonenc - @PixelEnvision
/*USAGE: Simply use that instead of the regular ScrollRect */
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu ("UI/Extensions/MultiTouchScrollRect")]
public class MultiTouchScrollRect : ScrollRect
{
private int pid = -100;
/// <summary>
/// Begin drag event
/// </summary>
public override void OnBeginDrag (UnityEngine.EventSystems.PointerEventData eventData)
{
pid = eventData.pointerId;
base.OnBeginDrag (eventData);
}
/// <summary>
/// Drag event
/// </summary>
public override void OnDrag (UnityEngine.EventSystems.PointerEventData eventData)
{
if (pid == eventData.pointerId)
base.OnDrag (eventData);
}
/// <summary>
/// End drag event
/// </summary>
public override void OnEndDrag (UnityEngine.EventSystems.PointerEventData eventData)
{
pid = -100;
base.OnEndDrag (eventData);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9f2bebd34aaa76541b97e61752a7d262
timeCreated: 1492273203
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 281614f4c0e3b7a4d9056bd377134172
folderAsset: yes
timeCreated: 1446117980
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More