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();
        }
예제 #2
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();
        }
예제 #3
0
        public override void OnNavigatedTo()
        {
            base.OnNavigatedTo();

            _logger.LogDebug("Syncing Properties with {type}: '{name}'", BackupItem.TypeName(), BackupItem.Name);
            PropertySync.Sync(BackupItem, this);
        }
예제 #4
0
        public void SyncStringDiff(string firstName, string lastName)
        {
            var personModel = new PersonModel {
                FirstName = firstName, LastName = lastName
            };
            var c = new MyClass();

            PropertySync.Sync(personModel, c);
            Assert.AreNotEqual(personModel.FirstName, c.StringProperty);
        }
예제 #5
0
        public override void OnNavigatedTo()
        {
            base.OnNavigatedTo();

            _logger.LogTrace("Opened settings");

            SettingsDir = _settings.GetSettingsDir();

            _logger.LogDebug("Syncing settings properties");
            PropertySync.Sync(_settings.Data, this);
        }
예제 #6
0
        public void SyncStringPerson(string firstName, string lastName)
        {
            var personModel = new PersonModel {
                FirstName = firstName, LastName = lastName
            };
            var personViewModel = new PersonViewModel();

            PropertySync.Sync(personModel, personViewModel);
            Assert.AreEqual(personModel.FirstName, personViewModel.FirstName);
            Assert.AreEqual(personModel.LastName, personViewModel.LastName);
        }
예제 #7
0
        public override void OnNavigatedTo()
        {
            base.OnNavigatedTo();

            Triggers = new BindableCollection <string> {
                "None", "Cron", "Timed", "BackupItem"
            };
            var ignores = new HashSet <string> {
                "BackupItem"
            };

            _logger.LogDebug("Syncing Properties with {type}: '{name}'", BackupItem.TypeName(), BackupItem.Name);
            PropertySync.Sync(BackupItem, this, ignores);

            BackupNames = new List <string>(_backupData.Data.Keys);

            Title = $"Edit '{Name}'";
        }
예제 #8
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();
        }
예제 #10
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();
        }
예제 #11
0
        public override void OnInspectorGUI()
        {
            PropertySync pb = target as PropertySync;

            ActionDelegateEditor.SetLabelWidth(80f);

            serializedObject.Update();

            if (pb.direction == PropertySync.Direction.TargetUpdatesSource && pb.target != null)
            {
                PropertyBindingReferenceDrawer.filter = pb.target.GetPropertyType();
            }

            GUILayout.Space(3f);
            PropertySync.Direction dir = (target as PropertySync).direction;

            PropertyBindingReferenceDrawer.mustRead = dir == PropertySync.Direction.SourceUpdatesTarget ||
                                                      dir == PropertySync.Direction.BiDirectional;
            PropertyBindingReferenceDrawer.mustWrite = dir == PropertySync.Direction.TargetUpdatesSource ||
                                                       dir == PropertySync.Direction.BiDirectional;

            ActionDelegateEditor.DrawProperty(serializedObject, "source");

            if (pb.direction == PropertySync.Direction.SourceUpdatesTarget && pb.source != null)
            {
                PropertyBindingReferenceDrawer.filter = pb.source.GetPropertyType();
            }

            if (pb.source.target != null)
            {
                GUILayout.Space(-18f);

                if (pb.direction == PropertySync.Direction.TargetUpdatesSource)
                {
                    GUILayout.Label("   \u25B2"); // Up
                }
                else if (pb.direction == PropertySync.Direction.SourceUpdatesTarget)
                {
                    GUILayout.Label("   \u25BC"); // Down
                }
                else
                {
                    GUILayout.Label("  \u25B2\u25BC");
                }
            }

            GUILayout.Space(1f);

            PropertyBindingReferenceDrawer.mustRead = dir == PropertySync.Direction.TargetUpdatesSource ||
                                                      dir == PropertySync.Direction.BiDirectional;
            PropertyBindingReferenceDrawer.mustWrite = dir == PropertySync.Direction.SourceUpdatesTarget ||
                                                       dir == PropertySync.Direction.BiDirectional;

            ActionDelegateEditor.DrawProperty(serializedObject, "target");

            PropertyBindingReferenceDrawer.mustRead  = false;
            PropertyBindingReferenceDrawer.mustWrite = false;
            PropertyBindingReferenceDrawer.filter    = typeof(void);

            GUILayout.Space(1f);
            ActionDelegateEditor.DrawPaddedProperty(serializedObject, "direction");
            ActionDelegateEditor.DrawPaddedProperty(serializedObject, "update");
            GUILayout.BeginHorizontal();
            ActionDelegateEditor.DrawProperty(" ", serializedObject, "editMode", GUILayout.Width(100f));
            GUILayout.Label("Update in Edit Mode");

            if (pb.source.GetPropertyType() == typeof(bool) && pb.target.GetPropertyType() == typeof(bool))
            {
                ActionDelegateEditor.DrawProperty(" ", serializedObject, "invertBool", GUILayout.Width(100f));
                GUILayout.Label("Invert Bool");
            }

            GUILayout.EndHorizontal();

            if (!serializedObject.isEditingMultipleObjects)
            {
                if (pb.source != null && pb.target != null &&
                    pb.source.GetPropertyType() != pb.target.GetPropertyType())
                {
                    if (pb.direction == PropertySync.Direction.BiDirectional)
                    {
                        EditorGUILayout.HelpBox(
                            "Bi-Directional updates require both Source and Target to reference values of the same type.",
                            MessageType.Error);
                    }
                    else if (pb.direction == PropertySync.Direction.SourceUpdatesTarget)
                    {
                        if (!PropertyBindingReference.Convert(pb.source.Get(), pb.target.GetPropertyType()))
                        {
                            EditorGUILayout.HelpBox(
                                "Unable to convert " + pb.source.GetPropertyType() + " to " +
                                pb.target.GetPropertyType(), MessageType.Error);
                        }
                    }
                    else if (!PropertyBindingReference.Convert(pb.target.Get(), pb.source.GetPropertyType()))
                    {
                        EditorGUILayout.HelpBox(
                            "Unable to convert " + pb.target.GetPropertyType() + " to " + pb.source.GetPropertyType(),
                            MessageType.Error);
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }