@@ -19,11 +19,12 @@ public static class PropertyChaining
1919 /// <returns>The tween itself to allow for chaining.</returns>
2020 public static T SetTarget < T > ( this T tween , Component target ) where T : Tween
2121 {
22- if ( target != null )
22+ if ( tween != null && target != null )
2323 {
2424 tween . id = target . GetHashCode ( ) ;
2525 tween . sceneIndex = target . gameObject . scene . buildIndex ;
2626 }
27+
2728 return tween ;
2829 }
2930
@@ -37,11 +38,12 @@ public static T SetTarget<T>(this T tween, Component target) where T: Tween
3738 /// <returns>The tween itself to allow for chaining.</returns>
3839 public static T SetTarget < T > ( this T tween , GameObject target ) where T : Tween
3940 {
40- if ( target != null )
41+ if ( tween != null && target != null )
4142 {
4243 tween . id = target . GetHashCode ( ) ;
4344 tween . sceneIndex = target . scene . buildIndex ;
4445 }
46+
4547 return tween ;
4648 }
4749
@@ -54,7 +56,10 @@ public static T SetTarget<T>(this T tween, GameObject target) where T: Tween
5456 /// <returns>The tween itself to allow for chaining.</returns>
5557 public static T SetId < T > ( this T tween , int id ) where T : Tween
5658 {
57- tween . id = id ;
59+ if ( tween != null ) {
60+ tween . id = id ;
61+ }
62+
5863 return tween ;
5964 }
6065
@@ -67,7 +72,10 @@ public static T SetId<T>(this T tween, int id) where T: Tween
6772 /// <returns>The tween itself to allow for chaining.</returns>
6873 public static T SetSceneIndex < T > ( this T tween , int index ) where T : Tween
6974 {
70- tween . sceneIndex = index ;
75+ if ( tween != null ) {
76+ tween . sceneIndex = index ;
77+ }
78+
7179 return tween ;
7280 }
7381
@@ -80,7 +88,10 @@ public static T SetSceneIndex<T>(this T tween, int index) where T: Tween
8088 /// <returns>The tween itself to allow for chaining.</returns>
8189 public static T SetEase < T > ( this T tween , Ease ease ) where T : Tween
8290 {
83- tween . ease = ease ;
91+ if ( tween != null ) {
92+ tween . ease = ease ;
93+ }
94+
8495 return tween ;
8596 }
8697
@@ -93,7 +104,10 @@ public static T SetEase<T>(this T tween, Ease ease) where T: Tween
93104 /// <returns>The tween itself to allow for chaining.</returns>
94105 public static T SetDuration < T > ( this T tween , float duration ) where T : Tween
95106 {
96- tween . duration = duration ;
107+ if ( tween != null ) {
108+ tween . duration = duration ;
109+ }
110+
97111 return tween ;
98112 }
99113
@@ -106,7 +120,10 @@ public static T SetDuration<T>(this T tween, float duration) where T: Tween
106120 /// <returns>The tween itself to allow for chaining.</returns>
107121 public static T SetDelay < T > ( this T tween , float delay ) where T : Tween
108122 {
109- tween . delay = delay ;
123+ if ( tween != null ) {
124+ tween . delay = delay ;
125+ }
126+
110127 return tween ;
111128 }
112129
@@ -120,8 +137,12 @@ public static T SetDelay<T>(this T tween, float delay) where T: Tween
120137 /// <returns>The tween itself to allow for chaining.</returns>
121138 public static T SetLoops < T > ( this T tween , int loops , LoopType loopType = LoopType . Restart ) where T : Tween
122139 {
123- tween . loops = loops ;
124- tween . loopType = loopType ;
140+ if ( tween != null )
141+ {
142+ tween . loops = loops ;
143+ tween . loopType = loopType ;
144+ }
145+
125146 return tween ;
126147 }
127148
@@ -134,7 +155,10 @@ public static T SetLoops<T>(this T tween, int loops, LoopType loopType = LoopTyp
134155 /// <returns>The tween itself to allow for chaining.</returns>
135156 public static T SetReversed < T > ( this T tween , bool reversed = true ) where T : Tween
136157 {
137- tween . reversed = reversed ;
158+ if ( tween != null ) {
159+ tween . reversed = reversed ;
160+ }
161+
138162 return tween ;
139163 }
140164
@@ -147,7 +171,10 @@ public static T SetReversed<T>(this T tween, bool reversed = true) where T: Twee
147171 /// <returns>The tween itself to allow for chaining.</returns>
148172 public static T SetSnapping < T > ( this T tween , bool snapping = true ) where T : Tween
149173 {
150- tween . snapping = snapping ;
174+ if ( tween != null ) {
175+ tween . snapping = snapping ;
176+ }
177+
151178 return tween ;
152179 }
153180
@@ -160,7 +187,10 @@ public static T SetSnapping<T>(this T tween, bool snapping = true) where T: Twee
160187 /// <returns>The tween itself to allow for chaining.</returns>
161188 public static T SetRecyclable < T > ( this T tween , bool recyclable ) where T : Tween
162189 {
163- tween . recyclable = recyclable ;
190+ if ( tween != null ) {
191+ tween . recyclable = recyclable ;
192+ }
193+
164194 return tween ;
165195 }
166196
@@ -173,7 +203,10 @@ public static T SetRecyclable<T>(this T tween, bool recyclable) where T: Tween
173203 /// <returns>The tween itself to allow for chaining.</returns>
174204 public static T SetAutoStart < T > ( this T tween , bool autoStart ) where T : Tween
175205 {
176- tween . autoStart = autoStart ;
206+ if ( tween != null ) {
207+ tween . autoStart = autoStart ;
208+ }
209+
177210 return tween ;
178211 }
179212
@@ -186,7 +219,10 @@ public static T SetAutoStart<T>(this T tween, bool autoStart) where T: Tween
186219 /// <returns>The tween itself to allow for chaining.</returns>
187220 public static T SetAutoKill < T > ( this T tween , bool autoKill ) where T : Tween
188221 {
189- tween . autoKill = autoKill ;
222+ if ( tween != null ) {
223+ tween . autoKill = autoKill ;
224+ }
225+
190226 return tween ;
191227 }
192228
@@ -199,7 +235,10 @@ public static T SetAutoKill<T>(this T tween, bool autoKill) where T: Tween
199235 /// <returns>The tween itself to allow for chaining.</returns>
200236 public static T OnUpdate < T > ( this T tween , TweenCallback callback ) where T : Tween
201237 {
202- tween . onUpdate += callback ;
238+ if ( tween != null ) {
239+ tween . onUpdate += callback ;
240+ }
241+
203242 return tween ;
204243 }
205244
@@ -212,7 +251,10 @@ public static T OnUpdate<T>(this T tween, TweenCallback callback) where T: Tween
212251 /// <returns>The tween itself to allow for chaining.</returns>
213252 public static T OnStart < T > ( this T tween , TweenCallback callback ) where T : Tween
214253 {
215- tween . onStart += callback ;
254+ if ( tween != null ) {
255+ tween . onStart += callback ;
256+ }
257+
216258 return tween ;
217259 }
218260
@@ -225,7 +267,10 @@ public static T OnStart<T>(this T tween, TweenCallback callback) where T: Tween
225267 /// <returns>The tween itself to allow for chaining.</returns>
226268 public static T OnStop < T > ( this T tween , TweenCallback callback ) where T : Tween
227269 {
228- tween . onStop += callback ;
270+ if ( tween != null ) {
271+ tween . onStop += callback ;
272+ }
273+
229274 return tween ;
230275 }
231276
@@ -238,7 +283,10 @@ public static T OnStop<T>(this T tween, TweenCallback callback) where T: Tween
238283 /// <returns>The tween itself to allow for chaining.</returns>
239284 public static T OnLoop < T > ( this T tween , TweenCallback callback ) where T : Tween
240285 {
241- tween . onLoop += callback ;
286+ if ( tween != null ) {
287+ tween . onLoop += callback ;
288+ }
289+
242290 return tween ;
243291 }
244292
@@ -251,7 +299,10 @@ public static T OnLoop<T>(this T tween, TweenCallback callback) where T: Tween
251299 /// <returns>The tween itself to allow for chaining.</returns>
252300 public static T OnComplete < T > ( this T tween , TweenCallback callback ) where T : Tween
253301 {
254- tween . onComplete += callback ;
302+ if ( tween != null ) {
303+ tween . onComplete += callback ;
304+ }
305+
255306 return tween ;
256307 }
257308
@@ -264,7 +315,10 @@ public static T OnComplete<T>(this T tween, TweenCallback callback) where T: Twe
264315 /// <returns>The tween itself to allow for chaining.</returns>
265316 public static T OnKill < T > ( this T tween , TweenCallback callback ) where T : Tween
266317 {
267- tween . onKill += callback ;
318+ if ( tween != null ) {
319+ tween . onKill += callback ;
320+ }
321+
268322 return tween ;
269323 }
270324
0 commit comments