1

我已经在我的面板中尝试了这个,通过计算总百分比的剩余量并将其设置为滑块的上限,但这似乎不准确,因为我的逻辑错误或者它破坏了面板。

目前,面板的脚本如下所示,滑块可以达到的最大值为 10,并带有一个显示总数的标签,所以我不复习,这是非常不切实际的。

public static int ammoxBoxesPercent = EditorPrefs.GetInt("Ammo");
    public static int medicKitsPercent = EditorPrefs.GetInt("MedicKits");
    public static int amountOfItemsPerZone =  EditorPrefs.GetInt("Amount");


    public static int totalPercentageVal;
    public static int maxTotalValue = 10;

    [MenuItem("Enviroment Controls/ Object Spawners Control Panel")]
    private static void showEditor()
    {
        EditorWindow.GetWindow<ObjectSpawnersControlPanel>(false, "OBJ Spawners CP");
    }


    void OnGUI()
    {


            ammoxBoxesPercent = EditorGUILayout.IntSlider("Ammox Box Percent", ammoxBoxesPercent, 1, 10);
            EditorPrefs.SetInt("Ammo", ammoxBoxesPercent);

            medicKitsPercent = EditorGUILayout.IntSlider("Medic Kit Percent", medicKitsPercent, 1, 10);
            EditorPrefs.SetInt("MedicKits", medicKitsPercent);


            amountOfItemsPerZone = EditorGUILayout.IntSlider("Amount of Items Spawned at Each Zone", amountOfItemsPerZone, 1, 5);
            EditorPrefs.SetInt("Amount", amountOfItemsPerZone);

            totalPercentageVal = medicKitsPercent + ammoxBoxesPercent;
            EditorGUILayout.LabelField ("Total Percentage so far : " + totalPercentageVal.ToString() + "0");
            EditorGUILayout.LabelField ("Total must not go above 100");

    }

目标是拥有它,所以当我将第一个滑块设置为 6 时,我将第二个滑块的限制设置为 4,因为百分比限制为 10(在我的情况下代表 100%)

有人知道我实现这一目标的体面方法吗?

4

1 回答 1

1

相当容易。只需计算并将其用作for10 - ammoxBoxesPercent的最大值。 您想要做的一件事是将下限设置为0,所以如果您点击 10 (因为您希望总数最多为 10)IntSlidermedicKitsPercent
medicKitsPercentammoxBoxesPercent


medicKitsPercent = EditorGUILayout.IntSlider("Medic Kit Percent", medicKitsPercent, 0, maxTotalValue - ammoxBoxesPercent);

于 2016-03-26T14:35:21.723 回答