/// <summary>
        /// 添加Lua的搜索路径,如果在采用require方法时无法导入其他路径脚本,可能是由于脚本文件的所在路径不在lua的搜索路径中。
        /// 可通过此方法进行添加。
        /// </summary>
        /// <param name="path">路径.</param>
        public void addSearchPath(string path)
        {
            if (!path.StartsWith("/") || path.StartsWith(Application.streamingAssetsPath))
            {
                                #if UNITY_ANDROID && !UNITY_EDITOR
                AndroidJavaObject luaCacheDir = getLuaCacheDir();
                if (!luaCacheDir.Call <bool> ("exists", new object[0]))
                {
                    luaCacheDir.Call <bool> ("mkdirs", new object[0]);
                }
                string cachePath = luaCacheDir.Call <string> ("toString", new object[0]);

                if (path.StartsWith(Application.streamingAssetsPath))
                {
                    path = path.Substring(Application.streamingAssetsPath.Length + 1);
                }

                path = string.Format("{0}/{1}", cachePath, path);
                                #else
                if (!path.StartsWith("/"))
                {
                    path = string.Format("{0}/{1}", Application.streamingAssetsPath, path);
                }
                                #endif
            }


            NativeUtils.addSearchPath(_nativeObjectId, path + "/?.lua");
        }
示例#2
0
 /// <summary>
 /// 添加Lua的搜索路径,如果在采用require方法时无法导入其他路径脚本,可能是由于脚本文件的所在路径不在lua的搜索路径中。
 /// 可通过此方法进行添加。
 /// </summary>
 /// <param name="path">路径.</param>
 public void addSearchPath(string path)
 {
     NativeUtils.addSearchPath(_nativeObjectId, path + "/?.lua");
 }