v3.9.1 Documentation
iTweenCommand.cs
Go to the documentation of this file.
1 // This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
2 // It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
3 
4 ´╗┐using UnityEngine;
5 using UnityEngine.Serialization;
6 
7 namespace Fungus
8 {
12  public enum iTweenAxis
13  {
15  None,
17  X,
19  Y,
21  Z
22  }
23 
27  [ExecuteInEditMode]
28  public abstract class iTweenCommand : Command
29  {
30  [Tooltip("Target game object to apply the Tween to")]
31  [SerializeField] protected GameObjectData _targetObject;
32 
33  [Tooltip("An individual name useful for stopping iTweens by name")]
34  [SerializeField] protected StringData _tweenName;
35 
36  [Tooltip("The time in seconds the animation will take to complete")]
37  [SerializeField] protected FloatData _duration = new FloatData(1f);
38 
39  [Tooltip("The shape of the easing curve applied to the animation")]
40  [SerializeField] protected iTween.EaseType easeType = iTween.EaseType.easeInOutQuad;
41 
42  [Tooltip("The type of loop to apply once the animation has completed")]
43  [SerializeField] protected iTween.LoopType loopType = iTween.LoopType.none;
44 
45  [Tooltip("Stop any previously added iTweens on this object before adding this iTween")]
46  [SerializeField] protected bool stopPreviousTweens = false;
47 
48  [Tooltip("Wait until the tween has finished before executing the next command")]
49  [SerializeField] protected bool waitUntilFinished = true;
50 
51  protected virtual void OniTweenComplete(object param)
52  {
53  Command command = param as Command;
54  if (command != null && command.Equals(this))
55  {
56  if (waitUntilFinished)
57  {
58  Continue();
59  }
60  }
61  }
62 
63  #region Public members
64 
65  public override void OnEnter()
66  {
67  if (_targetObject.Value == null)
68  {
69  Continue();
70  return;
71  }
72 
73  if (stopPreviousTweens)
74  {
75  // Force any existing iTweens on this target object to complete immediately
76  var tweens = _targetObject.Value.GetComponents<iTween>();
77  for (int i = 0; i < tweens.Length; i++)
78  {
79  var tween = tweens[i];
80  tween.time = 0;
81  tween.SendMessage("Update");
82  }
83  }
84 
85  DoTween();
86 
87  if (!waitUntilFinished)
88  {
89  Continue();
90  }
91  }
92 
93  public virtual void DoTween()
94  {}
95 
96  public override string GetSummary()
97  {
98  if (_targetObject.Value == null)
99  {
100  return "Error: No target object selected";
101  }
102 
103  return _targetObject.Value.name + " over " + _duration.Value + " seconds";
104  }
105 
106  public override Color GetButtonColor()
107  {
108  return new Color32(233, 163, 180, 255);
109  }
110 
111  #endregion
112 
113  #region Backwards compatibility
114 
115  [HideInInspector] [FormerlySerializedAs("target")] [FormerlySerializedAs("targetObject")] public GameObject targetObjectOLD;
116  [HideInInspector] [FormerlySerializedAs("tweenName")] public string tweenNameOLD = "";
117  [HideInInspector] [FormerlySerializedAs("duration")] public float durationOLD;
118 
119  protected virtual void OnEnable()
120  {
121  if (targetObjectOLD != null)
122  {
123  _targetObject.Value = targetObjectOLD;
124  targetObjectOLD = null;
125  }
126 
127  if (tweenNameOLD != "")
128  {
129  _tweenName.Value = tweenNameOLD;
130  tweenNameOLD = "";
131  }
132 
133  if (durationOLD != default(float))
134  {
135  _duration.Value = durationOLD;
136  durationOLD = default(float);
137  }
138  }
139 
140  #endregion
141  }
142 }
virtual void DoTween()
Fade all color components (RGBA).
Base class for Commands.
Definition: Command.cs:42
iTween.EaseType easeType
iTween.LoopType loopType
GameObjectData _targetObject
Container for a string variable reference or constant value.
´╗┐using UnityEngine
Definition: iTweenCommand.cs:4
override string GetSummary()
Returns the summary text to display in the command inspector.
Apply the tween on the Y axis only.
GameObject targetObjectOLD
iTweenAxis
Axis to apply the tween on.
virtual void OnEnable()
Abstract base class for iTween commands.
Container for a GameObject variable reference or constant value.
virtual void Continue()
End execution of this command and continue execution at the next command.
Definition: Command.cs:119
virtual void OniTweenComplete(object param)
Container for an float variable reference or constant value.
Apply the tween on the Z axis only.
override void OnEnter()
Called when this command starts execution.
Apply the tween on the X axis only.
Definition: Break.cs:6
override Color GetButtonColor()
Return the color for the command background in inspector.