Archived
添加了更多的材质函数,部分与引擎新特性重合,这是为了能够脱离引擎在多个版本中更具可移植性。
添加了多种对程序流程控制与保全的脚本,而且现在可以更快速的构建一个具有线性关系的协程了。 添加了一个支持多种模式的单维梯度控制器,类似unity的颜色梯度类型。 添加了一个用于看向某个物体的旋转控制器。 添加了一个加载宏。 完善了批处理脚本流程。
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
namespace XericLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 看向某物
|
||||
/// </summary>
|
||||
public class LookAtSomething : WeaklyMonoBase
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 看向目标的名称
|
||||
/// </summary>
|
||||
public string lookAtTargetName = "";
|
||||
|
||||
/// <summary>
|
||||
/// 看向的目标
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private Transform lookAtTarget = null;
|
||||
|
||||
/// <summary>
|
||||
/// 设定看向的目标
|
||||
/// </summary>
|
||||
public Transform LookAtTarget
|
||||
{
|
||||
get => lookAtTarget;
|
||||
set
|
||||
{
|
||||
lookAtTarget = value;
|
||||
targetValid = lookAtTarget != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反转看向轴
|
||||
/// </summary>
|
||||
public bool ReversLookVector = false;
|
||||
|
||||
/// <summary>
|
||||
/// 看向的轴
|
||||
/// </summary>
|
||||
public Vector3 LookAtVector = Vector3.forward;
|
||||
|
||||
/// <summary>
|
||||
/// 启用旋转的轴
|
||||
/// </summary>
|
||||
public Vector3 UseableRotateVector = Vector3.one;
|
||||
|
||||
/// <summary>
|
||||
/// 旋转角速度
|
||||
/// </summary>
|
||||
public float RotateSpeed = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 看向的目标有效
|
||||
/// </summary>
|
||||
private bool targetValid = true;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生命周期
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(lookAtTarget == null && lookAtTargetName != null && lookAtTargetName != "")
|
||||
{
|
||||
lookAtTarget = GameObject.Find(lookAtTargetName)?.transform;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
targetValid = lookAtTarget != null;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if(!targetValid)
|
||||
return;
|
||||
|
||||
var lookvec = ReversLookVector ?
|
||||
transform.position - lookAtTarget.position:
|
||||
lookAtTarget.position - transform.position;
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation(lookvec, LookAtVector);
|
||||
|
||||
// 使用 slerp 插值平滑旋转
|
||||
float step = RotateSpeed * Time.deltaTime;
|
||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, step);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb87994b0a073364bb4cd97dab579a0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user