mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-20 18:02:38 +08:00
49d01cac3d
# [4.0.0-preview.1](https://github.com/mob-sakai/UIEffect/compare/v3.2.0...v4.0.0-preview.1) (2020-04-10) ### Bug Fixes * adjusting the brightness of the shiny shader ([29b4dad](https://github.com/mob-sakai/UIEffect/commit/29b4dad9296f22b00687a27c6103820b58cbd890)) * the effect is kept even if the component is disabled (UIFlip, UIGradient) ([6124214](https://github.com/mob-sakai/UIEffect/commit/612421432defaf4e38fa97e12392021e9954027f)) ### Features * add asmdef files ([24710fc](https://github.com/mob-sakai/UIEffect/commit/24710fc892265c16a635ebad0940f779e0c9cdcd)) * new effect that synchronize with another effect ([7a2a97c](https://github.com/mob-sakai/UIEffect/commit/7a2a97c89e90cc94c14fb614544f248824e93f3f)), closes [#159](https://github.com/mob-sakai/UIEffect/issues/159) [#158](https://github.com/mob-sakai/UIEffect/issues/158) [#143](https://github.com/mob-sakai/UIEffect/issues/143) * transfer TextMeshPro support to another package ([be90210](https://github.com/mob-sakai/UIEffect/commit/be90210e6cbf39133bd829e4bf08b9005dd925f4)) * transfer UIEffectCapturedImage support to another package ([c2a2320](https://github.com/mob-sakai/UIEffect/commit/c2a23202e18d103d58d8ebf56851e693f5ac1bb7)) * update docs to support Unity Package Manager ([bdc891a](https://github.com/mob-sakai/UIEffect/commit/bdc891a88ea2b9456276cfe99286c2e799e9c36b)), closes [#141](https://github.com/mob-sakai/UIEffect/issues/141) * update the effect architecture ([4c08c8c](https://github.com/mob-sakai/UIEffect/commit/4c08c8c1621cc8d3a1f5d834c77d925b51331cd5)), closes [#202](https://github.com/mob-sakai/UIEffect/issues/202) [#198](https://github.com/mob-sakai/UIEffect/issues/198) [#195](https://github.com/mob-sakai/UIEffect/issues/195) [#189](https://github.com/mob-sakai/UIEffect/issues/189) [#173](https://github.com/mob-sakai/UIEffect/issues/173) [#104](https://github.com/mob-sakai/UIEffect/issues/104) * update the structure of shaders ([db06e68](https://github.com/mob-sakai/UIEffect/commit/db06e68cfbe3a89e7de9d6ceef841f29f99611a5)) * updated the Unity version used for development to 2018.3 ([c5f22c1](https://github.com/mob-sakai/UIEffect/commit/c5f22c1a3915dd9935b983af1971fa6018f2f320)), closes [#169](https://github.com/mob-sakai/UIEffect/issues/169) ### BREAKING CHANGES * Scenes, prefabs and scripts using UIEffect v3.x may not work properly. * The recommended Unity version is 2018.1 or later; it will work with Unity 2017.1, but it is not guaranteed to be supported. * UIEffectCapturedImage will be supported by another package. * TextMeshPro support has been removed from this package. It will be supported by another package.
239 lines
7.4 KiB
C#
239 lines
7.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Coffee.UIExtensions
|
|
{
|
|
/// <summary>
|
|
/// Base class for effects that modify the generated Mesh.
|
|
/// It works well not only for standard Graphic components (Image, RawImage, Text, etc.) but also for TextMeshPro and TextMeshProUGUI.
|
|
/// </summary>
|
|
[RequireComponent(typeof(Graphic))]
|
|
[RequireComponent(typeof(RectTransform))]
|
|
[ExecuteInEditMode]
|
|
public abstract class BaseMeshEffect : UIBehaviour, IMeshModifier
|
|
{
|
|
RectTransform _rectTransform;
|
|
Graphic _graphic;
|
|
BaseConnector _connector;
|
|
|
|
/// <summary>
|
|
/// The Graphic attached to this GameObject.
|
|
/// </summary>
|
|
protected BaseConnector connector
|
|
{
|
|
get { return _connector ?? (_connector = BaseConnector.FindConnector(graphic)); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Graphic attached to this GameObject.
|
|
/// </summary>
|
|
public Graphic graphic
|
|
{
|
|
get { return _graphic ? _graphic : _graphic = GetComponent<Graphic>(); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// The RectTransform attached to this GameObject.
|
|
/// </summary>
|
|
protected RectTransform rectTransform
|
|
{
|
|
get { return _rectTransform ? _rectTransform : _rectTransform = GetComponent<RectTransform>(); }
|
|
}
|
|
|
|
internal readonly List<UISyncEffect> syncEffects = new List<UISyncEffect>(0);
|
|
|
|
/// <summary>
|
|
/// The material for rendering.
|
|
/// </summary>
|
|
// public virtual Material material
|
|
// {
|
|
// get { return connector.GetMaterial(graphic); }
|
|
// set { connector.SetMaterial(graphic, value); }
|
|
// }
|
|
|
|
/// <summary>
|
|
/// Call used to modify mesh. (legacy)
|
|
/// </summary>
|
|
/// <param name="mesh">Mesh.</param>
|
|
public virtual void ModifyMesh(Mesh mesh)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Call used to modify mesh.
|
|
/// </summary>
|
|
/// <param name="vh">VertexHelper.</param>
|
|
public virtual void ModifyMesh(VertexHelper vh)
|
|
{
|
|
ModifyMesh(vh, graphic);
|
|
}
|
|
|
|
public virtual void ModifyMesh(VertexHelper vh, Graphic graphic)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mark the vertices as dirty.
|
|
/// </summary>
|
|
protected virtual void SetVerticesDirty()
|
|
{
|
|
connector.SetVerticesDirty(graphic);
|
|
|
|
foreach (var effect in syncEffects)
|
|
{
|
|
effect.SetVerticesDirty();
|
|
}
|
|
|
|
// #if TMP_PRESENT
|
|
// if (textMeshPro)
|
|
// {
|
|
// foreach (var info in textMeshPro.textInfo.meshInfo)
|
|
// {
|
|
// var mesh = info.mesh;
|
|
// if (mesh)
|
|
// {
|
|
// mesh.Clear();
|
|
// mesh.vertices = info.vertices;
|
|
// mesh.uv = info.uvs0;
|
|
// mesh.uv2 = info.uvs2;
|
|
// mesh.colors32 = info.colors32;
|
|
// mesh.normals = info.normals;
|
|
// mesh.tangents = info.tangents;
|
|
// mesh.triangles = info.triangles;
|
|
// }
|
|
// }
|
|
//
|
|
// if (canvasRenderer)
|
|
// {
|
|
// canvasRenderer.SetMesh(textMeshPro.mesh);
|
|
//
|
|
// GetComponentsInChildren(false, s_SubMeshUIs);
|
|
// foreach (var sm in s_SubMeshUIs)
|
|
// {
|
|
// sm.canvasRenderer.SetMesh(sm.mesh);
|
|
// }
|
|
//
|
|
// s_SubMeshUIs.Clear();
|
|
// }
|
|
//
|
|
// textMeshPro.havePropertiesChanged = true;
|
|
// }
|
|
// else
|
|
// #endif
|
|
// if (graphic)
|
|
// {
|
|
// graphic.SetVerticesDirty();
|
|
// }
|
|
}
|
|
|
|
|
|
//################################
|
|
// Protected Members.
|
|
//################################
|
|
/// <summary>
|
|
/// Should the effect modify the mesh directly for TMPro?
|
|
/// </summary>
|
|
// protected virtual bool isLegacyMeshModifier
|
|
// {
|
|
// get { return false; }
|
|
// }
|
|
// protected virtual void Initialize()
|
|
// {
|
|
// if (_initialized) return;
|
|
//
|
|
// _initialized = true;
|
|
// _graphic = _graphic ? _graphic : GetComponent<Graphic>();
|
|
//
|
|
// _connector = BaseConnector.FindConnector(_graphic);
|
|
//
|
|
// // _canvasRenderer = _canvasRenderer ?? GetComponent<CanvasRenderer> ();
|
|
// _rectTransform = _rectTransform ? _rectTransform : GetComponent<RectTransform>();
|
|
// // #if TMP_PRESENT
|
|
// // _textMeshPro = _textMeshPro ?? GetComponent<TMP_Text> ();
|
|
// // #endif
|
|
// }
|
|
|
|
/// <summary>
|
|
/// This function is called when the object becomes enabled and active.
|
|
/// </summary>
|
|
protected override void OnEnable()
|
|
{
|
|
connector.OnEnable(graphic);
|
|
SetVerticesDirty();
|
|
|
|
// SetVerticesDirty();
|
|
// #if TMP_PRESENT
|
|
// if (textMeshPro)
|
|
// {
|
|
// TMPro_EventManager.TEXT_CHANGED_EVENT.Add (OnTextChanged);
|
|
// }
|
|
// #endif
|
|
//
|
|
// #if UNITY_EDITOR && TMP_PRESENT
|
|
// if (graphic && textMeshPro)
|
|
// {
|
|
// GraphicRebuildTracker.TrackGraphic (graphic);
|
|
// }
|
|
// #endif
|
|
//
|
|
// #if UNITY_5_6_OR_NEWER
|
|
// if (graphic)
|
|
// {
|
|
// AdditionalCanvasShaderChannels channels = requiredChannels;
|
|
// var canvas = graphic.canvas;
|
|
// if (canvas && (canvas.additionalShaderChannels & channels) != channels)
|
|
// {
|
|
// Debug.LogWarningFormat (this, "Enable {1} of Canvas.additionalShaderChannels to use {0}.", GetType ().Name, channels);
|
|
// }
|
|
// }
|
|
// #endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// This function is called when the behaviour becomes disabled () or inactive.
|
|
/// </summary>
|
|
protected override void OnDisable()
|
|
{
|
|
connector.OnDisable(graphic);
|
|
SetVerticesDirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mark the effect parameters as dirty.
|
|
/// </summary>
|
|
protected virtual void SetEffectParamsDirty()
|
|
{
|
|
if (!isActiveAndEnabled) return;
|
|
SetVerticesDirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Callback for when properties have been changed by animation.
|
|
/// </summary>
|
|
protected override void OnDidApplyAnimationProperties()
|
|
{
|
|
if (!isActiveAndEnabled) return;
|
|
SetEffectParamsDirty();
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
protected override void Reset()
|
|
{
|
|
if (!isActiveAndEnabled) return;
|
|
SetVerticesDirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
|
|
/// </summary>
|
|
protected override void OnValidate()
|
|
{
|
|
if (!isActiveAndEnabled) return;
|
|
SetEffectParamsDirty();
|
|
}
|
|
#endif
|
|
}
|
|
}
|