using UnityEngine; using UnityEngine.UI; namespace Olympus { [RequireComponent(typeof(CanvasRenderer))] public sealed class RevealGraphic : MaskableGraphic { public float amount=6; public int style; Material owned; public void Configure(string id,int mode) { style=mode;int seed=17;foreach(char c in id)seed=unchecked(seed*31+c); if(!owned){var shader=Resources.Load("Olympus/ReferenceA/CanvasReveal");if(shader)owned=new Material(shader);} if(owned){material=owned;owned.SetFloat("_Seed",Mathf.Abs(seed%1000));owned.SetFloat("_Mode",mode);owned.SetFloat("_Reveal",amount/100);} SetVerticesDirty(); } public void SetAmount(float value){amount=value;if(owned){owned.SetFloat("_Reveal",Mathf.Clamp01(value/100));materialForRendering.SetFloat("_Reveal",Mathf.Clamp01(value/100));}} protected override void OnPopulateMesh(VertexHelper vh) { vh.Clear();var r=rectTransform.rect; vh.AddVert(new Vector3(r.xMin,r.yMin),color,new Vector2(0,0));vh.AddVert(new Vector3(r.xMin,r.yMax),color,new Vector2(0,1));vh.AddVert(new Vector3(r.xMax,r.yMax),color,new Vector2(1,1));vh.AddVert(new Vector3(r.xMax,r.yMin),color,new Vector2(1,0)); vh.AddTriangle(0,1,2);vh.AddTriangle(0,2,3); } protected override void OnDestroy(){if(owned){if(Application.isPlaying)Destroy(owned);else DestroyImmediate(owned);}base.OnDestroy();} } }