Unity3d(编辑器):使用 EditorUtility.OpenFilePanel() 打开多个文件

Unity3d(Editor): Opening Multiple files using EditorUtility.OpenFilePanel()

我在看this tutorial并完成了它,现在我想延长它。

我想使用 FileExplorer 统一打开多个图像,然后能够根据此图像中所见的滑块值显示图像:

感谢任何帮助。

这不是回答问题,而是回答您在评论中提出的问题

Can you give me a little code for "just create a list and have the opened images in it, when the value of the slider changes, just set the Raw Image's sprite to that of the image in the list by using an int to get the image from the list."?

[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): Opening Multiple files using EditorUtility.OpenFilePanel()

this thread it is not possible since EditorUtility.OpenFilePanel 所述 returns 只有一个文件路径如 string.

如此简短的回答是:(目前)不可能

有一个开放的 vote 用于为多个 select 离子添加该功能,因此您可能想在那里投票。

我的一个想法是尝试 select 文件夹路径并从该文件夹加载所有纹理,但这只是一种解决方法,并不是您真正要求的。

但我希望剩下的对你有所帮助:)