008 發送一個數組在C#中的Flash (提交一個陣列到Flash)

Post date: 2012/11/22 上午 10:19:34

Commit an array to Flash

Rate this thread

Permlink of this thread Subscribe to this thread

avatar
  • 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:

function SetUpInventory()
{
  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");
    TempObj.SetString("ItemName", Inventory[i].ItemName);
    TempObj.SetString("ItemType", Inventory[i].ItemType);
    TempObj.SetString("ItemDesc", Inventory[i].ItemDesc);
    DataProvider.SetElementObject(i, TempObj);
  }
  RootMC.SetObject("inventory", DataProvider);     
  ShowInventory();
}

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; 
pMovie->CreateObject(&parent); 
pMovie->CreateObject(&child); 
parent.SetMember("child", child);

this is not possible with Unity integration?

/img/forum/dark/default_avatar.png

Matthew, please help me out here :D

Author: DarthIwan

Replied: 2012-09-06 2:52 AM

I will as soon as I can. Please be patient, as I’ve got a huge backlog of forum questions I need to catch up on before I can get tot this. Thanks!

Author: MatthewDoyleArt

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:

C# Code
// 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[2];
// 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[0] = element0;
myUnityArray[1] = 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

Author: MatthewDoyleArt

Replied: 2012-09-11 3:53 AM

/img/forum/dark/default_avatar.png

Thank you for reply!

I have a similar solution, but it would be much more easier to create an empty AS3 object. Is there any plans to add this important feature to the Unity plugin?

Author: DarthIwan

Replied: 2012-09-11 4:49 AM

I don’t know what the plan is, but I’ll certainly pass this along to the team. I agree it would be nice to simply pass an object, instead of iterating through a for loop.

Author: MatthewDoyleArt

Replied: 2012-09-11 5:01 AM

/img/forum/dark/default_avatar.png

That would be great, indeed.

As always, thank you :D

Author: DarthIwan

Replied: 2012-09-11 5:33 AM

/img/forum/dark/default_avatar.png

I use this loop system in my UI to pass more complex objects. I +1 the idea of having passable objects. :)

Author: Jason O

Replied: 2012-09-11 6:57 AM

avatar
  • am964
  • Posted: 2012-09-24 9:47 AM

Hello-

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.

Thanks,

Ankur

avatar
  • am964
  • Posted: 2012-09-24 9:50 AM

Also, we will add support for CreateObject in the next iteration. Thanks for your patience!

-Ankur