v3.11.4 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  public override bool HasReference(Variable variable)
112  {
113  return _targetObject.gameObjectRef == variable || _tweenName.stringRef == variable ||
114  base.HasReference(variable);
115  }
116 
117  #endregion
118 
119  #region Backwards compatibility
120 
121  [HideInInspector] [FormerlySerializedAs("target")] [FormerlySerializedAs("targetObject")] public GameObject targetObjectOLD;
122  [HideInInspector] [FormerlySerializedAs("tweenName")] public string tweenNameOLD = "";
123  [HideInInspector] [FormerlySerializedAs("duration")] public float durationOLD;
124 
125  protected virtual void OnEnable()
126  {
127  if (targetObjectOLD != null)
128  {
129  _targetObject.Value = targetObjectOLD;
130  targetObjectOLD = null;
131  }
132 
133  if (tweenNameOLD != "")
134  {
135  _tweenName.Value = tweenNameOLD;
136  tweenNameOLD = "";
137  }
138 
139  if (durationOLD != default(float))
140  {
141  _duration.Value = durationOLD;
142  durationOLD = default(float);
143  }
144  }
145 
146  #endregion
147  }
148 }
virtual void DoTween()
Fade all color components (RGBA).
Base class for Commands.
Definition: Command.cs:42
iTween.EaseType easeType
iTween.LoopType loopType
GameObjectData _targetObject
GameObjectVariable gameObjectRef
Container for a string variable reference or constant value.
´╗┐using UnityEngine
Definition: iTweenCommand.cs:4
StringVariable stringRef
override string GetSummary()
Returns the summary text to display in the command inspector.
Apply the tween on the Y axis only.
Abstract base class for variables.
Definition: Variable.cs:102
GameObject targetObjectOLD
iTweenAxis
Axis to apply the tween on.
override bool HasReference(Variable variable)
Returns true if this command references the variable.
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:143
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.