CrabUI
Loading...
Searching...
No Matches
CrabUI.CUIAnimation Class Reference

WIP, can animate any property on any object Can run back and forth in [0..1] interval and interpolate any property between StartValue and EndValue. More...

Public Member Functions

Action< object > Convert< T > (Action< T > myActionT)
 
void Start ()
 Resumes animation in the same direction.
 
void Stop ()
 
void Forward ()
 Set Direction to Straight and Start.
 
void Back ()
 Set Direction to Reverse and Start.
 
void SetToStart ()
 Set Lambda to 0.
 
void SetToEnd ()
 Set Lambda to 1.
 
void ApplyValue ()
 
void Step (double time)
 
void LogStatus ()
 

Static Public Attributes

static HashSet< CUIAnimationActiveAnimations = new()
 
static float StartLambda = 0.0f
 
static float EndLambda = 1.0f
 

Properties

bool Debug [get, set]
 
object Target [get, set]
 Object containing animated property.
 
bool Active [get, set]
 
double Duration [get, set]
 In seconds.
 
double ReverseDuration [get, set]
 
bool Blocked [get, set]
 Will prevent it from starting.
 
double Lambda [get, set]
 Progress of animation [0..1].
 
double Speed = 0.01 [get, set]
 Lambda increase per update step, calculated when you set Duration.
 
double? BackSpeed [get, set]
 
bool Bounce [get, set]
 If true animation won't stop when reaching end, it will change direction.
 
bool Repeat [get, set]
 
CUIDirection Direction [get, set]
 Straight, Reverse.
 
object StartValue [get, set]
 Value will be interpolated between these values.
 
object EndValue [get, set]
 
string Property [get, set]
 Property name that is animated.
 
Func< float, object > Interpolate [get, set]
 You can set custon Interpolate function.
 

Events

Action< CUIDirection > OnStop
 

Detailed Description

WIP, can animate any property on any object Can run back and forth in [0..1] interval and interpolate any property between StartValue and EndValue.

Definition at line 18 of file CUIAnimation.cs.

Member Function Documentation

◆ ApplyValue()

void CrabUI.CUIAnimation.ApplyValue ( )

Definition at line 245 of file CUIAnimation.cs.

246 {
247 if (interpolate == null) return;
248 object value = interpolate.Invoke((float)Lambda);
249 setter?.Invoke(value);
250 }
double Lambda
Progress of animation [0..1].

◆ Back()

void CrabUI.CUIAnimation.Back ( )

Set Direction to Reverse and Start.

Definition at line 210 of file CUIAnimation.cs.

211 {
212 Direction = CUIDirection.Reverse;
213 Active = true;
214 }
CUIDirection Direction
Straight, Reverse.

◆ Convert< T >()

Action< object > CrabUI.CUIAnimation.Convert< T > ( Action< T > myActionT)

Definition at line 153 of file CUIAnimation.cs.

154 {
155 if (myActionT == null) return null;
156 else return new Action<object>(o => myActionT((T)o));
157 }

◆ Forward()

void CrabUI.CUIAnimation.Forward ( )

Set Direction to Straight and Start.

Definition at line 202 of file CUIAnimation.cs.

203 {
204 Direction = CUIDirection.Straight;
205 Active = true;
206 }

◆ Step()

void CrabUI.CUIAnimation.Step ( double time)

Definition at line 252 of file CUIAnimation.cs.

253 {
254 UpdateState();
255 ApplyValue();
256 Lambda += Direction == CUIDirection.Straight ? Speed : -(BackSpeed ?? Speed);
257 if (Debug) LogStatus();
258 }
double Speed
Lambda increase per update step, calculated when you set Duration.

◆ Stop()

void CrabUI.CUIAnimation.Stop ( )

Definition at line 194 of file CUIAnimation.cs.

195 {
196 Active = false;
197 OnStop?.Invoke(Direction);
198 }

Member Data Documentation

◆ ActiveAnimations

HashSet<CUIAnimation> CrabUI.CUIAnimation.ActiveAnimations = new()
static

Definition at line 25 of file CUIAnimation.cs.

◆ EndLambda

float CrabUI.CUIAnimation.EndLambda = 1.0f
static

Definition at line 39 of file CUIAnimation.cs.

◆ StartLambda

float CrabUI.CUIAnimation.StartLambda = 0.0f
static

Definition at line 38 of file CUIAnimation.cs.

Property Documentation

◆ Active

bool CrabUI.CUIAnimation.Active
getset

Definition at line 56 of file CUIAnimation.cs.

57 {
58 get => active;
59 set
60 {
61 if (Blocked || active == value) return;
62 active = value;
63
64 if (active) ActiveAnimations.Add(this);
65 else ActiveAnimations.Remove(this);
66 ApplyValue();
67 }
68 }
bool Blocked
Will prevent it from starting.

◆ BackSpeed

double? CrabUI.CUIAnimation.BackSpeed
getset

Definition at line 105 of file CUIAnimation.cs.

105{ get; set; }

◆ Blocked

bool CrabUI.CUIAnimation.Blocked
getset

Will prevent it from starting.

Definition at line 96 of file CUIAnimation.cs.

96{ get; set; }

◆ Bounce

bool CrabUI.CUIAnimation.Bounce
getset

If true animation won't stop when reaching end, it will change direction.

Definition at line 109 of file CUIAnimation.cs.

109{ get; set; }

◆ Debug

bool CrabUI.CUIAnimation.Debug
getset

Definition at line 37 of file CUIAnimation.cs.

37{ get; set; }

◆ Direction

CUIDirection CrabUI.CUIAnimation.Direction
getset

Straight, Reverse.

Definition at line 114 of file CUIAnimation.cs.

114{ get; set; }

◆ Duration

double CrabUI.CUIAnimation.Duration
getset

In seconds.

Definition at line 73 of file CUIAnimation.cs.

74 {
75 get => 1.0 / Speed * Timing.Step;
76 set
77 {
78 double steps = value / Timing.Step;
79 Speed = 1.0 / steps;
80 }
81 }

◆ EndValue

object CrabUI.CUIAnimation.EndValue
getset

Definition at line 119 of file CUIAnimation.cs.

119{ get; set; }

◆ Interpolate

Func<float, object> CrabUI.CUIAnimation.Interpolate
getset

You can set custon Interpolate function.

Definition at line 141 of file CUIAnimation.cs.

142 {
143 get => interpolate;
144 set
145 {
146 customInterpolate = value;
147 UpdateSetter();
148 }
149 }

◆ Lambda

double CrabUI.CUIAnimation.Lambda
getset

Progress of animation [0..1].

Definition at line 100 of file CUIAnimation.cs.

100{ get; set; }

◆ Property

string CrabUI.CUIAnimation.Property
getset

Property name that is animated.

Definition at line 127 of file CUIAnimation.cs.

128 {
129 get => property;
130 set
131 {
132 property = value;
133 UpdateSetter();
134 }
135 }

◆ Repeat

bool CrabUI.CUIAnimation.Repeat
getset

Definition at line 110 of file CUIAnimation.cs.

110{ get; set; }

◆ ReverseDuration

double CrabUI.CUIAnimation.ReverseDuration
getset

Definition at line 83 of file CUIAnimation.cs.

84 {
85 get => 1.0 / (BackSpeed ?? 0) * Timing.Step;
86 set
87 {
88 double steps = value / Timing.Step;
89 BackSpeed = 1.0 / steps;
90 }
91 }

◆ Speed

double CrabUI.CUIAnimation.Speed = 0.01
getset

Lambda increase per update step, calculated when you set Duration.

Definition at line 104 of file CUIAnimation.cs.

104{ get; set; } = 0.01;

◆ StartValue

object CrabUI.CUIAnimation.StartValue
getset

Value will be interpolated between these values.

Definition at line 118 of file CUIAnimation.cs.

118{ get; set; }

◆ Target

object CrabUI.CUIAnimation.Target
getset

Object containing animated property.

Definition at line 46 of file CUIAnimation.cs.

47 {
48 get => target;
49 set
50 {
51 target = value;
52 UpdateSetter();
53 }
54 }

Event Documentation

◆ OnStop

Action<CUIDirection> CrabUI.CUIAnimation.OnStop

Definition at line 137 of file CUIAnimation.cs.


The documentation for this class was generated from the following file: