构建时Unity Gear VR错误

时间:2017-02-23 12:04:21

标签: android unity3d virtual-reality gear-vr

我正在尝试设置和构建https://resources.samsungdevelopers.com/Gear_VR/030_Create_VR_App_or_Game_Using_a_Game_Engine/Exercise_2%3A_Create_a_Splash_Screen/Step_7%3A_Build_and_Run_the_Application

当我尝试构建应用程序时,它会抛出以下错误: Assets / Workshop / Scripts / TextureLoader.cs(114,31):错误CS1105:`TextureLoader.GetFilesWithExtensions(此DirectoryInfo,params string [])':扩展方法必须声明为static

// Gets the list of files in the directory by extention and filters for our specified ones (images)
public IEnumerable<FileInfo> GetFilesWithExtensions (this DirectoryInfo dir, params string[] extensions) {
    IEnumerable<FileInfo> files = dir.GetFiles();
    return files.Where(f => extensions.Contains(f.Extension));
}

public bool isFinishedLoadingFirstTexture() {
    return mFinishedFirstTexture;
}

我已将其更改为标题中的公共静态类。

2 个答案:

答案 0 :(得分:0)

我为了制作扩展方法,该类必须是publicstatic

该功能也必须是publicstatic。你错过了这部分。

public static class TextureLoader
{
    public static IEnumerable<FileInfo> GetFilesWithExtensions(this DirectoryInfo dir, params string[] extensions)
    {
        IEnumerable<FileInfo> files = dir.GetFiles();
        return files.Where(f => extensions.Contains(f.Extension));
    }
}

答案 1 :(得分:0)

以这种方式修改代码,错误将消失

private IEnumerable<FileInfo> GetFilesWithExtensions(DirectoryInfo dir, string[] extensions)
{
    IEnumerable<FileInfo> files = dir.GetFiles();
    return files.Where(f => extensions.Contains(f.Extension));
}