Skip to content

Commit

Permalink
Merge pull request #57 from JasonMa0012/2.x
Browse files Browse the repository at this point in the history
Add LwguiGradient(Color[] colors, float[] times)
  • Loading branch information
JasonMa0012 authored Aug 7, 2024
2 parents 22b2166 + 4dff25d commit 3ca75b0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Runtime/LwguiGradient/LwguiGradient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ public LwguiGradient(params Keyframe[] keys)
}
}

public LwguiGradient(Color[] colors, float[] times)
{
_curves = new List<AnimationCurve>();
for (int c = 0; c < (int)Channel.Num; c++)
_curves.Add(new AnimationCurve());

if (colors == null || times == null)
return;

for (int i = 0; i < Mathf.Min(colors.Length, times.Length); i++)
{
for (int c = 0; c < (int)Channel.Num; c++)
{
_curves[c].AddKey(new Keyframe(times[i], colors[i][c]).SetLinearTangentMode());
}
}
SetLinearTangentMode();
}

public LwguiGradient(List<AnimationCurve> inRgbaCurves) => SetRgbaCurves(inRgbaCurves);

#endregion
Expand Down Expand Up @@ -217,6 +236,14 @@ public Color Evaluate(float time, ChannelMask channelMask = ChannelMask.All, Gra
IsChannelIndexInMask((int)Channel.Alpha, channelMask) ? _curves[(int)Channel.Alpha].Evaluate(time) : 1);
}

public void SetLinearTangentMode()
{
for (int c = 0; c < (int)Channel.Num; c++)
{
_curves[c].SetLinearTangents();
}
}

#region LwguiGradient <=> Ramp Texture

public Color[] GetPixels(int width, int height, ChannelMask channelMask = ChannelMask.All)
Expand Down

0 comments on commit 3ca75b0

Please sign in to comment.