juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.09k stars 505 forks source link

I am passing data in an array from flutter to unity and want to rotate object using coroutine in unity #881

Open zubair999 opened 9 months ago

zubair999 commented 9 months ago

Describe the bug I am sending some data in an array from flutter app to unity and want to rotate game object using coroutine. I have successfully rotated the object in while putting array data directly in c sharp. Now I want to send that array from flutter to unity and want to rotate a game object. For example if I say in angle I want to rotate from x=0 degree to x=90 while y and z values can also be there.

Expected behavior

https://github.com/juicycleff/flutter-unity-view-widget/assets/30196482/16b11a40-f175-43da-967c-208b0d895e4c

**Flutter Version Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision f468f3366c (8 weeks ago) • 2023-07-12 15:19:05 -0700 Engine • revision cdbeda788a Tools • Dart 3.0.6 • DevTools 2.23.1

Screenshots If applicable, add screenshots to help explain your problem.

Unity (please complete the following information):

Smartphone (please complete the following information):

Additional context void setRotation() { var frameData = [ "Orient: x= 0.00 | y= 0.00 | z= 0", "Orient: x= 90.00 | y= 0.00 | z= 0" ]; _unityWidgetController.postMessage( 'myCricketBat', 'StartRotation', frameData, ); }

timbotimbo commented 9 months ago

When you want to send more than 1 basic variable to Unity, your best bet is using JSON. Encode your frame data into a JSON string in Flutter, and send that to Unity as the third parameter of postMessage. In unity you can decode the string and do whatever you like with the data.

I won't go further than that as the rest is just programming in dart/c# that is unrelated to this plugin.

zubair999 commented 9 months ago

When you want to send more than 1 basic variable to Unity, your best bet is using JSON. Encode your frame data into a JSON string in Flutter, and send that to Unity as the third parameter of postMessage. In unity you can decode the string and do whatever you like with the data.

I won't go further than that as the rest is just programming in dart/c# that is unrelated to this plugin.

I am able to send the data in json also but stuck after that. I also rotated the object when I put the data in C Sharp only, I only stuck when I passing data from flutter to C Sharp. Thanks for the support