Class MapAnimationExtensions
These functions are defined as extensions so that IMap can remain pure (that is, not access Time.time).
These methods are implemented as extension methods so that they do not become part of the "pure" interface of IMap. (Time.time is a "non-pure", very Unity-specific feature).
public static class MapAnimationExtensions
- Inheritance
-
MapAnimationExtensions
- Inherited Members
Methods
Animate<TPoint>(IMap<TPoint>, Func<Vector2, float, Vector2>)
Only use this method if animation(x, -t) is the inverse of animation(x, t).
public static IMap<TPoint> Animate<TPoint>(this IMap<TPoint> map, Func<Vector2, float, Vector2> animation) where TPoint : IGridPoint<TPoint>
Parameters
Returns
- IMap<TPoint>
Type Parameters
TPoint
Animate<TPoint>(IMap<TPoint>, Func<Vector2, float, Vector2>, Func<Vector2, float, Vector2>)
Animates this grid using a function animation that takes a point and time. The inverse animation is the inverse mapping at time t, that is,
inverseAmimation(animation(someVector, t), t) == someVector
public static IMap<TPoint> Animate<TPoint>(this IMap<TPoint> map, Func<Vector2, float, Vector2> animation, Func<Vector2, float, Vector2> inverseAnimation) where TPoint : IGridPoint<TPoint>
Parameters
map
IMap<TPoint>animation
Func<Vector2, float, Vector2>inverseAnimation
Func<Vector2, float, Vector2>
Returns
- IMap<TPoint>
Type Parameters
TPoint
Examples
Example:
map = new PointyHexMap(hexDimensions).AnchorCellMiddleCenter()
.WithWindow(ExampleUtils.ScreenRect)
.AlignMiddleCenter(grid)
//Rotate
.Animate((x, t) => x.Rotate(45 * t), (x, t) => x.Rotate(-45 * t))
//Translate
.Animate((x, t) => x + new Vector2(75 * Mathf.Sin(t * 5), 0),
(x, t) => x - new Vector2(75 * Mathf.Sin(t * 5), 0))
//Scale
.Animate((x, t) => x * (1 + Mathf.Sin(t * 7)),
(x, t) => x / (1 + Mathf.Sin(t * 7)));