暂且修了LookAt
This commit is contained in:
23
Assets/Scripts/Extensions/ColorExtensions.cs
Normal file
23
Assets/Scripts/Extensions/ColorExtensions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ColorExtensions
|
||||
{
|
||||
public static Gradient DefaultGradient()
|
||||
{
|
||||
Gradient gradient = new Gradient();
|
||||
GradientColorKey[] colorKeys = new GradientColorKey[2];
|
||||
colorKeys[0].color = Color.white;
|
||||
colorKeys[0].time = 0;
|
||||
colorKeys[1].color = Color.white;
|
||||
colorKeys[1].time = 1;
|
||||
GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2];
|
||||
alphaKeys[0].alpha = 1;
|
||||
alphaKeys[0].time = 0;
|
||||
alphaKeys[1].alpha = 1;
|
||||
alphaKeys[1].time = 1;
|
||||
gradient.SetKeys(colorKeys, alphaKeys);
|
||||
return gradient;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Extensions/ColorExtensions.cs.meta
Normal file
11
Assets/Scripts/Extensions/ColorExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b994ac82f6ab6cd42bf64438e79d1965
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/Scripts/Extensions/CustomCurvePresets.cs
Normal file
58
Assets/Scripts/Extensions/CustomCurvePresets.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 自定义曲线预设
|
||||
/// </summary>
|
||||
public static class CustomCurvePresets
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 瞬间完成
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AnimationCurve Instant()
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[2];
|
||||
keys[0] = new Keyframe(0, 1, 0, 0);
|
||||
keys[1] = new Keyframe(1, 1, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛物线曲线,在中间达到最大值,两端为起始值
|
||||
/// </summary>
|
||||
/// <param name="totalTime">总时间</param>
|
||||
/// <param name="startValue">起始(和结束)值</param>
|
||||
/// <param name="peakValue">中点最大值</param>
|
||||
public static AnimationCurve Parabolic(float totalTime, float startValue, float peakValue)
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[3];
|
||||
keys[0] = new Keyframe(0, startValue, 0, 0);
|
||||
keys[1] = new Keyframe(totalTime / 2, peakValue, 0, 0);
|
||||
keys[2] = new Keyframe(totalTime, startValue, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义峰值点位置的抛物线曲线,在指定时间点达到最大值,两端为起始值
|
||||
/// </summary>
|
||||
/// <param name="totalTime">总时间</param>
|
||||
/// <param name="startValue">起始(和结束)值</param>
|
||||
/// <param name="peakValue">最大值</param>
|
||||
/// <param name="peakTimePercent">最大值的比例点</param>
|
||||
/// <returns></returns>
|
||||
public static AnimationCurve CustomPeakTimeParabolic(float totalTime, float startValue, float peakValue, float peakTimePercent)
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[3];
|
||||
keys[0] = new Keyframe(0, startValue, 0, 0);
|
||||
keys[1] = new Keyframe(totalTime * peakTimePercent, peakValue, 0, 0);
|
||||
keys[2] = new Keyframe(totalTime, startValue, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Extensions/CustomCurvePresets.cs.meta
Normal file
11
Assets/Scripts/Extensions/CustomCurvePresets.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac4cc158ed88d48af9a350196b874508
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/Scripts/Extensions/ListExtension.cs
Normal file
12
Assets/Scripts/Extensions/ListExtension.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ListExtension
|
||||
{
|
||||
public static Vector3 Sum(this List<Vector3> list)
|
||||
{
|
||||
return list.Aggregate(Vector3.zero, (current, addition) => current + addition);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Extensions/ListExtension.cs.meta
Normal file
11
Assets/Scripts/Extensions/ListExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62a89393607258a4c858b3bfede996ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/Scripts/Extensions/ShaderExtension.cs
Normal file
28
Assets/Scripts/Extensions/ShaderExtension.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ShaderExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 对于从AssetBundle中加载的材质,修改Shader参数可能会出现异常情况。
|
||||
/// 此时需要在生成物体的时候,重新初始化Shader。
|
||||
/// </summary>
|
||||
public static void InitializeShader(this Renderer renderer)
|
||||
{
|
||||
foreach (Material material in renderer.materials)
|
||||
{
|
||||
string shaderName = material.shader.name;
|
||||
Shader shader = Shader.Find(shaderName);
|
||||
|
||||
if (shader != null)
|
||||
{
|
||||
material.shader = shader;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Shader '{shaderName}' not found for material '{material.name}' on renderer '{renderer.name}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Extensions/ShaderExtension.cs.meta
Normal file
11
Assets/Scripts/Extensions/ShaderExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b74e31a7b06bb9743b629a923718f2c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user