Skip to content

Instantly share code, notes, and snippets.

@VapidLinus VapidLinus/customeditor.cs Secret
Created Aug 7, 2019

Embed
What would you like to do?
public override VisualElement CreateInspectorGUI()
{
root.Clear();
tree.CloneTree(root);
const string SPEED_LOSS_LABEL_FORMAT = "0.0"; // display as one decimal
const float SPEED_LOSS_ROUND_VALUE = 10; // round to one decimal
Slider speedSlider = root.Q<Slider>(name: "speed-loss-slider");
Label speedLabel = root.Q<Label>(name: "speed-loss-label");
speedLabel.text = ((BallSpecAsset) target).SpeedLossPerLevelFactor.ToString(SPEED_LOSS_LABEL_FORMAT);
speedSlider.RegisterCallback<ChangeEvent<float>>(c =>
{
float roundedValue = Mathf.Round(c.newValue * SPEED_LOSS_ROUND_VALUE) / SPEED_LOSS_ROUND_VALUE;
if (roundedValue == c.newValue)
{
speedLabel.text = c.newValue.ToString(SPEED_LOSS_LABEL_FORMAT);
}
else
{
speedSlider.value = roundedValue;
}
});
return root;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.