178 lines
3.5 KiB
C#
178 lines
3.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class animation_curve_class
|
|
{
|
|
public bool curve_in_memory;
|
|
|
|
public string curve_text;
|
|
|
|
public Rect menu_rect;
|
|
|
|
public AnimationCurve curve;
|
|
|
|
public AnimationCurve default_curve;
|
|
|
|
public bool abs;
|
|
|
|
public curve_type_enum type;
|
|
|
|
public bool active;
|
|
|
|
public bool settings_foldout;
|
|
|
|
public float frequency;
|
|
|
|
public Vector2 offset;
|
|
|
|
public Vector2 offset_range;
|
|
|
|
public Vector2 offset_middle;
|
|
|
|
public int detail;
|
|
|
|
public float detail_strength;
|
|
|
|
public Transform pivot;
|
|
|
|
public float strength;
|
|
|
|
public bool rotation;
|
|
|
|
public float rotation_value;
|
|
|
|
public animation_curve_class()
|
|
{
|
|
curve_text = "Curve";
|
|
curve = new AnimationCurve();
|
|
default_curve = new AnimationCurve();
|
|
active = true;
|
|
settings_foldout = true;
|
|
frequency = 256f;
|
|
offset_range = new Vector2(5f, 5f);
|
|
detail = 1;
|
|
detail_strength = 2f;
|
|
strength = 1f;
|
|
}
|
|
|
|
public virtual void set_zero()
|
|
{
|
|
curve = AnimationCurve.Linear(0f, 0f, 1f, 0f);
|
|
}
|
|
|
|
public virtual void set_invert()
|
|
{
|
|
AnimationCurve animationCurve = new AnimationCurve();
|
|
for (int i = 0; i < curve.keys.Length; i++)
|
|
{
|
|
Keyframe key = curve.keys[i];
|
|
key.value = 1f - key.value;
|
|
float inTangent = key.inTangent;
|
|
key.inTangent *= -1f;
|
|
key.outTangent *= -1f;
|
|
animationCurve.AddKey(key);
|
|
}
|
|
curve = new AnimationCurve(animationCurve.keys);
|
|
}
|
|
|
|
public virtual void set_default()
|
|
{
|
|
curve = new AnimationCurve(default_curve.keys);
|
|
}
|
|
|
|
public virtual void set_as_default()
|
|
{
|
|
default_curve = new AnimationCurve(curve.keys);
|
|
}
|
|
|
|
public virtual void default_normal()
|
|
{
|
|
curve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
|
|
type = curve_type_enum.Normal;
|
|
}
|
|
|
|
public virtual void default_random()
|
|
{
|
|
curve = AnimationCurve.Linear(0f, 0f, 1f, 0f);
|
|
type = curve_type_enum.Random;
|
|
}
|
|
|
|
public virtual void default_perlin()
|
|
{
|
|
curve = AnimationCurve.Linear(0f, 1f, 1f, 1f);
|
|
type = curve_type_enum.Perlin;
|
|
frequency = 256f;
|
|
offset = new Vector2(0f, 0f);
|
|
offset_middle = new Vector2(0f, 0f);
|
|
detail = 7;
|
|
detail_strength = 2f;
|
|
abs = false;
|
|
}
|
|
|
|
public virtual void change_key(float time, float value)
|
|
{
|
|
if (curve.AddKey(time, value) != -1)
|
|
{
|
|
return;
|
|
}
|
|
Keyframe[] keys = curve.keys;
|
|
for (int i = 0; i < curve.keys.Length; i++)
|
|
{
|
|
if (keys[i].time == time)
|
|
{
|
|
keys[i].value = value;
|
|
}
|
|
}
|
|
curve = new AnimationCurve(keys);
|
|
}
|
|
|
|
public virtual void set_curve_linear()
|
|
{
|
|
AnimationCurve animationCurve = new AnimationCurve();
|
|
for (int i = 0; i < curve.keys.Length; i++)
|
|
{
|
|
float inTangent = 0f;
|
|
float outTangent = 0f;
|
|
bool flag = false;
|
|
bool flag2 = false;
|
|
Vector2 vector = default(Vector2);
|
|
Vector2 vector2 = default(Vector2);
|
|
Vector2 vector3 = default(Vector2);
|
|
Keyframe key = curve[i];
|
|
if (i == 0)
|
|
{
|
|
inTangent = 0f;
|
|
flag = true;
|
|
}
|
|
if (i == curve.keys.Length - 1)
|
|
{
|
|
outTangent = 0f;
|
|
flag2 = true;
|
|
}
|
|
if (!flag)
|
|
{
|
|
vector.x = curve.keys[i - 1].time;
|
|
vector.y = curve.keys[i - 1].value;
|
|
vector2.x = curve.keys[i].time;
|
|
vector2.y = curve.keys[i].value;
|
|
vector3 = vector2 - vector;
|
|
inTangent = vector3.y / vector3.x;
|
|
}
|
|
if (!flag2)
|
|
{
|
|
vector.x = curve.keys[i].time;
|
|
vector.y = curve.keys[i].value;
|
|
vector2.x = curve.keys[i + 1].time;
|
|
vector2.y = curve.keys[i + 1].value;
|
|
vector3 = vector2 - vector;
|
|
outTangent = vector3.y / vector3.x;
|
|
}
|
|
key.inTangent = inTangent;
|
|
key.outTangent = outTangent;
|
|
animationCurve.AddKey(key);
|
|
}
|
|
curve = animationCurve;
|
|
}
|
|
}
|