summaryrefslogtreecommitdiff
path: root/Assets/UIEffects/BaseUIEffect.cs
blob: 4ee46c98c9056cf6eb463332135ca49b1f21b733 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEditor;

[ExecuteInEditMode]
[RequireComponent(typeof(Graphic))]
public abstract class BaseUIEffect : UIBehaviour, IMeshModifier, IMaterialModifier
{
	[NonSerialized]
	private Graphic m_Graphic;

	protected Graphic graphic
	{
		get
		{
			if (m_Graphic == null)
				m_Graphic = GetComponent<Graphic>();

			return m_Graphic;
		}
	}

	protected override void OnEnable()
	{
		base.OnEnable();
		if (graphic != null)
			graphic.SetVerticesDirty();
	}

	protected override void OnDisable()
	{
		if (graphic != null)
			graphic.SetVerticesDirty();
		base.OnDisable();
	}

	protected override void OnDidApplyAnimationProperties()
	{
		if (graphic != null)
			graphic.SetVerticesDirty();
		base.OnDidApplyAnimationProperties();
	}

#if UNITY_EDITOR
	protected override void OnValidate()
	{
		base.OnValidate();
		if (graphic != null)
			graphic.SetVerticesDirty();
	}

#endif

	public void ModifyMesh(Mesh mesh)
	{
		using (var vh = new VertexHelper(mesh))
		{
			ModifyMesh(vh);
			vh.FillMesh(mesh);
		}
	}

	public virtual void ModifyMesh(VertexHelper vh)
	{
	}

	public virtual Material GetModifiedMaterial(Material baseMaterial)
	{
		return baseMaterial;
	}

}