iTweenValueTo.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Module Name: iTweenValueTo.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 Value To component
  9. // Use this component to create custom value transitions with the
  10. // OnUpdate event.
  11. // 1.00.00 - First build
  12. //
  13. // Check every tools and plugins we made for Unity at
  14. // https://www.assetstore.unity3d.com/en/publisher/4888
  15. //
  16. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  17. // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  18. // WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  19. using UnityEngine;
  20. using System.Collections;
  21. using UnityEngine.Events;
  22. using System;
  23. public class iTweenValueTo : iTweenEditor {
  24. public float valueFrom = 0.0f;
  25. public float valueTo = 1.0f;
  26. [System.Serializable]
  27. public class OnStart : UnityEvent { };
  28. public OnStart onStart;
  29. [System.Serializable]
  30. public class OnUpdate : UnityEvent<float> { };
  31. public OnUpdate onUpdate;
  32. [System.Serializable]
  33. public class OnComplete : UnityEvent { };
  34. public OnComplete onComplete;
  35. // Use this for initialization
  36. void Awake() {
  37. if ( this.autoPlay )
  38. this.iTweenPlay();
  39. }
  40. public override void iTweenPlay() {
  41. Hashtable ht = new Hashtable();
  42. ht.Add( "from", this.valueFrom );
  43. ht.Add( "to", this.valueTo );
  44. ht.Add( "time", this.tweenTime );
  45. ht.Add( "delay", this.waitTime );
  46. ht.Add( "looptype", this.loopType );
  47. ht.Add( "easetype", this.easeType );
  48. ht.Add( "onstart", (Action<object>)( newVal => {
  49. if ( onStart != null ) {
  50. onStart.Invoke();
  51. }
  52. if ( onUpdate != null ) {
  53. onUpdate.Invoke( this.valueFrom );
  54. }
  55. } ) );
  56. ht.Add( "onupdate", (Action<object>)( newVal => {
  57. if ( onUpdate != null ) {
  58. onUpdate.Invoke( (float)newVal );
  59. }
  60. } ) );
  61. ht.Add( "oncomplete", (Action<object>)( newVal => {
  62. if ( onComplete != null ) {
  63. onComplete.Invoke();
  64. }
  65. } ) );
  66. ht.Add( "ignoretimescale", ignoreTimescale );
  67. iTween.ValueTo( this.gameObject, ht );
  68. }
  69. }