88 lines
2.2 KiB
Plaintext
88 lines
2.2 KiB
Plaintext
using Sirenix.OdinInspector;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PHomeProjectileRotator : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
protected RotateType m_rotateType;
|
|
public RotateType RotateType
|
|
{
|
|
get
|
|
{
|
|
return m_rotateType;
|
|
}
|
|
}
|
|
|
|
[ShowIf("m_rotateType", RotateType.Contant)]
|
|
[SerializeField]
|
|
private float m_rotationSpeed;
|
|
|
|
[SerializeField]
|
|
protected Transform m_rotateTransf;
|
|
|
|
private PHomeProjectileMover m_moverScript;
|
|
private PHomeProjectileMover MoverScript
|
|
{
|
|
get
|
|
{
|
|
if (m_moverScript == null)
|
|
{
|
|
m_moverScript = GetComponent<PHomeProjectileMover>();
|
|
}
|
|
|
|
return m_moverScript;
|
|
}
|
|
}
|
|
|
|
protected virtual void Update()
|
|
{
|
|
Update_Rotate();
|
|
}
|
|
|
|
protected virtual void Update_Rotate()
|
|
{
|
|
Transform rotTrans = m_rotateTransf ?? transform;
|
|
|
|
switch (RotateType)
|
|
{
|
|
case RotateType.LookAtVelocity:
|
|
LookAtVelocity(rotTrans, MoverScript.Velocity);
|
|
break;
|
|
case RotateType.LookAtDestVelocity:
|
|
LookAtVelocity(rotTrans, MoverScript.DestVelocity);
|
|
break;
|
|
case RotateType.LookAtNextPos:
|
|
LookAtVelocity(rotTrans, MoverScript.nextPos);
|
|
break;
|
|
case RotateType.Contant:
|
|
{
|
|
rotTrans.Rotate(new Vector3()
|
|
{
|
|
x = 0,
|
|
y = 0,
|
|
z = m_rotationSpeed * Time.deltaTime,
|
|
});
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void LookAtVelocity(Transform tr, Vector3 lookAt)
|
|
{
|
|
tr.rotation = Quaternion.LookRotation(Vector3.forward, Vector3.Cross(Vector3.forward, lookAt));
|
|
}
|
|
}
|
|
|
|
public enum RotateType
|
|
{
|
|
LookAtEnd,// 朝向终点
|
|
LookAtTarget,// 朝向目标
|
|
LookAtVelocity,// 朝向速度
|
|
LookAtDestVelocity,// 朝向期望速度
|
|
LookAtNextPos,// 朝向下一位置
|
|
Contant,
|
|
} |