#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(USOverlayTextEvent))] public class USOverlayTextEventEditor : 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) { USOverlayTextEvent textEvent = TargetEvent as USOverlayTextEvent; if(textEvent == null) { Debug.LogWarning( "Trying to render an event as a USOverlayTextEvent, but it is a: " + TargetEvent.GetType().ToString() ); return myArea; } myArea = DrawDurationDefinedBox(myArea); using(new GUIBeginArea(myArea)) { //GUILayout.Label(GetReadableEventName(), DefaultLabel); GUILayout.Label(textEvent.Text, 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(textEvent, (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(USOverlayTextEvent textEvent, int width, int height) { bool refreshNeeded = (this.cachedFadeChart == null) || (width != this.cachedWidth) || (height != this.cachedHeight) || (textEvent.FadeInSeconds != this.cachedFadeInSeconds) || (textEvent.FadeOutSeconds != this.cachedFadeOutSeconds); if(refreshNeeded) { this.cachedFadeChart = new Texture2D(width, height, TextureFormat.ARGB32, false); #if false //float leftX = ConvertTimeToXPos(textEvent.FireTime); //float rightX = ConvertTimeToXPos(textEvent.FireTime + textEvent.Duration); //float #endif float duration = textEvent.Duration; Color blankColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); for(int x = 0; x < width; ++x) { float runningTime = (float)x * duration / width; float alpha = textEvent.CalculateOpacity(runningTime); 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.cachedFadeInSeconds = textEvent.FadeInSeconds; this.cachedFadeOutSeconds = textEvent.FadeOutSeconds; } 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; /// Fade in duration for which the current fade chart was created private float cachedFadeInSeconds; /// Fade out duration for which the current fade chart was created private float cachedFadeOutSeconds; } } // namespace Framework.UI #endif // HAVE_USEQUENCER