#if HAVE_USEQUENCER
using System;
using UnityEngine;
using WellFired;
using WellFired.Shared;
namespace Framework.Support {
/// Displays a UGUI fading event in the uSequencer timeline
[CustomUSEditor(typeof(USFadeMaterialEvent))]
public class USFadeMaterialEventEditor : 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) {
USFadeMaterialEvent materialEvent = TargetEvent as USFadeMaterialEvent;
if(materialEvent == null) {
Debug.LogWarning(
"Trying to render an event as a USFadeMaterialEvent, 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(materialEvent, (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(USFadeMaterialEvent materialEvent, int width, int height) {
bool refreshNeeded =
(this.cachedFadeChart == null) ||
(width != this.cachedWidth) ||
(height != this.cachedHeight) ||
(materialEvent.LeftAlpha != this.cachedLeftAlpha) ||
(materialEvent.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(
materialEvent.LeftAlpha, materialEvent.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 = materialEvent.LeftAlpha;
this.cachedRightAlpha = materialEvent.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.Support
#endif // HAVE_USEQUENCER