Welcome,
Guest
. Please
login
or
register
.
February 15, 2025, 12:24:34 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Event Delegates and UItweener
« previous
next »
Print
Pages: [
1
]
Author
Topic: Event Delegates and UItweener (Read 3255 times)
sfj
Newbie
Thank You
-Given: 1
-Receive: 0
Posts: 14
Event Delegates and UItweener
«
on:
March 11, 2015, 09:57:52 AM »
Hi,
I'm having some trouble with a tween controller class where I want to fire of multiple tweens and then wait for them to finish.
So basically I'm starting a tween...building a list with the tweens that are in progress and then removing from the list when they are done...although it doesn't seem to work properly so there must be something I didn't get missed/not understand:
// Use this for initialization
void
Awake
(
)
{
_uiTweeners
=
GetComponents
<
UITweener
>
(
)
;
if
(
_uiTweeners
.
Length
==
0
)
_uiTweeners
=
GetComponentsInChildren
<
UITweener
>
(
)
;
}
void
Start
(
)
{
foreach
(
UITweener tweener
in
_uiTweeners
)
{
EventDelegate onFinishedDelegate
=
new
EventDelegate
(
)
;
onFinishedDelegate
.
target
=
this
;
onFinishedDelegate
.
methodName
=
"TweenerFinished"
;
onFinishedDelegate
.
parameters
[
0
]
.
obj
=
tweener
;
EventDelegate
.
Add
(
tweener
.
onFinished
, onFinishedDelegate
)
;
}
}
void
TweenerFinished
(
UITweener sender
)
{
tweensInProgress
.
Remove
(
sender
)
;
if
(
tweensInProgress
.
Count
==
0
&&
onFinishedCallback
!=
null
)
onFinishedCallback
(
)
;
}
public
void
PlayForward
(
Action callback
)
{
if
(
tweensInProgress
.
Count
==
0
)
{
onFinishedCallback
=
callback
;
for
(
int
i
=
0
;
i
<
_uiTweeners
.
Length
;
i
++
)
{
UITweener tweener
=
_uiTweeners
[
i
]
;
tweensInProgress
.
Add
(
tweener
)
;
tweener
.
PlayForward
(
)
;
}
}
}
Is there anything crazy there?
Stefan
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Event Delegates and UItweener
«
Reply #1 on:
March 12, 2015, 07:55:08 PM »
A bit of a strange way of doing it, but your TweenerFinished function needs to be public, not private.
Logged
sfj
Newbie
Thank You
-Given: 1
-Receive: 0
Posts: 14
Re: Event Delegates and UItweener
«
Reply #2 on:
March 18, 2015, 06:09:16 AM »
Thanks...a totally strange way of doing it...although working now... what would be your advised way of doing it?
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Event Delegates and UItweener
«
Reply #3 on:
March 19, 2015, 06:29:51 AM »
I'd simply assign onFinished only to the tween that has the longest duration.
Logged
sfj
Newbie
Thank You
-Given: 1
-Receive: 0
Posts: 14
Re: Event Delegates and UItweener
«
Reply #4 on:
March 19, 2015, 10:32:53 AM »
yeah that sounds like efficient way to do it.. so have some code that picks out the longest tween and then assign OnFinished on that one,
well I ended up simplifying my old code with just counting the tweens..I guess not as efficient as your suggestions but more than the first and hopefully less strange:
foreach
(
UITweener tweener
in
_uiTweeners
)
{
tweener
.
SetOnFinished
(
(
)
=>
{
tweenersInProgressCount
--;
if
(
tweenersInProgressCount
==
0
&&
onFinishedCallback
!=
null
)
onFinishedCallback
(
)
;
}
)
;
}
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Event Delegates and UItweener