#if HAVE_USEQUENCER using System; using UnityEngine; using WellFired; using WellFired.Shared; namespace Framework.UI { /// Displays a UGUI fading event in the uSequencer timeline [CustomUSEditor(typeof(USFadeUGUIEvent))] public class USFadeUGUIEventEditor : USEventBaseEditor { /// Renders the event in the uSequencer timeline /// Area covered by the event /// The rectangle the event has covered public override Rect RenderEvent(Rect myArea) { USFadeUGUIEvent guiEvent = TargetEvent as USFadeUGUIEvent; if(guiEvent == null) { Debug.LogWarning( "Trying to render an event as a USFadeUGUIEvent, but it is a: " + TargetEvent.GetType().ToString() ); return myArea; } myArea = DrawDurationDefinedBox(myArea); using(new GUIBeginArea(myArea)) { GUILayout.Label(GetReadableEventName(), DefaultLabel); Rect box = GUILayoutUtility.GetRect(0.0f, 1000.0f, 0.0f, 1000.0f); if((box.width > 1) && (box.height > 1)) { box.y += 2; box.height -= 2; GUI.Box(box, getFadeChart(guiEvent, (int)box.width, (int)box.height)); } } return myArea; } /// Provides a fade chart for the current GUI event /// GUI event for which a fade chart will be provided /// Fade chart width /// Fade chart height /// The fade chart for the specified event and size private Texture2D getFadeChart(USFadeUGUIEvent guiEvent, int width, int height) { bool refreshNeeded = (this.cachedFadeChart == null) || (width != this.cachedWidth) || (height != this.cachedHeight) || (guiEvent.LeftAlpha != this.cachedLeftAlpha) || (guiEvent.RightAlpha != this.cachedRightAlpha); if(refreshNeeded) { this.cachedFadeChart = new Texture2D(width, height, TextureFormat.ARGB32, false); Color blankColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); for(int x = 0; x < width; ++x) { float alpha = Mathf.Lerp(guiEvent.LeftAlpha, guiEvent.RightAlpha, (float)x / width); Color filledColor = new Color(1.0f, 1.0f, 1.0f, alpha); int split = (int)(alpha * height); for(int y = 0; y < split; ++y) { this.cachedFadeChart.SetPixel(x, y, filledColor); } for(int y = split; y < height; ++y) { this.cachedFadeChart.SetPixel(x, y, blankColor); } this.cachedWidth = width; this.cachedHeight = height; this.cachedLeftAlpha = guiEvent.LeftAlpha; this.cachedRightAlpha = guiEvent.RightAlpha; } this.cachedFadeChart.Apply(false); } return this.cachedFadeChart; } /// Fade chart texture created for the event private Texture2D cachedFadeChart; /// Width for which the current fade chart was created private int cachedWidth; /// Height for which the current fade chart was created private int cachedHeight; /// Starting alpha for which the current fade chart was created private float cachedLeftAlpha; /// Ending alpha for which the current fade chart was created private float cachedRightAlpha; } } // namespace Framework.UI #endif // HAVE_USEQUENCER