答案 0 :(得分:0)
这不是回答问题,而是您在评论中提出的问题
您能给我一些代码吗?“只是创建一个列表并在其中包含打开的图像,当滑块的值发生变化时,只需使用int将Raw Image的sprite设置为列表中图像的sprite即可。从列表中获取图像。”?
[RequireComponent(typeof(RawImage))]
public class ImageSwitcher : MonoBehaviour
{
private RawImage image;
public Slider SliderComponent;
// Get the textures somehow
public List<Texture>() textures = new List<Texture>();
private void Awake()
{
image = GetComponent<RawImage>();
if(!SliderComponent)
{
Debug.LogError("No SliderComponent referenced!", this);
return;
}
// Make the slider accept only whole numbers
SliderComponent.wholeNumbers = true;
SliderComponent.value = 0;
SliderComponent.minValue = 0;
// Index is 0 based so can maximal be list count -1
SliderComponent.maxValue = textures.Count - 1;
// Register a listener for onValueChanged
// Remove the listener first to avoid multiple listeners added
SliderComponent.onValueChanged.RemoveListener(OnSliderChanged);
SliderComponent.onValueChanged.AddListener(OnSliderChanged);
}
private void OnDestroy ()
{
// Allways clean up listeners when not needed anymore
SliderComponent.onValueChanged.RemoveListener(OnSliderChanged);
}
// Use this to change the Texture list
// and Max value of the slider afterwards
public void UpdateSlider(List<Texture> textures)
{
// Update the texture list
this.textures = textures;
// Update the max value of the slider
SliderComponent.maxValue = textures.Count - 1;
// Unity might automatically clamp the slider value
// after the maxValue was changed
// But just to be sure we can do it as well
SliderComponent.value = Mathf.Clamp(SliderComponent.value, 0, textures.Count - 1);
}
// Called when the slider value is changed
private void OnSliderChanged()
{
// Get the value as int
int index = (int)SliderComponent.value;
if(index < 0 || index > textures.Count - 1)
{
// Should actually be impossible but just in case log it
Debug.Log("Slider produced impossible index: " + index, this);
return;
}
// Get according texture from list
var texture = textures[index];
// Set texture
image.texture = texture;
}
}
但这不能完全解决您的问题
Unity3d(编辑器):使用EditorUtility.OpenFilePanel()打开多个文件
如this thread中所述,因为EditorUtility.OpenFilePanel
仅返回一个单个文件路径作为string
。
这么短的答案是:(当前)不可能。
有一个开放的vote,用于为多项选择添加该功能,因此您可能需要在其中投票。
我的一个想法是尝试选择一个文件夹路径,然后从该文件夹中加载所有纹理,但这只是一种解决方法,并不是您真正要求的。
但我希望其余的对您有所帮助:)