Ejemplo n.º 1
0
        public override void Connect()
        {
            var viewModelEndPoint = MakeViewModelEndPoint(viewModelPropertyName, null, null);

            var propertySync = new PropertySync(
                // Source
                viewModelEndPoint,

                // Dest
                new PropertyEndPoint(
                    this,
                    "ChildrenActive",
                    CreateAdapter(viewAdapterTypeName),
                    viewAdapterOptions,
                    "view",
                    this
                    ),

                // Errors, exceptions and validation.
                null, // Validation not needed

                this
                );

            viewModelWatcher = viewModelEndPoint.Watch(
                () => propertySync.SyncFromSource()
                );

            // Copy the initial value over from the view-model.
            propertySync.SyncFromSource();
        }
        public override void Connect()
        {
            string    propertyName;
            Component view;

            ParseViewEndPointReference(viewPropertyName, out propertyName, out view);

            var viewModelEndPoint = MakeViewModelEndPoint(
                viewModelPropertyName,
                viewModelAdapterTypeName,
                viewModelAdapterOptions
                );

            var propertySync = new PropertySync(
                // Source
                viewModelEndPoint,

                // Dest
                new PropertyEndPoint(
                    view,
                    propertyName,
                    CreateAdapter(viewAdapterTypeName),
                    viewAdapterOptions,
                    "view",
                    this
                    ),

                // Errors, exceptions and validation.
                !string.IsNullOrEmpty(exceptionPropertyName)
                    ? MakeViewModelEndPoint(
                    exceptionPropertyName,
                    exceptionAdapterTypeName,
                    exceptionAdapterOptions
                    )
                    : null
                ,

                this
                );

            viewModelWatcher = viewModelEndPoint.Watch(
                () => propertySync.SyncFromSource()
                );

            string eventName;
            string eventComponentType;

            ParseEndPointReference(viewEventName, out eventName, out eventComponentType);

            var eventView = GetComponent(eventComponentType);

            unityEventWatcher = new UnityEventWatcher(
                eventView,
                eventName,
                () => propertySync.SyncFromDest()
                );

            // Copy the initial value over from the view-model.
            propertySync.SyncFromSource();
        }
Ejemplo n.º 3
0
        public override void Connect()
        {
            string    propertyName;
            Component view;

            ParseViewEndPointReference(viewPropertyName, out propertyName, out view);

            var viewModelEndPoint = MakeViewModelEndPoint(viewModelPropertyName, null, null);

            var propertySync = new PropertySync(
                // Source
                viewModelEndPoint,

                // Dest
                new PropertyEndPoint(
                    view,
                    propertyName,
                    TypeResolver.GetAdapter(ViewAdapterId),
                    viewAdapterOptions,
                    "view",
                    this
                    ),

                // Errors, exceptions and validation.
                null, // Validation not needed

                this
                );

            viewModelWatcher = viewModelEndPoint.Watch(
                () => propertySync.SyncFromSource()
                );

            // Copy the initial value over from the view-model.
            propertySync.SyncFromSource();
        }
        public override void Connect()
        {
            dropdown = GetComponent <Dropdown>();

            var selectionPropertyEndPoint = MakeViewModelEndPoint(viewModelSelectionPropertyName, selectionUIToViewModelAdapter, null);

            var selectionPropertySync = new PropertySync(
                // Source
                selectionPropertyEndPoint,

                // Dest
                new PropertyEndPoint(
                    this,
                    "SelectedOption",
                    CreateAdapter(selectionViewModelToUIAdapter),
                    null,
                    "view",
                    this
                    ),

                // Errors, exceptions and validation.
                !string.IsNullOrEmpty(exceptionPropertyName)
                    ? MakeViewModelEndPoint(exceptionPropertyName, exceptionAdapterTypeName, null)
                    : null
                ,

                this
                );

            selectionPropertyWatcher = selectionPropertyEndPoint
                                       .Watch(() => selectionPropertySync.SyncFromSource());

            selectionEventWatcher = new UnityEventWatcher(
                dropdown,
                "onValueChanged",
                () =>
            {
                selectedOption = Options[dropdown.value];     // Copy value back from dropdown.
                selectionPropertySync.SyncFromDest();
            }
                );

            var optionsPropertySync = new PropertySync(
                // Source
                MakeViewModelEndPoint(viewModelOptionsPropertyName, null, null),

                // Dest
                new PropertyEndPoint(
                    this,
                    "Options",
                    CreateAdapter(optionsAdapter),
                    null,
                    "view",
                    this
                    ),

                // Errors, exceptions and validation.
                null, // Validation not needed

                this
                );

            // Copy the initial value from view-model to view.
            selectionPropertySync.SyncFromSource();
            optionsPropertySync.SyncFromSource();
            UpdateOptions();
        }
Ejemplo n.º 5
0
        public override void Connect()
        {
            if (boundAnimator == null)
            {
                boundAnimator = GetComponent <Animator>();
            }

            Assert.IsTrue(
                boundAnimator != null,
                "Animator is null!"
                );

            Assert.IsTrue(
                !string.IsNullOrEmpty(AnimatorParameterName),
                "AnimatorParameter is not set"
                );

            string propertyName;

            switch (AnimatorParameterType)
            {
            case AnimatorControllerParameterType.Float:
                propertyName = "FloatParameter";
                break;

            case AnimatorControllerParameterType.Int:
                propertyName = "IntParameter";
                break;

            case AnimatorControllerParameterType.Bool:
                propertyName = "BoolParameter";
                break;

            case AnimatorControllerParameterType.Trigger:
                propertyName = "TriggerParameter";
                break;

            default:
                throw new IndexOutOfRangeException("Unexpected animator parameter type");
            }

            var viewModelEndPoint = MakeViewModelEndPoint(viewModelPropertyName, null, null);

            // If the binding property is an AnimatorParameterTrigger,
            // we change the owner to the instance of the property
            // and change the property to "TriggerSetOrReset"
            if (AnimatorParameterType == AnimatorControllerParameterType.Trigger)
            {
                viewModelEndPoint = new PropertyEndPoint(viewModelEndPoint.GetValue(), "TriggerSetOrReset", null, null, "view-model", this);
            }

            var propertySync = new PropertySync(
                // Source
                viewModelEndPoint,

                // Dest
                new PropertyEndPoint(
                    this,
                    propertyName,
                    CreateAdapter(viewAdapterTypeName),
                    viewAdapterOptions,
                    "Animator",
                    this
                    ),

                // Errors, exceptions and validation.
                null, // Validation not needed

                this
                );

            viewModelWatcher = viewModelEndPoint.Watch(
                () => propertySync.SyncFromSource()
                );

            // Copy the initial value over from the view-model.
            propertySync.SyncFromSource();
        }