Welcome,
Guest
. Please
login
or
register
.
March 27, 2025, 05:09:15 AM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Passing Instance References Via EventDelegate
« previous
next »
Print
Pages:
1
[
2
]
Author
Topic: Passing Instance References Via EventDelegate (Read 10078 times)
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Passing Instance References Via EventDelegate
«
Reply #15 on:
June 21, 2014, 04:05:40 PM »
del.parameters.SetValue(insc, 0) sets the value of the first parameter -- that is you need to actually
have
a parameter for it to work.
Give your function a parameter.
Logged
maxdev
Newbie
Thank You
-Given: 2
-Receive: 0
Posts: 11
Re: Passing Instance References Via EventDelegate
«
Reply #16 on:
June 21, 2014, 04:21:44 PM »
IEnumerator SpawnCalc
(
)
{
GameObject insc
=
Instantiate
(
prefab, transform
.
position
, Quaternion
.
identity
)
as
GameObject
;
insc
.
GetComponent
<
TweenPosition
>
(
)
.
enabled
=
true
;
EventDelegate
.
Parameter
a
=
new
EventDelegate
.
Parameter
(
)
;
a
.
obj
=
insc
;
a
.
field
=
"test"
;
EventDelegate del
=
new
EventDelegate
(
this
.
testyay
)
;
EventDelegate
.
Add
(
insc
.
GetComponent
<
TweenPosition
>
(
)
.
onFinished
, del
)
;
del
.
parameters
.
SetValue
(
a,
0
)
;
}
private
void
testyay
(
EventDelegate
.
Parameter
f
)
{
print
(
f
.
obj
.
name
)
;
}
Why doesnt this work? I'd very much appreciate a working example since it seems to me like I've tried
every combination I can think of or find and it still doesnt work...
«
Last Edit: June 21, 2014, 04:27:16 PM by maxdev
»
Logged
trenrod
Newbie
Thank You
-Given: 0
-Receive: 1
Posts: 4
Re: Passing Instance References Via EventDelegate
«
Reply #17 on:
June 22, 2014, 07:03:59 PM »
I got a working example its all in one class called MyClass
public
class
MyClass
:
MonoBehaviour
{
...
// Used to make a reference to the value of the parameter for the method you want to call.
// Used for EventDelegate.Parameter.Set(...
public
string
ITEM_VALUE
=
"XXX"
;
...
public
void
init
(
)
{
//EventDelegate to call method test in the same class with a given parameter where the value is ITEM_VALUE
EventDelegate eventDel
=
new
EventDelegate
(
)
;
//Target object
eventDel
.
target
=
this
;
//Method name
eventDel
.
methodName
=
"test"
;
//EventDelegate.Parameter for the parameter in the methode defined before
//First parameter is the object which contains the attribute wich has the name of the second parameter
EventDelegate
.
Parameter
p
=
new
EventDelegate
.
Parameter
(
this
,
"ITEM_VALUE"
)
;
eventDel
.
parameters
.
SetValue
(
p,
0
)
;
EventDelegate
.
Set
(
isbn
.
GetComponentInChildren
<
UIButton
>
(
)
.
onClick
, eventDel
)
;
...
public
void
test
(
string
panelName
)
{
Debug
.
Log
(
"Test was pressed: "
+
panelName
)
;
}
...
Output after a click on the button:
Test was pressed: XXX
Drop a comment if you cant to adjust it to your exsample.
Have fun.
Edit: comments
«
Last Edit: June 22, 2014, 07:12:22 PM by trenrod
»
Logged
maxdev
Newbie
Thank You
-Given: 2
-Receive: 0
Posts: 11
Re: Passing Instance References Via EventDelegate
«
Reply #18 on:
June 22, 2014, 08:47:41 PM »
Thanks very very much trenrod, it works perfectly!
Logged
Print
Pages:
1
[
2
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Passing Instance References Via EventDelegate