iTweenPositionTo.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Module Name: iTweenPositionTo.cs
  2. // Project: iTween Editor br Vortex Game Studios
  3. // Version: 1.00.00
  4. // Developed by: Alexandre Ribeiro de Sá (@themonkeytail)
  5. // Copyright(c) Vortex Game Studios LTDA ME.
  6. // http://www.vortexstudios.com
  7. //
  8. // iTween Position To component
  9. // Use this component to create position tween from your component.
  10. // 1.00.00 - First build
  11. //
  12. // Check every tools and plugins we made for Unity at
  13. // https://www.assetstore.unity3d.com/en/publisher/4888
  14. //
  15. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  16. // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  17. // WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  18. using UnityEngine;
  19. using System.Collections;
  20. using UnityEngine.Events;
  21. using System;
  22. using UnityEngine.UI;
  23. public class iTweenPositionTo : iTweenEditor {
  24. public Vector3 valueFrom = Vector3.zero;
  25. public Vector3 valueTo = Vector3.one;
  26. [System.Serializable]
  27. public class OnStart : UnityEvent { };
  28. public OnStart onStart;
  29. [System.Serializable]
  30. public class OnComplete : UnityEvent { };
  31. public OnComplete onComplete;
  32. private Vector3 _transition = Vector3.zero;
  33. // Use this for initialization
  34. void Awake() {
  35. if ( this.autoPlay )
  36. this.iTweenPlay();
  37. }
  38. public override void iTweenPlay() {
  39. Hashtable ht = new Hashtable();
  40. ht.Add( "from", 0.0f );
  41. ht.Add( "to", 1.0f );
  42. ht.Add( "time", this.tweenTime );
  43. ht.Add( "delay", this.waitTime );
  44. ht.Add( "looptype", this.loopType );
  45. ht.Add( "easetype", this.easeType );
  46. ht.Add( "onstart", (Action<object>)( newVal => {
  47. _onUpdate( 0.0f );
  48. if ( onStart != null ) {
  49. onStart.Invoke();
  50. }
  51. } ) );
  52. ht.Add( "onupdate", (Action<object>)( newVal => {
  53. _onUpdate( (float)newVal );
  54. } ) );
  55. ht.Add( "oncomplete", (Action<object>)( newVal => {
  56. if ( onComplete != null ) {
  57. onComplete.Invoke();
  58. }
  59. } ) );
  60. ht.Add( "ignoretimescale", ignoreTimescale );
  61. _transition = valueTo - valueFrom;
  62. iTween.ValueTo( this.gameObject, ht );
  63. }
  64. private void _onUpdate( float value ) {
  65. this.transform.localPosition = valueFrom + _transition * value;
  66. }
  67. }