This repository has been archived on 2025-09-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
XericLibrary-OLD/Runtime/MicroLibrary/MacroSmooth.cs
LiRuoChen a658cc424b 添加了更多的材质函数,部分与引擎新特性重合,这是为了能够脱离引擎在多个版本中更具可移植性。
添加了多种对程序流程控制与保全的脚本,而且现在可以更快速的构建一个具有线性关系的协程了。
  添加了一个支持多种模式的单维梯度控制器,类似unity的颜色梯度类型。
  添加了一个用于看向某个物体的旋转控制器。
  添加了一个加载宏。
  完善了批处理脚本流程。
2023-11-23 11:10:40 +08:00

364 lines
7.1 KiB
C#

using Codice.Client.BaseCommands.BranchExplorer;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XericLibrary.Runtime.Type;
namespace XericLibrary.Runtime.MacroLibrary
{
/// <summary>
/// Ć˝ťŹşę
/// </summary>
public static partial class MacroSmooth
{
#region y=f(x)
public static double Linear(double k)
{
return k;
}
public static double QuadraticIn(double k)
{
return k * k;
}
public static double QuadraticOut(double k)
{
return k * (2 - k);
}
public static double QuadraticInOut(double k)
{
if((k *= 2) < 1)
{
return 0.5 * k * k;
}
return -0.5 * (--k * (k - 2) - 1);
}
public static double CubicIn(double k)
{
return k * k * k;
}
public static double CubicOut(double k)
{
return --k * k * k + 1;
}
public static double CubicInOut(double k)
{
if((k *= 2) < 1)
{
return 0.5 * k * k * k;
}
return 0.5 * ((k -= 2) * k * k + 2);
}
public static double QuarticIn(double k)
{
return k * k * k * k;
}
public static double QuarticOut(double k)
{
return 1 - --k * k * k * k;
}
public static double QuarticInOut(double k)
{
if((k *= 2) < 1)
{
return 0.5 * k * k * k * k;
}
return -0.5 * ((k -= 2) * k * k * k - 2);
}
public static double QuinticIn(double k)
{
return k * k * k * k * k;
}
public static double QuinticOut(double k)
{
return --k * k * k * k * k + 1;
}
public static double QuinticInOut(double k)
{
if((k *= 2) < 1)
{
return 0.5 * k * k * k * k * k;
}
return 0.5 * ((k -= 2) * k * k * k * k + 2);
}
public static double SinusoidalIn(double k)
{
return 1 - Math.Cos((k * Math.PI) / 2);
}
public static double SinusoidalOut(double k)
{
return Math.Sin((k * Math.PI) / 2);
}
public static double SinusoidalInOut(double k)
{
return 0.5 * (1 - Math.Cos(Math.PI * k));
}
public static double ExponentialIn(double k)
{
return k == 0 ? 0 : Math.Pow(1024, k - 1);
}
public static double ExponentialOut(double k)
{
return k == 1 ? 1 : 1 - Math.Pow(2, -10 * k);
}
public static double ExponentialInOut(double k)
{
if(k == 0)
{
return 0;
}
if(k == 1)
{
return 1;
}
if((k *= 2) < 1)
{
return 0.5 * Math.Pow(1024, k - 1);
}
return 0.5 * (-Math.Pow(2, -10 * (k - 1)) + 2);
}
public static double CircularIn(double k)
{
return 1 - Math.Sqrt(1 - k * k);
}
public static double CircularOut(double k)
{
return Math.Sqrt(1 - --k * k);
}
public static double CircularInOut(double k)
{
if((k *= 2) < 1)
{
return -0.5 * (Math.Sqrt(1 - k * k) - 1);
}
return 0.5 * (Math.Sqrt(1 - (k -= 2) * k) + 1);
}
public static double ElasticIn(double k)
{
double s;
var a = 0.1;
var p = 0.4;
if(k == 0)
{
return 0;
}
if(k == 1)
{
return 1;
}
if(a != 0 || a < 1)
{
a = 1;
s = p / 4;
}
else
{
s = (p * Math.Asin(1 / a)) / (2 * Math.PI);
}
return -(
a *
Math.Pow(2, 10 * (k -= 1)) *
Math.Sin(((k - s) * (2 * Math.PI)) / p)
);
}
public static double ElasticOut(double k)
{
double s;
var a = 0.1;
var p = 0.4;
if(k == 0)
{
return 0;
}
if(k == 1)
{
return 1;
}
if(a != 0 || a < 1)
{
a = 1;
s = p / 4;
}
else
{
s = (p * Math.Asin(1 / a)) / (2 * Math.PI);
}
return (
a * Math.Pow(2, -10 * k) * Math.Sin(((k - s) * (2 * Math.PI)) / p) + 1
);
}
public static double ElasticInOut(double k)
{
double s;
var a = 0.1;
var p = 0.4;
if(k == 0)
{
return 0;
}
if(k == 1)
{
return 1;
}
if(a != 0 || a < 1)
{
a = 1;
s = p / 4;
}
else
{
s = (p * Math.Asin(1 / a)) / (2 * Math.PI);
}
if((k *= 2) < 1)
{
return (
-0.5 *
(a *
Math.Pow(2, 10 * (k -= 1)) *
Math.Sin(((k - s) * (2 * Math.PI)) / p))
);
}
return (
a *
Math.Pow(2, -10 * (k -= 1)) *
Math.Sin(((k - s) * (2 * Math.PI)) / p) *
0.5 +
1
);
}
// ÔÚijҝśŻť­żŞĘźŃŘָʞľÄ¡žś˝řĐĐśŻť­´ŚŔíǰÉÔÉÔĘŐťŘ¸ĂśŻť­ľÄŇĆśŻ
public static double BackIn(double k)
{
var s = 1.70158;
return k * k * ((s + 1) * k - s);
}
public static double BackOut(double k)
{
var s = 1.70158;
return --k * k * ((s + 1) * k + s) + 1;
}
public static double BackInOut(double k)
{
var s = 1.70158 * 1.525;
if((k *= 2) < 1)
{
return 0.5 * (k * k * ((s + 1) * k - s));
}
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
}
public static double BounceIn(double k)
{
return 1 - BounceOut(1 - k);
}
public static double BounceOut(double k)
{
if(k < 1 / 2.75)
{
return 7.5625 * k * k;
}
else if(k < 2 / 2.75)
{
return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
}
else if(k < 2.5 / 2.75)
{
return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
}
else
{
return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
}
}
public static double BounceInOut(double k)
{
if(k < 0.5)
{
return BounceIn(k * 2) * 0.5;
}
return BounceIn(k * 2 - 1) * 0.5 + 0.5;
}
#endregion
#region śŕşŻĘýҝ՞ʽ˝âžö
/// <summary>
/// ÇĐťťťşśŻÄŁĘ˝
/// </summary>
/// <param name="k"></param>
/// <param name="mode"></param>
/// <returns></returns>
public static double SwitchEasing(this double k, EasingMode mode)
{
switch(mode)
{
default:
case EasingMode.Linear:
return Linear(k);
case EasingMode.QuadraticIn:
return QuadraticIn(k);
case EasingMode.QuadraticOut:
return QuadraticOut(k);
case EasingMode.QuadraticInOut:
return QuadraticInOut(k);
case EasingMode.CubicIn:
return CubicIn(k);
case EasingMode.CubicOut:
return CubicOut(k);
case EasingMode.CubicInOut:
return CubicInOut(k);
case EasingMode.QuarticIn:
return QuarticIn(k);
case EasingMode.QuarticOut:
return QuarticOut(k);
case EasingMode.QuarticInOut:
return QuarticInOut(k);
case EasingMode.QuinticIn:
return QuinticIn(k);
case EasingMode.QuinticOut:
return QuinticOut(k);
case EasingMode.QuinticInOut:
return QuinticInOut(k);
case EasingMode.SinusoidalIn:
return SinusoidalIn(k);
case EasingMode.SinusoidalOut:
return SinusoidalOut(k);
case EasingMode.SinusoidalInOut:
return SinusoidalInOut(k);
case EasingMode.ExponentialIn:
return ExponentialIn(k);
case EasingMode.ExponentialOut:
return ExponentialOut(k);
case EasingMode.ExponentialInOut:
return ExponentialInOut(k);
case EasingMode.CircularIn:
return CircularIn(k);
case EasingMode.CircularOut:
return CircularOut(k);
case EasingMode.CircularInOut:
return CircularInOut(k);
case EasingMode.ElasticIn:
return ElasticIn(k);
case EasingMode.ElasticOut:
return ElasticOut(k);
case EasingMode.ElasticInOut:
return ElasticInOut(k);
case EasingMode.BackIn:
return BackIn(k);
case EasingMode.BounceIn:
return BounceIn(k);
case EasingMode.BounceOut:
return BounceOut(k);
case EasingMode.BounceInOut:
return BounceInOut(k);
}
}
#endregion
}
}