예제 #1
0
        /// <summary>
        /// 从Lua脚本文件中解析Lua脚本
        /// </summary>
        /// <returns>返回值</returns>
        /// <param name="filePath">Lua脚本文件路径</param>
        public LuaValue evalScriptFromFile(string filePath)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (!filePath.StartsWith("/") || filePath.StartsWith(Application.streamingAssetsPath, true, null))
            {
                if (filePath.StartsWith(Application.streamingAssetsPath, true, null))
                {
                    filePath = filePath.Substring(Application.streamingAssetsPath.Length + 1);
                }

                //初始化lua的缓存目录
                setupLuaCacheDir();

                filePath = getLuaCacheFilePath(filePath);
            }
#elif UNITY_EDITOR_WIN
            Regex regex = new Regex("^[a-zA-Z]:/.*");
            if (!regex.IsMatch(filePath))
            {
                //Window下不带盘符的路径为相对路径,需要拼接streamingAssetsPath
                filePath = string.Format("{0}/{1}", Application.streamingAssetsPath, filePath);
            }
#else
            if (!filePath.StartsWith("/"))
            {
                filePath = string.Format("{0}/{1}", Application.streamingAssetsPath, filePath);
            }
#endif
            IntPtr   resultPtr;
            int      size     = NativeUtils.evalScriptFromFile(_nativeObjectId, filePath, out resultPtr);
            LuaValue retValue = LuaObjectDecoder.DecodeObject(resultPtr, size) as LuaValue;

            return(retValue);
        }
예제 #2
0
        /// <summary>
        /// 从Lua脚本文件中解析Lua脚本
        /// </summary>
        /// <returns>返回值</returns>
        /// <param name="filePath">Lua脚本文件路径</param>
        public LuaValue evalScriptFromFile(string filePath)
        {
                        #if UNITY_ANDROID && !UNITY_EDITOR
            if (!filePath.StartsWith("/") || filePath.StartsWith(Application.streamingAssetsPath, true, null))
            {
                if (filePath.StartsWith(Application.streamingAssetsPath, true, null))
                {
                    filePath = filePath.Substring(Application.streamingAssetsPath.Length + 1);
                }

                //初始化lua的缓存目录
                setupLuaCacheDir();

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

            IntPtr   resultPtr;
            int      size     = NativeUtils.evalScriptFromFile(_nativeObjectId, filePath, out resultPtr);
            LuaValue retValue = LuaObjectDecoder.DecodeObject(resultPtr, size) as LuaValue;

//			#if UNITY_ANDROID && !UNITY_EDITOR
//
//			if (needRemoveFile && File.Exists(filePath))
//			{
//				File.Delete(filePath);
//			}
//
//			#endif

            return(retValue);
        }