Path.GetFileNameWithoutExtension 在 Unity 5 中抛出错误

Path.GetFileNameWithoutExtension throwing error in Unity 5

我特别从 IntegrationTest class 得到了这个错误,它可以通过 Unity Asset Store 免费下载。

引发错误的具体行在这里:

var fileName = Path.GetFileNameWithoutExtension(sceneName);

但您可以在此处查看上下文。

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class DynamicTestAttribute : Attribute
{
    private readonly string m_SceneName;

    public DynamicTestAttribute(string sceneName)
    {
        if (sceneName.EndsWith(".unity"))
            sceneName = sceneName.Substring(0, sceneName.Length - ".unity".Length);
        m_SceneName = sceneName;
    }

    public bool IncludeOnScene(string sceneName)
    {
        var fileName = Path.GetFileNameWithoutExtension(sceneName);
        return fileName == m_SceneName;
    }
}

Unity 编译器说:

Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/IntegrationTest.cs(154,33): error CS0117: `Path' does not contain a definition for `GetFileNameWithoutExtension'

根据 Unity 文档,这是正确的用法。也许我错过了 Unity 5 的新文档 link。

好的,所以问题是我刚刚从 Asset Store 导入了 iTween Examples,其中有一个名为 Path 的 class,所以两个 class 定义 - Unity 的默认定义和iTweens 示例中的定义存在冲突,编译器认为 iTween 是 'the' 并且不包含上面引用的方法。

也许我应该给 Pixel Placement 的家伙发一封关于它的便条。

请注意,您可以使用源文件顶部的 "using Path = System.IO.Path;" 行解决错误。 (我意识到在这种情况下这不是你的代码,但如果你想在本地修复它,或者其他人有问题。)

感谢@yoyo 提供答案!