Exemplo n.º 1
0
 public override void Disconnect()
 {
     if (eventWatcher != null)
     {
         eventWatcher.Dispose();
         eventWatcher = null;
     }
 }
        public override void Connect()
        {
            string    propertyName;
            Component view;

            ParseViewEndPointReference(uiPropertyName, out propertyName, out view);

            var viewModelEndPoint = MakeViewModelEndPoint(viewModelPropertyName, viewModelAdapterTypeName);

            var propertySync = new PropertySync(
                // Source
                viewModelEndPoint,

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

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

                this
                );

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

            string eventName;
            string eventComponentType;

            ParseEndPointReference(uiEventName, 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();
        }
        public override void Disconnect()
        {
            if (viewModelWatcher != null)
            {
                viewModelWatcher.Dispose();
                viewModelWatcher = null;
            }

            if (unityEventWatcher != null)
            {
                unityEventWatcher.Dispose();
                unityEventWatcher = null;
            }
        }
        public override void Disconnect()
        {
            if (selectionPropertyWatcher != null)
            {
                selectionPropertyWatcher.Dispose();
                selectionPropertyWatcher = null;
            }

            if (selectionEventWatcher != null)
            {
                selectionEventWatcher.Dispose();
                selectionEventWatcher = null;
            }

            dropdown = null;
        }
Exemplo n.º 5
0
        public override void Connect()
        {
            string methodName;
            object viewModel;

            ParseViewModelEndPointReference(viewModelMethodName, out methodName, out viewModel);
            var viewModelMethod = viewModel.GetType().GetMethod(methodName, new Type[0]);

            string    eventName;
            Component view;

            ParseViewEndPointReference(uiEventName, out eventName, out view);

            eventWatcher = new UnityEventWatcher(view, eventName,
                                                 () => viewModelMethod.Invoke(viewModel, new object[0])
                                                 );
        }
        public override void Connect()
        {
            dropdown = GetComponent <Dropdown>();

            var selectionPropertyEndPoint = MakeViewModelEndPoint(viewModelSelectionPropertyName, selectionUIToViewModelAdapter);

            var selectionPropertySync = new PropertySync(
                // Source
                selectionPropertyEndPoint,

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

                // Errors, exceptions and validation.
                !string.IsNullOrEmpty(exceptionPropertyName)
                    ? MakeViewModelEndPoint(exceptionPropertyName, exceptionAdapterTypeName)
                    : 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),

                // Dest
                new PropertyEndPoint(
                    this,
                    "Options",
                    CreateAdapter(optionsAdapter),
                    "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();
        }