├── .gitignore ├── EasingCore.cs ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | [Ll]ogs/ 7 | Assets/AssetStoreTools* 8 | 9 | # Windows 10 | Thumbs.db 11 | Desktop.ini 12 | 13 | # macOS 14 | .DS_Store 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # [Aa]ssets/AssetStoreTools* 18 | 19 | # TextMesh Pro files 20 | [Aa]ssets/TextMesh*Pro/ 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | .vscode/ 25 | 26 | # Gradle cache directory 27 | .gradle/ 28 | 29 | # Autogenerated VS/MD/Consulo solution and project files 30 | ExportedObj/ 31 | .consulo/ 32 | *.csproj 33 | *.unityproj 34 | *.sln 35 | *.suo 36 | *.tmp 37 | *.user 38 | *.userprefs 39 | *.pidb 40 | *.booproj 41 | *.svd 42 | *.pdb 43 | *.mdb 44 | *.opendb 45 | *.VC.db 46 | 47 | # Unity3D generated meta files 48 | *.pidb.meta 49 | *.pdb.meta 50 | *.mdb.meta 51 | 52 | # Unity3D generated file on crash reports 53 | sysinfo.txt 54 | 55 | # Builds 56 | *.apk 57 | *.unitypackage 58 | 59 | # Crashlytics generated file 60 | crashlytics-build.properties 61 | -------------------------------------------------------------------------------- /EasingCore.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * EasingCore (https://github.com/setchi/EasingCore) 3 | * Copyright (c) 2019 setchi 4 | * Licensed under MIT (https://github.com/setchi/EasingCore/blob/master/LICENSE) 5 | */ 6 | 7 | using UnityEngine; 8 | 9 | namespace EasingCore 10 | { 11 | public enum Ease 12 | { 13 | Linear, 14 | InBack, 15 | InBounce, 16 | InCirc, 17 | InCubic, 18 | InElastic, 19 | InExpo, 20 | InQuad, 21 | InQuart, 22 | InQuint, 23 | InSine, 24 | OutBack, 25 | OutBounce, 26 | OutCirc, 27 | OutCubic, 28 | OutElastic, 29 | OutExpo, 30 | OutQuad, 31 | OutQuart, 32 | OutQuint, 33 | OutSine, 34 | InOutBack, 35 | InOutBounce, 36 | InOutCirc, 37 | InOutCubic, 38 | InOutElastic, 39 | InOutExpo, 40 | InOutQuad, 41 | InOutQuart, 42 | InOutQuint, 43 | InOutSine, 44 | } 45 | 46 | public delegate float EasingFunction(float t); 47 | 48 | public static class Easing 49 | { 50 | /// 51 | /// Gets the easing function 52 | /// 53 | /// Ease type 54 | /// Easing function 55 | public static EasingFunction Get(Ease type) 56 | { 57 | switch (type) 58 | { 59 | case Ease.Linear: return linear; 60 | case Ease.InBack: return inBack; 61 | case Ease.InBounce: return inBounce; 62 | case Ease.InCirc: return inCirc; 63 | case Ease.InCubic: return inCubic; 64 | case Ease.InElastic: return inElastic; 65 | case Ease.InExpo: return inExpo; 66 | case Ease.InQuad: return inQuad; 67 | case Ease.InQuart: return inQuart; 68 | case Ease.InQuint: return inQuint; 69 | case Ease.InSine: return inSine; 70 | case Ease.OutBack: return outBack; 71 | case Ease.OutBounce: return outBounce; 72 | case Ease.OutCirc: return outCirc; 73 | case Ease.OutCubic: return outCubic; 74 | case Ease.OutElastic: return outElastic; 75 | case Ease.OutExpo: return outExpo; 76 | case Ease.OutQuad: return outQuad; 77 | case Ease.OutQuart: return outQuart; 78 | case Ease.OutQuint: return outQuint; 79 | case Ease.OutSine: return outSine; 80 | case Ease.InOutBack: return inOutBack; 81 | case Ease.InOutBounce: return inOutBounce; 82 | case Ease.InOutCirc: return inOutCirc; 83 | case Ease.InOutCubic: return inOutCubic; 84 | case Ease.InOutElastic: return inOutElastic; 85 | case Ease.InOutExpo: return inOutExpo; 86 | case Ease.InOutQuad: return inOutQuad; 87 | case Ease.InOutQuart: return inOutQuart; 88 | case Ease.InOutQuint: return inOutQuint; 89 | case Ease.InOutSine: return inOutSine; 90 | default: return linear; 91 | } 92 | 93 | float linear(float t) => t; 94 | 95 | float inBack(float t) => t * t * t - t * Mathf.Sin(t * Mathf.PI); 96 | 97 | float outBack(float t) => 1f - inBack(1f - t); 98 | 99 | float inOutBack(float t) => 100 | t < 0.5f 101 | ? 0.5f * inBack(2f * t) 102 | : 0.5f * outBack(2f * t - 1f) + 0.5f; 103 | 104 | float inBounce(float t) => 1f - outBounce(1f - t); 105 | 106 | float outBounce(float t) => 107 | t < 4f / 11.0f ? 108 | (121f * t * t) / 16.0f : 109 | t < 8f / 11.0f ? 110 | (363f / 40.0f * t * t) - (99f / 10.0f * t) + 17f / 5.0f : 111 | t < 9f / 10.0f ? 112 | (4356f / 361.0f * t * t) - (35442f / 1805.0f * t) + 16061f / 1805.0f : 113 | (54f / 5.0f * t * t) - (513f / 25.0f * t) + 268f / 25.0f; 114 | 115 | float inOutBounce(float t) => 116 | t < 0.5f 117 | ? 0.5f * inBounce(2f * t) 118 | : 0.5f * outBounce(2f * t - 1f) + 0.5f; 119 | 120 | float inCirc(float t) => 1f - Mathf.Sqrt(1f - (t * t)); 121 | 122 | float outCirc(float t) => Mathf.Sqrt((2f - t) * t); 123 | 124 | float inOutCirc(float t) => 125 | t < 0.5f 126 | ? 0.5f * (1 - Mathf.Sqrt(1f - 4f * (t * t))) 127 | : 0.5f * (Mathf.Sqrt(-((2f * t) - 3f) * ((2f * t) - 1f)) + 1f); 128 | 129 | float inCubic(float t) => t * t * t; 130 | 131 | float outCubic(float t) => inCubic(t - 1f) + 1f; 132 | 133 | float inOutCubic(float t) => 134 | t < 0.5f 135 | ? 4f * t * t * t 136 | : 0.5f * inCubic(2f * t - 2f) + 1f; 137 | 138 | float inElastic(float t) => Mathf.Sin(13f * (Mathf.PI * 0.5f) * t) * Mathf.Pow(2f, 10f * (t - 1f)); 139 | 140 | float outElastic(float t) => Mathf.Sin(-13f * (Mathf.PI * 0.5f) * (t + 1)) * Mathf.Pow(2f, -10f * t) + 1f; 141 | 142 | float inOutElastic(float t) => 143 | t < 0.5f 144 | ? 0.5f * Mathf.Sin(13f * (Mathf.PI * 0.5f) * (2f * t)) * Mathf.Pow(2f, 10f * ((2f * t) - 1f)) 145 | : 0.5f * (Mathf.Sin(-13f * (Mathf.PI * 0.5f) * ((2f * t - 1f) + 1f)) * Mathf.Pow(2f, -10f * (2f * t - 1f)) + 2f); 146 | 147 | float inExpo(float t) => Mathf.Approximately(0.0f, t) ? t : Mathf.Pow(2f, 10f * (t - 1f)); 148 | 149 | float outExpo(float t) => Mathf.Approximately(1.0f, t) ? t : 1f - Mathf.Pow(2f, -10f * t); 150 | 151 | float inOutExpo(float v) => 152 | Mathf.Approximately(0.0f, v) || Mathf.Approximately(1.0f, v) 153 | ? v 154 | : v < 0.5f 155 | ? 0.5f * Mathf.Pow(2f, (20f * v) - 10f) 156 | : -0.5f * Mathf.Pow(2f, (-20f * v) + 10f) + 1f; 157 | 158 | float inQuad(float t) => t * t; 159 | 160 | float outQuad(float t) => -t * (t - 2f); 161 | 162 | float inOutQuad(float t) => 163 | t < 0.5f 164 | ? 2f * t * t 165 | : -2f * t * t + 4f * t - 1f; 166 | 167 | float inQuart(float t) => t * t * t * t; 168 | 169 | float outQuart(float t) 170 | { 171 | var u = t - 1f; 172 | return u * u * u * (1f - t) + 1f; 173 | } 174 | 175 | float inOutQuart(float t) => 176 | t < 0.5f 177 | ? 8f * inQuart(t) 178 | : -8f * inQuart(t - 1f) + 1f; 179 | 180 | float inQuint(float t) => t * t * t * t * t; 181 | 182 | float outQuint(float t) => inQuint(t - 1f) + 1f; 183 | 184 | float inOutQuint(float t) => 185 | t < 0.5f 186 | ? 16f * inQuint(t) 187 | : 0.5f * inQuint(2f * t - 2f) + 1f; 188 | 189 | float inSine(float t) => Mathf.Sin((t - 1f) * (Mathf.PI * 0.5f)) + 1f; 190 | 191 | float outSine(float t) => Mathf.Sin(t * (Mathf.PI * 0.5f)); 192 | 193 | float inOutSine(float t) => 0.5f * (1f - Mathf.Cos(t * Mathf.PI)); 194 | } 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 setchi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasingCore [![license](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/setchi/Easings/blob/master/LICENSE) [![openupm](https://img.shields.io/npm/v/jp.setchi.easingcore?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/jp.setchi.easingcore/) 2 | Core Easing Implementation for Unity. 3 | 4 | ## API 5 | ```csharp 6 | public static EasingFunction Get(Ease type) 7 | ``` 8 | 9 | ## Usage 10 | ```csharp 11 | var easeOutCubic = Easing.Get(Ease.OutCubic); 12 | var p = easeOutCubic(0.5f); 13 | ``` 14 | 15 | ## Installation 16 | ### OpenUPM 17 | Add a package from [OpenUPM](https://openupm.com/) registry to your project. 18 | 19 | ``` 20 | openupm add jp.setchi.easingcore 21 | ``` 22 | 23 | ### Unity Package Manager 24 | Add a reference to the repository in the [`Packages\manifest.json`](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@1.8/manual/index.html#project-manifests) file in your project directory: 25 | 26 | ```json 27 | { 28 | "dependencies": { 29 | "jp.setchi.easingcore": "https://github.com/setchi/EasingCore.git#upm" 30 | } 31 | } 32 | ``` 33 | 34 | ### Manual 35 | Clone or download this repository into the Assets directory of your project. 36 | 37 | ## Author 38 | [setchi](https://github.com/setchi) 39 | 40 | ## License 41 | [MIT](https://github.com/setchi/EasingCore/blob/master/LICENSE) 42 | --------------------------------------------------------------------------------