-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to configure dependencies between options? For example, whether option B is displayed depends on option A. #3
Comments
Right now, you would have to reference the dependency in every dependee and subscribe to their respective change event during Setting initialization. Then you would need to have your event handler react to any changes by updating the dependee's I am aware that this is not an ideal workflow, and I am currently in the process of conceptualizing a way that remedies things like this (and also related stuff like Setting value validation). Example for what I mentioned above. public abstract class DependantSetting<T, U> : SettingBase<T>
{
[SerializeField] private SettingBase<U> dependency;
[SerializeField] private U compareValue;
[SerializeField] private SettingVisibility matchingVisibility = SettingVisibility.Visible;
[SerializeField] private SettingVisibility nonMatchingVisibility = SettingVisibility.Disabled;
protected override void OnInitialize()
{
if(dependency != null)
{
dependency.ValueChanged += DependencyValueChangedHandler;
SetVisibilityWithoutNotify(GetGoalVisibility()); // Make sure the Setting starts out correctly
}
}
private void DependencyValueChangedHandler(ValueChangeMode mode)
{
var visibility = GetGoalVisibility();
SetVisibility(visibility);
}
private SettingVisibility GetGoalVisibility()
{
if(dependency == null)
return Visibility; // If there is no dependency configured, stick with current visibility
var dependencyFulfilled = dependency.CompareEquality(dependency.CurrentValue, compareValue);
return dependencyFulfilled ? matchingVisibility : nonMatchingVisibility;
}
} Some of the For an example implementation, see the ToggleControl. |
Alternatively, you could reverse the process I described earlier and have the dependency maintain a list of dependees and their required values, and proactively update them when its value updates. |
Thanks for the replies! |
You're welcome! |
Update: See commit e805487 and the Note: |
No description provided.
The text was updated successfully, but these errors were encountered: