Hello, i want to make an regular filter drop down picklist with options. But i dont have idea how to write it on C#. I kind of understand how to make it on UI.
So as you can see on my mockup - i have filters with options and filtering objects.
And just like in any filter functionality, only the Object should remain that matches the conditions / criteria. And if I delete the criteria, then other Objects should appear
I am currently not on my pc but I can write you some examples when I have access to it again. How ever what I can recommend you to do is to look at the current value of the dropdown and try to work with if/else or even add them together and then look for fitting criteria through switch/case.
As I said I can write you an exsample as soon as I have access to my computer so no exsample right now.
using UintyEngine.UI;
//For the dropdowns that make up the final option
public class DropdownScript : MonoBehavior
{
//The Dropdown its attached to
Dropdown dropdown;
//To subtract the old value and add the new one to prevent the current Value of the button going off into infinty
int oldValue;
// List here all the option buttons you want to be affected
public OptionScript[] affectedButtons;
void Start()
{
//Get the dropdown to read its current value
dropdown = GetComponent<Dropdown>();
}
void Update()
{
oldValue = dropdown.value;
dropdown.onValueChanged.AddListener(delegate {DropdownValueChanged();});
}
void DropdownValueChanged()
{
//Loop through all buttons that should get affected
for(int i = 0; i < affectedButtons.Length; i++)
{
affectedButtons.currValue -= oldValue;
affectedButtons.currValue += dropdown.value;
}
}
}
using UnityEngine.UI;
//For the buttons that contain the Option availavble
public class OptionScript : MonoBehavior
{
public int currValue;
public int[] valuesToChangeOption;
//If you want to change the OnClick() function
public Button thisButton;
void Start()
{
//thisButton = GetComponent<Button>();
}
void Update()
{
switch(currValue)
{
case valuesToChangeOption[0]:
//subscribe to the onClick event
thisButton.onClick.AddListener(CustomButton_onClick);
void CustomButton_onClick()
{
//Do stuff...
}
break;
case valuesToChangeOption[1]:
//subscribe to the onClick event
thisButton.onClick.AddListener(CustomButton_onClick);
void CustomButton_onClick()
{
//Do stuff...
}
break;
//etc...
}
}
}
This should do it I havn’t tried it out in unity but this should give each button a value on which you can put in your code to want to do when given value(currValue) is true