using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Cyber.Util {
///
/// Lerps stuff.
///
public class Lerper : MonoBehaviour {
private struct PositionLerp {
public Vector3 Target;
public float Speed;
public PositionLerp(Vector3 target, float speed) {
Target = target;
Speed = speed;
}
}
private static Lerper Singleton;
private Dictionary PositionLerps = new Dictionary();
///
/// Sets the singleton.
///
public Lerper() {
Singleton = this;
}
///
/// Lerps the transform world position.
///
/// Transform.
/// To.
/// Speed.
public static void LerpTransformPosition(Transform transform, Vector3 to, float speed) {
if (Singleton != null) {
Singleton.PositionLerps[transform] = new PositionLerp(to, speed);
}
}
private void LateUpdate() {
List RemoveThese = new List();
foreach (Transform Transform in PositionLerps.Keys) {
if (Transform == null) {
PositionLerps.Remove(Transform);
continue;
}
Transform.position = Vector3.Lerp(Transform.position,
PositionLerps[Transform].Target, PositionLerps[Transform].Speed * Time.deltaTime);
if ((Transform.position - PositionLerps[Transform].Target).magnitude < 0.001f) {
Transform.position = PositionLerps[Transform].Target;
RemoveThese.Add(Transform);
}
}
foreach (Transform Transform in RemoveThese) {
PositionLerps.Remove(Transform);
}
}
}
}