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(); }
private void SyncFromSource(PropertyEndPoint viewModelEndPoint) { SetAllChildrenActive((bool)viewModelEndPoint.GetValue()); }