Skip to content

Commit 0472495

Browse files
committed
feat: Update Unity demo to use structured data for Flutter communication
This commit enhances the Unity demo by replacing anonymous object literals with structured data classes for messages sent to Flutter. The `ResetData` and `ReadyData` classes are introduced to improve clarity and maintainability of the data being communicated. This change ensures a more robust interaction between Unity and Flutter, aligning with best practices for data handling.
1 parent ca3946c commit 0472495

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

templates/unity/Scripts/GameFrameworkDemo.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private void Reset(string data)
349349
}
350350

351351
// Notify Flutter
352-
SendToFlutter("onReset", new { success = true });
352+
SendToFlutter("onReset", new ResetData { success = true });
353353

354354
Log("Demo reset");
355355
}
@@ -393,11 +393,13 @@ private void GetState(string data)
393393

394394
private void NotifyFlutterReady()
395395
{
396-
SendToFlutter("onReady", new
396+
SendToFlutter("onReady", new ReadyData
397397
{
398398
success = true,
399399
initialSpeed = _rotationSpeed,
400-
initialAxis = new { x = _rotationAxis.x, y = _rotationAxis.y, z = _rotationAxis.z },
400+
initialAxisX = _rotationAxis.x,
401+
initialAxisY = _rotationAxis.y,
402+
initialAxisZ = _rotationAxis.z,
401403
message = "Unity cube demo ready!"
402404
});
403405

@@ -471,6 +473,23 @@ public class CubeState
471473
public int messageCount;
472474
}
473475

476+
[Serializable]
477+
public class ResetData
478+
{
479+
public bool success;
480+
}
481+
482+
[Serializable]
483+
public class ReadyData
484+
{
485+
public bool success;
486+
public float initialSpeed;
487+
public float initialAxisX;
488+
public float initialAxisY;
489+
public float initialAxisZ;
490+
public string message;
491+
}
492+
474493
#endregion
475494
}
476495
}

0 commit comments

Comments
 (0)