#if HAVE_USEQUENCER using System; using UnityEngine; using WellFired; using WellFired.Shared; namespace Framework.Camera { /// Displays a camera targeting event in the uSequencer timeline [CustomUSEditor(typeof(USFadeCameraEvent))] public class USFadeCameraEventEditor : 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) { USFadeCameraEvent cameraEvent = TargetEvent as USFadeCameraEvent; if(cameraEvent == null) { Debug.LogWarning( "Trying to render an event as a USFadeCameraEvent, 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(cameraEvent, (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(USFadeCameraEvent guiEvent, int width, int height) { bool refreshNeeded = (this.cachedFadeChart == null) || (width != this.cachedWidth) || (height != this.cachedHeight) || (guiEvent.LeftFadeLevel != this.cachedLeftFadeLevel) || (guiEvent.RightFadeLevel != this.cachedRightFadeLevel); 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 interpolationPoint = (float)x / width; Color filledColor = new Color( 1.0f, 1.0f, 1.0f, Mathf.Lerp(guiEvent.LeftFadeLevel, guiEvent.RightFadeLevel, interpolationPoint) ); int split = (int)Mathf.Lerp( guiEvent.LeftFadeLevel * height, guiEvent.RightFadeLevel * height, interpolationPoint ); 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.cachedLeftFadeLevel = guiEvent.LeftFadeLevel; this.cachedRightFadeLevel = guiEvent.RightFadeLevel; } 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 fade level for which the current fade chart was created private float cachedLeftFadeLevel; /// Ending fade level for which the current fade chart was created private float cachedRightFadeLevel; } } // namespace Framework.Camera #endif // HAVE_USEQUENCER