114 lines
2.5 KiB
C#
114 lines
2.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class MegaMorphLinkDesc
|
|
{
|
|
public string name = string.Empty;
|
|
|
|
public Transform target;
|
|
|
|
public int channel;
|
|
|
|
public MegaAxis axis;
|
|
|
|
public MegaLinkSrc src = MegaLinkSrc.LocalRotation;
|
|
|
|
public float min;
|
|
|
|
public float max = 90f;
|
|
|
|
public bool useCurve;
|
|
|
|
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 1f));
|
|
|
|
public bool late;
|
|
|
|
public bool active;
|
|
|
|
public Quaternion rot;
|
|
|
|
public float low;
|
|
|
|
public float high = 1f;
|
|
|
|
private float Ang(Quaternion rotationA, Quaternion rotationB, MegaLinkSrc t)
|
|
{
|
|
Vector3 vector = rotationA * Vector3.forward;
|
|
Vector3 vector2 = rotationB * Vector3.forward;
|
|
float current = 0f;
|
|
float num = 0f;
|
|
switch (t)
|
|
{
|
|
case MegaLinkSrc.RotationXY:
|
|
current = Mathf.Atan2(vector.x, vector.y) * 57.29578f;
|
|
num = Mathf.Atan2(vector2.x, vector2.y) * 57.29578f;
|
|
break;
|
|
case MegaLinkSrc.RotationXZ:
|
|
current = Mathf.Atan2(vector.x, vector.z) * 57.29578f;
|
|
num = Mathf.Atan2(vector2.x, vector2.z) * 57.29578f;
|
|
break;
|
|
case MegaLinkSrc.RotationYZ:
|
|
current = Mathf.Atan2(vector.y, vector.z) * 57.29578f;
|
|
num = Mathf.Atan2(vector2.y, vector2.z) * 57.29578f;
|
|
break;
|
|
}
|
|
return Mathf.DeltaAngle(current, num);
|
|
}
|
|
|
|
public float GetVal()
|
|
{
|
|
float result = 0f;
|
|
if ((bool)target)
|
|
{
|
|
switch (src)
|
|
{
|
|
case MegaLinkSrc.Position:
|
|
result = target.position[(int)axis];
|
|
break;
|
|
case MegaLinkSrc.Rotation:
|
|
result = target.rotation.eulerAngles[(int)axis];
|
|
break;
|
|
case MegaLinkSrc.LocalPosition:
|
|
result = target.localPosition[(int)axis];
|
|
break;
|
|
case MegaLinkSrc.LocalRotation:
|
|
result = target.localRotation.eulerAngles[(int)axis];
|
|
break;
|
|
case MegaLinkSrc.Scale:
|
|
result = target.localScale[(int)axis];
|
|
break;
|
|
case MegaLinkSrc.DotRotation:
|
|
result = Quaternion.Dot(target.localRotation, rot);
|
|
break;
|
|
case MegaLinkSrc.Angle:
|
|
result = Quaternion.Angle(target.localRotation, rot);
|
|
break;
|
|
case MegaLinkSrc.RotationXY:
|
|
result = Ang(target.localRotation, rot, src);
|
|
break;
|
|
case MegaLinkSrc.RotationXZ:
|
|
result = Ang(target.localRotation, rot, src);
|
|
break;
|
|
case MegaLinkSrc.RotationYZ:
|
|
result = Ang(target.localRotation, rot, src);
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public void Update(MegaMorph morph, bool islate)
|
|
{
|
|
if (active && late == islate)
|
|
{
|
|
float num = Mathf.Clamp01((GetVal() - min) / (max - min));
|
|
if (useCurve)
|
|
{
|
|
num = curve.Evaluate(num);
|
|
}
|
|
morph.SetPercentLim(channel, Mathf.Lerp(low, high, num));
|
|
}
|
|
}
|
|
}
|