64 lines
1.5 KiB
C#
64 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
public class LipSyncDemo_Control : MonoBehaviour
|
|
{
|
|
[Tooltip("Key used to rotate the demo object up to 45 degrees to the left.")]
|
|
public KeyCode rotateLeftKey = KeyCode.LeftArrow;
|
|
|
|
[Tooltip("Key used to rotate the demo object up to 45 degrees to the right.")]
|
|
public KeyCode rotateRightKey = KeyCode.RightArrow;
|
|
|
|
[Tooltip("Key used to reset demo object rotation.")]
|
|
public KeyCode resetRotationKey = KeyCode.DownArrow;
|
|
|
|
private float resetRotation = 180f;
|
|
|
|
private float rotationAmount = 20f;
|
|
|
|
private float rotationMax = 45f;
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKey(rotateLeftKey))
|
|
{
|
|
RotateObject(rotationAmount);
|
|
}
|
|
else if (Input.GetKey(rotateRightKey))
|
|
{
|
|
RotateObject(0f - rotationAmount);
|
|
}
|
|
else if (Input.GetKey(resetRotationKey))
|
|
{
|
|
RotateObject(resetRotation, true);
|
|
}
|
|
}
|
|
|
|
private void RotateObject(float amountDegrees, bool absolute = false)
|
|
{
|
|
GameObject gameObject = GameObject.Find("LipSyncMorphTarget_Female");
|
|
if (gameObject == null)
|
|
{
|
|
gameObject = GameObject.Find("RobotHead_TextureFlip");
|
|
}
|
|
if (!gameObject)
|
|
{
|
|
return;
|
|
}
|
|
if (absolute)
|
|
{
|
|
float num = amountDegrees - gameObject.transform.eulerAngles.y;
|
|
gameObject.transform.Rotate(Vector3.up * num);
|
|
return;
|
|
}
|
|
float num2 = Time.deltaTime * amountDegrees;
|
|
if (num2 + gameObject.transform.eulerAngles.y >= resetRotation - rotationMax && num2 + gameObject.transform.eulerAngles.y <= resetRotation + rotationMax)
|
|
{
|
|
gameObject.transform.Rotate(Vector3.up * num2);
|
|
}
|
|
}
|
|
}
|