mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
feat: TransitionAutoPlaySpeed, TransitionTexSpeed, and EdgeShinyAutoPlaySpeed are previewed only when the object is selected in edit mode
close #319
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user