public override void Connect() { if (viewModelPropertyWatcher != null) { // Already connected - no need to connect again. return; } string propertyName; object viewModel; ParseViewModelEndPointReference(viewModelPropertyName, out propertyName, out viewModel); viewModelPropertyWatcher = new PropertyWatcher(viewModel, propertyName, NotifyPropertyChanged_PropertyChanged); UpdateViewModel(); }
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(); }