008 發送一個數組在C＃中的Flash (提交一個陣列到Flash)
Post date: 2012/11/22 上午 10:19:34
Commit an array to Flash
Rate this thread
- Total Posts: 63
- Joined: 04 July 2012 07:57 PM
I have another question :)
I’ve seen an UDK example about how to pass an array to flash and vice verse.
Here is the code:
local byte i;
local GFxObject DataProvider;
local GFxObject TempObj;
local GFxObject RootMC;
RootMC = GetVariableObject("_root");
DataProvider = CreateArray();
for (i = 0; i < Inventory.Length; i++)
TempObj = CreateObject("Object");
It’s very simple, but i was not able to do something similar (like TempObj) in Unity. My problem was, that i was not able to create a Value and set different members. I could only create a Value with string, double and bool in it.
My question is, how can i create a Value and pass multiple members to the array/vector in Flash?
Didn’t found something similar in examples. HelloWorld have one, but its only manipulating an element of array.
Thanks in advance
P.S: why is there no CreateObject-function? In ‘Scaleform game communication overview’ document you can see this example:
Movie* pMovie = … ;
Value parent, child;
this is not possible with Unity integration?
Replied: 2012-09-06 2:52 AM
Replied: 2012-09-06 3:37 AM
Ok, so after some research, I’ve got a solution for you for setting a Flash array. This solution uses a for loop to set each element of the array:
// Create two test variables that will be used in our Unity array
String someString = "This is a test.";
int someInteger = 5;
// Create an array of Values with 2 elements
Value myUnityArray = new Value;
// Create two new values (a string, and an integer) to populte the array of Values
Value element0 = new Value(someString, this.MovieID);
Value element1 = new Value(someInteger, this.MovieID);
// Populate the unity array with these elements
myUnityArray = element0;
myUnityArray = element1;
// Populate the Flash array with the data stored in the Unity array
// This assumes there is an Array named myFlashArray
// on the current frame of the Flash timeline, or in the Main.as class for this movie (myMovie)
Value myCachedFlashArray = myMovie.GetMember( "myFlashArray" );
for ( uint i = 0; i < myUnityArray.Length; ++i )
myCachedFlashArray.SetElement( i, myUnityArray[i] );
Debug.Log( myCachedFlashArray.GetElement( 0 ) ); // Traces "This is a test."
Debug.Log( myCachedFlashArray.GetElement( 1 ) ); // Traces 5
Replied: 2012-09-11 3:53 AM
Replied: 2012-09-11 4:49 AM
Replied: 2012-09-11 5:01 AM
Replied: 2012-09-11 5:33 AM
Replied: 2012-09-11 6:57 AM
Agreed that it will be very useful to be able to pass objects, the problem is with marshalling- we need to know the layout of the object in memory so it can be passed from managed to unmanaged layer. With known types such as Value, this is taken care of by the integration.
Can you guys please provide some samples of the C# code that you would like to work? I’d then investigate if it’s possible to support it.
Also, we will add support for CreateObject in the next iteration. Thanks for your patience!