public XamlPadBindingContext(MonoBehaviour disposer) { AutoParse = new InternalReactiveProperty <bool>(disposer); XamlSource = new InternalReactiveProperty <string>(disposer); CompileResult = new InternalReactiveProperty <string>(disposer); FontSizeSelectedIndex = new InternalReactiveProperty <int>(disposer); _fontSize = new InternalReactiveProperty <double>(disposer); FontSize = new InternalReadOnlyReactiveProperty <double>(_fontSize, disposer); RootPage = new InternalReactiveProperty <Xamarin.Forms.View>(disposer); var cmd = new InternalReactiveCommand(disposer); cmd.Subscribe(_ => { try { var page = new Xamarin.Forms.Grid(); Xamarin.Forms.Platform.Unity.XamlLoader.LoadXaml(page, XamlSource.Value); RootPage.Value = page; CompileResult.Value = "Success!"; } catch (Exception e) { while (e.InnerException != null) { e = e.InnerException; } CompileResult.Value = e.Message; } }); CompileCommand = cmd; FontSizeSelectedIndex.Subscribe(value => { value = Math.Max(Math.Min(value, FontSizeList.Length - 1), 0); _fontSize.Value = double.Parse(FontSizeList[value]); }); IDisposable o = null; AutoParse.Subscribe(value => { o?.Dispose(); if (value) { o = XamlSource .Throttle(new TimeSpan(TimeSpan.TicksPerSecond)) .ObserveOnMainThread() .Subscribe(_ => cmd.Execute()); } }); }
public SampleBindingContext(MonoBehaviour disposer) { var cmd = new InternalReactiveCommand(disposer); cmd.Subscribe(_ => { var go = GameObject.CreatePrimitive(PrimitiveType.Sphere); UnityEngine.Object.Destroy(go, 5.0f); go.transform.position = new Vector3((float)(_rnd.NextDouble() * 2.0 - 1.0), 5.0f, (float)(_rnd.NextDouble() * 2.0 - 1.0)); var rb = go.AddComponent <Rigidbody>(); rb.useGravity = true; Counter.Value++; DoubleValue.Value = _rnd.NextDouble(); }).AddTo(disposer); InstantiateCommand = cmd; Counter = new InternalReactiveProperty <int>(disposer); DoubleValue = new InternalReactiveProperty <double>(disposer); }