ui基本完毕,修了一大把的bug

This commit is contained in:
FloatGaming
2026-07-13 02:28:39 +08:00
parent 1e20d73e90
commit fd22501f71
958 changed files with 378289 additions and 41038 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Artyom Sovetnikov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 122bd61b1d27e1c4a877a23cf2f9b16e
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ace73f7a7e4482a4181e5d03b2451e97
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 465cdadf8542ec84b903ca3aa97e2568
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 83705c0b31b26e640ae3aabe9d44f996
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,240 @@
// Draws an HDR outline over the sprite borders.
// Based on Sprites/Default shader from Unity 2017.3.
Shader "Sprites/Outline"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Color("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap("Pixel snap", Float) = 0
[HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {}
[PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0
[MaterialToggle] _IsOutlineEnabled("Enable Outline", float) = 0
[HDR] _OutlineColor("Outline Color", Color) = (1,1,1,1)
_OutlineSize("Outline Size", Range(1, 10)) = 1
_AlphaThreshold("Alpha Threshold", Range(0, 1)) = 0.01
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex ComputeVertex
#pragma fragment ComputeFragment
#pragma target 2.0
#pragma multi_compile_instancing
#pragma multi_compile_local _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma multi_compile _ SPRITE_OUTLINE_OUTSIDE
#ifndef SAMPLE_DEPTH_LIMIT
#define SAMPLE_DEPTH_LIMIT 10
#endif
#ifdef UNITY_INSTANCING_ENABLED
UNITY_INSTANCING_BUFFER_START(PerDrawSprite)
UNITY_DEFINE_INSTANCED_PROP(fixed4, unity_SpriteRendererColorArray)
UNITY_DEFINE_INSTANCED_PROP(fixed2, unity_SpriteFlipArray)
UNITY_INSTANCING_BUFFER_END(PerDrawSprite)
#define _RendererColor UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteRendererColorArray)
#define _Flip UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteFlipArray)
UNITY_INSTANCING_BUFFER_START(PerDrawSpriteOutline)
UNITY_DEFINE_INSTANCED_PROP(float, _IsOutlineEnabledArray)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _OutlineColorArray)
UNITY_DEFINE_INSTANCED_PROP(float, _OutlineSizeArray)
UNITY_DEFINE_INSTANCED_PROP(float, _AlphaThresholdArray)
UNITY_INSTANCING_BUFFER_END(PerDrawSpriteOutline)
#define _IsOutlineEnabled UNITY_ACCESS_INSTANCED_PROP(PerDrawSpriteOutline, _IsOutlineEnabledArray)
#define _OutlineColor UNITY_ACCESS_INSTANCED_PROP(PerDrawSpriteOutline, _OutlineColorArray)
#define _OutlineSize UNITY_ACCESS_INSTANCED_PROP(PerDrawSpriteOutline, _OutlineSizeArray)
#define _AlphaThreshold UNITY_ACCESS_INSTANCED_PROP(PerDrawSpriteOutline, _AlphaThresholdArray)
#endif
CBUFFER_START(UnityPerDrawSprite)
#ifndef UNITY_INSTANCING_ENABLED
fixed4 _RendererColor;
fixed2 _Flip;
#endif
float _EnableExternalAlpha;
CBUFFER_END
CBUFFER_START(UnityPerDrawSpriteOutline)
#ifndef UNITY_INSTANCING_ENABLED
fixed4 _OutlineColor;
float _IsOutlineEnabled, _OutlineSize, _AlphaThreshold;
#endif
CBUFFER_END
sampler2D _MainTex, _AlphaTex;
float4 _MainTex_TexelSize;
fixed4 _Color;
struct VertexInput
{
float4 Vertex : POSITION;
float4 Color : COLOR;
float2 TexCoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VertexOutput
{
float4 Vertex : SV_POSITION;
fixed4 Color : COLOR;
float2 TexCoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
inline float4 UnityFlipSprite(in float3 pos, in fixed2 flip)
{
return float4(pos.xy * flip, pos.z, 1.0);
}
VertexOutput ComputeVertex(VertexInput vertexInput)
{
VertexOutput vertexOutput;
UNITY_SETUP_INSTANCE_ID(vertexInput);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(vertexOutput);
vertexOutput.Vertex = UnityFlipSprite(vertexInput.Vertex, _Flip);
vertexOutput.Vertex = UnityObjectToClipPos(vertexInput.Vertex);
vertexOutput.TexCoord = vertexInput.TexCoord;
vertexOutput.Color = vertexInput.Color * _Color * _RendererColor;
#ifdef PIXELSNAP_ON
vertexOutput.Vertex = UnityPixelSnap(vertexOutput.Vertex);
#endif
return vertexOutput;
}
// Determines whether _OutlineColor should replace sampledColor at the given texCoord when drawing inside the sprite borders.
// Will return 1 when the test is positive (should draw outline), 0 otherwise.
int ShouldDrawOutlineInside (fixed4 sampledColor, float2 texCoord, int isOutlineEnabled, int outlineSize, float alphaThreshold)
{
// Won't draw if effect is disabled, outline size is zero or sampled fragment is tranpsarent.
if (isOutlineEnabled * outlineSize * sampledColor.a == 0) return 0;
float2 texDdx = ddx(texCoord);
float2 texDdy = ddy(texCoord);
// Looking for a transparent pixel (sprite border from inside) around computed fragment with given depth (_OutlineSize).
// Also checking if sampled fragment is out of the texture space (UV is out of 0-1 range); considering such fragment as sprite border.
for (int i = 1; i <= SAMPLE_DEPTH_LIMIT; i++)
{
float2 pixelUpTexCoord = texCoord + float2(0, i * _MainTex_TexelSize.y);
fixed pixelUpAlpha = pixelUpTexCoord.y > 1.0 ? 0.0 : tex2Dgrad(_MainTex, pixelUpTexCoord, texDdx, texDdy).a;
if (pixelUpAlpha <= alphaThreshold) return 1;
float2 pixelDownTexCoord = texCoord - float2(0, i * _MainTex_TexelSize.y);
fixed pixelDownAlpha = pixelDownTexCoord.y < 0.0 ? 0.0 : tex2Dgrad(_MainTex, pixelDownTexCoord, texDdx, texDdy).a;
if (pixelDownAlpha <= alphaThreshold) return 1;
float2 pixelRightTexCoord = texCoord + float2(i * _MainTex_TexelSize.x, 0);
fixed pixelRightAlpha = pixelRightTexCoord.x > 1.0 ? 0.0 : tex2Dgrad(_MainTex, pixelRightTexCoord, texDdx, texDdy).a;
if (pixelRightAlpha <= alphaThreshold) return 1;
float2 pixelLeftTexCoord = texCoord - float2(i * _MainTex_TexelSize.x, 0);
fixed pixelLeftAlpha = pixelLeftTexCoord.x < 0.0 ? 0.0 : tex2Dgrad(_MainTex, pixelLeftTexCoord, texDdx, texDdy).a;
if (pixelLeftAlpha <= alphaThreshold) return 1;
if (i > outlineSize) break;
}
return 0;
}
// Determines whether _OutlineColor should replace sampledColor at the given texCoord when drawing outside the sprite borders.
// Will return 1 when the test is positive (should draw outline), 0 otherwise.
int ShouldDrawOutlineOutside (fixed4 sampledColor, float2 texCoord, int isOutlineEnabled, int outlineSize, float alphaThreshold)
{
// Won't draw if effect is disabled, outline size is zero or sampled fragment is above alpha threshold.
if (isOutlineEnabled * outlineSize == 0) return 0;
if (sampledColor.a > alphaThreshold) return 0;
float2 texDdx = ddx(texCoord);
float2 texDdy = ddy(texCoord);
// Looking for an opaque pixel (sprite border from outise) around computed fragment with given depth (_OutlineSize).
for (int i = 1; i <= SAMPLE_DEPTH_LIMIT; i++)
{
float2 pixelUpTexCoord = texCoord + float2(0, i * _MainTex_TexelSize.y);
fixed pixelUpAlpha = tex2Dgrad(_MainTex, pixelUpTexCoord, texDdx, texDdy).a;
if (pixelUpAlpha > alphaThreshold) return 1;
float2 pixelDownTexCoord = texCoord - float2(0, i * _MainTex_TexelSize.y);
fixed pixelDownAlpha = tex2Dgrad(_MainTex, pixelDownTexCoord, texDdx, texDdy).a;
if (pixelDownAlpha > alphaThreshold) return 1;
float2 pixelRightTexCoord = texCoord + float2(i * _MainTex_TexelSize.x, 0);
fixed pixelRightAlpha = tex2Dgrad(_MainTex, pixelRightTexCoord, texDdx, texDdy).a;
if (pixelRightAlpha > alphaThreshold) return 1;
float2 pixelLeftTexCoord = texCoord - float2(i * _MainTex_TexelSize.x, 0);
fixed pixelLeftAlpha = tex2Dgrad(_MainTex, pixelLeftTexCoord, texDdx, texDdy).a;
if (pixelLeftAlpha > alphaThreshold) return 1;
if (i > outlineSize) break;
}
return 0;
}
fixed4 SampleSpriteTexture(float2 uv)
{
fixed4 color = tex2D(_MainTex, uv);
#if ETC1_EXTERNAL_ALPHA
fixed4 alpha = tex2D(_AlphaTex, uv);
color.a = lerp(color.a, alpha.r, _EnableExternalAlpha);
#endif
return color;
}
fixed4 ComputeFragment(VertexOutput vertexOutput) : SV_Target
{
fixed4 color = SampleSpriteTexture(vertexOutput.TexCoord) * vertexOutput.Color;
color.rgb *= color.a;
#ifdef SPRITE_OUTLINE_OUTSIDE
int shouldDrawOutline = ShouldDrawOutlineOutside(color, vertexOutput.TexCoord, _IsOutlineEnabled, _OutlineSize, _AlphaThreshold);
#else
int shouldDrawOutline = ShouldDrawOutlineInside(color, vertexOutput.TexCoord, _IsOutlineEnabled, _OutlineSize, _AlphaThreshold);
#endif
color.rgb = lerp(color.rgb, _OutlineColor.rgb * _OutlineColor.a, shouldDrawOutline);
return color;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c20308b0e23b78d4c85098af31f19cb4
timeCreated: 1473362089
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e97733e71c7a1b04f8da98e3d94b5a69
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,3 @@
{
"name": "Elringus.SpriteGlow.Runtime"
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c7027099d74e3bf40a721835d6ab892e
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,193 @@
using System.Collections;
using UnityEngine;
namespace SpriteGlow
{
/// <summary>
/// Adds an HDR outline over the SpriteRenderer's sprite borders.
/// Can be used in conjuction with bloom post-processing to create a glow effect.
/// </summary>
[AddComponentMenu("Effects/Sprite Glow")]
[RequireComponent(typeof(SpriteRenderer)), DisallowMultipleComponent, ExecuteInEditMode]
public class SpriteGlowEffect : MonoBehaviour
{
public SpriteRenderer Renderer { get; private set; }
public Color GlowColor
{
get => glowColor;
set { if (glowColor != value) { glowColor = value; SetMaterialProperties(); } }
}
public float GlowBrightness
{
get => glowBrightness;
set { if (glowBrightness != value) { glowBrightness = value; SetMaterialProperties(); } }
}
public int OutlineWidth
{
get => outlineWidth;
set { if (outlineWidth != value) { outlineWidth = value; SetMaterialProperties(); } }
}
public float AlphaThreshold
{
get => alphaThreshold;
set { if (alphaThreshold != value) { alphaThreshold = value; SetMaterialProperties(); } }
}
public bool DrawOutside
{
get => drawOutside;
set { if (drawOutside != value) { drawOutside = value; SetMaterialProperties(); } }
}
public bool EnableInstancing
{
get => enableInstancing;
set { if (enableInstancing != value) { enableInstancing = value; SetMaterialProperties(); } }
}
[Tooltip("Base color of the glow.")]
[SerializeField] private Color glowColor = Color.white;
[Tooltip("The brightness (power) of the glow."), Range(1, 10)]
[SerializeField] private float glowBrightness = 2f;
[Tooltip("Width of the outline, in texels."), Range(0, 10)]
[SerializeField] private int outlineWidth = 1;
[Tooltip("Threshold to determine sprite borders."), Range(0f, 1f)]
[SerializeField] private float alphaThreshold = .01f;
[Tooltip("Whether the outline should only be drawn outside of the sprite borders. Make sure sprite texture has sufficient transparent space for the required outline width.")]
[SerializeField] private bool drawOutside = false;
[Tooltip("Whether to enable GPU instancing.")]
[SerializeField] private bool enableInstancing = false;
private static readonly int isOutlineEnabledId = Shader.PropertyToID("_IsOutlineEnabled");
private static readonly int outlineColorId = Shader.PropertyToID("_OutlineColor");
private static readonly int outlineSizeId = Shader.PropertyToID("_OutlineSize");
private static readonly int alphaThresholdId = Shader.PropertyToID("_AlphaThreshold");
private MaterialPropertyBlock materialProperties;
private Coroutine alphaMonitorRoutine;
private Coroutine alphaFadeRoutine;
private void Awake()
{
Renderer = GetComponent<SpriteRenderer>();
}
private void Start()
{
StartAlphaMonitor();
}
private void OnEnable()
{
SetMaterialProperties();
StartAlphaMonitor();
}
private void OnDisable()
{
if (alphaMonitorRoutine != null)
{
StopCoroutine(alphaMonitorRoutine);
alphaMonitorRoutine = null;
}
if (alphaFadeRoutine != null)
{
StopCoroutine(alphaFadeRoutine);
alphaFadeRoutine = null;
}
SetMaterialProperties();
}
private void OnValidate()
{
if (!isActiveAndEnabled) return;
SetMaterialProperties();
}
private void OnDidApplyAnimationProperties()
{
SetMaterialProperties();
}
private void SetMaterialProperties()
{
if (!Renderer) return;
Renderer.sharedMaterial = SpriteGlowMaterial.GetSharedFor(this);
if (materialProperties == null)
materialProperties = new MaterialPropertyBlock();
materialProperties.SetFloat(isOutlineEnabledId, isActiveAndEnabled ? 1 : 0);
materialProperties.SetColor(outlineColorId, GlowColor * GlowBrightness);
materialProperties.SetFloat(outlineSizeId, OutlineWidth);
materialProperties.SetFloat(alphaThresholdId, AlphaThreshold);
Renderer.SetPropertyBlock(materialProperties);
}
private void StartAlphaMonitor()
{
if (alphaMonitorRoutine != null || Renderer == null)
return;
alphaMonitorRoutine = StartCoroutine(AlphaMonitorRoutine());
}
private IEnumerator AlphaMonitorRoutine()
{
while (true)
{
if (Renderer != null)
{
Color color = Renderer.color;
if (color.a != 0f)
{
if (alphaFadeRoutine == null)
{
alphaFadeRoutine = StartCoroutine(FadeRendererAlphaToZero());
}
yield break;
}
}
yield return new WaitForSecondsRealtime(1f);
}
}
private IEnumerator FadeRendererAlphaToZero()
{
if (Renderer == null)
yield break;
float duration = 0.18f;
float elapsed = 0f;
Color startColor = Renderer.color;
Color endColor = startColor;
endColor.a = 0f;
while (elapsed < duration)
{
if (Renderer == null)
yield break;
elapsed += Time.unscaledDeltaTime;
float t = Mathf.Clamp01(elapsed / duration);
Renderer.color = Color.LerpUnclamped(startColor, endColor, t);
yield return null;
}
if (Renderer != null)
{
Color c = Renderer.color;
c.a = 0f;
Renderer.color = c;
}
alphaFadeRoutine = null;
alphaMonitorRoutine = null;
}
}
}
@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: e8f6d3c6e4250e84192f5b34ce9e71bc
timeCreated: 1497183103
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences:
- spriteOutlineMaterial: {fileID: 2100000, guid: 03131355b57b4a24094896e8d133d808,
type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using UnityEngine;
namespace SpriteGlow
{
public class SpriteGlowMaterial : Material
{
public Texture SpriteTexture => mainTexture;
public bool DrawOutside => IsKeywordEnabled(outsideMaterialKeyword);
public bool InstancingEnabled => enableInstancing;
private const string outlineShaderName = "Sprites/Outline";
private const string outsideMaterialKeyword = "SPRITE_OUTLINE_OUTSIDE";
private static readonly Shader outlineShader = Shader.Find(outlineShaderName);
private static readonly List<SpriteGlowMaterial> sharedMaterials = new List<SpriteGlowMaterial>();
public SpriteGlowMaterial (Texture spriteTexture, bool drawOutside = false, bool instancingEnabled = false)
: base(outlineShader)
{
if (!outlineShader) Debug.LogError($"`{outlineShaderName}` shader not found. Make sure the shader is included to the build.");
mainTexture = spriteTexture;
if (drawOutside) EnableKeyword(outsideMaterialKeyword);
if (instancingEnabled) enableInstancing = true;
}
public static Material GetSharedFor (SpriteGlowEffect spriteGlow)
{
for (int i = 0; i < sharedMaterials.Count; i++)
{
if (sharedMaterials[i].SpriteTexture == spriteGlow.Renderer.sprite.texture &&
sharedMaterials[i].DrawOutside == spriteGlow.DrawOutside &&
sharedMaterials[i].InstancingEnabled == spriteGlow.EnableInstancing)
return sharedMaterials[i];
}
var material = new SpriteGlowMaterial(spriteGlow.Renderer.sprite.texture, spriteGlow.DrawOutside, spriteGlow.EnableInstancing);
material.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor | HideFlags.NotEditable;
sharedMaterials.Add(material);
return material;
}
}
}
@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: a7af5f0dbc0a2fd48b175d8fd1ae86a4
timeCreated: 1497183103
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences:
- spriteOutlineMaterial: {fileID: 2100000, guid: 03131355b57b4a24094896e8d133d808,
type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+11
View File
@@ -0,0 +1,11 @@
{
"name": "com.elringus.spriteglow",
"version": "1.8.0",
"displayName": "SpriteGlow",
"description": "A sprite glow effect for Unity game engine",
"unity": "2019.3",
"author": {
"name": "Elringus",
"url": "https://elringus.me"
}
}
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 34bdb647c1b23044dae93cb1bfe93be1
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: