mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-19 17:22:37 +08:00
feat: Allow specifying a preset as the target for UIEffectReplica
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Coffee.UIEffects.Editors
|
||||
{
|
||||
@@ -14,6 +15,7 @@ namespace Coffee.UIEffects.Editors
|
||||
private SerializedProperty _samplingScale;
|
||||
private SerializedProperty _allowToModifyMeshShape;
|
||||
private SerializedProperty _flip;
|
||||
private SerializedProperty _customRoot;
|
||||
private Editor _uiEffectEditor;
|
||||
|
||||
private void OnEnable()
|
||||
@@ -23,13 +25,43 @@ namespace Coffee.UIEffects.Editors
|
||||
_samplingScale = serializedObject.FindProperty("m_SamplingScale");
|
||||
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
|
||||
_flip = serializedObject.FindProperty("m_Flip");
|
||||
_customRoot = serializedObject.FindProperty("m_CustomRoot");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(_target);
|
||||
|
||||
var r = EditorGUILayout.GetControlRect();
|
||||
r.width -= 60;
|
||||
EditorGUI.PropertyField(r, _target);
|
||||
|
||||
// Preset button.
|
||||
r.x += r.width;
|
||||
r.width = 60;
|
||||
if (GUI.Button(r, EditorGUIUtility.TrTempContent("Preset"), "MiniPopup"))
|
||||
{
|
||||
UIEffectEditor.DropDownPreset(r, x => !x.builtin, p =>
|
||||
{
|
||||
_target.objectReferenceValue = p;
|
||||
_target.serializedObject.ApplyModifiedProperties();
|
||||
});
|
||||
}
|
||||
|
||||
// Preset mode warning.
|
||||
if (_target.objectReferenceValue is UIEffect targetEffect && !targetEffect.gameObject.scene.IsValid())
|
||||
{
|
||||
r = EditorGUILayout.GetControlRect();
|
||||
r.width -= EditorGUIUtility.labelWidth;
|
||||
r.x += EditorGUIUtility.labelWidth;
|
||||
EditorGUI.HelpBox(r, "The target effect is not in the scene. (Preset mode)", MessageType.Warning);
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(_useTargetTransform);
|
||||
EditorGUI.BeginDisabledGroup(_useTargetTransform.boolValue);
|
||||
EditorGUILayout.PropertyField(_customRoot);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUILayout.PropertyField(_samplingScale);
|
||||
EditorGUILayout.PropertyField(_allowToModifyMeshShape);
|
||||
EditorGUILayout.PropertyField(_flip);
|
||||
|
||||
@@ -1339,7 +1339,7 @@ namespace Coffee.UIEffects
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
protected override void UpdateContext(UIEffectContext c)
|
||||
internal override void UpdateContext(UIEffectContext c)
|
||||
{
|
||||
c.toneFilter = m_ToneFilter;
|
||||
c.toneIntensity = m_ToneIntensity;
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace Coffee.UIEffects
|
||||
MaterialRepository.Release(ref _material);
|
||||
}
|
||||
|
||||
protected abstract void UpdateContext(UIEffectContext c);
|
||||
internal abstract void UpdateContext(UIEffectContext c);
|
||||
|
||||
public virtual void ApplyContextToMaterial(Material material)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace Coffee.UIEffects
|
||||
[SerializeField]
|
||||
protected bool m_AllowToModifyMeshShape = true;
|
||||
|
||||
[SerializeField]
|
||||
protected RectTransform m_CustomRoot = null;
|
||||
|
||||
[SerializeField]
|
||||
protected Flip m_Flip = 0;
|
||||
|
||||
@@ -45,6 +48,17 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
public RectTransform customRoot
|
||||
{
|
||||
get => m_CustomRoot;
|
||||
set
|
||||
{
|
||||
if (m_CustomRoot == value) return;
|
||||
m_CustomRoot = value;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public float samplingScale
|
||||
{
|
||||
get => m_SamplingScale;
|
||||
@@ -84,11 +98,25 @@ namespace Coffee.UIEffects
|
||||
public override bool canModifyShape => m_AllowToModifyMeshShape;
|
||||
|
||||
public override uint effectId => target ? target.effectId : 0;
|
||||
public override UIEffectContext context => target && target.isActiveAndEnabled ? target.context : null;
|
||||
|
||||
public override RectTransform transitionRoot => useTargetTransform && target
|
||||
public override UIEffectContext context
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!target) return null;
|
||||
if (!isTargetInScene) return base.context;
|
||||
|
||||
return target.isActiveAndEnabled ? target.context : null;
|
||||
}
|
||||
}
|
||||
|
||||
public override RectTransform transitionRoot => useTargetTransform && isTargetInScene
|
||||
? target.transitionRoot
|
||||
: transform as RectTransform;
|
||||
: m_CustomRoot
|
||||
? m_CustomRoot
|
||||
: transform as RectTransform;
|
||||
|
||||
private bool isTargetInScene => target && target.gameObject.scene.IsValid();
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
@@ -117,7 +145,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
internal override void SetEnablePreviewIfSelected(GameObject[] selection)
|
||||
{
|
||||
if (!target) return;
|
||||
if (!isTargetInScene) return;
|
||||
target.SetEnablePreviewIfSelected(selection);
|
||||
}
|
||||
#endif
|
||||
@@ -130,10 +158,17 @@ namespace Coffee.UIEffects
|
||||
_currentTarget.replicas.Remove(this);
|
||||
}
|
||||
|
||||
_currentTarget = newTarget;
|
||||
if (_currentTarget)
|
||||
if (newTarget)
|
||||
{
|
||||
_currentTarget.replicas.Add(this);
|
||||
_currentTarget = newTarget;
|
||||
if (isTargetInScene)
|
||||
{
|
||||
_currentTarget.replicas.Add(this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,19 +176,24 @@ namespace Coffee.UIEffects
|
||||
{
|
||||
base.OnBeforeCanvasRebuild();
|
||||
|
||||
if (useTargetTransform && target && CheckTransformChangedWith(target.transform))
|
||||
if (useTargetTransform && isTargetInScene && CheckTransformChangedWith(target.transform))
|
||||
{
|
||||
SetVerticesDirty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateContext(UIEffectContext c)
|
||||
internal override void UpdateContext(UIEffectContext c)
|
||||
{
|
||||
if (target && !isTargetInScene)
|
||||
{
|
||||
target.UpdateContext(c);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ApplyContextToMaterial(Material material)
|
||||
{
|
||||
if (!isActiveAndEnabled || !target || !target.isActiveAndEnabled) return;
|
||||
if (!isActiveAndEnabled || !target) return;
|
||||
if (isTargetInScene && !target.isActiveAndEnabled) return;
|
||||
|
||||
base.ApplyContextToMaterial(material);
|
||||
}
|
||||
@@ -164,7 +204,9 @@ namespace Coffee.UIEffects
|
||||
|
||||
public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
|
||||
{
|
||||
return !target || target.IsRaycastLocationValid(sp, eventCamera);
|
||||
if (!isActiveAndEnabled || !isTargetInScene) return true;
|
||||
|
||||
return target.IsRaycastLocationValid(sp, eventCamera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,11 +219,6 @@ namespace Coffee.UIEffects
|
||||
|
||||
s_RegisteredInstances.Add(textMeshProUGUI);
|
||||
var effect = textMeshProUGUI.GetComponent<UIEffectBase>();
|
||||
var target = effect is UIEffect uiEffect
|
||||
? uiEffect
|
||||
: effect is UIEffectReplica parentReplica
|
||||
? parentReplica.target
|
||||
: null;
|
||||
var subMeshes = InternalListPool<TMP_SubMeshUI>.Rent();
|
||||
var modifiers = InternalListPool<IMeshModifier>.Rent();
|
||||
var subModifiers = InternalListPool<IMeshModifier>.Rent();
|
||||
@@ -256,16 +251,31 @@ namespace Coffee.UIEffects
|
||||
var subMeshUI = GetSubMeshUI(subMeshes, meshInfo.material, i - 1);
|
||||
if (!subMeshUI) break;
|
||||
|
||||
if (target)
|
||||
var replica = subMeshUI.GetOrAddComponent<UIEffectReplica>();
|
||||
if (effect is UIEffect pEffect && pEffect.isActiveAndEnabled)
|
||||
{
|
||||
var replica = subMeshUI.GetOrAddComponent<UIEffectReplica>();
|
||||
replica.target = target;
|
||||
replica.target = pEffect;
|
||||
replica.useTargetTransform = true;
|
||||
replica.customRoot = null;
|
||||
replica.flip = pEffect.flip;
|
||||
}
|
||||
else if (effect is UIEffectReplica pReplica && pReplica.isActiveAndEnabled)
|
||||
{
|
||||
replica.target = pReplica.target;
|
||||
replica.useTargetTransform = pReplica.useTargetTransform;
|
||||
replica.customRoot = pReplica.customRoot;
|
||||
replica.flip = pReplica.flip;
|
||||
}
|
||||
else
|
||||
{
|
||||
replica.target = null;
|
||||
replica.customRoot = null;
|
||||
}
|
||||
|
||||
subMeshUI.GetComponents(subModifiers);
|
||||
foreach (var modifier in subModifiers)
|
||||
{
|
||||
modifier.ModifyMesh(s_VertexHelper);
|
||||
}
|
||||
subMeshUI.GetComponents(subModifiers);
|
||||
foreach (var modifier in subModifiers)
|
||||
{
|
||||
modifier.ModifyMesh(s_VertexHelper);
|
||||
}
|
||||
|
||||
s_VertexHelper.FillMesh(s_Mesh);
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace Coffee.UIEffects
|
||||
effectPlayer.OnDisable();
|
||||
}
|
||||
|
||||
protected override void UpdateContext(UIEffectContext c)
|
||||
internal override void UpdateContext(UIEffectContext c)
|
||||
{
|
||||
c.transitionFilter = TransitionFilter.Dissolve;
|
||||
c.transitionRate = m_EffectFactor;
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void UpdateContext(UIEffectContext c)
|
||||
internal override void UpdateContext(UIEffectContext c)
|
||||
{
|
||||
(c.toneFilter, c.samplingFilter) = (m_EffectMode, m_BlurMode).Convert();
|
||||
if (context.samplingFilter == SamplingFilter.Pixelation)
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Coffee.UIEffects
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void UpdateContext(UIEffectContext c)
|
||||
internal override void UpdateContext(UIEffectContext c)
|
||||
{
|
||||
c.colorFilter = ColorFilter.HsvModifier;
|
||||
c.colorIntensity = 1;
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace Coffee.UIEffects
|
||||
effectPlayer.Stop(reset);
|
||||
}
|
||||
|
||||
protected override void UpdateContext(UIEffectContext c)
|
||||
internal override void UpdateContext(UIEffectContext c)
|
||||
{
|
||||
c.transitionFilter = TransitionFilter.Shiny;
|
||||
c.transitionRate = m_EffectFactor;
|
||||
|
||||
@@ -237,7 +237,7 @@ namespace Coffee.UIEffects
|
||||
return !passRayOnHidden || effectFactor < 1;
|
||||
}
|
||||
|
||||
protected override void UpdateContext(UIEffectContext c)
|
||||
internal override void UpdateContext(UIEffectContext c)
|
||||
{
|
||||
c.transitionFilter = m_EffectMode.Convert();
|
||||
c.transitionRate = m_EffectFactor;
|
||||
|
||||
Reference in New Issue
Block a user