Esempio n. 1
0
            /// <summary> Will show a diameter edit UI that can modify the current selected circle </summary>
            private void ShowDiameterEditUi()
            {
                Log.MethodEntered();

                var editUi = targetView.GetViewStack().ShowView("DiameterEditUi");
                var map    = editUi.GetLinkMap();

                // Get a selector that always returns the current selected circle:
                var selectedCircleId = store.SelectElement(s => s.selectedCircle);
                // Get a selector that always returns the latest state of the current selected circle:
                var selectedCicrle = store.SelectListEntry(s => s.circles, c => c?.id == selectedCircleId());

                Text text = map.Get <Text>("CircleInfoText");

                text.SubscribeToStateChanges(store, x => x.selectedCircle, (_) => {
                    text.text = $"Adjust diameter of circle at ({selectedCicrle().x}, {selectedCicrle().y})";
                });

                Slider slider = map.Get <Slider>("DiameterSlider");

                slider.SubscribeToStateChanges(store, model => selectedCicrle().diameter);

                // Instantly render the changed diameter in the UI:
                slider.SetOnValueChangedAction((newDiameter) => {
                    // Use the GameObject lookup dictionary to access the UI GO efficiently:
                    var selectedCircleGo = circleGOs[selectedCircleId()];
                    SetSizeOfCircleUi(selectedCircleGo.GetComponent <RectTransform>(), newDiameter);
                    return(true);
                });

                // Only persist the diameter change after a delay to avoid spamming the store with dispatched actions:
                slider.AddOnValueChangedActionThrottled((newDiameter) => {
                    store.Dispatch(new ChangeDiameterAction()
                    {
                        targetCircleId = selectedCircleId(),
                        newDiameter    = newDiameter
                    });
                });
            }