├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NavMeshLayers.asset ├── TimeManager.asset ├── DynamicsManager.asset ├── EditorSettings.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── GraphicsSettings.asset ├── Physics2DSettings.asset └── EditorBuildSettings.asset ├── Assets ├── GoKitLite.meta ├── GoKitLiteDemo.meta ├── GoKitLiteDemo │ ├── WaterMaterial.mat │ ├── water-texture.jpg │ ├── 1. SimpleTween.unity │ ├── 2. Stress Test.unity │ ├── 4. Tween Flows.unity │ ├── 3. Tween Chaining.unity │ ├── TransDiffuseMaterial.mat │ ├── scripts.meta │ ├── 5. Custom Properties.unity │ ├── 1. SimpleTween.unity.meta │ ├── 2. Stress Test.unity.meta │ ├── 4. Tween Flows.unity.meta │ ├── 3. Tween Chaining.unity.meta │ ├── 5. Custom Properties.unity.meta │ ├── WaterMaterial.mat.meta │ ├── TransDiffuseMaterial.mat.meta │ ├── scripts │ │ ├── TweenFlowUI.cs.meta │ │ ├── GoKitLiteActions.cs.meta │ │ ├── SimpleTweenUI.cs.meta │ │ ├── StressTestGUI.cs.meta │ │ ├── TweenChainingUI.cs.meta │ │ ├── CustomPropertiesUI.cs.meta │ │ ├── CustomPropertiesUI.cs │ │ ├── TweenFlowUI.cs │ │ ├── TweenChainingUI.cs │ │ ├── GoKitLiteActions.cs │ │ ├── SimpleTweenUI.cs │ │ └── StressTestGUI.cs │ └── water-texture.jpg.meta └── GoKitLite │ ├── GoKitLite.cs.meta │ ├── GoKitLiteTweenFlow.cs.meta │ ├── GoKitLitePropertyTweens.cs.meta │ ├── GoKitLiteEasing.cs.meta │ ├── GoKitLiteEaseType.cs.meta │ ├── GoKitLiteTweenFlow.cs │ ├── GoKitLiteEaseType.cs │ ├── GoKitLitePropertyTweens.cs │ ├── GoKitLiteEasing.cs │ └── GoKitLite.cs ├── .gitignore └── README.md /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.0.1f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Assets/GoKitLite.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ee938f09a37c4492996705471f415dc 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5efdda6c518ef4b73a053c27080e723e 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/WaterMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/WaterMaterial.mat -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/water-texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/water-texture.jpg -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/1. SimpleTween.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/1. SimpleTween.unity -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/2. Stress Test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/2. Stress Test.unity -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/4. Tween Flows.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/4. Tween Flows.unity -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/3. Tween Chaining.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/3. Tween Chaining.unity -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/TransDiffuseMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/TransDiffuseMaterial.mat -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ab8ffd3eaeaf465782542da8562ee12 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/5. Custom Properties.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/GoKitLite/HEAD/Assets/GoKitLiteDemo/5. Custom Properties.unity -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/1. SimpleTween.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 25b888c2734bc4a30be1cdbd0b65c390 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/2. Stress Test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3bc2be074df1546d6970c485c8cd18c4 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/4. Tween Flows.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55a6500d11aec4c2c887ac5f1332cc5b 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/3. Tween Chaining.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 398a4fe68805f4ad09e10e2f6ac2d209 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/5. Custom Properties.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6942e7422d834442896c1ebf900c1f6 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/WaterMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91e2aa9bd4ee64df79bce08b3f0161c2 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/TransDiffuseMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09b076fa73c294f2283d4fa4c58d1a8d 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | 5 | # Autogenerated VS/MD solution and project files 6 | *.csproj 7 | *.unityproj 8 | *.sln 9 | *.pidb 10 | Xcode 11 | GoKitLite.userprefs 12 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLite.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd2c5a35631584e6cb778c4025881953 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLiteTweenFlow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8bf8bb99540974252b7c734bedc3ca86 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLitePropertyTweens.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4add0e8600704c5f9ab98e46c8d2c60 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/TweenFlowUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8b7ed835a310941559b886cc7a474bd6 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/GoKitLiteActions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3efa7286b840a4e4ebf6d77ca6239bbd 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/SimpleTweenUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 916f62531382a4b46a35d20000e4f9ec 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/StressTestGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eb8fd1081c729463191ec62ad7cb22ad 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/TweenChainingUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e8fa6d47e92e44ac98d07c7af76fa4dd 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/CustomPropertiesUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b259613be15144d408a3219e955b9256 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLiteEasing.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 599ac61fb930f49f2ab516642f7b00bb 3 | timeCreated: 1428961069 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLiteEaseType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab3adb016eaea4e4b9f222b6649dcefc 3 | timeCreated: 1428961056 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/water-texture.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6649aff3e47a84c4ba2a9bd50ad6021c 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: -1 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/CustomPropertiesUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using Prime31.GoKitLite; 4 | 5 | 6 | public class CustomPropertiesUI : MonoBehaviour 7 | { 8 | public Transform cube; 9 | 10 | // custom property example 11 | public float width 12 | { 13 | set 14 | { 15 | cube.localScale = new Vector3( value, cube.localScale.y, cube.localScale.z ); 16 | } 17 | get 18 | { 19 | return cube.localScale.x; 20 | } 21 | } 22 | 23 | public float height 24 | { 25 | set 26 | { 27 | cube.localScale = new Vector3( cube.localScale.x, value, cube.localScale.z ); 28 | } 29 | get 30 | { 31 | return cube.localScale.y; 32 | } 33 | } 34 | 35 | 36 | void OnGUI() 37 | { 38 | if( GUILayout.Button( "Tween Custom Property (width -> localScale.x)" ) ) 39 | { 40 | var prop = new FloatTweenProperty( this, "width", 8f ); 41 | GoKitLite.instance.propertyTween( prop, 2f ) 42 | .setEaseType( EaseType.BounceOut ); 43 | } 44 | 45 | 46 | if( GUILayout.Button( "Relative Tween of Custom Property (height -> localScale.y)" ) ) 47 | { 48 | var prop = new FloatTweenProperty( this, "height", 2f, true ); 49 | GoKitLite.instance.propertyTween( prop, 1f ) 50 | .setEaseType( EaseType.BounceOut ); 51 | } 52 | 53 | 54 | if( GUILayout.Button( "Position Tween" ) ) 55 | { 56 | var toTenTween = new Vector3TweenProperty( cube, "position", new Vector3( 10, 10, 10 ) ); 57 | var backHomeTween = new Vector3TweenProperty( cube, "position", Vector3.zero ); 58 | 59 | GoKitLite.instance.propertyTween( toTenTween, 1f ) 60 | .setEaseType( EaseType.BounceOut ) 61 | .next( 1f, backHomeTween ); 62 | } 63 | 64 | 65 | if( GUILayout.Button( "Tween Main Texture Offset" ) ) 66 | { 67 | var prop = new Vector2TweenProperty( cube.GetComponent().material, "mainTextureOffset", new Vector2( 50, 50 ) ); 68 | GoKitLite.instance.propertyTween( prop, 60f ) 69 | .setEaseType( EaseType.Linear ); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/TweenFlowUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Prime31.GoKitLite; 5 | 6 | 7 | public class TweenFlowUI : MonoBehaviour 8 | { 9 | public Transform cube; 10 | 11 | 12 | void OnGUI() 13 | { 14 | GUI.matrix = Matrix4x4.Scale( new Vector3( 2, 2, 2 ) ); 15 | 16 | if( GUILayout.Button( "Tween Position/Rotation Flow" ) ) 17 | { 18 | Debug.Log( "Do a position tween that lasts 5 seconds and do a rotation tween every second for 0.5 seconds while the position tween is going" ); 19 | 20 | var flow = new TweenFlow().add( 0, () => { return GoKitLite.instance.positionTo( cube, 5f, new Vector3( 10, 10, 10 ) ); } ) 21 | .add( 1f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 90, 0, 0 ) ); } ) 22 | .add( 2f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 0, 90, 0 ) ); } ) 23 | .add( 3f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 0, 0, 90 ) ); } ) 24 | .add( 4f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 180, 180, 180 ) ); } ) 25 | .setCompletionHandler( () => { Debug.Log( "All done with the position/rotation flow" ); } ); 26 | 27 | StartCoroutine( flow.start() ); 28 | } 29 | 30 | 31 | if( GUILayout.Button( "Bounce and Tween Color" ) ) 32 | { 33 | Debug.Log( "First move to 0,0,0 then do a position tween up/down/up/down while simultaneously tweening the color" ); 34 | 35 | // first we add our position tweens 36 | var flow = new TweenFlow().add( 0, () => { return GoKitLite.instance.positionTo( cube, 1f, new Vector3( 0, 0, 0 ) ); } ) 37 | .add( 1, () => { return GoKitLite.instance.positionTo( cube, 1f, new Vector3( 0, 5, 0 ) ); } ) 38 | .add( 2, () => { return GoKitLite.instance.positionTo( cube, 1f, new Vector3( 0, 0, 0 ) ); } ) 39 | .add( 3, () => { return GoKitLite.instance.positionTo( cube, 1f, new Vector3( 0, 5, 0 ) ); } ) 40 | .add( 4, () => { return GoKitLite.instance.positionTo( cube, 1f, new Vector3( 0, 0, 0 ) ); } ); 41 | 42 | // now we add the color tweens. each will start just after the position tween starts 43 | flow.add( 1.2f, () => { return GoKitLite.instance.colorTo( cube, 0.5f, Color.magenta ); } ) 44 | .add( 2.2f, () => { return GoKitLite.instance.colorTo( cube, 0.5f, Color.blue ); } ) 45 | .add( 3.2f, () => { return GoKitLite.instance.colorTo( cube, 0.5f, Color.yellow ); } ) 46 | .add( 4.2f, () => { return GoKitLite.instance.colorTo( cube, 0.5f, Color.green ); } ); 47 | 48 | StartCoroutine( flow.start() ); 49 | } 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/TweenChainingUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Prime31.GoKitLite; 5 | 6 | 7 | 8 | public class TweenChainingUI : MonoBehaviour 9 | { 10 | public Transform cube; 11 | 12 | 13 | void OnGUI() 14 | { 15 | GUI.matrix = Matrix4x4.Scale( new Vector3( 2, 2, 2 ) ); 16 | 17 | if( GUILayout.Button( "Tween Position Queue" ) ) 18 | { 19 | GoKitLite.instance.positionTo( cube, 0.4f, new Vector3( 10, 10, 10 ) ) 20 | .setEaseType( EaseType.QuadInOut ) 21 | .next( 0.4f, new Vector3( 0, 0, 0 ) ) 22 | .next( 0.4f, new Vector3( 0, -5, -10 ) ) 23 | .next( 0.4f, new Vector3( -3, 5, 20 ) ) 24 | .next( 0.4f, new Vector3( 0, 0, 0 ) ); 25 | } 26 | 27 | 28 | if( GUILayout.Button( "Tween Position Queue with Delays" ) ) 29 | { 30 | GoKitLite.instance.positionTo( cube, 0.4f, new Vector3( 10, 10, 10 ) ) 31 | .setDelay( 0.3f ) 32 | .setEaseType( EaseType.QuadInOut ) 33 | .next( 0.4f, new Vector3( 0, 0, 0 ), 0.3f ) 34 | .next( 0.4f, new Vector3( 0, -5, -10 ), 0.3f ) 35 | .next( 0.4f, new Vector3( -3, 5, 20 ), 0.3f ) 36 | .next( 0.4f, new Vector3( 0, 0, 0 ), 0.3f ); 37 | } 38 | 39 | 40 | if( GUILayout.Button( "Tween Position and Rotation Queue" ) ) 41 | { 42 | GoKitLite.instance.positionTo( cube, 0.4f, new Vector3( -8, -3, 0 ) ) 43 | .setEaseType( EaseType.QuadInOut ) 44 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 90f, 0, 0 ) ) 45 | .next( GoKitLite.TweenType.Position, 0.4f, new Vector3( 1, 2, -5 ) ) 46 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 0, 90, 90 ) ) 47 | .next( GoKitLite.TweenType.Position, 0.4f, new Vector3( 0, 0, 0 ) ) 48 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 360, 360, 0 ) ) 49 | .setCompletionHandler( trans => { Debug.Log( "Position and Rotation Queue Done" ); } ); 50 | } 51 | 52 | 53 | if( GUILayout.Button( "Lots of Stuff Queue" ) ) 54 | { 55 | GoKitLite.instance.positionTo( cube, 0.4f, new Vector3( -8, -3, 0 ) ) 56 | .setEaseType( EaseType.QuadInOut ) 57 | .next( 0.3f, Color.red ) 58 | .next( GoKitLite.TweenType.Position, 0.4f, new Vector3( 1, 2, -5 ) ) 59 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 0, 90, 90 ) ) 60 | .next( 0.3f, Color.yellow ) 61 | .next( GoKitLite.TweenType.Scale, 0.8f, new Vector3( 3, 3, 3 ) ) 62 | .setEaseType( EaseType.Punch ) 63 | .next( GoKitLite.TweenType.Position, 0.4f, new Vector3( 0, 0, 0 ) ) 64 | .next( 0.3f, Color.blue ) 65 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 360, 360, 0 ), true ) 66 | .next( GoKitLite.TweenType.Scale, 0.8f, new Vector3( 4f, 0.2f, 0.2f ) ) 67 | .setEaseType( EaseType.BounceOut ) 68 | .setLoopType( GoKitLite.LoopType.PingPong, 1 ) 69 | .next( 1.3f, Color.gray, "_Color" ) 70 | .setDelay( 0.2f ); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLiteTweenFlow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using Prime31.GoKitLite; 6 | 7 | 8 | /// 9 | /// totally optional classes for making tween flows 10 | /// 11 | namespace Prime31.GoKitLite 12 | { 13 | public class TweenFlow 14 | { 15 | /// 16 | /// used internally as a wrapper to handle TweenFlows 17 | /// 18 | internal struct TweenFlowItem : IComparable 19 | { 20 | internal float startTime; 21 | internal System.Func actionTween; 22 | 23 | 24 | public TweenFlowItem( float startTime, System.Func actionTween ) 25 | { 26 | this.actionTween = actionTween; 27 | this.startTime = startTime; 28 | } 29 | 30 | 31 | public int CompareTo( object obj ) 32 | { 33 | return ((TweenFlowItem)obj).startTime.CompareTo( startTime ); 34 | } 35 | 36 | } 37 | 38 | 39 | private List _tweenFlows = new List(); 40 | private System.Action _onComplete; 41 | private int _currentlyRunningTweenId; 42 | private int _completionHandlersWaitingToFire = 0; 43 | 44 | 45 | private void onTweenComplete( Transform trans ) 46 | { 47 | _completionHandlersWaitingToFire--; 48 | 49 | if( _completionHandlersWaitingToFire == 0 && _tweenFlows.Count == 0 && _onComplete != null ) 50 | _onComplete(); 51 | } 52 | 53 | 54 | public TweenFlow add( float startTime, System.Func actionTween ) 55 | { 56 | _tweenFlows.Add( new TweenFlowItem( startTime, actionTween ) ); 57 | return this; 58 | } 59 | 60 | 61 | public TweenFlow setCompletionHandler( System.Action onComplete ) 62 | { 63 | _onComplete = onComplete; 64 | return this; 65 | } 66 | 67 | 68 | public IEnumerator start() 69 | { 70 | // sort our list so we can iterate backwards and remove items as necessary 71 | _tweenFlows.Sort(); 72 | 73 | // state for the flow 74 | var elapsedTime = 0f; 75 | var running = true; 76 | 77 | while( running ) 78 | { 79 | elapsedTime += Time.deltaTime; 80 | 81 | // loop backwards so we can remove items as we run them and break the loop when we get past any flow items set to run 82 | for( var i = _tweenFlows.Count - 1; i >= 0; i-- ) 83 | { 84 | if( elapsedTime >= _tweenFlows[i].startTime ) 85 | { 86 | var flowItem = _tweenFlows[i]; 87 | _tweenFlows.RemoveAt( i ); 88 | _currentlyRunningTweenId = flowItem.actionTween().setCompletionHandler( onTweenComplete ).getId(); 89 | _completionHandlersWaitingToFire++; 90 | } 91 | else 92 | { 93 | break; 94 | } 95 | } 96 | 97 | yield return null; 98 | } 99 | } 100 | 101 | 102 | public void stop( bool bringCurrentlyRunningTweenToCompletion ) 103 | { 104 | _tweenFlows.Clear(); 105 | GoKitLite.instance.stopTween( _currentlyRunningTweenId, bringCurrentlyRunningTweenToCompletion ); 106 | } 107 | 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLiteEaseType.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | namespace Prime31.GoKitLite 6 | { 7 | public enum EaseType 8 | { 9 | Linear, 10 | 11 | SineIn, 12 | SineOut, 13 | SineInOut, 14 | 15 | QuadIn, 16 | QuadOut, 17 | QuadInOut, 18 | 19 | CubicIn, 20 | CubicOut, 21 | CubicInOut, 22 | 23 | QuartIn, 24 | QuartOut, 25 | QuartInOut, 26 | 27 | QuintIn, 28 | QuintOut, 29 | QuintInOut, 30 | 31 | ExpoIn, 32 | ExpoOut, 33 | ExpoInOut, 34 | 35 | CircIn, 36 | CircOut, 37 | CircInOut, 38 | 39 | ElasticIn, 40 | ElasticOut, 41 | ElasticInOut, 42 | Punch, 43 | 44 | BackIn, 45 | BackOut, 46 | BackInOut, 47 | 48 | BounceIn, 49 | BounceOut, 50 | BounceInOut 51 | } 52 | 53 | 54 | /// 55 | /// helper with a single method that takes in an EaseType and applies that ease equation with the given 56 | /// duration and time parameters. We do this to avoid passing around Funcs which create bogs of trash for 57 | /// the garbage collector (function pointers please!) 58 | /// 59 | public static class EaseHelper 60 | { 61 | public static float ease( EaseType easeType, float t, float duration ) 62 | { 63 | switch( easeType ) 64 | { 65 | case EaseType.Linear: 66 | return Easing.Linear.EaseNone( t, duration ); 67 | 68 | case EaseType.BackIn: 69 | return Easing.Back.EaseIn( t, duration ); 70 | case EaseType.BackOut: 71 | return Easing.Back.EaseOut( t, duration ); 72 | case EaseType.BackInOut: 73 | return Easing.Back.EaseInOut( t, duration ); 74 | 75 | case EaseType.BounceIn: 76 | return Easing.Bounce.EaseIn( t, duration ); 77 | case EaseType.BounceOut: 78 | return Easing.Bounce.EaseOut( t, duration ); 79 | case EaseType.BounceInOut: 80 | return Easing.Bounce.EaseInOut( t, duration ); 81 | 82 | case EaseType.CircIn: 83 | return Easing.Circular.EaseIn( t, duration ); 84 | case EaseType.CircOut: 85 | return Easing.Circular.EaseOut( t, duration ); 86 | case EaseType.CircInOut: 87 | return Easing.Circular.EaseInOut( t, duration ); 88 | 89 | case EaseType.CubicIn: 90 | return Easing.Cubic.EaseIn( t, duration ); 91 | case EaseType.CubicOut: 92 | return Easing.Cubic.EaseOut( t, duration ); 93 | case EaseType.CubicInOut: 94 | return Easing.Cubic.EaseInOut( t, duration ); 95 | 96 | case EaseType.ElasticIn: 97 | return Easing.Elastic.EaseIn( t, duration ); 98 | case EaseType.ElasticOut: 99 | return Easing.Elastic.EaseOut( t, duration ); 100 | case EaseType.ElasticInOut: 101 | return Easing.Elastic.EaseInOut( t, duration ); 102 | case EaseType.Punch: 103 | return Easing.Elastic.Punch( t, duration ); 104 | 105 | case EaseType.ExpoIn: 106 | return Easing.Exponential.EaseIn( t, duration ); 107 | case EaseType.ExpoOut: 108 | return Easing.Exponential.EaseOut( t, duration ); 109 | case EaseType.ExpoInOut: 110 | return Easing.Exponential.EaseInOut( t, duration ); 111 | 112 | case EaseType.QuadIn: 113 | return Easing.Quadratic.EaseIn( t, duration ); 114 | case EaseType.QuadOut: 115 | return Easing.Quadratic.EaseOut( t, duration ); 116 | case EaseType.QuadInOut: 117 | return Easing.Quadratic.EaseInOut( t, duration ); 118 | 119 | case EaseType.QuartIn: 120 | return Easing.Quartic.EaseIn( t, duration ); 121 | case EaseType.QuartOut: 122 | return Easing.Quartic.EaseOut( t, duration ); 123 | case EaseType.QuartInOut: 124 | return Easing.Quartic.EaseInOut( t, duration ); 125 | 126 | case EaseType.QuintIn: 127 | return Easing.Quintic.EaseIn( t, duration ); 128 | case EaseType.QuintOut: 129 | return Easing.Quintic.EaseOut( t, duration ); 130 | case EaseType.QuintInOut: 131 | return Easing.Quintic.EaseInOut( t, duration ); 132 | 133 | case EaseType.SineIn: 134 | return Easing.Sinusoidal.EaseIn( t, duration ); 135 | case EaseType.SineOut: 136 | return Easing.Sinusoidal.EaseOut( t, duration ); 137 | case EaseType.SineInOut: 138 | return Easing.Sinusoidal.EaseInOut( t, duration ); 139 | 140 | default: 141 | return Easing.Linear.EaseNone( t, duration ); 142 | } 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GoKitLite 2 | ========= 3 | 4 | GoKitLite is a *crazy* fast tweening library for Unity. It is optimized for mobile with near zero allocations at runtime. GoKitLite can tween position, localPosition, scale, rotation, localRotation, material color and any properties (float, Vector2, Vector3 or Color). It will tween "to" a value or "from" one to the current value. GoKitLite can also call your own custom Action so that you can tween anything that you want that isn't supported or isnt a property. 5 | 6 | GoKitLite usage is dead simple. Below are some examples: 7 | 8 | // tween the position of an object to 10, 10, 10 over 1 second 9 | GoKitLite.instance.positionTo( someTransform, 1s, new Vector3( 10, 10, 10 ) ); 10 | 11 | // tween the rotation of an object to 0, 90, 0 over 0.5 seconds with a custom ease type 12 | GoKitLite.instance.rotationTo( someTransform, 0.5f, new Vector3( 0, 90f, 0 ) ) 13 | .setEaseFunction( GoKitLiteEasing.Back.EaseOut ); 14 | 15 | // tween the color of a material to red over 1 second with a 3 second delay before starting 16 | GoKitLite.instance.colorTo( someTransform, 1, Color.red, 3 ); 17 | 18 | Up above we mentioned that you can use a custom Action to handle a tween as well. Here is an example: 19 | 20 | // tween the position of an object to 10, 10, 10 over 1 second 21 | GoKitLite.instance.customAction( someTransform, 1s, ( trans, t ) => { 22 | // do something really cool here like tweening a string or changing multiple objects/properties at once 23 | }); 24 | 25 | 26 | GoKitLite also has a tween chaining system to setup a series of tweens that will all run one after the other. Here is an example alternating position and rotation tweens with a completion handler that will fire when the entire chain is complete: 27 | 28 | GoKitLite.instance.positionTo( cube, 0.4f, new Vector3( -8, -3, 0 ) ) 29 | .setEaseFunction( GoKitLiteEasing.Quadratic.EaseInOut ) 30 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 90f, 0, 0 ) ) 31 | .next( GoKitLite.TweenType.Position, 0.4f, new Vector3( 1, 2, -5 ) ) 32 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 0, 90, 90 ) ) 33 | .next( GoKitLite.TweenType.Position, 0.4f, new Vector3( 0, 0, 0 ) ) 34 | .next( GoKitLite.TweenType.Rotation, 0.4f, new Vector3( 360, 360, 0 ) ) 35 | .setCompletionHandler( trans => { Debug.Log( "Position and Rotation Queue Done" ); } ); 36 | 37 | 38 | Building on the tween chaining system there is also a tween flow system. TweenFlows let you setup a timeline of tweens each with a specific start time. Unlike TweenQueues, tweens in a TweenFlow can be running simultaneously. Here is an example of a position tween that has 4 rotation tweens applied while it is still in transit to it's final position. Note that the start method must be called as a coroutine: 39 | 40 | var flow = new GoKitLite.TweenFlow().add( 0, () => { return GoKitLite.instance.positionTo( cube, 5f, new Vector3( 10, 10, 10 ) ); } ) 41 | .add( 1f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 90, 0, 0 ) ); } ) 42 | .add( 2f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 0, 90, 0 ) ); } ) 43 | .add( 3f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 0, 0, 90 ) ); } ) 44 | .add( 4f, () => { return GoKitLite.instance.rotationTo( cube, 0.5f, new Vector3( 180, 180, 180 ) ); } ) 45 | .setCompletionHandler( () => { Debug.Log( "All done with the position/rotation flow" ); } ); 46 | StartCoroutine( flow.start() ); 47 | 48 | 49 | 50 | GoKitActions 51 | ========= 52 | 53 | GoKitActions is an optional class that contains additional actions that can be used with GoKitLite's customAction() method: 54 | 55 | GoKitLite.instance.customAction( cube, 2, GoKitLiteActions.ShakePosition( cube, 0.6f ), 0, GoKitLiteEasing.Linear.EaseNone ); 56 | 57 | 58 | What about GoKit? 59 | ========= 60 | 61 | GoKit has a slightly different focus than GoKitLite. It is highly customizeable and can tween anything at all. GoKit has all kinds of nifty features like chains, flows and full tween control in real time that arent ever going to be in GoKitLite. GoKitLite is made for folks who want a really easy API and just want to tween stuff now without much thought. 62 | 63 | 64 | 65 | License 66 | ----- 67 | [Attribution-NonCommercial-ShareAlike 3.0 Unported](http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode) with [simple explanation](http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US) with the attribution clause waived. You are free to use GoKitLite in any and all games that you make. You cannot sell GoKitLite directly or as part of a larger game asset. 68 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/GoKitLiteActions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | /// 6 | /// This class contains a few custom GoKitLite actions. Thanks to Prime31 for this great little tweening library. 7 | /// 8 | public static class GoKitLiteActions 9 | { 10 | /// 11 | /// Shakes the position of the given transform at the starting shake intensity and decreases until dt = 1 at which point shakeIntensity = 0 and 12 | /// the transform's position is returned to its original value. 13 | /// 14 | /// 15 | /// An action delegate to be used in a GoKitLite.instance.customAction() method call. 16 | /// 17 | /// 18 | /// The transform of the object to shake 19 | /// 20 | /// 21 | /// The starting shake intensity. 22 | /// 23 | public static System.Action shakePosition( Transform trans, float shakeIntensity ) 24 | { 25 | var origPos = trans.position; 26 | 27 | System.Action action = ( t, dt ) => 28 | { 29 | // start at full shake intensity and ramp down from there 30 | t.position = origPos + Random.insideUnitSphere * shakeIntensity * ( 1 - dt ); 31 | 32 | if( dt >= 1 ) 33 | t.position = origPos; 34 | }; 35 | return action; 36 | } 37 | 38 | 39 | /// 40 | /// Ramps up the shake intensity until it reaches the specified value (occurs at dt = 0.5f) at which 41 | /// point the shake intensity ramps back down to 0 and the transform's position is returned to its 42 | /// original value. 43 | /// 44 | /// 45 | /// An action delegate to be used in a GoKitLite.instance.customAction() method call. 46 | /// 47 | /// 48 | /// The transform of the object to shake 49 | /// 50 | /// 51 | /// The maximum shake intensity (occurs at dt = 0.5 which is duration / 2) 52 | /// 53 | public static System.Action shakePositionRamp( Transform trans, float maxShakeIntensity ) 54 | { 55 | // store original position 56 | var origPos = trans.position; 57 | 58 | System.Action action = ( t, dt ) => 59 | { 60 | // ramp up 61 | if( dt < 0.5f ) 62 | t.position = origPos + Random.insideUnitSphere * maxShakeIntensity * 2 * dt; 63 | else // ramp down 64 | t.position = origPos + Random.insideUnitSphere * maxShakeIntensity * 2 * ( 1 - dt ); 65 | 66 | // return to original position 67 | if( dt >= 1 ) 68 | t.position = origPos; 69 | }; 70 | return action; 71 | } 72 | 73 | 74 | /// 75 | /// Shakes the scale of the given transform at the starting shake intensity 76 | /// and decreases until dt = 1 at which point shakeIntensity = 0 and 77 | /// the transform's scale is returned to its original value. 78 | /// 79 | /// 80 | /// An action delegate to be used in a GoKitLite.instance.customAction() method call. 81 | /// 82 | /// 83 | /// The transform of the object to shake 84 | /// 85 | /// 86 | /// The starting shake intensity. 87 | /// 88 | public static System.Action shakeScale( Transform trans, float shakeIntensity ) 89 | { 90 | var origScale = trans.localScale; 91 | 92 | System.Action action = ( t, dt ) => 93 | { 94 | t.localScale = origScale + Random.insideUnitSphere * shakeIntensity * ( 1 - dt ); 95 | 96 | if( dt >= 1 ) 97 | t.localScale = origScale; 98 | 99 | }; 100 | return action; 101 | } 102 | 103 | 104 | /// 105 | /// Ramps up the shake intensity until it reaches the specified value (occurs at dt = 0.5f) at which 106 | /// point the shake intensity ramps back down to 0 and the transform's scale is returned to its 107 | /// original value. 108 | /// 109 | /// 110 | /// An action delegate to be used in a GoKitLite.instance.customAction() method call. 111 | /// 112 | /// 113 | /// The transform of the object to shake 114 | /// 115 | /// 116 | /// The maximum shake intensity (occurs at dt = 0.5 which is duration / 2) 117 | /// 118 | public static System.Action shakeScaleRamp( Transform trans, float maxShakeIntensity ) 119 | { 120 | // store original position 121 | var origScale = trans.localScale; 122 | 123 | System.Action action = ( t, dt ) => 124 | { 125 | // ramp up 126 | if( dt < 0.5f ) 127 | t.localScale = origScale + Random.insideUnitSphere * maxShakeIntensity * 2 * dt; 128 | else // ramp down 129 | t.localScale = origScale + Random.insideUnitSphere * maxShakeIntensity * 2 * ( 1 - dt ); 130 | 131 | // return to original position 132 | if( dt >= 1 ) 133 | t.localScale = origScale; 134 | }; 135 | return action; 136 | } 137 | 138 | } 139 | 140 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/SimpleTweenUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using Prime31.GoKitLite; 4 | using UnityEngine.UI; 5 | 6 | 7 | public class SimpleTweenUI : MonoBehaviour 8 | { 9 | public Transform cube; 10 | public AnimationCurve easeCurve; 11 | public RectTransform panel; 12 | 13 | 14 | void Start() 15 | { 16 | // start it off with our cube friend coming into view 17 | GoKitLite.instance.positionFrom( cube, Random.Range( 0.2f, 1 ), new Vector3( 10, 10, 0 ) ); 18 | } 19 | 20 | 21 | void OnGUI() 22 | { 23 | if( GUILayout.Button( "Position Tween with PingPong Loop" ) ) 24 | { 25 | GoKitLite.instance.positionTo( cube, Random.Range( 1f, 2f ), new Vector3( 10, 5, 0 ) ) 26 | .setEaseType( EaseType.BounceOut ) 27 | .setLoopType( GoKitLite.LoopType.PingPong, 2 ) 28 | .setLoopCompletionHandler( t => Debug.Log( "Loop iteration done" ) ) 29 | .setCompletionHandler( t => Debug.Log( "Tween complete" ) ); 30 | } 31 | 32 | 33 | if( GUILayout.Button( "Relative Position Tween" ) ) 34 | { 35 | GoKitLite.instance.positionTo( cube, Random.Range( 0.2f, 1 ), new Vector3( 1, 0, 0 ), true ) 36 | .setEaseType( EaseType.CubicIn ); 37 | } 38 | 39 | 40 | if( GUILayout.Button( "AnimationCurve for Easing Scale" ) ) 41 | { 42 | GoKitLite.instance.scaleTo( cube, 2f, new Vector3( 3, 3, 3 ) ) 43 | .setAnimationCurve( easeCurve ); 44 | } 45 | 46 | 47 | if( GUILayout.Button( "Scale to 2" ) ) 48 | { 49 | GoKitLite.instance.scaleTo( cube, Random.Range( 0.2f, 1 ), new Vector3( 2, 2, 2 ) ); 50 | } 51 | 52 | 53 | if( GUILayout.Button( "Scale to 0.5" ) ) 54 | { 55 | GoKitLite.instance.scaleTo( cube, Random.Range( 0.2f, 1 ), new Vector3( 0.5f, 0.5f, 0.5f ) ) 56 | .setEaseType( EaseType.BounceOut ); 57 | } 58 | 59 | 60 | if( GUILayout.Button( "Punch Scale to 3" ) ) 61 | { 62 | GoKitLite.instance.scaleTo( cube, Random.Range( 0.2f, 1 ), new Vector3( 3, 3, 3 ) ) 63 | .setEaseType( EaseType.Punch ); 64 | } 65 | 66 | 67 | if( GUILayout.Button( "Rotation to 90,0,0" ) ) 68 | { 69 | GoKitLite.instance.rotationTo( cube, Random.Range( 0.2f, 1 ), new Vector3( 90f, 0, 0 ) ) 70 | .setEaseType( EaseType.BackOut ); 71 | } 72 | 73 | 74 | if( GUILayout.Button( "Rotation to 270,0,0" ) ) 75 | { 76 | GoKitLite.instance.rotationTo( cube, Random.Range( 0.2f, 1 ), new Vector3( 270f, 0, 0 ) ) 77 | .setEaseType( EaseType.BackOut ); 78 | } 79 | 80 | 81 | if( GUILayout.Button( "Rotation to 0,310,0" ) ) 82 | { 83 | GoKitLite.instance.rotationTo( cube, Random.Range( 0.2f, 1 ), new Vector3( 0, 310, 0 ) ) 84 | .setEaseType( EaseType.BackOut ); 85 | } 86 | 87 | if( GUILayout.Button( "Rotation by 360,0,0 (relative tween)" ) ) 88 | { 89 | GoKitLite.instance.rotationTo( cube, 1, new Vector3( 360f, 0, 0 ), true ) 90 | .setEaseType( EaseType.BackOut ); 91 | } 92 | 93 | 94 | if( GUILayout.Button( "Custom Action Tween of Alpha to 0 with 1s Delay" ) ) 95 | { 96 | // dt 0 to 1 (except for bouce, punch they go a bit less than 0 and a bit more than 1) 97 | System.Action action = ( trans, dt ) => 98 | { 99 | var color = trans.GetComponent().material.color; 100 | color.a = 1 - dt; 101 | trans.GetComponent().material.color = color; 102 | }; 103 | 104 | GoKitLite.instance.customAction( cube, Random.Range( 0.2f, 1 ), action ) 105 | .setDelay( 1f ) 106 | .setEaseType( EaseType.Linear ); 107 | } 108 | 109 | 110 | if( GUILayout.Button( "Custom Action Tween of Alpha to 1" ) ) 111 | { 112 | System.Action action = ( trans, dt ) => 113 | { 114 | var color = trans.GetComponent().material.color; 115 | color.a = dt; 116 | trans.GetComponent().material.color = color; 117 | }; 118 | 119 | GoKitLite.instance.customAction( cube, Random.Range( 0.2f, 1 ), action ) 120 | .setEaseType( EaseType.Linear ) 121 | .setCompletionHandler( t => 122 | { 123 | Debug.Log( "All done with custom action" ); 124 | } ); 125 | } 126 | 127 | 128 | if( GUILayout.Button( "Color to Red" ) ) 129 | { 130 | GoKitLite.instance.colorTo( cube, Random.Range( 0.2f, 1 ), Color.red ); 131 | } 132 | 133 | 134 | if( GUILayout.Button( "Color Cycler" ) ) 135 | { 136 | GoKitLite.instance.colorTo( cube, Random.Range( 0.2f, 1 ), Color.blue ) 137 | .next( Random.Range( 0.2f, 1 ), Color.red ) 138 | .setLoopType( GoKitLite.LoopType.PingPong, 2 ); 139 | } 140 | 141 | 142 | if( GUILayout.Button( "Shake Position Ramp up/down Tween" ) ) 143 | { 144 | GoKitLite.instance.customAction( cube, 2, GoKitLiteActions.shakePositionRamp( cube, 0.6f ) ) 145 | .setEaseType( EaseType.Linear ); 146 | } 147 | 148 | 149 | if( GUILayout.Button( "Shake Position Tween" ) ) 150 | { 151 | GoKitLite.instance.customAction( cube, 2, GoKitLiteActions.shakePosition( cube, 0.6f ) ) 152 | .setEaseType( EaseType.Linear ); 153 | } 154 | 155 | 156 | if( GUILayout.Button( "Shake Scale Tween" ) ) 157 | { 158 | GoKitLite.instance.customAction( cube, 2, GoKitLiteActions.shakeScale( cube, 0.6f ) ) 159 | .setEaseType( EaseType.Linear ); 160 | } 161 | 162 | 163 | if( GUILayout.Button( "RectTransform Panel Position Tween" ) ) 164 | { 165 | GoKitLite.instance.rectTransformPositionTo( panel, 1.0f, new Vector3( -Screen.width * 0.5f, -Screen.height * 0.5f ), true ) 166 | .setEaseType( EaseType.BounceOut ) 167 | .setLoopType( GoKitLite.LoopType.PingPong, 2, 0.2f ); 168 | } 169 | 170 | 171 | if( GUILayout.Button( "RectTransform Button Position Tween" ) ) 172 | { 173 | GoKitLite.instance.rectTransformPositionTo( panel.GetChild( 0 ) as RectTransform, 1.0f, new Vector3( 0f, panel.rect.height * 0.8f ), true ) 174 | .setLoopType( GoKitLite.LoopType.PingPong, 1, 0.5f ); 175 | 176 | GoKitLite.instance.rectTransformPositionTo( panel.GetChild( 1 ) as RectTransform, 1.0f, new Vector3( 0f, panel.rect.height * 0.8f ), true ) 177 | .setDelay( 0.2f ) 178 | .setLoopType( GoKitLite.LoopType.PingPong, 1, 0.5f ) 179 | .setEaseType( EaseType.BackOut ); 180 | } 181 | 182 | 183 | if( GUILayout.Button( "Stop All tweens" ) ) 184 | { 185 | GoKitLite.instance.stopAllTweens( true ); 186 | } 187 | } 188 | 189 | } 190 | -------------------------------------------------------------------------------- /Assets/GoKitLiteDemo/scripts/StressTestGUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using Prime31.GoKitLite; 4 | 5 | 6 | public class StressTestGUI : MonoBehaviour 7 | { 8 | private Transform[] _cubes = new Transform[1500]; 9 | private Vector3[] _originalPositions = new Vector3[1500]; 10 | private Perlin _perlinNoiseGenerator = new Perlin(); 11 | private float _updateDelta = 0.0f; 12 | private float _timeX; 13 | private float _timeY; 14 | private float _timeZ; 15 | 16 | 17 | void Start() 18 | { 19 | Application.targetFrameRate = 60; 20 | 21 | // original stress test algorithm (flying perlin cubes) adapted from LeanTweens comparison demo 22 | for( var i = 0; i < _cubes.Length; i++ ) 23 | { 24 | var cube = GameObject.CreatePrimitive( PrimitiveType.Cube ); 25 | Destroy( cube.GetComponent() ); 26 | cube.transform.position = new Vector3( i * 0.1f - 10, cube.transform.position.y, i % 10 ); 27 | _cubes[i] = cube.transform; 28 | _originalPositions[i] = cube.transform.position; 29 | } 30 | 31 | StartCoroutine( runTest() ); 32 | } 33 | 34 | 35 | private IEnumerator runTest() 36 | { 37 | var waiter = new WaitForSeconds( 1.0f ); 38 | var targetPoint = Vector3.zero; 39 | var goKitLite = GoKitLite.instance; 40 | 41 | while( true ) 42 | { 43 | for( var i = 0; i < _cubes.Length; i++ ) 44 | { 45 | _timeX = _updateDelta * 0.15f; 46 | _timeY = _updateDelta * 0.3f; 47 | _timeZ = _updateDelta * 3.0f; 48 | 49 | targetPoint.x = _perlinNoiseGenerator.Noise( _timeX ) * 100 + _originalPositions[i].x; 50 | targetPoint.y = _perlinNoiseGenerator.Noise( _timeY ) * 100 + _originalPositions[i].y; 51 | targetPoint.z = _perlinNoiseGenerator.Noise( _timeZ ) * 100 + _originalPositions[i].z; 52 | 53 | goKitLite.positionTo( _cubes[i], 1.0f, targetPoint ); 54 | 55 | _updateDelta += Time.deltaTime * 100; 56 | } 57 | 58 | yield return waiter; 59 | } 60 | } 61 | 62 | 63 | public class Perlin 64 | { 65 | // Original C code derived from 66 | // http://astronomy.swin.edu.au/~pbourke/texture/perlin/perlin.c 67 | // http://astronomy.swin.edu.au/~pbourke/texture/perlin/perlin.h 68 | const int B = 0x100; 69 | const int BM = 0xff; 70 | const int N = 0x1000; 71 | int[] p = new int[B + B + 2]; 72 | float[,] g3 = new float [B + B + 2, 3]; 73 | float[,] g2 = new float[B + B + 2, 2]; 74 | float[] g1 = new float[B + B + 2]; 75 | 76 | 77 | float s_curve( float t ) 78 | { 79 | return t * t * ( 3.0F - 2.0F * t ); 80 | } 81 | 82 | 83 | float lerp( float t, float a, float b ) 84 | { 85 | return a + t * ( b - a ); 86 | } 87 | 88 | 89 | void setup( float value, out int b0, out int b1, out float r0, out float r1 ) 90 | { 91 | float t = value + N; 92 | b0 = ( (int)t ) & BM; 93 | b1 = ( b0 + 1 ) & BM; 94 | r0 = t - (int)t; 95 | r1 = r0 - 1.0F; 96 | } 97 | 98 | 99 | float at2( float rx, float ry, float x, float y ) 100 | { 101 | return rx * x + ry * y; 102 | } 103 | 104 | 105 | float at3( float rx, float ry, float rz, float x, float y, float z ) 106 | { 107 | return rx * x + ry * y + rz * z; 108 | } 109 | 110 | 111 | public float Noise( float arg ) 112 | { 113 | int bx0, bx1; 114 | float rx0, rx1, sx, u, v; 115 | setup( arg, out bx0, out bx1, out rx0, out rx1 ); 116 | 117 | sx = s_curve( rx0 ); 118 | u = rx0 * g1[p[bx0]]; 119 | v = rx1 * g1[p[bx1]]; 120 | 121 | return( lerp( sx, u, v ) ); 122 | } 123 | 124 | 125 | public float Noise( float x, float y ) 126 | { 127 | int bx0, bx1, by0, by1, b00, b10, b01, b11; 128 | float rx0, rx1, ry0, ry1, sx, sy, a, b, u, v; 129 | int i, j; 130 | 131 | setup( x, out bx0, out bx1, out rx0, out rx1 ); 132 | setup( y, out by0, out by1, out ry0, out ry1 ); 133 | 134 | i = p[bx0]; 135 | j = p[bx1]; 136 | 137 | b00 = p[i + by0]; 138 | b10 = p[j + by0]; 139 | b01 = p[i + by1]; 140 | b11 = p[j + by1]; 141 | 142 | sx = s_curve( rx0 ); 143 | sy = s_curve( ry0 ); 144 | 145 | u = at2( rx0, ry0, g2[b00, 0], g2[b00, 1] ); 146 | v = at2( rx1, ry0, g2[b10, 0], g2[b10, 1] ); 147 | a = lerp( sx, u, v ); 148 | 149 | u = at2( rx0, ry1, g2[b01, 0], g2[b01, 1] ); 150 | v = at2( rx1, ry1, g2[b11, 0], g2[b11, 1] ); 151 | b = lerp( sx, u, v ); 152 | 153 | return lerp( sy, a, b ); 154 | } 155 | 156 | 157 | public float Noise( float x, float y, float z ) 158 | { 159 | int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; 160 | float rx0, rx1, ry0, ry1, rz0, rz1, sy, sz, a, b, c, d, t, u, v; 161 | int i, j; 162 | 163 | setup( x, out bx0, out bx1, out rx0, out rx1 ); 164 | setup( y, out by0, out by1, out ry0, out ry1 ); 165 | setup( z, out bz0, out bz1, out rz0, out rz1 ); 166 | 167 | i = p[bx0]; 168 | j = p[bx1]; 169 | 170 | b00 = p[i + by0]; 171 | b10 = p[j + by0]; 172 | b01 = p[i + by1]; 173 | b11 = p[j + by1]; 174 | 175 | t = s_curve( rx0 ); 176 | sy = s_curve( ry0 ); 177 | sz = s_curve( rz0 ); 178 | 179 | u = at3( rx0, ry0, rz0, g3[b00 + bz0, 0], g3[b00 + bz0, 1], g3[b00 + bz0, 2] ); 180 | v = at3( rx1, ry0, rz0, g3[b10 + bz0, 0], g3[b10 + bz0, 1], g3[b10 + bz0, 2] ); 181 | a = lerp( t, u, v ); 182 | 183 | u = at3( rx0, ry1, rz0, g3[b01 + bz0, 0], g3[b01 + bz0, 1], g3[b01 + bz0, 2] ); 184 | v = at3( rx1, ry1, rz0, g3[b11 + bz0, 0], g3[b11 + bz0, 1], g3[b11 + bz0, 2] ); 185 | b = lerp( t, u, v ); 186 | 187 | c = lerp( sy, a, b ); 188 | 189 | u = at3( rx0, ry0, rz1, g3[b00 + bz1, 0], g3[b00 + bz1, 2], g3[b00 + bz1, 2] ); 190 | v = at3( rx1, ry0, rz1, g3[b10 + bz1, 0], g3[b10 + bz1, 1], g3[b10 + bz1, 2] ); 191 | a = lerp( t, u, v ); 192 | 193 | u = at3( rx0, ry1, rz1, g3[b01 + bz1, 0], g3[b01 + bz1, 1], g3[b01 + bz1, 2] ); 194 | v = at3( rx1, ry1, rz1, g3[b11 + bz1, 0], g3[b11 + bz1, 1], g3[b11 + bz1, 2] ); 195 | b = lerp( t, u, v ); 196 | 197 | d = lerp( sy, a, b ); 198 | 199 | return lerp( sz, c, d ); 200 | } 201 | 202 | 203 | void normalize2( ref float x, ref float y ) 204 | { 205 | float s; 206 | 207 | s = (float)Mathf.Sqrt( x * x + y * y ); 208 | x = y / s; 209 | y = y / s; 210 | } 211 | 212 | 213 | void normalize3( ref float x, ref float y, ref float z ) 214 | { 215 | float s; 216 | s = (float)Mathf.Sqrt( x * x + y * y + z * z ); 217 | x = y / s; 218 | y = y / s; 219 | z = z / s; 220 | } 221 | 222 | 223 | public Perlin() 224 | { 225 | int i, j, k; 226 | System.Random rnd = new System.Random(); 227 | 228 | for( i = 0; i < B; i++ ) 229 | { 230 | p[i] = i; 231 | g1[i] = (float)( rnd.Next( B + B ) - B ) / B; 232 | 233 | for( j = 0; j < 2; j++ ) 234 | g2[i, j] = (float)( rnd.Next( B + B ) - B ) / B; 235 | normalize2( ref g2[i, 0], ref g2[i, 1] ); 236 | 237 | for( j = 0; j < 3; j++ ) 238 | g3[i, j] = (float)( rnd.Next( B + B ) - B ) / B; 239 | 240 | 241 | normalize3( ref g3[i, 0], ref g3[i, 1], ref g3[i, 2] ); 242 | } 243 | 244 | while( --i != 0 ) 245 | { 246 | k = p[i]; 247 | p[i] = p[j = rnd.Next( B )]; 248 | p[j] = k; 249 | } 250 | 251 | for( i = 0; i < B + 2; i++ ) 252 | { 253 | p[B + i] = p[i]; 254 | g1[B + i] = g1[i]; 255 | for( j = 0; j < 2; j++ ) 256 | g2[B + i, j] = g2[i, j]; 257 | for( j = 0; j < 3; j++ ) 258 | g3[B + i, j] = g3[i, j]; 259 | } 260 | } 261 | } 262 | 263 | } 264 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLitePropertyTweens.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System; 4 | using System.Reflection; 5 | 6 | 7 | namespace Prime31.GoKitLite 8 | { 9 | /// 10 | /// helper class to fetch property delegates 11 | /// 12 | internal class Utils 13 | { 14 | /// 15 | /// either returns a super fast Delegate to set the given property or null if it couldn't be found 16 | /// via reflection 17 | /// 18 | public static T setterForProperty( System.Object targetObject, string propertyName ) 19 | { 20 | // first get the property 21 | #if NETFX_CORE 22 | var propInfo = targetObject.GetType().GetRuntimeProperty( propertyName ); 23 | #else 24 | var propInfo = targetObject.GetType().GetProperty( propertyName ); 25 | #endif 26 | 27 | if( propInfo == null ) 28 | { 29 | Debug.Log( "could not find property with name: " + propertyName ); 30 | return default( T ); 31 | } 32 | 33 | #if NETFX_CORE 34 | // Windows Phone/Store new API 35 | return (T)(object)propInfo.SetMethod.CreateDelegate( typeof( T ), targetObject ); 36 | #else 37 | return (T)(object)Delegate.CreateDelegate( typeof( T ), targetObject, propInfo.GetSetMethod() ); 38 | #endif 39 | } 40 | 41 | 42 | /// 43 | /// either returns a super fast Delegate to get the given property or null if it couldn't be found 44 | /// via reflection 45 | /// 46 | public static T getterForProperty( System.Object targetObject, string propertyName ) 47 | { 48 | // first get the property 49 | #if NETFX_CORE 50 | var propInfo = targetObject.GetType().GetRuntimeProperty( propertyName ); 51 | #else 52 | var propInfo = targetObject.GetType().GetProperty( propertyName ); 53 | #endif 54 | 55 | if( propInfo == null ) 56 | { 57 | Debug.Log( "could not find property with name: " + propertyName ); 58 | return default( T ); 59 | } 60 | 61 | #if NETFX_CORE 62 | // Windows Phone/Store new API 63 | return (T)(object)propInfo.GetMethod.CreateDelegate( typeof( T ), targetObject ); 64 | #else 65 | return (T)(object)Delegate.CreateDelegate( typeof( T ), targetObject, propInfo.GetGetMethod() ); 66 | #endif 67 | } 68 | 69 | } 70 | 71 | 72 | /// 73 | /// interface to make working with property and custom tweens easier 74 | /// 75 | public interface ITweenable 76 | { 77 | void prepareForUse(); 78 | void tick( float easedTime ); 79 | } 80 | 81 | 82 | /// 83 | /// tweens any float property 84 | /// 85 | public struct FloatTweenProperty : ITweenable 86 | { 87 | private Action _setter; 88 | private Func _getter; 89 | private bool _isRelative; 90 | private float _targetValue; 91 | private float _startValue; 92 | private float _diffValue; 93 | 94 | 95 | public FloatTweenProperty( object target, string propertyName, float endValue, bool isRelative = false ) 96 | { 97 | _setter = Utils.setterForProperty>( target, propertyName ); 98 | _getter = Utils.getterForProperty>( target, propertyName ); 99 | _targetValue = endValue; 100 | _isRelative = isRelative; 101 | _startValue = _diffValue = 0; 102 | 103 | #if UNITY_EDITOR 104 | if( _setter == null || _getter == null ) 105 | Debug.LogError( "either the property (" + propertyName + ") setter or getter could not be found on the object " + target ); 106 | #endif 107 | } 108 | 109 | 110 | public void prepareForUse() 111 | { 112 | _startValue = _getter(); 113 | 114 | if( _isRelative ) 115 | _diffValue = _targetValue; 116 | else 117 | _diffValue = _targetValue - _startValue; 118 | } 119 | 120 | 121 | public void tick( float easedTime ) 122 | { 123 | _setter( _startValue + _diffValue * easedTime ); 124 | } 125 | 126 | } 127 | 128 | 129 | /// 130 | /// tweens any Vector2 property 131 | /// 132 | public struct Vector2TweenProperty : ITweenable 133 | { 134 | private Action _setter; 135 | private Func _getter; 136 | private bool _isRelative; 137 | private Vector2 _targetValue; 138 | private Vector2 _startValue; 139 | private Vector2 _diffValue; 140 | 141 | 142 | public Vector2TweenProperty( object target, string propertyName, Vector2 endValue, bool isRelative = false ) 143 | { 144 | _setter = Utils.setterForProperty>( target, propertyName ); 145 | _getter = Utils.getterForProperty>( target, propertyName ); 146 | _targetValue = endValue; 147 | _isRelative = isRelative; 148 | _startValue = _diffValue = Vector2.zero; 149 | 150 | #if UNITY_EDITOR 151 | if( _setter == null || _getter == null ) 152 | Debug.LogError( "either the property (" + propertyName + ") setter or getter could not be found on the object " + target ); 153 | #endif 154 | } 155 | 156 | 157 | public void prepareForUse() 158 | { 159 | _startValue = _getter(); 160 | 161 | if( _isRelative ) 162 | _diffValue = _targetValue; 163 | else 164 | _diffValue = _targetValue - _startValue; 165 | } 166 | 167 | 168 | public void tick( float easedTime ) 169 | { 170 | var vec = new Vector2 171 | ( 172 | _startValue.x + _diffValue.x * easedTime, 173 | _startValue.y + _diffValue.y * easedTime 174 | ); 175 | _setter( vec ); 176 | } 177 | 178 | } 179 | 180 | 181 | /// 182 | /// tweens any Vector3 property 183 | /// 184 | public struct Vector3TweenProperty : ITweenable 185 | { 186 | private Action _setter; 187 | private Func _getter; 188 | private bool _isRelative; 189 | private Vector3 _targetValue; 190 | private Vector3 _startValue; 191 | private Vector3 _diffValue; 192 | 193 | 194 | public Vector3TweenProperty( object target, string propertyName, Vector3 endValue, bool isRelative = false ) 195 | { 196 | _setter = Utils.setterForProperty>( target, propertyName ); 197 | _getter = Utils.getterForProperty>( target, propertyName ); 198 | _targetValue = endValue; 199 | _isRelative = isRelative; 200 | _startValue = _diffValue = Vector3.zero; 201 | 202 | #if UNITY_EDITOR 203 | if( _setter == null || _getter == null ) 204 | Debug.LogError( "either the property (" + propertyName + ") setter or getter could not be found on the object " + target ); 205 | #endif 206 | } 207 | 208 | 209 | public void prepareForUse() 210 | { 211 | _startValue = _getter(); 212 | 213 | if( _isRelative ) 214 | _diffValue = _targetValue; 215 | else 216 | _diffValue = _targetValue - _startValue; 217 | } 218 | 219 | 220 | public void tick( float easedTime ) 221 | { 222 | var vec = new Vector3 223 | ( 224 | _startValue.x + _diffValue.x * easedTime, 225 | _startValue.y + _diffValue.y * easedTime, 226 | _startValue.z + _diffValue.z * easedTime 227 | ); 228 | _setter( vec ); 229 | } 230 | 231 | } 232 | 233 | 234 | /// 235 | /// tweens any Color property 236 | /// 237 | public struct ColorTweenProperty : ITweenable 238 | { 239 | private Action _setter; 240 | private Func _getter; 241 | private bool _isRelative; 242 | private Color _targetValue; 243 | private Color _startValue; 244 | private Color _diffValue; 245 | 246 | 247 | public ColorTweenProperty( object target, string propertyName, Color endValue, bool isRelative = false ) 248 | { 249 | _setter = Utils.setterForProperty>( target, propertyName ); 250 | _getter = Utils.getterForProperty>( target, propertyName ); 251 | _targetValue = endValue; 252 | _isRelative = isRelative; 253 | _startValue = _diffValue = Color.white; 254 | 255 | #if UNITY_EDITOR 256 | if( _setter == null || _getter == null ) 257 | Debug.LogError( "either the property (" + propertyName + ") setter or getter could not be found on the object " + target ); 258 | #endif 259 | } 260 | 261 | 262 | public void prepareForUse() 263 | { 264 | _startValue = _getter(); 265 | 266 | if( _isRelative ) 267 | _diffValue = _targetValue; 268 | else 269 | _diffValue = _targetValue - _startValue; 270 | } 271 | 272 | 273 | public void tick( float easedTime ) 274 | { 275 | var vec = new Color 276 | ( 277 | _startValue.r + _diffValue.r * easedTime, 278 | _startValue.g + _diffValue.g * easedTime, 279 | _startValue.b + _diffValue.b * easedTime 280 | ); 281 | _setter( vec ); 282 | } 283 | 284 | } 285 | 286 | } -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLiteEasing.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System; 4 | 5 | 6 | namespace Prime31.GoKitLite 7 | { 8 | /// 9 | /// standard easing equations simplified by replacing the b and c params (begin and change values) with 0 and 10 | /// 1 then reducing. This is done so that we can get back a raw value between 0 - 1 (except elastic/bounce which 11 | /// purposely go over the bounds) and then use that value to lerp anything. 12 | /// 13 | public static class Easing 14 | { 15 | public static class Linear 16 | { 17 | public static float EaseNone(float t, float d) 18 | { 19 | return t / d; 20 | } 21 | } 22 | 23 | 24 | public static class Quadratic 25 | { 26 | public static float EaseIn(float t, float d) 27 | { 28 | return (t /= d) * t; 29 | } 30 | 31 | 32 | public static float EaseOut(float t, float d) 33 | { 34 | return -1 * (t /= d) * (t - 2); 35 | } 36 | 37 | 38 | public static float EaseInOut(float t, float d) 39 | { 40 | if ((t /= d / 2) < 1) 41 | return 0.5f * t * t; 42 | 43 | return -0.5f * ((--t) * (t - 2) - 1); 44 | } 45 | } 46 | 47 | 48 | public static class Back 49 | { 50 | public static float EaseIn(float t, float d) 51 | { 52 | return (t /= d) * t * ((1.70158f + 1) * t - 1.70158f); 53 | } 54 | 55 | 56 | public static float EaseOut(float t, float d) 57 | { 58 | return ((t = t / d - 1) * t * ((1.70158f + 1) * t + 1.70158f) + 1); 59 | } 60 | 61 | 62 | public static float EaseInOut(float t, float d) 63 | { 64 | float s = 1.70158f; 65 | if ((t /= d / 2) < 1) 66 | { 67 | return 0.5f * (t * t * (((s *= (1.525f)) + 1) * t - s)); 68 | } 69 | return 0.5f * ((t -= 2) * t * (((s *= (1.525f)) + 1) * t + s) + 2); 70 | } 71 | } 72 | 73 | 74 | public static class Bounce 75 | { 76 | public static float EaseOut(float t, float d) 77 | { 78 | if ((t /= d) < (1 / 2.75)) 79 | { 80 | return (7.5625f * t * t); 81 | } 82 | else if (t < (2 / 2.75)) 83 | { 84 | return (7.5625f * (t -= (1.5f / 2.75f)) * t + .75f); 85 | } 86 | else if (t < (2.5 / 2.75)) 87 | { 88 | return (7.5625f * (t -= (2.25f / 2.75f)) * t + .9375f); 89 | } 90 | else 91 | { 92 | return (7.5625f * (t -= (2.625f / 2.75f)) * t + .984375f); 93 | } 94 | } 95 | 96 | 97 | public static float EaseIn(float t, float d) 98 | { 99 | return 1 - EaseOut(d - t, d); 100 | } 101 | 102 | 103 | public static float EaseInOut(float t, float d) 104 | { 105 | if (t < d / 2) 106 | return EaseIn(t * 2, d) * 0.5f; 107 | else 108 | return EaseOut(t * 2 - d, d) * .5f + 1 * 0.5f; 109 | } 110 | } 111 | 112 | 113 | public static class Circular 114 | { 115 | public static float EaseIn(float t, float d) 116 | { 117 | return -(Mathf.Sqrt(1 - (t /= d) * t) - 1); 118 | } 119 | 120 | 121 | public static float EaseOut(float t, float d) 122 | { 123 | return Mathf.Sqrt(1 - (t = t / d - 1) * t); 124 | } 125 | 126 | 127 | public static float EaseInOut(float t, float d) 128 | { 129 | if ((t /= d / 2) < 1) 130 | return -0.5f * (Mathf.Sqrt(1 - t * t) - 1); 131 | 132 | return 0.5f * (Mathf.Sqrt(1 - (t -= 2) * t) + 1); 133 | } 134 | } 135 | 136 | 137 | public static class Cubic 138 | { 139 | public static float EaseIn(float t, float d) 140 | { 141 | return (t /= d) * t * t; 142 | } 143 | 144 | 145 | public static float EaseOut(float t, float d) 146 | { 147 | return ((t = t / d - 1) * t * t + 1); 148 | } 149 | 150 | 151 | public static float EaseInOut(float t, float d) 152 | { 153 | if ((t /= d / 2) < 1) 154 | return 0.5f * t * t * t; 155 | 156 | return 0.5f * ((t -= 2) * t * t + 2); 157 | } 158 | } 159 | 160 | 161 | public static class Elastic 162 | { 163 | public static float EaseIn(float t, float d) 164 | { 165 | if (Mathf.Approximately(t, 0)) 166 | return 0; 167 | 168 | if (Mathf.Approximately(t /= d, 1)) 169 | return 1; 170 | 171 | float p = d * .3f; 172 | float s = p / 4; 173 | return -(1 * Mathf.Pow(2, 10 * (t -= 1)) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p)); 174 | } 175 | 176 | 177 | public static float EaseOut(float t, float d) 178 | { 179 | if (Mathf.Approximately(t, 0)) 180 | return 0; 181 | 182 | if (Mathf.Approximately(t /= d, 1)) 183 | return 1; 184 | 185 | float p = d * .3f; 186 | float s = p / 4; 187 | return (1 * Mathf.Pow(2, -10 * t) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p) + 1); 188 | } 189 | 190 | 191 | public static float EaseInOut(float t, float d) 192 | { 193 | if (Mathf.Approximately(t, 0)) 194 | return 0; 195 | 196 | if (Mathf.Approximately(t /= d / 2, 2)) 197 | return 1; 198 | 199 | float p = d * (.3f * 1.5f); 200 | float s = p / 4; 201 | 202 | if (t < 1) 203 | return -.5f * (Mathf.Pow(2, 10 * (t -= 1)) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p)); 204 | 205 | return (Mathf.Pow(2f, -10f * (t -= 1f)) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p) * 0.5f + 1f); 206 | } 207 | 208 | 209 | public static float Punch(float t, float d) 210 | { 211 | if (Mathf.Approximately(t, 0)) 212 | return 0; 213 | 214 | if (Mathf.Approximately(t /= d, 1)) 215 | return 0; 216 | 217 | const float p = 0.3f; 218 | return (Mathf.Pow(2, -10 * t) * Mathf.Sin(t * (2 * Mathf.PI) / p)); 219 | } 220 | } 221 | 222 | 223 | public static class Exponential 224 | { 225 | public static float EaseIn(float t, float d) 226 | { 227 | return Mathf.Approximately(t, 0) ? 0 : Mathf.Pow(2, 10 * (t / d - 1)); 228 | } 229 | 230 | 231 | public static float EaseOut(float t, float d) 232 | { 233 | return Mathf.Approximately(t, d) ? 1 : (-Mathf.Pow(2, -10 * t / d) + 1); 234 | } 235 | 236 | 237 | public static float EaseInOut(float t, float d) 238 | { 239 | if (Mathf.Approximately(t, 0)) 240 | return 0; 241 | 242 | if (Mathf.Approximately(t, d)) 243 | return 1; 244 | 245 | if ((t /= d / 2) < 1) 246 | { 247 | return 0.5f * Mathf.Pow(2, 10 * (t - 1)); 248 | } 249 | return 0.5f * (-Mathf.Pow(2, -10 * --t) + 2); 250 | } 251 | } 252 | 253 | 254 | public static class Quartic 255 | { 256 | public static float EaseIn(float t, float d) 257 | { 258 | return (t /= d) * t * t * t; 259 | } 260 | 261 | 262 | public static float EaseOut(float t, float d) 263 | { 264 | return -1 * ((t = t / d - 1) * t * t * t - 1); 265 | } 266 | 267 | 268 | public static float EaseInOut(float t, float d) 269 | { 270 | t /= d / 2; 271 | if (t < 1) 272 | return 0.5f * t * t * t * t; 273 | 274 | t -= 2; 275 | return -0.5f * (t * t * t * t - 2); 276 | } 277 | } 278 | 279 | 280 | public static class Quintic 281 | { 282 | public static float EaseIn(float t, float d) 283 | { 284 | return (t /= d) * t * t * t * t; 285 | } 286 | 287 | 288 | public static float EaseOut(float t, float d) 289 | { 290 | return ((t = t / d - 1) * t * t * t * t + 1); 291 | } 292 | 293 | 294 | public static float EaseInOut(float t, float d) 295 | { 296 | if ((t /= d / 2) < 1) 297 | return 0.5f * t * t * t * t * t; 298 | 299 | return 0.5f * ((t -= 2) * t * t * t * t + 2); 300 | } 301 | } 302 | 303 | 304 | public static class Sinusoidal 305 | { 306 | public static float EaseIn(float t, float d) 307 | { 308 | return -1 * Mathf.Cos(t / d * (Mathf.PI / 2)) + 1f; 309 | } 310 | 311 | 312 | public static float EaseOut(float t, float d) 313 | { 314 | return Mathf.Sin(t / d * (Mathf.PI / 2)); 315 | } 316 | 317 | 318 | public static float EaseInOut(float t, float d) 319 | { 320 | return -0.5f * (Mathf.Cos(Mathf.PI * t / d) - 1); 321 | } 322 | } 323 | } 324 | } 325 | -------------------------------------------------------------------------------- /Assets/GoKitLite/GoKitLite.cs: -------------------------------------------------------------------------------- 1 | using EaseFunction = System.Func; 2 | using UnityEngine; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | 8 | namespace Prime31.GoKitLite 9 | { 10 | public class GoKitLite : MonoBehaviour 11 | { 12 | #region Internal classes and enums 13 | 14 | public class Tween 15 | { 16 | private enum TargetValueType 17 | { 18 | None, 19 | Vector3, 20 | Color 21 | } 22 | 23 | // common properties 24 | internal int id; 25 | internal Transform transform; 26 | internal RectTransform rectTransform; 27 | internal TweenType tweenType; 28 | internal bool isTimeScaleIndependent; 29 | internal bool isRunningInReverse; 30 | internal float duration; 31 | internal float delay; 32 | internal float delayBetweenLoops; 33 | internal EaseType easeType; 34 | internal AnimationCurve animCurve; 35 | internal bool isRelativeTween; 36 | internal Action onComplete; 37 | internal Action onLoopComplete; 38 | internal LoopType loopType; 39 | internal int loops = 0; 40 | internal Tween nextTween; 41 | 42 | // tweenable: Vector3 43 | internal Vector3 targetVector; 44 | private Vector3 _startVector; 45 | private Vector3 _diffVector; 46 | 47 | // tweenable: Color 48 | internal Color targetColor; 49 | private Color _startColor; 50 | private Color _diffColor; 51 | private Material _material; 52 | internal string materialProperty; 53 | 54 | // tweenable: Action and property 55 | internal Action customAction; 56 | internal ITweenable propertyTween; 57 | 58 | // internal state 59 | private float _elapsedTime; 60 | private TargetValueType targetValueType; 61 | internal bool isPaused; 62 | 63 | 64 | internal void reset() 65 | { 66 | // any pointers or values that are not guaranteed to be set later are defaulted here 67 | transform = null; 68 | rectTransform = null; 69 | targetVector = _startVector = _diffVector = Vector3.zero; 70 | delay = delayBetweenLoops = 0f; 71 | isTimeScaleIndependent = isRunningInReverse = isPaused = false; 72 | loopType = LoopType.None; 73 | easeType = GoKitLite.defaultEaseType; 74 | animCurve = null; 75 | isRelativeTween = false; 76 | onComplete = onLoopComplete = null; 77 | customAction = null; 78 | propertyTween = null; 79 | _material = null; 80 | materialProperty = null; 81 | 82 | if( nextTween != null ) 83 | { 84 | // null out and return to the stack all additional tweens 85 | GoKitLite.instance._inactiveTweenStack.Push( nextTween ); 86 | nextTween.reset(); 87 | } 88 | 89 | nextTween = null; 90 | } 91 | 92 | 93 | /// 94 | /// sets the appropriate start value and calculates the diffValue 95 | /// 96 | internal void prepareForUse() 97 | { 98 | switch( tweenType ) 99 | { 100 | case TweenType.Position: 101 | targetValueType = TargetValueType.Vector3; 102 | _startVector = transform.position; 103 | break; 104 | case TweenType.LocalPosition: 105 | targetValueType = TargetValueType.Vector3; 106 | _startVector = transform.localPosition; 107 | break; 108 | case TweenType.Scale: 109 | targetValueType = TargetValueType.Vector3; 110 | _startVector = transform.localScale; 111 | break; 112 | case TweenType.Rotation: 113 | targetValueType = TargetValueType.Vector3; 114 | _startVector = transform.rotation.eulerAngles; 115 | 116 | if( isRelativeTween ) 117 | _diffVector = targetVector; 118 | else 119 | _diffVector = new Vector3( Mathf.DeltaAngle( _startVector.x, targetVector.x ), Mathf.DeltaAngle( _startVector.y, targetVector.y ), Mathf.DeltaAngle( _startVector.z, targetVector.z ) ); 120 | break; 121 | case TweenType.LocalRotation: 122 | targetValueType = TargetValueType.Vector3; 123 | _startVector = transform.localRotation.eulerAngles; 124 | 125 | if( isRelativeTween ) 126 | _diffVector = targetVector; 127 | else 128 | _diffVector = new Vector3( Mathf.DeltaAngle( _startVector.x, targetVector.x ), Mathf.DeltaAngle( _startVector.y, targetVector.y ), Mathf.DeltaAngle( _startVector.z, targetVector.z ) ); 129 | break; 130 | case TweenType.RectTransformPosition: 131 | targetValueType = TargetValueType.Vector3; 132 | _startVector = rectTransform.anchoredPosition3D; 133 | break; 134 | case TweenType.Color: 135 | targetValueType = TargetValueType.Color; 136 | break; 137 | case TweenType.Action: 138 | targetValueType = TargetValueType.None; 139 | break; 140 | case TweenType.Property: 141 | targetValueType = TargetValueType.None; 142 | propertyTween.prepareForUse(); 143 | break; 144 | } 145 | 146 | _elapsedTime = -delay; 147 | 148 | // we have to be careful with rotations because we always want to rotate in the shortest angle so we set the diffValue with that in mind 149 | if( targetValueType == TargetValueType.Vector3 && tweenType != TweenType.Rotation && tweenType != TweenType.LocalRotation ) 150 | { 151 | if( isRelativeTween ) 152 | _diffVector = targetVector; 153 | else 154 | _diffVector = targetVector - _startVector; 155 | } 156 | else if( targetValueType == TargetValueType.Color ) 157 | { 158 | _material = transform.GetComponent().material; 159 | _startColor = _material.GetColor( materialProperty ); 160 | 161 | if( isRelativeTween ) 162 | _diffColor = targetColor; 163 | else 164 | _diffColor = targetColor - _startColor; 165 | } 166 | } 167 | 168 | 169 | /// 170 | /// handles the tween. returns true if it is complete and ready for removal 171 | /// 172 | internal bool tick( bool completeTweenThisStep = false ) 173 | { 174 | // fetch our deltaTime. It will either be taking this to completion or standard delta/unscaledDelta 175 | var deltaTime = completeTweenThisStep ? float.MaxValue : ( isTimeScaleIndependent ? Time.unscaledDeltaTime : Time.deltaTime ); 176 | 177 | // add deltaTime to our elapsed time and clamp it from -delay to duration 178 | _elapsedTime = Mathf.Clamp( _elapsedTime + deltaTime, -delay, duration ); 179 | 180 | // if we have a delay, we will have a negative elapsedTime until the delay is complete 181 | if( _elapsedTime <= 0 ) 182 | return false; 183 | 184 | var modifiedElapsedTime = isRunningInReverse ? duration - _elapsedTime : _elapsedTime; 185 | var easedTime = ( animCurve == null ) ? EaseHelper.ease( easeType, modifiedElapsedTime, duration ) : animCurve.Evaluate( modifiedElapsedTime / duration ); 186 | 187 | // special case: Action tweens 188 | if( tweenType == TweenType.Action ) 189 | customAction( transform, easedTime ); 190 | else if( tweenType == TweenType.Property ) 191 | propertyTween.tick( easedTime ); 192 | 193 | if( targetValueType == TargetValueType.Vector3 ) 194 | { 195 | var vec = new Vector3 196 | ( 197 | _startVector.x + _diffVector.x * easedTime, 198 | _startVector.y + _diffVector.y * easedTime, 199 | _startVector.z + _diffVector.z * easedTime 200 | ); 201 | setVectorAsRequiredPerCurrentTweenType( ref vec ); 202 | } 203 | else if( targetValueType == TargetValueType.Color ) 204 | { 205 | _material.SetColor( materialProperty, new Color 206 | ( 207 | _startColor.r + _diffColor.r * easedTime, 208 | _startColor.g + _diffColor.g * easedTime, 209 | _startColor.b + _diffColor.b * easedTime, 210 | _startColor.a + _diffColor.a * easedTime 211 | ) ); 212 | } 213 | 214 | // if we have a loopType and we are done do the loop 215 | if( loopType != GoKitLite.LoopType.None && Mathf.Approximately(_elapsedTime, duration) ) 216 | handleLooping(); 217 | 218 | return Mathf.Approximately(_elapsedTime, duration); 219 | } 220 | 221 | 222 | /// 223 | /// handles loop logic 224 | /// 225 | private void handleLooping() 226 | { 227 | loops--; 228 | if( loopType == GoKitLite.LoopType.RestartFromBeginning ) 229 | { 230 | if( targetValueType == TargetValueType.Vector3 ) 231 | setVectorAsRequiredPerCurrentTweenType( ref _startVector ); 232 | else if( targetValueType == TargetValueType.Color ) 233 | _material.SetColor( materialProperty, _startColor ); 234 | 235 | prepareForUse(); 236 | } 237 | else // ping-pong 238 | { 239 | isRunningInReverse = !isRunningInReverse; 240 | } 241 | 242 | if( loopType == GoKitLite.LoopType.RestartFromBeginning || loops % 2 == 1 ) 243 | { 244 | if( onLoopComplete != null ) 245 | onLoopComplete( transform ); 246 | } 247 | 248 | // kill our loop if we have no loops left and zero out the delay then prepare for use 249 | if( loops == 0 ) 250 | loopType = GoKitLite.LoopType.None; 251 | 252 | delay = delayBetweenLoops; 253 | _elapsedTime = -delay; 254 | } 255 | 256 | 257 | /// 258 | /// if we have an appropriate tween type that takes a vector value this will correctly set it 259 | /// 260 | private void setVectorAsRequiredPerCurrentTweenType( ref Vector3 vec ) 261 | { 262 | switch( tweenType ) 263 | { 264 | case TweenType.Position: 265 | transform.position = vec; 266 | break; 267 | case TweenType.LocalPosition: 268 | transform.localPosition = vec; 269 | break; 270 | case TweenType.Scale: 271 | transform.localScale = vec; 272 | break; 273 | case TweenType.Rotation: 274 | transform.eulerAngles = vec; 275 | break; 276 | case TweenType.LocalRotation: 277 | transform.localEulerAngles = vec; 278 | break; 279 | case TweenType.RectTransformPosition: 280 | rectTransform.anchoredPosition3D = vec; 281 | break; 282 | } 283 | } 284 | 285 | 286 | /// 287 | /// reverses the current tween. if it was going forward it will be going backwards and vice versa. 288 | /// 289 | public void reverseTween() 290 | { 291 | isRunningInReverse = !isRunningInReverse; 292 | _elapsedTime = duration - _elapsedTime; 293 | } 294 | 295 | 296 | /// 297 | /// chainable. Sets the EaseType used by the tween. 298 | /// 299 | public Tween setEaseType( EaseType easeType ) 300 | { 301 | this.easeType = easeType; 302 | return this; 303 | } 304 | 305 | 306 | public Tween setAnimationCurve( AnimationCurve animCurve ) 307 | { 308 | this.animCurve = animCurve; 309 | return this; 310 | } 311 | 312 | 313 | /// 314 | /// chainable. sets the action that should be called when the tween is complete. do not store a reference to the tween! 315 | /// 316 | public Tween setCompletionHandler( Action onComplete ) 317 | { 318 | this.onComplete = onComplete; 319 | return this; 320 | } 321 | 322 | 323 | /// 324 | /// chainable. sets the action that should be called when a loop is complete. A loop is either when the first part of 325 | /// a ping-pong animation completes or when starting over when using a restart-from-beginning loop type. Note that ping-pong 326 | /// loops (which are really two part tweens) will not fire the loop completion handler on the last iteration. The normal 327 | /// tween completion handler will fire though 328 | /// 329 | public Tween setLoopCompletionHandler( Action onLoopComplete ) 330 | { 331 | this.onLoopComplete = onLoopComplete; 332 | return this; 333 | } 334 | 335 | 336 | /// 337 | /// chainable. set the loop type for the tween. a single pingpong loop means going from start-finish-start. 338 | /// 339 | public Tween setLoopType( LoopType loopType, int loops = 1, float delayBetweenLoops = 0f ) 340 | { 341 | this.loopType = loopType; 342 | this.delayBetweenLoops = delayBetweenLoops; 343 | 344 | // double the loop count for ping-pong 345 | if( loopType == LoopType.PingPong ) 346 | loops = loops * 2 - 1; 347 | this.loops = loops; 348 | 349 | return this; 350 | } 351 | 352 | 353 | /// 354 | /// chainable. sets the delay for the tween. 355 | /// 356 | public Tween setDelay( float delay ) 357 | { 358 | this.delay = delay; 359 | _elapsedTime = -delay; 360 | return this; 361 | } 362 | 363 | 364 | /// 365 | /// sets the tween to be time scale independent 366 | /// 367 | /// The Tween 368 | public Tween setTimeScaleIndependent() 369 | { 370 | isTimeScaleIndependent = true; 371 | return this; 372 | } 373 | 374 | 375 | /// 376 | /// gets the id which can be used to stop the tween later 377 | /// 378 | public int getId() 379 | { 380 | return id; 381 | } 382 | 383 | 384 | /// 385 | /// adds a vector tween using this tween's Transform and type that will start as soon as this completes 386 | /// 387 | public Tween next( float duration, Vector3 targetVector, float delay = 0 ) 388 | { 389 | var tween = GoKitLite.instance.vectorTweenTo( transform, tweenType, duration, targetVector, false ); 390 | tween.delay = delay; 391 | nextTween = tween; 392 | 393 | return tween; 394 | } 395 | 396 | 397 | /// 398 | /// adds a vector tween using this tween's Transform and type that will start as soon as this completes 399 | /// 400 | public Tween next( float duration, Vector3 targetVector, float delay, EaseFunction easeFunction, bool isRelativeTween = false ) 401 | { 402 | var tween = GoKitLite.instance.vectorTweenTo( transform, tweenType, duration, targetVector, isRelativeTween ); 403 | tween.delay = delay; 404 | nextTween = tween; 405 | 406 | return tween; 407 | } 408 | 409 | 410 | /// 411 | /// adds a tween that will start as soon as this tween completes 412 | /// 413 | public Tween next( TweenType tweenType, float duration, Vector3 targetVector, bool isRelativeTween = false ) 414 | { 415 | var tween = GoKitLite.instance.vectorTweenTo( transform, tweenType, duration, targetVector, isRelativeTween ); 416 | tween.delay = delay; 417 | nextTween = tween; 418 | 419 | return tween; 420 | } 421 | 422 | 423 | /// 424 | /// adds a tween that will start as soon as this tween completes 425 | /// 426 | public Tween next( Transform trans, TweenType tweenType, float duration, Vector3 targetVector, bool isRelativeTween = false ) 427 | { 428 | var tween = GoKitLite.instance.vectorTweenTo( trans, tweenType, duration, targetVector, isRelativeTween ); 429 | tween.delay = delay; 430 | nextTween = tween; 431 | 432 | return tween; 433 | } 434 | 435 | 436 | /// 437 | /// adds a color tween using this tween's Transform and type that will start as soon as this completes 438 | /// 439 | public Tween next( float duration, Color targetColor ) 440 | { 441 | var tween = GoKitLite.instance.colorTweenTo( transform, duration, targetColor, "_Color", false ); 442 | tween.easeType = easeType; 443 | nextTween = tween; 444 | 445 | return tween; 446 | } 447 | 448 | 449 | /// 450 | /// adds a color tween using this tween's Transform that will start as soon as this completes 451 | /// 452 | public Tween next( float duration, Color targetColor, string materialProperty, bool isRelativeTween = false ) 453 | { 454 | var tween = GoKitLite.instance.colorTweenTo( transform, duration, targetColor, materialProperty, isRelativeTween ); 455 | tween.easeType = easeType; 456 | nextTween = tween; 457 | 458 | return tween; 459 | } 460 | 461 | 462 | /// 463 | /// adds a property tween that will start as soon as the current tween completes 464 | /// 465 | public Tween next( float duration, ITweenable newPropertyTween ) 466 | { 467 | var tween = GoKitLite.instance.nextAvailableTween( transform, duration, TweenType.Property ); 468 | tween.easeType = easeType; 469 | tween.propertyTween = newPropertyTween; 470 | 471 | nextTween = tween; 472 | 473 | return tween; 474 | } 475 | 476 | 477 | /// 478 | /// adds a custom action tween using this tween's Transform that will start as soon as the current tween completes 479 | /// 480 | public Tween next( float duration, Action action ) 481 | { 482 | var tween = GoKitLite.instance.nextAvailableTween( transform, duration, TweenType.Action ); 483 | tween.easeType = easeType; 484 | tween.customAction = action; 485 | 486 | nextTween = tween; 487 | 488 | return tween; 489 | } 490 | 491 | 492 | /// 493 | /// adds a custom action tween that will start as soon as the current tween completes 494 | /// 495 | public Tween next( Transform trans, float duration, Action action ) 496 | { 497 | var tween = GoKitLite.instance.nextAvailableTween( trans, duration, TweenType.Action ); 498 | tween.easeType = easeType; 499 | tween.customAction = action; 500 | 501 | nextTween = tween; 502 | 503 | return tween; 504 | } 505 | 506 | } 507 | 508 | 509 | public enum TweenType 510 | { 511 | Position, 512 | LocalPosition, 513 | Rotation, 514 | LocalRotation, 515 | Scale, 516 | RectTransformPosition, 517 | Color, 518 | Action, 519 | Property 520 | } 521 | 522 | 523 | public enum LoopType 524 | { 525 | None, 526 | RestartFromBeginning, 527 | PingPong 528 | } 529 | 530 | #endregion 531 | 532 | 533 | private List _activeTweens = new List( 20 ); 534 | internal Stack _inactiveTweenStack = new Stack( 20 ); 535 | private int _tweenIdCounter = 0; 536 | public static EaseType defaultEaseType = EaseType.QuartIn; 537 | 538 | /// 539 | /// holds the singleton instance. creates one on demand if none exists. 540 | /// 541 | private static GoKitLite _instance; 542 | public static GoKitLite instance 543 | { 544 | get 545 | { 546 | if( !_instance ) 547 | { 548 | // check if there is a GoKitLite instance already available in the scene graph before creating one 549 | _instance = FindObjectOfType( typeof( GoKitLite ) ) as GoKitLite; 550 | 551 | if( !_instance ) 552 | { 553 | var obj = new GameObject( "GoKitLite" ); 554 | _instance = obj.AddComponent(); 555 | DontDestroyOnLoad( obj ); 556 | } 557 | } 558 | 559 | return _instance; 560 | } 561 | } 562 | 563 | 564 | #region MonoBehaviour 565 | 566 | private void OnApplicationQuit() 567 | { 568 | _instance = null; 569 | Destroy( gameObject ); 570 | } 571 | 572 | 573 | private void Update() 574 | { 575 | // loop backwards so we can remove completed tweens 576 | for( var i = _activeTweens.Count - 1; i >= 0; --i ) 577 | { 578 | var tween = _activeTweens[i]; 579 | if( tween.isPaused ) 580 | continue; 581 | 582 | if( tween.transform == null || tween.tick() ) 583 | { 584 | if( tween.onComplete != null ) 585 | tween.onComplete( tween.transform ); 586 | 587 | // handle nextTween if we have a chain 588 | if( tween.nextTween != null ) 589 | { 590 | tween.nextTween.prepareForUse(); 591 | _activeTweens.Add( tween.nextTween ); 592 | 593 | // null out the nextTween so that the reset method doesnt remove it! 594 | tween.nextTween = null; 595 | } 596 | 597 | removeTween( tween, i ); 598 | } 599 | } 600 | 601 | #if UNITY_EDITOR 602 | gameObject.name = "GoKitLite. active tweens: " + _activeTweens.Count; 603 | #endif 604 | } 605 | 606 | #endregion 607 | 608 | 609 | #region Private 610 | 611 | internal Tween vectorTweenTo( Transform trans, TweenType tweenType, float duration, Vector3 targetVector, bool isRelativeTween = false ) 612 | { 613 | var tween = nextAvailableTween( trans, duration, tweenType ); 614 | tween.targetVector = targetVector; 615 | tween.isRelativeTween = isRelativeTween; 616 | 617 | return tween; 618 | } 619 | 620 | 621 | internal Tween colorTweenTo( Transform trans, float duration, Color targetColor, string materialProperty = "_Color", bool isRelativeTween = false ) 622 | { 623 | var tween = nextAvailableTween( trans, duration, TweenType.Color ); 624 | tween.targetColor = targetColor; 625 | tween.materialProperty = materialProperty; 626 | tween.isRelativeTween = isRelativeTween; 627 | 628 | return tween; 629 | } 630 | 631 | 632 | private Tween nextAvailableTween( Transform trans, float duration, TweenType tweenType ) 633 | { 634 | Tween tween = null; 635 | if( _inactiveTweenStack.Count > 0 ) 636 | tween = _inactiveTweenStack.Pop(); 637 | else 638 | tween = new Tween(); 639 | 640 | tween.id = ++_tweenIdCounter; 641 | tween.transform = trans; 642 | tween.duration = duration; 643 | tween.tweenType = tweenType; 644 | 645 | return tween; 646 | } 647 | 648 | 649 | private void removeTween( Tween tween, int index ) 650 | { 651 | _activeTweens.RemoveAt( index ); 652 | 653 | tween.reset(); 654 | _inactiveTweenStack.Push( tween ); 655 | } 656 | 657 | #endregion 658 | 659 | 660 | #region Public 661 | 662 | public Tween positionTo( Transform trans, float duration, Vector3 targetPosition, bool isRelativeTween = false ) 663 | { 664 | var tween = vectorTweenTo( trans, TweenType.Position, duration, targetPosition, isRelativeTween ); 665 | 666 | tween.prepareForUse(); 667 | _activeTweens.Add( tween ); 668 | 669 | return tween; 670 | } 671 | 672 | 673 | public Tween positionFrom( Transform trans, float duration, Vector3 targetPosition, bool isRelativeTween = false ) 674 | { 675 | var currentPosition = trans.position; 676 | trans.position = targetPosition; 677 | 678 | return positionTo( trans, duration, currentPosition, isRelativeTween ); 679 | } 680 | 681 | 682 | public Tween localPositionTo( Transform trans, float duration, Vector3 targetPosition, bool isRelativeTween = false ) 683 | { 684 | var tween = vectorTweenTo( trans, TweenType.LocalPosition, duration, targetPosition, isRelativeTween ); 685 | 686 | tween.prepareForUse(); 687 | _activeTweens.Add( tween ); 688 | 689 | return tween; 690 | } 691 | 692 | 693 | public Tween localPositionFrom( Transform trans, float duration, Vector3 targetPosition, bool isRelativeTween = false ) 694 | { 695 | var currentPosition = trans.localPosition; 696 | trans.localPosition = targetPosition; 697 | 698 | return localPositionTo( trans, duration, currentPosition, isRelativeTween ); 699 | } 700 | 701 | 702 | public Tween scaleTo( Transform trans, float duration, Vector3 targetScale, bool isRelativeTween = false ) 703 | { 704 | var tween = vectorTweenTo( trans, TweenType.Scale, duration, targetScale, isRelativeTween ); 705 | 706 | tween.prepareForUse(); 707 | _activeTweens.Add( tween ); 708 | 709 | return tween; 710 | } 711 | 712 | 713 | public Tween scaleFrom( Transform trans, float duration, Vector3 targetScale, bool isRelativeTween = false ) 714 | { 715 | var currentScale = trans.localScale; 716 | trans.localScale = targetScale; 717 | 718 | return scaleTo( trans, duration, currentScale, isRelativeTween ); 719 | } 720 | 721 | 722 | public Tween rotationTo( Transform trans, float duration, Vector3 targetEulers, bool isRelativeTween = false ) 723 | { 724 | var tween = vectorTweenTo( trans, TweenType.Rotation, duration, targetEulers, isRelativeTween ); 725 | 726 | tween.prepareForUse(); 727 | _activeTweens.Add( tween ); 728 | 729 | return tween; 730 | } 731 | 732 | 733 | public Tween rectTransformPositionTo( RectTransform trans, float duration, Vector3 targetScale, bool isRelativeTween = false ) 734 | { 735 | var tween = vectorTweenTo( trans, TweenType.RectTransformPosition, duration, targetScale, isRelativeTween ); 736 | tween.rectTransform = trans; 737 | 738 | tween.prepareForUse(); 739 | _activeTweens.Add( tween ); 740 | 741 | return tween; 742 | } 743 | 744 | 745 | public Tween rotationFrom( Transform trans, float duration, Vector3 targetEulers, bool isRelativeTween = false ) 746 | { 747 | var currentEulers = trans.eulerAngles; 748 | trans.eulerAngles = targetEulers; 749 | 750 | return rotationTo( trans, duration, currentEulers, isRelativeTween ); 751 | } 752 | 753 | 754 | public Tween localRotationTo( Transform trans, float duration, Vector3 targetEulers, bool isRelativeTween = false ) 755 | { 756 | var tween = vectorTweenTo( trans, TweenType.LocalRotation, duration, targetEulers, isRelativeTween ); 757 | 758 | tween.prepareForUse(); 759 | _activeTweens.Add( tween ); 760 | 761 | return tween; 762 | } 763 | 764 | 765 | public Tween localRotationFrom( Transform trans, float duration, Vector3 targetEulers, bool isRelativeTween = false ) 766 | { 767 | var currentEulers = trans.localEulerAngles; 768 | trans.localEulerAngles = targetEulers; 769 | 770 | return localRotationTo( trans, duration, currentEulers, isRelativeTween ); 771 | } 772 | 773 | 774 | public Tween colorTo( Transform trans, float duration, Color targetColor, string materialProperty = "_Color", bool isRelativeTween = false ) 775 | { 776 | var tween = colorTweenTo( trans, duration, targetColor, materialProperty, isRelativeTween ); 777 | 778 | tween.prepareForUse(); 779 | _activeTweens.Add( tween ); 780 | 781 | return tween; 782 | } 783 | 784 | 785 | public Tween colorFrom( Transform trans, float duration, Color targetColor, string materialProperty = "_Color", bool isRelativeTween = false ) 786 | { 787 | var currentColor = trans.GetComponent().material.GetColor( materialProperty ); 788 | trans.GetComponent().material.SetColor( materialProperty, targetColor ); 789 | 790 | return colorTo( trans, duration, currentColor, materialProperty, isRelativeTween ); 791 | } 792 | 793 | 794 | public Tween customAction( Transform trans, float duration, Action action ) 795 | { 796 | var tween = nextAvailableTween( trans, duration, TweenType.Action ); 797 | tween.customAction = action; 798 | tween.prepareForUse(); 799 | 800 | _activeTweens.Add( tween ); 801 | 802 | return tween; 803 | } 804 | 805 | 806 | public Tween propertyTween( ITweenable propertyTween, float duration ) 807 | { 808 | var tween = nextAvailableTween( this.transform, duration, TweenType.Property ); 809 | tween.propertyTween = propertyTween; 810 | 811 | tween.prepareForUse(); 812 | _activeTweens.Add( tween ); 813 | 814 | return tween; 815 | } 816 | 817 | #endregion 818 | 819 | 820 | #region Tween Management 821 | 822 | /// 823 | /// stops the tween optionally bringing it to its final value first. returns true if the tween was found and stopped. 824 | /// 825 | public bool stopTween( int id, bool bringToCompletion ) 826 | { 827 | for( var i = 0; i < _activeTweens.Count; i++ ) 828 | { 829 | if( _activeTweens[i].id == id ) 830 | { 831 | // send in a delta of float.max if we should be completing this tween before killing it 832 | if( bringToCompletion ) 833 | _activeTweens[i].tick( true ); 834 | 835 | removeTween( _activeTweens[i], i ); 836 | return true; 837 | } 838 | } 839 | 840 | return false; 841 | } 842 | 843 | /// 844 | /// stops all the tweens for a specified transform optionally bringing it to its final value first. returns true if a tween was found and stopped. 845 | /// 846 | public bool stopTweenForTransform( Transform trans, bool bringToCompletion) 847 | { 848 | bool didRemoveTween = false; 849 | for (var i = 0; i < _activeTweens.Count; i++) { 850 | if (_activeTweens[i].transform.Equals(trans)) { 851 | if( bringToCompletion ) 852 | _activeTweens[i].tick( true ); 853 | 854 | removeTween( _activeTweens[i], i ); 855 | didRemoveTween = true; 856 | } 857 | } 858 | 859 | return didRemoveTween; 860 | } 861 | 862 | /// 863 | /// Stops all in-progress tweens optionally bringing them to their final values. 864 | /// 865 | /// If true, then all active tweens are broght to completion before they are stopped 866 | public void stopAllTweens( bool bringToCompletion ) 867 | { 868 | for( var i = _activeTweens.Count - 1; i >= 0; --i ) 869 | { 870 | // send in a delta of float.max if we should be completing this tween before killing it 871 | if( bringToCompletion ) 872 | _activeTweens[i].tick( true ); 873 | 874 | removeTween( _activeTweens[i], i ); 875 | } 876 | } 877 | 878 | 879 | /// 880 | /// set the tween's pause state. returns true if the tween was found. 881 | /// 882 | public bool setTweenPauseState( int id, bool isPaused ) 883 | { 884 | for( var i = 0; i < _activeTweens.Count; i++ ) 885 | { 886 | if( _activeTweens[i].id == id ) 887 | { 888 | _activeTweens[i].isPaused = isPaused; 889 | return true; 890 | } 891 | } 892 | 893 | return false; 894 | } 895 | 896 | 897 | /// 898 | /// set all in-progress tween's pause state. 899 | /// 900 | public void setAllTweenPauseState( bool isPaused ) 901 | { 902 | for( var i = 0; i < _activeTweens.Count; i++ ) 903 | _activeTweens[i].isPaused = isPaused; 904 | } 905 | 906 | 907 | /// 908 | /// Checks if the current tween is active 909 | /// 910 | /// 911 | /// True if the tween is active, false otherwise 912 | public bool isTweenActive( int id ) 913 | { 914 | for( var i = 0; i < _activeTweens.Count; i++ ) 915 | { 916 | if( _activeTweens[i].id == id ) 917 | return true; 918 | } 919 | 920 | return false; 921 | } 922 | 923 | 924 | /// 925 | /// reverses the tween. if it was going forward it will be going backwards and vice versa. 926 | /// 927 | /// 928 | /// True if the tween is active, false otherwise 929 | private bool reverseTween( int id ) 930 | { 931 | for( var i = 0; i < _activeTweens.Count; i++ ) 932 | { 933 | if( _activeTweens[i].id == id ) 934 | { 935 | _activeTweens[i].reverseTween(); 936 | return true; 937 | } 938 | } 939 | 940 | return false; 941 | } 942 | 943 | 944 | /// 945 | /// find an active tween with given id, do not store a reference to the tween! 946 | /// 947 | public Tween getActiveTween( int id ) 948 | { 949 | for( var i = 0; i < _activeTweens.Count; i++ ) 950 | { 951 | if( _activeTweens[i].id == id ) 952 | return _activeTweens[i]; 953 | } 954 | 955 | return null; 956 | } 957 | 958 | #endregion 959 | 960 | } 961 | } 962 | --------------------------------------------------------------------------------