error CS1525: Unexpected symbol `end-of-file'

今天写脚本莫名其妙报了一些错,折腾了很久终于搞清楚了

    public static GameObject LoadUI(string assetPath)
    {
        GameObject go = null;

        if (Application.isEditor && !ResConst.IsSimulateMode)
        {
#if UNITY_EDITOR
            assetPath = ResConst.AssetBundleSourcePath + assetPath + ".prefab";
            Debug.Log("LoadUI " + assetPath);
            go = AssetDatabase.LoadAssetAtPath(assetPath);
            if (go == null)
            {
                Debug.LogError("AssetDatabase.LoadAssetAtPath There is no asset at path " + assetPath);
                return null;
            }
        }
        else
        {
            go = NewAssetBundleLoad.LoadGameObject(assetPath) as GameObject;
        }
#endif
        return go;
    }

编辑器里编译没有报错,但是build资源包的时候报错,但是实际提示的位置完全不对
开始的想法是提示的位置有问题,一直在那里找
最后全部删了代码,才发现是这里的问题
当打资源包的时候,会去掉

#if UNITY_EDITOR 
...
#endif

之间的内容,于是去掉后的代码变成了

    public static GameObject LoadUI(string assetPath)
    {
        GameObject go = null;

        if (Application.isEditor && !ResConst.IsSimulateMode)
        {

        return go;
    }

很明显少了个"}"
以后写这种代码的时候要注意了

你可能感兴趣的:(error CS1525: Unexpected symbol `end-of-file')