c# - Unity3d(Editor):使用 EditorUtility.OpenFilePanel() 打开多个文件
解决方案
这并没有回答问题,而是您在评论中提出的问题
你能给我一些代码吗“只需创建一个列表并在其中包含打开的图像,当滑块的值发生变化时,只需使用 int 将原始图像的精灵设置为列表中图像的精灵来获取列表中的图像。”?
[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 ()
{
// Always 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 = Mathf.RoundToInt(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(Editor):使用 EditorUtility.OpenFilePanel() 打开多个文件
如该线程中所述,这是不可能的,因为EditorUtility.OpenFilePanel
仅返回一个文件路径为string
.
所以简短的回答是:(目前)不可能。
有一个为多项选择添加该功能的公开投票,因此您可能想在那里投票。
我的一个想法是尝试选择一个文件夹路径并从该文件夹加载所有纹理,但这只是一种解决方法,并不是您真正要求的。
但我希望其余的对你有所帮助:)
推荐阅读
- javascript - 将 imagesloaded.js 与从文件夹导入图像的 php 代码一起使用
- runtime-error - Anylogic - 绘制动画帧时出错
- redux-form - FieldArray 的每个元素中有 2 个字段,但 fields.get(index) 无法获取第二个字段
- c - 有没有办法在运行时命令不要在 C(Linux)中调用特定函数(将其注释掉)?
- swift - SwiftUI:在 NavigationLink 或 Sheet 中显示时,使用 Apple 按钮登录会使应用程序崩溃
- scala - 单元测试 IO Scala
- python-3.x - 在 Pandas 中读取嵌套的 json
- java - H2 Embedded db需要通过java更改数据库文件h2db.mv.db的权限
- ios - 如何从 iPhone 上的 collectionView 拖放?
- html - 在列表项处于活动状态时更改其字体大小