i'm currently working on a Unity project in which i need to update 8 Slider values from a JSON file. I tested the loading part and everything works but when i apply the values to the sliders, they dont behave like i thought they would.
I have a OnButton function that: 1. Triggers JSON Loading -> 2. Passes the loaded JSON values to static variables -> 3. Calls a function to update the sliders.
Now here is the problem: On Button press, only one slider at a time gets updated, top to bottom and I do not understand why. So in order for every time you load a json file, you have to press the LOAD button up to 8 times, before every slider is updated. I use the same LoadSliders function for when the UI loads and it works there.
Thanks for your help!
using UnityEngine;
using UnityEngine.UI;
.
.
.
public void UpdateSettings(BoidPresetSaveData loadedSave)
{
maxSpeed = loadedSave.maxSpeed;
maxForce = loadedSave.maxForce;
arriveRadius = loadedSave.arriveRadius;
desiredSeparation = loadedSave.desiredSeparation;
neighbourDistance = loadedSave.neighbourDistance;
//Weights
separation = loadedSave.separation;
alignment = loadedSave.alignment;
cohesion = loadedSave.cohesion;
wander = loadedSave.wander;
avoidWalls = loadedSave.avoidWalls;
}
public void LoadSliders()
{
maxSpeedSlider.value = maxSpeed;
maxForceSlider.value = maxForce;
arriveRadiusSlider.value = arriveRadius;
desiredSeperationSlider.value = desiredSeparation;
neighbourDistanceSlider.value = neighbourDistance;
separationSlider.value = separation;
alignmentSlider.value = alignment;
cohesionSlider.value = cohesion;
wanderSlider.value = wander;
avoidWallsSlider.value = avoidWalls;
}
And the OnButton function isnt very fancy either:
public void LoadPreset()
{
var loadKey = presetDropdown.captionText.text;
if (!SaveManager.SaveExists(loadKey,folderKey))
{
Debug.Log("Preset file does not exist.");
return;
}
BoidPresetSaveData loadedSave = SaveManager.Load<BoidPresetSaveData>(loadKey, folderKey);
BoidSettings.instance.UpdateSettings(loadedSave);
BoidSettings.instance.LoadSliders();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…