养成基本完毕,新UI,修bug,装备初步,

This commit is contained in:
FloatGaming
2026-03-23 22:37:14 +08:00
parent 49e45ac464
commit dd205b6cb4
2349 changed files with 261722 additions and 283 deletions
@@ -0,0 +1,250 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
public class idolMaterialController : MonoBehaviour
{
public enum SweepSide
{
FromLeft = 0,
FromRight = 1,
}
[Header("Material")]
public Material materialTemplate;
[Header("Animation")]
public SweepSide enterDirection = SweepSide.FromLeft;
public SweepSide exitDirection = SweepSide.FromRight;
public float enterDuration = 0.35f;
public float exitDuration = 0.25f;
[Range(0f, 1f)]
public float hiddenAmount = 0f;
[Range(0f, 1f)]
public float shownAmount = 1f;
public bool playEnterOnEnable = false;
private Image image;
private Material runtimeMaterial;
private Coroutine transitionCoroutine;
private Sprite pendingSprite;
private static readonly int DissolveAmountId = Shader.PropertyToID("_DissolveAmount");
private static readonly int DirectionId = Shader.PropertyToID("_Direction");
private void Awake()
{
image = GetComponent<Image>();
EnsureRuntimeMaterial();
ApplyInstantState(shownAmount, GetShaderDirectionForEnter(enterDirection));
}
private void OnEnable()
{
EnsureRuntimeMaterial();
if (playEnterOnEnable && image != null && image.sprite != null)
{
PlayEnter();
}
else
{
ApplyInstantState(shownAmount, GetShaderDirectionForEnter(enterDirection));
}
}
private void OnDisable()
{
if (transitionCoroutine != null)
{
StopCoroutine(transitionCoroutine);
transitionCoroutine = null;
}
}
private void OnDestroy()
{
if (runtimeMaterial != null)
{
if (image != null && image.material == runtimeMaterial)
{
image.material = null;
}
Destroy(runtimeMaterial);
}
}
public void SetSpriteImmediate(Sprite sprite)
{
EnsureRuntimeMaterial();
if (image == null)
{
return;
}
image.sprite = sprite;
ApplyInstantState(shownAmount, GetShaderDirectionForEnter(enterDirection));
}
public void PlayEnter()
{
EnsureRuntimeMaterial();
if (image == null || runtimeMaterial == null)
{
return;
}
if (transitionCoroutine != null)
{
StopCoroutine(transitionCoroutine);
}
transitionCoroutine = StartCoroutine(AnimateAmount(hiddenAmount, shownAmount, Mathf.Max(0.01f, enterDuration), GetShaderDirectionForEnter(enterDirection), null));
}
public void PlayExit()
{
EnsureRuntimeMaterial();
if (image == null || runtimeMaterial == null)
{
return;
}
if (transitionCoroutine != null)
{
StopCoroutine(transitionCoroutine);
}
transitionCoroutine = StartCoroutine(AnimateAmount(shownAmount, hiddenAmount, Mathf.Max(0.01f, exitDuration), GetShaderDirectionForExit(exitDirection), null));
}
public void TransitionToSprite(Sprite sprite)
{
EnsureRuntimeMaterial();
if (image == null)
{
return;
}
pendingSprite = sprite;
if (transitionCoroutine != null)
{
StopCoroutine(transitionCoroutine);
}
bool hasCurrentSprite = image.sprite != null;
bool spriteChanged = image.sprite != sprite;
transitionCoroutine = StartCoroutine(TransitionRoutine(hasCurrentSprite, spriteChanged));
}
private IEnumerator TransitionRoutine(bool hasCurrentSprite, bool spriteChanged)
{
if (runtimeMaterial == null || image == null)
{
yield break;
}
if (hasCurrentSprite && spriteChanged)
{
yield return AnimateAmount(shownAmount, hiddenAmount, Mathf.Max(0.01f, exitDuration), GetShaderDirectionForExit(exitDirection), null);
}
image.sprite = pendingSprite;
if (pendingSprite == null)
{
ApplyInstantState(hiddenAmount, GetShaderDirectionForEnter(enterDirection));
transitionCoroutine = null;
yield break;
}
yield return AnimateAmount(hiddenAmount, shownAmount, Mathf.Max(0.01f, enterDuration), GetShaderDirectionForEnter(enterDirection), null);
transitionCoroutine = null;
}
private IEnumerator AnimateAmount(float from, float to, float duration, float directionValue, System.Action onComplete)
{
if (runtimeMaterial == null)
{
yield break;
}
runtimeMaterial.SetFloat(DirectionId, directionValue);
runtimeMaterial.SetFloat(DissolveAmountId, from);
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.unscaledDeltaTime;
float t = Mathf.Clamp01(elapsed / duration);
runtimeMaterial.SetFloat(DissolveAmountId, Mathf.Lerp(from, to, t));
yield return null;
}
runtimeMaterial.SetFloat(DissolveAmountId, to);
onComplete?.Invoke();
}
private void ApplyInstantState(float amount, float directionValue)
{
EnsureRuntimeMaterial();
if (runtimeMaterial == null)
{
return;
}
runtimeMaterial.SetFloat(DirectionId, directionValue);
runtimeMaterial.SetFloat(DissolveAmountId, Mathf.Clamp01(amount));
}
private void EnsureRuntimeMaterial()
{
if (image == null)
{
image = GetComponent<Image>();
}
if (image == null)
{
return;
}
Material source = materialTemplate != null
? materialTemplate
: image.material;
if (source == null)
{
return;
}
if (runtimeMaterial != null && runtimeMaterial.shader == source.shader)
{
if (image.material != runtimeMaterial)
{
image.material = runtimeMaterial;
}
return;
}
if (runtimeMaterial != null)
{
Destroy(runtimeMaterial);
}
runtimeMaterial = new Material(source);
runtimeMaterial.name = source.name + " (idol runtime)";
image.material = runtimeMaterial;
}
private static float GetShaderDirectionForEnter(SweepSide side)
{
return side == SweepSide.FromLeft ? 0f : 1f;
}
private static float GetShaderDirectionForExit(SweepSide side)
{
return side == SweepSide.FromLeft ? 1f : 0f;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d5ba3f6cc7c25934d9454cef8e2238d2
+70
View File
@@ -0,0 +1,70 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: material_idol
m_Shader: {fileID: 4800000, guid: 34e07e2b8017ff642a00f89a5485a325, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- UNITY_UI_ALPHACLIP
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 1
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
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}
- _MaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BlockCountX: 33
- _BlockCountY: 84
- _ColorMask: 15
- _Direction: 0
- _DissolveAmount: 1
- _DissolveColorOpacity: 0.2
- _EdgeWidth: 0.137
- _EnableExternalAlpha: 0
- _GlitchJitter: 0.1
- _GlitchRgbSplit: 0.0156
- _GlitchStripeIntensity: 0.141
- _GlowIntensity: 0.95
- _NoiseScale: 107
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UseUIAlphaClip: 1
- _ZWrite: 0
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _DissolveColor: {r: 1.5952897, g: 0, b: 4.7609406, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b1cac587f3017934696a268317218ce7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant: