public void AddControlsToUnityFrame() { FrameLayout layout = MUnityPlayer; { Button myButton = new Button(this); myButton.Text = "Show Main"; myButton.SetX(10); myButton.SetY(500); myButton.Click += (_, __) => { ShowMainActivity(""); }; } { Button myButton = new Button(this); myButton.Text = "Send Msg"; myButton.SetX(320); myButton.SetY(500); myButton.Click += (_, __) => { UnityPlayer.UnitySendMessage("Cube", "ChangeColor", "yellow"); }; layout.AddView(myButton, 300, 200); } { Button myButton = new Button(this); myButton.Text = "Unload"; myButton.SetX(630); myButton.SetY(500); myButton.Click += (_, __) => { MUnityPlayer.Unload(); }; layout.AddView(myButton, 300, 200); } { Button myButton = new Button(this); myButton.Text = "Finish"; myButton.SetX(630); myButton.SetY(800); myButton.Click += (_, __) => { Finish(); }; layout.AddView(myButton, 300, 200); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Button btn1 = new Button(this) { Text = "Зелёный" }; btn1.SetY(0); btn1.SetX(10); btn1.Click += (s, e) => UnityPlayer.UnitySendMessage("Cube", "SetColorGreen", ""); Button btn2 = new Button(this) { Text = "Красный" }; btn2.SetY(200); btn2.SetX(10); btn2.Click += (s, e) => UnityPlayer.UnitySendMessage("Cube", "SetColorRed", ""); UnityFrameLayout.AddView(btn1, 500, 100); UnityFrameLayout.AddView(btn2, 500, 100); }
public void UnitySendMessage(string gameObject, string function, string param) { UnityPlayer.UnitySendMessage(gameObject, function, param); }