Example #1
0
        /// <summary>
        /// Call script of script path (relative) specify
        ///
        /// We don't recommend use this method, please use ImportScript which has Caching!
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public object CallScript(string path)
        {
            var scriptPath = GetScriptPath(path);

            byte[]         script;
            HotBytesLoader loader = null;

            try
            {
                loader = HotBytesLoader.Load(scriptPath, LoaderMode.Sync);
                Debuger.Assert(!loader.IsError, "Something wrong or Not exist Lua: " + scriptPath);
                script = loader.Bytes;
            }
            finally
            {
                if (loader != null)
                {
                    loader.Release();
                }
            }
//            if (Log.IsUnityEditor)
//                script = File.ReadAllBytes(scriptPath);
//            else
//                script = KResourceModule.LoadSyncFromStreamingAssets(scriptPath);
            var ret = ExecuteScript(script);

            return(ret);
        }
        /// <summary>
        /// Default load setting strategry,  editor load file, runtime resources.load
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static byte[] DefaultLoadSetting(string path)
        {
            byte[] fileContent;
            var    loader = HotBytesLoader.Load(SettingFolderName + "/" + path, LoaderMode.Sync);

            Debuger.Assert(!loader.IsError);
            fileContent = loader.Bytes;

            loader.Release();
            return(fileContent);
        }
Example #3
0
        /// <summary>
        /// Default load setting strategry,  editor load file, runtime resources.load
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static byte[] DefaultLoadSetting(string path)
        {
            //NOTE 在Editor下Reload 配置表失败
#if UNITY_EDITOR
            return(LoadSettingFromFile(path));
#else
            byte[] fileContent;
            var    loader = HotBytesLoader.Load(SettingFolderName + "/" + path, LoaderMode.Sync);
            Debuger.Assert(!loader.IsError);
            fileContent = loader.Bytes;

            loader.Release();
            return(fileContent);
#endif
        }
        private static IEnumerator CoLoadAssetBundleAsync(string relativePath, ResourceDepRequest request)
        {
            // manifest
            string manifestPath = ResourceDepUtils.GetBuildPath(String.Format("{0}.manifest{1}", relativePath,
                                                                              AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));
            var manifestLoader = HotBytesLoader.Load(manifestPath, LoaderMode.Sync);

            while (!manifestLoader.IsCompleted)
            {
                yield return(null);
            }

            // manifest读取失败,可能根本没有manifest,是允许的
            if (manifestLoader.IsSuccess)
            {
                var manifestBytes = manifestLoader.Bytes;
                manifestLoader.Release(); // 释放掉文本字节
                string[] manifestList = GetManifestList(manifestBytes);
                for (var i = 0; i < manifestList.Length; i++)
                {
                    var depPath   = manifestList[i] + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt);
                    var depLoader = KAssetFileLoader.Load(depPath);
                    if (request.Loaders == null)
                    {
                        request.Loaders = new List <KAbstractResourceLoader>();
                    }
                    request.Loaders.Add(depLoader);
                    while (!depLoader.IsCompleted)
                    {
                        yield return(null);
                    }
                }
            }
            string path =
                GetBuildPath(String.Format("{0}{1}", relativePath,
                                           AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));

            // 获取后缀名
            var ext = Path.GetExtension(relativePath);

            if (ext == ".unity" || ext == ".shader")
            {
                // Scene
                var sceneLoader = KAssetBundleLoader.Load(path);

                if (request.Loaders == null)
                {
                    request.Loaders = new List <KAbstractResourceLoader>();
                }
                request.Loaders.Add(sceneLoader);
                while (!sceneLoader.IsCompleted)
                {
                    yield return(null);
                }
            }
            else
            {
                var assetLoader = KAssetFileLoader.Load(path);
                while (!assetLoader.IsCompleted)
                {
                    yield return(null);
                }
                request.Asset = assetLoader.Asset;
            }

            request.IsDone = true;
        }
        /// <summary>
        /// 同步加载AssetBundle
        /// </summary>
        /// <param name="relativePath"></param>
        /// <returns></returns>
        public static Object LoadAssetBundleSync(string relativePath)
        {
            //CheckLoadShadersPrefab();
            // manifest
            string manifestPath = ResourceDepUtils.GetBuildPath(String.Format("{0}.manifest{1}", relativePath,
                                                                              AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));
            var manifestLoader = HotBytesLoader.Load(manifestPath, LoaderMode.Sync);
            //while (!manifestLoader.IsCompleted)
            //    yield return null;
            var manifestBytes = manifestLoader.Bytes;

            manifestLoader.Release(); // 释放掉文本字节
            if (manifestBytes != null)
            {
                var manifestList = GetManifestList(manifestBytes);
                for (var i = 0; i < manifestList.Length; i++)
                {
                    var depPath = manifestList[i] + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt);
                    //var depLoader =
                    KAssetFileLoader.Load(depPath);
                    //while (!depLoader.IsCompleted)
                    //{
                    //    yield return null;
                    //}

                    /*if (Application.isEditor)
                     * {
                     *  Log.Info("Load dep sync:{0}, from: {1}", depPath, relativePath);
                     * }*/
                }
            }
            else
            {
                Log.Warning("Cannot find Manifest: {0}", relativePath);
            }

            string path =
                GetBuildPath(String.Format("{0}{1}", relativePath,
                                           AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt)));

            //while (!assetLoader.IsCompleted)
            //    yield return null;
            // 获取后缀名
            var ext = Path.GetExtension(relativePath);

            if (ext == ".unity" || ext == ".shader")
            {
                // Scene
                //var sceneLoader =
                KAssetBundleLoader.Load(path);
                //while (!sceneLoader.IsCompleted)
                //    yield return null;
                return(null);
            }
            else
            {
                var assetLoader = KAssetFileLoader.Load(path);
                //while (!assetLoader.IsCompleted)
                //    yield return null;
                return(assetLoader.Asset);
            }
        }