初始化

This commit is contained in:
come
2025-07-26 16:56:42 +08:00
parent 8291dbb91c
commit fa81439a8c
2574 changed files with 328492 additions and 2170 deletions

View File

@@ -0,0 +1,12 @@
using UnityEngine;
namespace YIUIFramework
{
public class DontDestroyOnLoadSelf : MonoBehaviour
{
private void Awake()
{
DontDestroyOnLoad(this);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6cab7ade402b47a59bac4364f126f5e2
timeCreated: 1686305565

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 68e0b5cacd4464943b44fd79240b87bd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5179c1895e56a09479b597dab49cee80
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: YIUIImageBackGaussianBlur
m_Shader: {fileID: 4800000, guid: b87c7e95a7d24459a865da64d4f3dc0f, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OutlineZOffsetMaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AdditionalLightIgnoreCelShade: 0.9
- _BlurAmount: 1
- _BlurSize: 1
- _BumpScale: 1
- _CelShadeMidPoint: -0.5
- _CelShadeSoftness: 0.05
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DirectLightMultiplier: 1
- _DstBlend: 0
- _EmissionMulByBaseColor: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _IndirectLightMultiplier: 1
- _IsFace: 0
- _MainLightIgnoreCelShade: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionRemapEnd: 1
- _OcclusionRemapStart: 0
- _OcclusionStrength: 1
- _OutlineWidth: 1
- _OutlineZOffset: 0.0001
- _OutlineZOffsetMaskRemapEnd: 1
- _OutlineZOffsetMaskRemapStart: 0
- _Parallax: 0.02
- _ReceiveShadowMappingAmount: 0.65
- _ReceiveShadowMappingPosOffset: 0
- _Size: 2.69
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseAlphaClipping: 0
- _UseEmission: 0
- _UseOcclusion: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
- _blurSizeXY: 2
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _EmissionMapChannelMask: {r: 1, g: 1, b: 1, a: 0}
- _IndirectLightMinColor: {r: 0.1, g: 0.1, b: 0.1, a: 1}
- _OcclusionMapChannelMask: {r: 1, g: 0, b: 0, a: 0}
- _OutlineColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _ShadowMapColor: {r: 1, g: 0.825, b: 0.78, a: 1}
m_BuildTextureStacks: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b243a8b8a144cb5488839c274b4072cc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: YIUIImageSelfGaussianBlur
m_Shader: {fileID: 4800000, guid: eb17f9241e3a4581bb550a6de10f9a08, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OutlineZOffsetMaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AdditionalLightIgnoreCelShade: 0.9
- _BlurAmount: 1
- _BlurSize: 1
- _BumpScale: 1
- _CelShadeMidPoint: -0.5
- _CelShadeSoftness: 0.05
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DirectLightMultiplier: 1
- _DstBlend: 0
- _EmissionMulByBaseColor: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _IndirectLightMultiplier: 1
- _IsFace: 0
- _MainLightIgnoreCelShade: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionRemapEnd: 1
- _OcclusionRemapStart: 0
- _OcclusionStrength: 1
- _OutlineWidth: 1
- _OutlineZOffset: 0.0001
- _OutlineZOffsetMaskRemapEnd: 1
- _OutlineZOffsetMaskRemapStart: 0
- _Parallax: 0.02
- _ReceiveShadowMappingAmount: 0.65
- _ReceiveShadowMappingPosOffset: 0
- _Size: 5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseAlphaClipping: 0
- _UseEmission: 0
- _UseOcclusion: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
- _blurSizeXY: 2
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _EmissionMapChannelMask: {r: 1, g: 1, b: 1, a: 0}
- _IndirectLightMinColor: {r: 0.1, g: 0.1, b: 0.1, a: 1}
- _OcclusionMapChannelMask: {r: 1, g: 0, b: 0, a: 0}
- _OutlineColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _ShadowMapColor: {r: 1, g: 0.825, b: 0.78, a: 1}
m_BuildTextureStacks: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ca3c9f0dd5f094b4ba6f37b2706a4e58
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f1a0effc252dac64aa48cee03bf2b6d6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d7d20bdc19810bb46ae73540310e0036
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
Shader "YIUIShader/YIUICameraGaussianBlur"
{
// 高斯模糊
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {} // 主纹理
_BlurSize ("Blur Size", Float) = 1.0 // 模糊尺寸(纹理坐标的偏移量)
}
SubShader
{
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex; // 主纹理
half4 _MainTex_TexelSize; // _MainTex的像素尺寸大小, float4(1/width, 1/height, width, height)
float _BlurSize; // 模糊尺寸(纹理坐标的偏移量)
struct v2f
{
float4 pos : SV_POSITION; // 模型空间顶点坐标
half2 uv[5]: TEXCOORD0; // 5个邻域的纹理坐标
};
v2f vertBlurVertical(appdata_img v)
{
// 垂直模糊顶点着色器
v2f o;
o.pos = UnityObjectToClipPos(v.vertex); // 模型空间顶点坐标变换到裁剪空间, 等价于: mul(UNITY_MATRIX_MVP, v.vertex)
half2 uv = v.texcoord;
o.uv[0] = uv;
o.uv[1] = uv + float2(0.0, _MainTex_TexelSize.y * 1.0) * _BlurSize;
o.uv[2] = uv - float2(0.0, _MainTex_TexelSize.y * 1.0) * _BlurSize;
o.uv[3] = uv + float2(0.0, _MainTex_TexelSize.y * 2.0) * _BlurSize;
o.uv[4] = uv - float2(0.0, _MainTex_TexelSize.y * 2.0) * _BlurSize;
return o;
}
v2f vertBlurHorizontal(appdata_img v)
{
// 水平模糊顶点着色器
v2f o;
o.pos = UnityObjectToClipPos(v.vertex); // 模型空间顶点坐标变换到裁剪空间, 等价于: mul(UNITY_MATRIX_MVP, v.vertex)
half2 uv = v.texcoord;
o.uv[0] = uv;
o.uv[1] = uv + float2(_MainTex_TexelSize.x * 1.0, 0.0) * _BlurSize;
o.uv[2] = uv - float2(_MainTex_TexelSize.x * 1.0, 0.0) * _BlurSize;
o.uv[3] = uv + float2(_MainTex_TexelSize.x * 2.0, 0.0) * _BlurSize;
o.uv[4] = uv - float2(_MainTex_TexelSize.x * 2.0, 0.0) * _BlurSize;
return o;
}
fixed4 fragBlur(v2f i) : SV_Target
{
float weight[3] = {0.4026, 0.2442, 0.0545}; // 大小为5的一维高斯核实际只需记录3个权值
fixed3 sum = tex2D(_MainTex, i.uv[0]).rgb * weight[0];
for (int j = 1; j < 3; j++)
{
sum += tex2D(_MainTex, i.uv[j * 2 - 1]).rgb * weight[j]; // 中心右侧或下侧的纹理*权值
sum += tex2D(_MainTex, i.uv[j * 2]).rgb * weight[j]; // 中心左侧或上侧的纹理*权值
}
return fixed4(sum, 1.0);
}
ENDCG
ZTest Always Cull Off ZWrite Off
Pass
{
NAME "GAUSSIAN_BLUR_VERTICAL"
CGPROGRAM
#pragma vertex vertBlurVertical
#pragma fragment fragBlur
ENDCG
}
Pass
{
NAME "GAUSSIAN_BLUR_HORIZONTAL"
CGPROGRAM
#pragma vertex vertBlurHorizontal
#pragma fragment fragBlur
ENDCG
}
}
FallBack "Diffuse"
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6f7e2d96029d0f040a214d05230aec54
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
Shader "YIUIShader/YIUICameraMotionBlur"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {} // 主纹理
_BlurAmount ("Blur Amount", Float) = 1.0 // 模糊值, 通过alpha通道控制当前屏幕纹理与历史屏幕纹理进行混合
}
SubShader
{
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex; // 主纹理
fixed _BlurAmount; // 模糊值, 通过alpha通道控制当前屏幕纹理与历史屏幕纹理进行混合
fixed4 fragRGB(v2f_img i) : SV_Target
{
// v2f_img为内置结构体, 里面只包含pos和uv
return fixed4(tex2D(_MainTex, i.uv).rgb, _BlurAmount);
}
half4 fragA(v2f_img i) : SV_Target
{
// v2f_img为内置结构体, 里面只包含pos和uv
return tex2D(_MainTex, i.uv);
}
ENDCG
ZTest Always Cull Off ZWrite Off
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB // 允许通过的颜色通道, 取值有: 0、R、G、B、A、RGBA的组合(RG、RGB等)
CGPROGRAM
#pragma vertex vert_img // 使用内置的vert_img顶点着色器
#pragma fragment fragRGB // _BlurAmount只参与混合, 不影响alpha值
ENDCG
}
Pass
{
Blend One Zero
ColorMask A // 允许通过的颜色通道, 取值有: 0、R、G、B、A、RGBA的组合(RG、RGB等)
CGPROGRAM
#pragma vertex vert_img // 使用内置的vert_img顶点着色器
#pragma fragment fragA // 使用纹理原本的alpha值
ENDCG
}
}
FallBack Off
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7198712ca3044b794c0b7fb9b85d81a
timeCreated: 1687675483

View File

@@ -0,0 +1,267 @@
Shader "YIUIShader/YIUIImageBackGaussianBlur"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
_Size ("Size", Range(0, 20)) = 1
}
Category
{
// We must be transparent, so other objects are drawn before this one.
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
SubShader
{
// Horizontal blur
GrabPass
{
Tags
{
"LightMode" = "Always"
}
}
Pass
{
Tags
{
"LightMode" = "Always"
}
Name "BackBlurHor"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float4 vertex : POSITION;
float4 uvgrab : TEXCOORD0;
float4 color : COLOR;
};
v2f vert(appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
#if UNITY_UV_STARTS_AT_TOP
float scale = -1.0;
#else
float scale = 1.0;
#endif
o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y * scale) + o.vertex.w) * 0.5;
o.uvgrab.zw = o.vertex.zw;
o.color = v.color;
return o;
}
sampler2D _GrabTexture;
float4 _GrabTexture_TexelSize;
float4 _MainTex_TexelSize;
float _Size;
uniform float4 _Color;
// static float GaussianKernel[9] = {
// 0.05, 0.09, 0.12,
// 0.15, 0.18, 0.15,
// 0.12, 0.09, 0.05
// };
// static float GaussianKernel[19] = {
// 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09,
// 0.1,
// 0.09, 0.08, 0.07, 0.06, 0.05, 0.04, 0.03, 0.02, 0.01,
// };
// static float GaussianKernelD[19] = {
// -9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0,
// 0.0,
// +1.0, +2.0, +3.0, +4.0, +5.0, +6.0, +7.0, +8.0, +9.0,
// };
half4 GrabPixel(v2f i, float weight, float kernelx)
{
if (i.uvgrab.x == 0 && i.uvgrab.y == 0)
{
kernelx = 0;
}
return tex2Dproj(_GrabTexture,
UNITY_PROJ_COORD(
float4(i.uvgrab.x + _GrabTexture_TexelSize.x*kernelx*_Size, i.uvgrab.y, i.
uvgrab.z, i.uvgrab.w))) * weight;
}
half4 frag(v2f i) : COLOR
{
half4 sum = half4(0, 0, 0, 0);
// #define GRABPIXEL(weight, kernelx) tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
sum += GrabPixel(i, 0.05, -4.0);
sum += GrabPixel(i, 0.09, -3.0);
sum += GrabPixel(i, 0.12, -2.0);
sum += GrabPixel(i, 0.15, -1.0);
sum += GrabPixel(i, 0.18, 0.0);
sum += GrabPixel(i, 0.15, +1.0);
sum += GrabPixel(i, 0.12, +2.0);
sum += GrabPixel(i, 0.09, +3.0);
sum += GrabPixel(i, 0.05, +4.0);
// sum += GrabPixel(i, 0.01, -9.0);
// sum += GrabPixel(i, 0.02, -8.0);
// sum += GrabPixel(i, 0.03, -7.0);
// sum += GrabPixel(i, 0.04, -6.0);
// sum += GrabPixel(i, 0.05, -5.0);
// sum += GrabPixel(i, 0.06, -4.0);
// sum += GrabPixel(i, 0.07, -3.0);
// sum += GrabPixel(i, 0.08, -2.0);
// sum += GrabPixel(i, 0.09, -1.0);
// sum += GrabPixel(i, 0.10, 0.0);
// sum += GrabPixel(i, 0.09, +1.0);
// sum += GrabPixel(i, 0.08, +2.0);
// sum += GrabPixel(i, 0.07, +3.0);
// sum += GrabPixel(i, 0.06, +4.0);
// sum += GrabPixel(i, 0.05, +5.0);
// sum += GrabPixel(i, 0.04, +6.0);
// sum += GrabPixel(i, 0.03, +7.0);
// sum += GrabPixel(i, 0.02, +8.0);
// sum += GrabPixel(i, 0.01, +9.0);
float4 col5 = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
float decayFactor = 1.0f;
if (i.uvgrab.x == 0 && i.uvgrab.y == 0)
{
decayFactor = 0;
}
sum = lerp(col5, sum, decayFactor) * i.color * _Color;
return sum;
}
ENDCG
}
// Vertical blur
GrabPass
{
Tags
{
"LightMode" = "Always"
}
}
Pass
{
Tags
{
"LightMode" = "Always"
}
Name "BackBlurVer"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord: TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float4 vertex : POSITION;
float4 uvgrab : TEXCOORD0;
float4 color : COLOR;
};
v2f vert(appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
#if UNITY_UV_STARTS_AT_TOP
float scale = -1.0;
#else
float scale = 1.0;
#endif
o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y * scale) + o.vertex.w) * 0.5;
o.uvgrab.zw = o.vertex.zw;
o.color = v.color;
return o;
}
sampler2D _GrabTexture;
float4 _GrabTexture_TexelSize;
float _Size;
uniform float4 _Color;
half4 GrabPixel(v2f i, float weight, float kernely)
{
if (i.uvgrab.x == 0 && i.uvgrab.y == 0)
{
kernely = 0;
}
return tex2Dproj(_GrabTexture,
UNITY_PROJ_COORD(
float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y*kernely*_Size, i.
uvgrab.z, i.uvgrab.w))) * weight;
}
half4 frag(v2f i) : COLOR
{
half4 sum = half4(0, 0, 0, 0);
// #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely*_Size, i.uvgrab.z, i.uvgrab.w))) * weight
sum += GrabPixel(i, 0.05, -4.0);
sum += GrabPixel(i, 0.09, -3.0);
sum += GrabPixel(i, 0.12, -2.0);
sum += GrabPixel(i, 0.15, -1.0);
sum += GrabPixel(i, 0.18, 0.0);
sum += GrabPixel(i, 0.15, +1.0);
sum += GrabPixel(i, 0.12, +2.0);
sum += GrabPixel(i, 0.09, +3.0);
sum += GrabPixel(i, 0.05, +4.0);
// sum += GrabPixel(i, 0.01, -9.0);
// sum += GrabPixel(i, 0.02, -8.0);
// sum += GrabPixel(i, 0.03, -7.0);
// sum += GrabPixel(i, 0.04, -6.0);
// sum += GrabPixel(i, 0.05, -5.0);
// sum += GrabPixel(i, 0.06, -4.0);
// sum += GrabPixel(i, 0.07, -3.0);
// sum += GrabPixel(i, 0.08, -2.0);
// sum += GrabPixel(i, 0.09, -1.0);
// sum += GrabPixel(i, 0.10, 0.0);
// sum += GrabPixel(i, 0.09, +1.0);
// sum += GrabPixel(i, 0.08, +2.0);
// sum += GrabPixel(i, 0.07, +3.0);
// sum += GrabPixel(i, 0.06, +4.0);
// sum += GrabPixel(i, 0.05, +5.0);
// sum += GrabPixel(i, 0.04, +6.0);
// sum += GrabPixel(i, 0.03, +7.0);
// sum += GrabPixel(i, 0.02, +8.0);
// sum += GrabPixel(i, 0.01, +9.0);
float4 col5 = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
float decayFactor = 1.0f;
if (i.uvgrab.x == 0 && i.uvgrab.y == 0)
{
decayFactor = 0;
}
sum = lerp(col5, sum, decayFactor) * i.color * _Color;
return sum;
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b87c7e95a7d24459a865da64d4f3dc0f
timeCreated: 1687676969

View File

@@ -0,0 +1,373 @@
Shader "YIUIShader/YIUIImageSelfGaussianBlur"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[HideInInspector]_StencilComp ("Stencil Comparison", Float) = 8
[HideInInspector]_Stencil ("Stencil ID", Float) = 0
[HideInInspector]_StencilOp ("Stencil Operation", Float) = 0
[HideInInspector]_StencilWriteMask ("Stencil Write Mask", Float) = 255
[HideInInspector]_StencilReadMask ("Stencil Read Mask", Float) = 255
[HideInInspector]_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
_Size ("Size", Range(0, 50)) = 5
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
Name "FrontBlurHor"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
fixed4 _Color;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
v2f vert(appdata_t IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color;
return OUT;
}
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float _Size;
half4 GrabPixel(v2f i, float weight, float kernelx)
{
if (_Size <= 1 || weight == 0)
{
return tex2D(_MainTex, half2(i.texcoord.x + _MainTex_TexelSize.x * kernelx * _Size, i.texcoord.y)) *
weight;
}
else
{
half4 sum = half4(0, 0, 0, 0);
sum += tex2D(_MainTex, half2(i.texcoord.x + _MainTex_TexelSize.x * kernelx * _Size * 0.2,
i.texcoord.y)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x + _MainTex_TexelSize.x * kernelx * _Size * 0.4,
i.texcoord.y)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x + _MainTex_TexelSize.x * kernelx * _Size * 0.6,
i.texcoord.y)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x + _MainTex_TexelSize.x * kernelx * _Size * 0.8,
i.texcoord.y)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x + _MainTex_TexelSize.x * kernelx * _Size * 1.0,
i.texcoord.y)) * 0.2;
return (sum + _TextureSampleAdd) * weight;
}
}
half4 GrabPixely(v2f i, float weight, float kernely)
{
if (_Size <= 1 || weight == 0)
{
return tex2D(_MainTex, half2(i.texcoord.x, i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size)) *
weight;
}
else
{
half4 sum = half4(0, 0, 0, 0);
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.2)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.4)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.6)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.8)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 1.0)) * 0.2;
return (sum + _TextureSampleAdd) * weight;
}
}
fixed4 frag(v2f IN) : SV_Target
{
half4 sum = half4(0, 0, 0, 0);
// #define GRABPIXEL(weight, kernelx) (tex2D(_MainTex, half2(IN.texcoord.x + _MainTex_TexelSize.x * kernelx*_Size, IN.texcoord.y)) + _TextureSampleAdd) * weight
// sum += GrabPixel(IN, 0.05, -4.0);
// sum += GrabPixel(IN, 0.09, -3.0);
// sum += GrabPixel(IN, 0.12, -2.0);
// sum += GrabPixel(IN, 0.15, -1.0);
// sum += GrabPixel(IN, 0.18, 0.0);
// sum += GrabPixel(IN, 0.15, +1.0);
// sum += GrabPixel(IN, 0.12, +2.0);
// sum += GrabPixel(IN, 0.09, +3.0);
// sum += GrabPixel(IN, 0.05, +4.0);
for (int i = 0; i < 9; i++)
{
sum += GrabPixel(IN, 1.0 / 9, i - 4.0);
}
// half4 sumy = half4(0,0,0,0);
// for(int i=0;i<15;i++){
// sumy += GrabPixely(IN, 1.0/15, i-7.0);
// }
// half4 sum = (sumx + sumy) * 0.5;
// sum += GrabPixel(IN, 0.01, -9.0);
// sum += GrabPixel(IN, 0.02, -8.0);
// sum += GrabPixel(IN, 0.03, -7.0);
// sum += GrabPixel(IN, 0.04, -6.0);
// sum += GrabPixel(IN, 0.05, -5.0);
// sum += GrabPixel(IN, 0.06, -4.0);
// sum += GrabPixel(IN, 0.07, -3.0);
// sum += GrabPixel(IN, 0.08, -2.0);
// sum += GrabPixel(IN, 0.09, -1.0);
// sum += GrabPixel(IN, 0.10, 0.0);
// sum += GrabPixel(IN, 0.09, +1.0);
// sum += GrabPixel(IN, 0.08, +2.0);
// sum += GrabPixel(IN, 0.07, +3.0);
// sum += GrabPixel(IN, 0.06, +4.0);
// sum += GrabPixel(IN, 0.05, +5.0);
// sum += GrabPixel(IN, 0.04, +6.0);
// sum += GrabPixel(IN, 0.03, +7.0);
// sum += GrabPixel(IN, 0.02, +8.0);
// sum += GrabPixel(IN, 0.01, +9.0);
sum = sum * IN.color;
sum.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#ifdef UNITY_UI_ALPHACLIP
clip (sum.a - 0.001);
#endif
return sum;
// float distance = _Distance;
// fixed4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x + distance, IN.texcoord.y + distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x + distance, IN.texcoord.y)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x + distance, IN.texcoord.y - distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x, IN.texcoord.y - distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x - distance, IN.texcoord.y - distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x - distance, IN.texcoord.y)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x - distance, IN.texcoord.y + distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x, IN.texcoord.y + distance)) + _TextureSampleAdd) * IN.color;
// color /= 9;
// color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
// #ifdef UNITY_UI_ALPHACLIP
// clip (color.a - 0.001);
// #endif
// return color;
}
ENDCG
}
Pass
{
Name "FrontBlurVer"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
fixed4 _Color;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
v2f vert(appdata_t IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color;
return OUT;
}
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float _Size;
half4 GrabPixel(v2f i, float weight, float kernely)
{
if (_Size <= 1 || weight == 0)
{
return tex2D(_MainTex, half2(i.texcoord.x, i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size)) *
weight;
}
else
{
half4 sum = half4(0, 0, 0, 0);
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.2)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.4)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.6)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 0.8)) * 0.2;
sum += tex2D(_MainTex, half2(i.texcoord.x,
i.texcoord.y + _MainTex_TexelSize.y * kernely * _Size * 1.0)) * 0.2;
return (sum + _TextureSampleAdd) * weight;
}
}
fixed4 frag(v2f IN) : SV_Target
{
half4 sum = half4(0, 0, 0, 0);
// #define GRABPIXEL(weight, kernely) (tex2D(_MainTex, half2(IN.texcoord.x, IN.texcoord.y + _MainTex_TexelSize.y * kernely*_Size)) + _TextureSampleAdd) * weight
// sum += GrabPixel(IN, 0.05, -4.0);
// sum += GrabPixel(IN, 0.09, -3.0);
// sum += GrabPixel(IN, 0.12, -2.0);
// sum += GrabPixel(IN, 0.15, -1.0);
// sum += GrabPixel(IN, 0.18, 0.0);
// sum += GrabPixel(IN, 0.15, +1.0);
// sum += GrabPixel(IN, 0.12, +2.0);
// sum += GrabPixel(IN, 0.09, +3.0);
// sum += GrabPixel(IN, 0.05, +4.0);
for (int i = 0; i < 9; i++)
{
sum += GrabPixel(IN, 1.0 / 9, i - 4.0);
}
// sum += GrabPixel(IN, 0.01, -9.0);
// sum += GrabPixel(IN, 0.02, -8.0);
// sum += GrabPixel(IN, 0.03, -7.0);
// sum += GrabPixel(IN, 0.04, -6.0);
// sum += GrabPixel(IN, 0.05, -5.0);
// sum += GrabPixel(IN, 0.06, -4.0);
// sum += GrabPixel(IN, 0.07, -3.0);
// sum += GrabPixel(IN, 0.08, -2.0);
// sum += GrabPixel(IN, 0.09, -1.0);
// sum += GrabPixel(IN, 0.10, 0.0);
// sum += GrabPixel(IN, 0.09, +1.0);
// sum += GrabPixel(IN, 0.08, +2.0);
// sum += GrabPixel(IN, 0.07, +3.0);
// sum += GrabPixel(IN, 0.06, +4.0);
// sum += GrabPixel(IN, 0.05, +5.0);
// sum += GrabPixel(IN, 0.04, +6.0);
// sum += GrabPixel(IN, 0.03, +7.0);
// sum += GrabPixel(IN, 0.02, +8.0);
// sum += GrabPixel(IN, 0.01, +9.0);
sum = sum * IN.color;
sum.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#ifdef UNITY_UI_ALPHACLIP
clip (sum.a - 0.001);
#endif
return sum;
// float distance = _Distance;
// fixed4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x + distance, IN.texcoord.y + distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x + distance, IN.texcoord.y)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x + distance, IN.texcoord.y - distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x, IN.texcoord.y - distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x - distance, IN.texcoord.y - distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x - distance, IN.texcoord.y)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x - distance, IN.texcoord.y + distance)) + _TextureSampleAdd) * IN.color;
// color += (tex2D(_MainTex, half2(IN.texcoord.x, IN.texcoord.y + distance)) + _TextureSampleAdd) * IN.color;
// color /= 9;
// color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
// #ifdef UNITY_UI_ALPHACLIP
// clip (color.a - 0.001);
// #endif
// return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eb17f9241e3a4581bb550a6de10f9a08
timeCreated: 1687676099

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 50be4e96eeea40549787af25e84adb8d
timeCreated: 1685603306

View File

@@ -0,0 +1,334 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace YIUIFramework
{
public class ContentSizeFilterByChildren: UIBehaviour, ILayoutElement, ILayoutSelfController, ILayoutGroup
{
public enum FitMode
{
Width,
Height,
Both
}
public enum SizeMode
{
Add,
Max
}
[SerializeField]
protected SizeMode m_Size = SizeMode.Add;
[SerializeField]
protected FitMode m_Fit = FitMode.Height;
public FitMode fit
{
get
{
return m_Fit;
}
set
{
m_Fit = value;
}
}
[SerializeField]
protected float m_MaxSize = int.MaxValue;
public float maxSize
{
get
{
return m_MaxSize;
}
set
{
m_MaxSize = value;
}
}
[SerializeField]
protected int m_layoutPriority = 1;
public int layoutPriority
{
get
{
return m_layoutPriority;
}
set
{
m_layoutPriority = value;
}
}
[SerializeField]
protected float m_minWidth = -1;
public float minWidth
{
get
{
return m_minWidth;
}
set
{
m_minWidth = value;
}
}
[SerializeField]
protected float m_minHeight = -1;
public float minHeight
{
get
{
return m_minHeight;
}
set
{
m_minHeight = value;
}
}
[SerializeField]
protected float m_Space = 0;
[System.NonSerialized]
private RectTransform m_Rect;
private RectTransform rectTransform
{
get
{
if (m_Rect == null)
m_Rect = GetComponent<RectTransform>();
return m_Rect;
}
}
private HorizontalOrVerticalLayoutGroup m_LayoutGroup = null;
public void AutoSize()
{
if (m_Fit == FitMode.Width || m_Fit == FitMode.Both)
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,
((ILayoutElement)this).preferredWidth);
if (m_Fit == FitMode.Height || m_Fit == FitMode.Both)
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
((ILayoutElement)this).preferredHeight);
}
void ILayoutController.SetLayoutHorizontal()
{
AutoSize();
}
void ILayoutController.SetLayoutVertical()
{
AutoSize();
}
float ILayoutElement.minWidth
{
get
{
return m_minWidth;
}
}
float ILayoutElement.preferredWidth
{
get
{
float size = -1;
float max = -2;
if (m_Fit == FitMode.Width || m_Fit == FitMode.Both)
{
max = 0;
size = 0;
float spacing = m_Space;
if (m_LayoutGroup != null)
{
size = size + m_LayoutGroup.padding.left + m_LayoutGroup.padding.right;
if (m_LayoutGroup is HorizontalLayoutGroup)
spacing = m_LayoutGroup.spacing;
}
int One = 1;
for (int i = 0; i < rectTransform.childCount; ++i)
{
var child = rectTransform.GetChild(i) as RectTransform;
if (child.gameObject.activeSelf)
{
var ignore = child.GetComponent<ILayoutIgnorer>();
if (ignore != null && ignore.ignoreLayout)
continue;
if (m_Size == SizeMode.Add)
{
size += Mathf.Max(0, LayoutUtility.GetPreferredWidth(child));
if (One == 0)
size += spacing;
if (One == 1)
One = 0;
}
//else if (m_Size == SizeMode.Max)
//{
// size = size + Mathf.Max(size, LayoutUtility.GetPreferredWidth(child));
// break;
//}
else if (m_Size == SizeMode.Max)
{
max = Mathf.Max(max, LayoutUtility.GetPreferredWidth(child) + size);
}
}
}
if (m_Size == SizeMode.Max)
size = max;
size = Mathf.Min(maxSize, size);
if (minWidth > 0)
{
size = Mathf.Max(minWidth, size);
}
}
return size;
}
}
float ILayoutElement.flexibleWidth
{
get
{
return -1;
}
}
float ILayoutElement.minHeight
{
get
{
return m_minHeight;
}
}
float ILayoutElement.preferredHeight
{
get
{
float size = -1;
float max = 0;
if (m_Fit == FitMode.Height || m_Fit == FitMode.Both)
{
size = 0;
float spacing = m_Space;
if (m_LayoutGroup != null)
{
size = size + m_LayoutGroup.padding.top + m_LayoutGroup.padding.bottom;
if (m_LayoutGroup is VerticalLayoutGroup)
spacing = m_LayoutGroup.spacing;
}
int One = 1;
for (int i = 0; i < rectTransform.childCount; ++i)
{
var child = rectTransform.GetChild(i) as RectTransform;
if (child.gameObject.activeSelf)
{
var ignore = child.GetComponent<ILayoutIgnorer>();
if (ignore != null && ignore.ignoreLayout)
continue;
if (m_Size == SizeMode.Add)
{
size += Mathf.Max(0, LayoutUtility.GetPreferredHeight(child));
if (One == 0)
size += spacing;
if (One == 1)
One = 0;
}
else if (m_Size == SizeMode.Max)
{
max = Mathf.Max(max, LayoutUtility.GetPreferredHeight(child) + size);
}
}
}
if (m_Size == SizeMode.Max)
size = max;
size = Mathf.Min(maxSize, size);
if (minHeight > 0)
{
size = Mathf.Max(minHeight, size);
}
}
return size;
}
}
float ILayoutElement.flexibleHeight
{
get
{
return -1;
}
}
int ILayoutElement.layoutPriority
{
get
{
return m_layoutPriority;
}
}
void ILayoutElement.CalculateLayoutInputHorizontal()
{
AutoSize();
}
void ILayoutElement.CalculateLayoutInputVertical()
{
AutoSize();
}
protected override void OnEnable()
{
base.OnEnable();
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
}
protected override void OnDisable()
{
base.OnDisable();
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
}
protected override void Awake()
{
m_LayoutGroup = GetComponent<HorizontalOrVerticalLayoutGroup>();
}
#if UNITY_EDITOR
protected override void OnValidate()
{
OnEnable();
m_LayoutGroup = GetComponent<HorizontalOrVerticalLayoutGroup>();
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d75fd91549d34a5f9f811c6159dd09f5
timeCreated: 1685603306

View File

@@ -0,0 +1,105 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace YIUIFramework
{
public class ContentSizeFilterByRect : UIBehaviour, ILayoutElement
{
public enum FitMode
{
Width,
Height,
Both,
}
[SerializeField]
protected FitMode m_Fit = FitMode.Both;
public FitMode fit
{
get { return m_Fit; }
set { m_Fit = value; }
}
[System.NonSerialized]
private RectTransform m_Rect;
private RectTransform rectTransform
{
get
{
if (m_Rect == null)
m_Rect = GetComponent<RectTransform>();
return m_Rect;
}
}
float ILayoutElement.minWidth
{
get { return ((ILayoutElement)this).preferredWidth; }
}
float ILayoutElement.preferredWidth
{
get
{
if (m_Fit == FitMode.Both || m_Fit == FitMode.Width)
return rectTransform.rect.width;
else
return -1;
}
}
float ILayoutElement.flexibleWidth
{
get { return -1; }
}
float ILayoutElement.minHeight
{
get { return ((ILayoutElement)this).preferredHeight; }
}
float ILayoutElement.preferredHeight
{
get
{
if (m_Fit == FitMode.Both || m_Fit == FitMode.Height)
return rectTransform.rect.height;
else
return -1;
}
}
float ILayoutElement.flexibleHeight
{
get { return -1; }
}
int ILayoutElement.layoutPriority
{
get { return 1; }
}
void ILayoutElement.CalculateLayoutInputHorizontal()
{
}
void ILayoutElement.CalculateLayoutInputVertical()
{
}
protected override void OnEnable()
{
base.OnEnable();
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
}
protected override void OnDisable()
{
base.OnDisable();
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8dd126203a544f88b9f34f27f68cc9c9
timeCreated: 1685603306

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6186b8e335f184c478290e546e273795
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 高斯模糊特效
/// </summary>
[ExecuteInEditMode] // 编辑态可以查看脚本运行效果
[RequireComponent(typeof(Camera))] // 需要相机组件
public class YIUICameraGaussianBlur : MonoBehaviour
{
[Range(0, 4)]
public int iterations = 3; // 高斯模糊迭代次数
[Range(0.2f, 3.0f)]
public float blurSpread = 0.6f; // 每次迭代纹理坐标偏移的速度
[Range(1, 8)]
public int downSample = 2; // 降采样比率
private Material material = null; // 材质
private void Start()
{
material = new Material(Shader.Find("YIUIShader/YIUICameraGaussianBlur"));
material.hideFlags = HideFlags.DontSave;
}
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
if (material != null)
{
int rtW = src.width / downSample; // 降采样的纹理宽度
int rtH = src.height / downSample; // 降采样的纹理高度
RenderTexture buffer0 = RenderTexture.GetTemporary(rtW, rtH, 0);
buffer0.filterMode = FilterMode.Bilinear; // 滤波模式设置为双线性
Graphics.Blit(src, buffer0);
for (int i = 0; i < iterations; i++)
{
material.SetFloat("_BlurSize", 1.0f + i * blurSpread); // 设置模糊尺寸(纹理坐标的偏移量)
RenderTexture buffer1 = RenderTexture.GetTemporary(rtW, rtH, 0);
Graphics.Blit(buffer0, buffer1, material, 0); // 渲染垂直的Pass
RenderTexture.ReleaseTemporary(buffer0);
buffer0 = buffer1;
buffer1 = RenderTexture.GetTemporary(rtW, rtH, 0);
Graphics.Blit(buffer0, buffer1, material, 1); // 渲染水平的Pass
RenderTexture.ReleaseTemporary(buffer0);
buffer0 = buffer1;
}
Graphics.Blit(buffer0, dest);
RenderTexture.ReleaseTemporary(buffer0);
}
else
{
Graphics.Blit(src, dest);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 05dc8c238e41430f83e9e0d0278b96e2
timeCreated: 1687674753

View File

@@ -0,0 +1,52 @@
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 运动模糊特效
/// </summary>
[RequireComponent(typeof(Camera))] // 需要相机组件
public class YIUICameraMotionBlur : MonoBehaviour
{
[Range(0.0f, 0.9f)]
public float blurAmount = 0.5f; // 模糊值, 值越大拖尾效果越明显
private RenderTexture historyTexture; // 历史屏幕纹理
private Material material = null; // 材质
private void Start()
{
material = new Material(Shader.Find("YIUIShader/YIUICameraMotionBlur"));
material.hideFlags = HideFlags.DontSave;
}
void OnDisable()
{
// 脚本不运行时立即销毁, 下次开始应用运动模糊时, 重新混合图像
DestroyImmediate(historyTexture);
}
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
if (material != null)
{
// 初始化时或窗口尺寸变化时, 创建叠加纹理
if (historyTexture == null || historyTexture.width != src.width || historyTexture.height != src.height)
{
DestroyImmediate(historyTexture);
historyTexture = new RenderTexture(src.width, src.height, 0);
historyTexture.hideFlags = HideFlags.HideAndDontSave;
Graphics.Blit(src, historyTexture);
}
material.SetFloat("_BlurAmount", 1.0f - blurAmount); // 设置模糊值, 通过alpha通道控制当前屏幕纹理与历史屏幕纹理进行混合
Graphics.Blit(src, historyTexture, material);
Graphics.Blit(historyTexture, dest);
}
else
{
Graphics.Blit(src, dest);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c1166d12e60c4b7bb71939e1d5c3762f
timeCreated: 1687675445

View File

@@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8203712829968715909
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6187606721477242293}
- component: {fileID: 1806377903031401790}
- component: {fileID: 8893579309878970462}
m_Layer: 5
m_Name: YIUIImageBackGaussianBlur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6187606721477242293
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8203712829968715909}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1806377903031401790
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8203712829968715909}
m_CullTransparentMesh: 1
--- !u!114 &8893579309878970462
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8203712829968715909}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 2100000, guid: b243a8b8a144cb5488839c274b4072cc, type: 2}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b0840c9a860a39f4da384be99598b879
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3554010424902499222
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3433778286568191839}
- component: {fileID: 154720680013837306}
- component: {fileID: 1533940618106898788}
m_Layer: 5
m_Name: YIUIImageSelfGaussianBlur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3433778286568191839
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3554010424902499222}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &154720680013837306
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3554010424902499222}
m_CullTransparentMesh: 1
--- !u!114 &1533940618106898788
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3554010424902499222}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 2100000, guid: ca3c9f0dd5f094b4ba6f37b2706a4e58, type: 2}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b8555a9e30644f748bccd04169b1734b
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.UI;
namespace YIUIFramework
{
/// <summary>
///自适应不同分辨率。
/// </summary>
[RequireComponent(typeof(CanvasScaler))]
[ExecuteInEditMode]
public class ResolutionAdapter : MonoBehaviour
{
private Canvas canvas;
private CanvasScaler scaler;
private void Awake()
{
this.canvas = this.GetComponent<Canvas>();
if (null == this.canvas || !this.canvas.isRootCanvas)
{
return;
}
this.AdaptResolution();
}
#if UNITY_EDITOR
private void Update()
{
this.AdaptResolution();
}
private void OnValidate()
{
this.AdaptResolution();
}
#endif
private void AdaptResolution()
{
#if UNITY_EDITOR
var prefabType = PrefabUtility.GetPrefabAssetType(this.gameObject);
if (prefabType == PrefabAssetType.Regular)
{
return;
}
#endif
if (null == this.scaler)
{
this.scaler = this.GetComponent<CanvasScaler>();
}
var radio = (float)Screen.width / Screen.height;
var refRadio = this.scaler.referenceResolution.x / this.scaler.referenceResolution.y;
if (radio >= refRadio)
{
this.scaler.matchWidthOrHeight = 1.0f;
}
else
{
this.scaler.matchWidthOrHeight = 0.0f;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bfab45850b3741c2b940fc389674b52e
timeCreated: 1685603306

View File

@@ -0,0 +1,85 @@
using UnityEngine;
using UnityEngine.EventSystems;
using DG.Tweening;
using UnityEngine.UI;
namespace YIUIFramework
{
/// <summary>
/// 点击按钮影响组件大小
/// </summary>
public class YIUIClickEffect : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[Tooltip("被影响的目标")]
public RectTransform targetTsf;
[Tooltip("变化大小 (倍数)")]
public float scaleValue = 0.9f;
[Tooltip("变小时间")]
public float scaleTime = 0;
[Tooltip("变大时间")]
public float popTime = 0;
private Button m_button;
private Vector3 targetScale; //目标大小
private Vector3 atScale; //当前大小
/// <summary>
/// 可调整动画状态
/// </summary>
public Ease ease = Ease.OutElastic;
private void Awake()
{
m_button = GetComponent<Button>(); //需要先挂button 否则无效
if (targetTsf == null) //如果没有目标则默认自己为目标
{
targetTsf = transform.gameObject.GetComponent<RectTransform>();
}
atScale = targetTsf.localScale;
targetScale = atScale * scaleValue;
}
private void OnDestroy()
{
targetTsf.DOKill();
}
//按下
public void OnPointerDown(PointerEventData eventData)
{
if (m_button)
{
if (m_button.enabled && m_button.interactable)
{
targetTsf.DOScale(targetScale, scaleTime).SetEase(ease);
}
}
else
{
targetTsf.DOScale(targetScale, scaleTime).SetEase(ease);
}
}
//抬起
public void OnPointerUp(PointerEventData eventData)
{
targetTsf.DOKill();
targetTsf.DOScale(atScale, popTime).SetEase(ease); //回到本来大小
}
#if UNITY_EDITOR
private void OnValidate()
{
if (targetTsf == null) //如果没有目标则默认自己为目标
{
targetTsf = transform.gameObject.GetComponent<RectTransform>();
}
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 39a07d1afeeb4dcc812559d0b9fea3b9
timeCreated: 1685603306

View File

@@ -0,0 +1,88 @@
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using UnityEngine.EventSystems;
using EventSystem = UnityEngine.EventSystems.EventSystem;
namespace YIUIFramework
{
/// <summary>
/// 点击穿透
/// 只支持穿透一层
/// 可嵌套使用 达到无限穿透效果
/// </summary>
[AddComponentMenu("YIUIFramework/Widget/点击穿透 【YIUIClickEventPenetration】")]
public class YIUIClickEventPenetration: MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
{
[LabelText("穿透 按下")]
public bool Down = true;
[LabelText("穿透 抬起")]
public bool Up = true;
[LabelText("穿透 点击")]
public bool Click = true;
public void OnPointerDown(PointerEventData eventData)
{
if (!Down) return;
PassEvent(eventData, ExecuteEvents.pointerDownHandler);
}
public void OnPointerUp(PointerEventData eventData)
{
if (!Up) return;
PassEvent(eventData, ExecuteEvents.pointerUpHandler);
}
public void OnPointerClick(PointerEventData eventData)
{
if (!Click) return;
PassEvent(eventData, ExecuteEvents.pointerClickHandler);
}
private void PassEvent<T>(PointerEventData pointerEventData, ExecuteEvents.EventFunction<T> eventFunction) where T : IEventSystemHandler
{
var raycastResults = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerEventData, raycastResults);
GameObject nextGameObject = null;
for (int i = 0; i < raycastResults.Count; i++)
{
if (raycastResults[i].gameObject == gameObject)
{
if (i + 1 < raycastResults.Count)
{
nextGameObject = raycastResults[i + 1].gameObject;
}
break;
}
}
if (nextGameObject != null && nextGameObject != gameObject)
{
ExecuteEvents.ExecuteHierarchy(nextGameObject, pointerEventData, eventFunction);
}
}
}
/*
1.下层Button没响应问题
如果只传递一层的情况 Button的Text文本 或者Button下面有遮挡物 并且Raycast Target是true的情况
它会传递给Text或者 其他遮挡物 而Button 不会收到点击消息 所以如果想要下层百分百生效 最好的情况是
把Button 下面的遮挡物 Raycast Target设置为false 因为如果一直往下传递的话
当前点击的位置无论叠加多少层Button 他都会响应 所以一直往下传递是不可控的情况
2.下层Toggle没响应问题
再有一种情况是Toggle 我在UI上的Toggle 自身没有Image 组件 Toggle的Target Graphic
设置的是Background 然后事件传递到Backgeround 之后 Toggle并没有响应 所以如果想让Toggle也响应该事件
需要将Toggle的Target Graphic设置为自身 给Toggle添加一个Image 并且Raycast Target 设置为true 并且没有遮挡物即可
总结注意下一层是什么 有可能是你不知道的东西阻挡了 所以没有达到你的效果
*/
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c3984fa60b73484ea0cb07d95f4e0c5f
timeCreated: 1727426512

View File

@@ -0,0 +1,62 @@
using UnityEngine;
using UnityEngine.UI;
namespace YIUIFramework
{
/// <summary>
/// 不可见的一个图用来阻挡UI的投射。
/// </summary>
public class UIBlock : Graphic, ICanvasRaycastFilter
{
public override bool raycastTarget
{
get => true;
set { }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "Reviewed. Suppression is OK here.")]
public override Texture mainTexture
{
get { return null; }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "Reviewed. Suppression is OK here.")]
public override Material materialForRendering
{
get { return null; }
}
public bool IsRaycastLocationValid(
Vector2 screenPoint, Camera eventCamera)
{
return true;
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
}
public override void SetAllDirty()
{
}
public override void SetLayoutDirty()
{
}
public override void SetVerticesDirty()
{
}
public override void SetMaterialDirty()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 189105a42ee74f83ba5487327c2d3580
timeCreated: 1683685551

View File

@@ -0,0 +1,113 @@
using UnityEngine;
using UnityEngine.UI;
namespace YIUIFramework
{
/// <summary>
/// 图像与多边形块
/// </summary>
[RequireComponent(typeof(PolygonCollider2D))]
public sealed class UIBlockPolygon : Graphic, ICanvasRaycastFilter
{
public override bool raycastTarget
{
get { return true; }
set { }
}
private PolygonCollider2D polygon = null;
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "Reviewed. Suppression is OK here.")]
public override Texture mainTexture
{
get { return null; }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "Reviewed. Suppression is OK here.")]
public override Material materialForRendering
{
get { return null; }
}
private PolygonCollider2D Polygon
{
get
{
if (this.polygon == null)
{
this.polygon = this.GetComponent<PolygonCollider2D>();
Physics2D.Simulate(0);
}
return this.polygon;
}
}
public bool IsRaycastLocationValid(
Vector2 screenPoint, Camera eventCamera)
{
if (eventCamera != null)
{
Vector3 worldPoint;
if (RectTransformUtility.ScreenPointToWorldPointInRectangle(
this.rectTransform,
screenPoint,
eventCamera,
out worldPoint))
{
return this.Polygon.OverlapPoint(worldPoint);
}
return false;
}
else
{
return this.Polygon.OverlapPoint(screenPoint);
}
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
}
public override void SetAllDirty()
{
}
public override void SetLayoutDirty()
{
}
public override void SetVerticesDirty()
{
}
public override void SetMaterialDirty()
{
}
#if UNITY_EDITOR
protected override void Reset()
{
base.Reset();
this.transform.localPosition = Vector3.zero;
float w = (this.rectTransform.sizeDelta.x * 0.5f) + 0.1f;
float h = (this.rectTransform.sizeDelta.y * 0.5f) + 0.1f;
this.Polygon.points = new Vector2[]
{
new Vector2(-w, -h),
new Vector2(w, -h),
new Vector2(w, h),
new Vector2(-w, h)
};
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f08f0e78a63f4f3fa2552a445caabfc8
timeCreated: 1683685651