You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
81
Assets/3rd/UIEffect/Scripts/UISyncEffect.cs
Normal file
81
Assets/3rd/UIEffect/Scripts/UISyncEffect.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace Coffee.UIEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// Dissolve effect for uGUI.
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
public class UISyncEffect : BaseMaterialEffect
|
||||
{
|
||||
[Tooltip("The target effect to synchronize.")] [SerializeField]
|
||||
private BaseMeshEffect m_TargetEffect;
|
||||
|
||||
public BaseMeshEffect targetEffect
|
||||
{
|
||||
get { return this.m_TargetEffect != this ? this.m_TargetEffect : null; }
|
||||
set
|
||||
{
|
||||
if (this.m_TargetEffect == value) return;
|
||||
this.m_TargetEffect = value;
|
||||
|
||||
SetVerticesDirty();
|
||||
SetMaterialDirty();
|
||||
SetEffectParamsDirty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (this.targetEffect) this.targetEffect.syncEffects.Add(this);
|
||||
base.OnEnable();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
if (this.targetEffect) this.targetEffect.syncEffects.Remove(this);
|
||||
base.OnDisable();
|
||||
}
|
||||
|
||||
public override Hash128 GetMaterialHash(Material baseMaterial)
|
||||
{
|
||||
if (!this.isActiveAndEnabled) return k_InvalidHash;
|
||||
|
||||
var matEffect = this.targetEffect as BaseMaterialEffect;
|
||||
if (!matEffect || !matEffect.isActiveAndEnabled) return k_InvalidHash;
|
||||
|
||||
return matEffect.GetMaterialHash(baseMaterial);
|
||||
}
|
||||
|
||||
public override void ModifyMaterial(Material newMaterial, Graphic graphic)
|
||||
{
|
||||
if (!this.isActiveAndEnabled) return;
|
||||
|
||||
var matEffect = this.targetEffect as BaseMaterialEffect;
|
||||
if (!matEffect || !matEffect.isActiveAndEnabled) return;
|
||||
|
||||
matEffect.ModifyMaterial(newMaterial, graphic);
|
||||
}
|
||||
|
||||
public override void ModifyMesh(VertexHelper vh, Graphic graphic)
|
||||
{
|
||||
if (!this.isActiveAndEnabled) return;
|
||||
if (!this.targetEffect || !this.targetEffect.isActiveAndEnabled) return;
|
||||
|
||||
this.targetEffect.ModifyMesh(vh, graphic);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnValidate()
|
||||
{
|
||||
SetVerticesDirty();
|
||||
SetMaterialDirty();
|
||||
SetEffectParamsDirty();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user