feat: TransitionAutoPlaySpeed, TransitionTexSpeed, and EdgeShinyAutoPlaySpeed are previewed only when the object is selected in edit mode

close #319
This commit is contained in:
mob-sakai
2025-03-13 09:16:44 +09:00
parent 2540b75349
commit 952a94f50b
5 changed files with 62 additions and 5 deletions
+15
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Coffee.UIEffectInternal;
using UnityEngine;
using UnityEngine.Rendering;
@@ -988,6 +989,20 @@ namespace Coffee.UIEffects
context?.SetGradationDirty();
base.OnValidate();
}
internal override void SetEnablePreviewIfSelected(GameObject[] selection)
{
var selected = 0 < selection.Length
&& (selection.Contains(gameObject)
|| replicas.Any(x => x && selection.Contains(x.gameObject)));
context.SetEnablePreview(selected, effectMaterial);
foreach (var r in replicas)
{
if (!r || !r.isActiveAndEnabled || r.context == null) continue;
r.context.SetEnablePreview(selected, r.effectMaterial);
}
}
#endif
protected override void OnBeforeCanvasRebuild()
+13 -1
View File
@@ -26,6 +26,7 @@ namespace Coffee.UIEffects
private bool _canModifyMesh;
private Matrix4x4 _prevTransformHash;
public Material effectMaterial => _material;
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
public virtual uint effectId => (uint)GetInstanceID();
public virtual float actualSamplingScale => 1;
@@ -153,6 +154,10 @@ namespace Coffee.UIEffects
{
OnValidate();
}
internal virtual void SetEnablePreviewIfSelected(GameObject[] selection)
{
}
#endif
protected override void OnRectTransformDimensionsChange()
@@ -207,10 +212,17 @@ namespace Coffee.UIEffects
if (!isActiveAndEnabled || context == null || !material) return;
context.ApplyToMaterial(material, actualSamplingScale);
Misc.QueuePlayerLoopUpdate();
#if UNITY_EDITOR
Profiler.BeginSample("(Editor/UIE)[UIEffect] ApplyContextToMaterial Post Process");
if (!Application.isPlaying)
{
SetEnablePreviewIfSelected(Selection.gameObjects);
Misc.QueuePlayerLoopUpdate();
}
UIEffectProjectSettings.shaderRegistry.RegisterVariant(material, "UI > UIEffect");
Profiler.EndSample();
#endif
}
+8
View File
@@ -429,6 +429,14 @@ namespace Coffee.UIEffects
Profiler.EndSample();
}
public void SetEnablePreview(bool enable, Material material)
{
if (!material) return;
material.SetVector(s_TransitionTex_Speed, enable ? (Vector4)transitionTexSpeed : Vector4.zero);
material.SetFloat(s_TransitionAutoPlaySpeed, enable ? transitionAutoPlaySpeed : 0);
material.SetFloat(s_EdgeShinyAutoPlaySpeed, enable ? edgeShinyAutoPlaySpeed : 0);
}
private static void SetKeyword(Material material, string[] keywords, int index)
{
for (var i = 0; i < keywords.Length; i++)
@@ -128,6 +128,24 @@ namespace Coffee.UIEffects
("c67f821adbb6348a3a21573a25b55de0", "Hidden-TMP_SDF-UIEffect-Unity6.shader")
});
EditorApplication.update += ShaderSampleImporter.Update;
Selection.selectionChanged += () =>
{
if (Application.isPlaying || Misc.isBatchOrBuilding) return;
var selection = Selection.gameObjects;
foreach (var c in FindAll())
{
if (!c || !c.isActiveAndEnabled) continue;
c.SetEnablePreviewIfSelected(selection);
}
};
}
private static IEnumerable<UIEffectBase> FindAll()
{
return Misc.FindObjectsOfType<UIEffectBase>()
.Concat(Misc.GetAllComponentsInPrefabStage<UIEffectBase>());
}
protected override void OnEnable()
@@ -222,8 +240,7 @@ namespace Coffee.UIEffects
}
// Refresh all UIEffect instances.
foreach (var c in Misc.FindObjectsOfType<UIEffectBase>()
.Concat(Misc.GetAllComponentsInPrefabStage<UIEffectBase>()))
foreach (var c in FindAll())
{
c.ReleaseMaterial();
}
@@ -232,8 +249,7 @@ namespace Coffee.UIEffects
// Refresh all UIEffect instances.
EditorApplication.delayCall += () =>
{
foreach (var c in Misc.FindObjectsOfType<UIEffectBase>()
.Concat(Misc.GetAllComponentsInPrefabStage<UIEffectBase>()))
foreach (var c in FindAll())
{
c.SetMaterialDirty();
c.SetVerticesDirty();
+6
View File
@@ -89,6 +89,12 @@ namespace Coffee.UIEffects
RefreshTarget(target);
base.OnValidate();
}
internal override void SetEnablePreviewIfSelected(GameObject[] selection)
{
if (!target) return;
target.SetEnablePreviewIfSelected(selection);
}
#endif
private void RefreshTarget(UIEffect newTarget)