Exemple #1
0
    IEnumerator LoadPrefabModel(string path, string name, Action count_load = null)
    {
        load_error_flag = false;
        //防止卡死
        yield return(new WaitForEndOfFrame());

        DebugLog.DebugLogInfo("00FF00", "assetbundle loading ---" + path + name);

        string temp_path = PublicClass.tempPath + name + "temp.dat";
        AssetBundleCreateRequest assetBundleCreateRequest = null;

        try
        {
            Vesal_DirFiles.GetAbfile2(path, temp_path);
            assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(temp_path);

            //assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(Vesal_DirFiles.GetAbfile(path, temp_path));
        }
        catch (Exception ex)
        {
            load_error_flag = true;
            vesal_log.vesal_write_log("assetbundle load error in :" + name);
            vesal_log.vesal_write_log("error message:" + ex.Message);
        }


        if (assetBundleCreateRequest != null && load_error_flag == false)
        {
            yield return(assetBundleCreateRequest);

            GameObject         CurrentObj = null;
            GameObject         realObj    = null;
            AssetBundleRequest abr        = null;
            try
            {
                abr = assetBundleCreateRequest.assetBundle.LoadAssetAsync(name, typeof(GameObject));
            }
            catch (Exception ex)
            {
                load_error_flag = true;
                vesal_log.vesal_write_log("assetbundle load error in :" + name);
                vesal_log.vesal_write_log("error message:" + ex.Message);
            }
            yield return(abr);

            if (abr != null && abr.asset != null)
            {
                CurrentObj = (GameObject)abr.asset;
                realObj    = Instantiate(CurrentObj);
            }
            else
            {
                load_error_flag = true;
                vesal_log.vesal_write_log("assetbundle load error in :" + name);
            }
            if (CurrentObj != null && realObj != null & load_error_flag == false)
            {
                realObj.name = realObj.name.Replace("(Clone)", "");

                ReadModel(realObj);

                Transform Transform_parent = PublicClass.Transform_parent;
                realObj.transform.SetParent(Transform_parent);

                assetBundleCreateRequest.assetBundle.Unload(false);
                //Transform_parent.gameObject.SetActive(false);

                load_list[load_count].source   = CurrentObj;
                load_list[load_count].instance = realObj;
                if (File.Exists(temp_path))
                {
                    try
                    {
                        Vesal_DirFiles.DelFile(temp_path);
                    }
                    catch { }
                }
            }
        }
        if (count_load != null)
        {
            count_load();
        }
    }
Exemple #2
0
    bool load_error_flag = false; //记录模型加载过程中的异常错误
    IEnumerator LoadPrefabModel(string path, string name, Action count_load = null)
    {
        load_error_flag = false;
        //encrypt.DecryptFile(path, path.Remove(path.LastIndexOf('/')) + "/vesal.temp", "Vesal17788051918");
        //解压ab文件
        //yield return null;
        //防止卡死
        yield return(new WaitForEndOfFrame());

        string temp_path = PublicClass.tempPath + name + "temp.dat";
        //vesal_log.vesal_write_log("load model phase 1 start: " + DateTime.Now.Ticks);
        //yield return null;
        AssetBundleCreateRequest assetBundleCreateRequest = null;

        try
        {
            if (load_list[load_count].type == "TEMP")
            {
                assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(path);
            }
            else
            {
                Vesal_DirFiles.GetAbfile2(path, temp_path);
                assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(temp_path);
            }
            //assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(Vesal_DirFiles.GetAbfile(path, temp_path));
        }
        catch (Exception ex)
        {
            load_error_flag = true;
            UnityEngine.Debug.Log(ex.Message);
            UnityEngine.Debug.Log(ex.StackTrace);
            vesal_log.vesal_write_log("assetbundle load error in :" + name);
            vesal_log.vesal_write_log("error message:" + ex.Message);
            if (File.Exists(temp_path))
            {
                try
                {
                    Vesal_DirFiles.DelFile(temp_path);
                }
                catch { }
            }
        }
        //Vesal_DirFiles.DelFile(temp_path);

        if (assetBundleCreateRequest != null && load_error_flag == false)
        {
            yield return(assetBundleCreateRequest);

            //vesal_log.vesal_write_log("load model phase 3 start: " + DateTime.Now.Ticks);

            //AssetBundle curBundleObj = AssetBundle.LoadFromMemory(Vesal_DirFiles.GetAbfile(path, temp_path));
            GameObject         CurrentObj = null;
            GameObject         realObj    = null;
            AssetBundleRequest abr        = null;
            try
            {
                if (load_list[load_count].type == "TEMP")
                {
                    abr = assetBundleCreateRequest.assetBundle.LoadAssetAsync(Vesal_DirFiles.get_file_name_from_full_path(name), typeof(GameObject));
                }
                else
                {
                    abr = assetBundleCreateRequest.assetBundle.LoadAssetAsync(name, typeof(GameObject));

                    //vesal_log.vesal_write_log("load model phase 4 start: " + DateTime.Now.Ticks);
                }
            }
            catch (Exception ex)
            {
                load_error_flag = true;
                UnityEngine.Debug.Log(ex.Message);
                UnityEngine.Debug.Log(ex.StackTrace);
                vesal_log.vesal_write_log("assetbundle load error in :" + name);
                vesal_log.vesal_write_log("error message:" + ex.Message);
            }
            yield return(abr);

            if (abr != null && abr.asset != null)
            {
                CurrentObj = (GameObject)abr.asset;
                realObj    = Instantiate(CurrentObj);
            }
            else
            {
                load_error_flag = true;
                vesal_log.vesal_write_log("assetbundle load error in :" + name);
            }

            if (CurrentObj != null && realObj != null & load_error_flag == false)
            {
                yield return(realObj);

                //vesal_log.vesal_write_log("load model phase 5 start: " + DateTime.Now.Ticks);
                realObj.name = realObj.name.Replace("(Clone)", "");

                Transform Transform_parent;

                print("name :" + load_list[load_count].name + " type: " + load_list[load_count].type);
                if (load_list[load_count].type == "TEMP")
                {
                    print("---------- temp model 管理器");
                    Transform_parent = PublicClass.Transform_temp;
                }
                else
                {
                    ReadModel(realObj);
                    Transform_parent               = PublicClass.Transform_parent;
                    load_list[load_count].source   = CurrentObj;
                    load_list[load_count].instance = realObj;
                }
                realObj.transform.SetParent(Transform_parent);

                assetBundleCreateRequest.assetBundle.Unload(false);

                Transform_parent.gameObject.SetActive(false);


                if ((load_list[load_count].type != "TEMP") && (File.Exists(temp_path)))
                {
                    try
                    {
                        Vesal_DirFiles.DelFile(temp_path);
                    }
                    catch { }
                }
                //vesal_log.vesal_write_log("load model phase 5 end: " + DateTime.Now.Ticks);
            }
        }
        if (count_load != null)
        {
            count_load();
        }
    }
Exemple #3
0
    //public static bool stepLoad = false;
    IEnumerator LoadPrefabModel(string path, string name, Action count_load = null)
    {
        Debug.Log(name);
        //encrypt.DecryptFile(path, path.Remove(path.LastIndexOf('/')) + "/vesal.temp", "Vesal17788051918");
        //解压ab文件
        //yield return null;
        //防止卡死
        load_error_flag = false;
        //while (!stepLoad) {
        //    yield return null;
        //}

        yield return(new WaitForEndOfFrame());

        string temp_path = PublicClass.tempPath + name + "temp.dat";

        vesal_log.vesal_write_log(name);
        //vesal_log.vesal_write_log("load model phase 1 start: " + DateTime.Now.Ticks);
        //yield return null;
        AssetBundleCreateRequest assetBundleCreateRequest = null;

        try
        {
            Vesal_DirFiles.GetAbfile2(path, temp_path);
            //if (File.Exists(temp_path))
            //    Debug.Log(temp_path + "exsit!!!!!!!!!!!!!");

            assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(temp_path);

            //assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(Vesal_DirFiles.GetAbfile(path, temp_path));
        }
        catch (Exception ex)
        {
            load_error_flag = true;
            vesal_log.vesal_write_log("assetbundle load error in :" + name);
            vesal_log.vesal_write_log("error message:" + ex.Message);
        }
        //Vesal_DirFiles.DelFile(temp_path);

        if (assetBundleCreateRequest != null && load_error_flag == false)
        {
            yield return(assetBundleCreateRequest);

            GameObject         CurrentObj = null;
            GameObject         realObj    = null;
            AssetBundleRequest abr        = null;
            try
            {
                // abr = assetBundleCreateRequest.assetBundle.LoadAssetAsync(name, typeof(GameObject));
                CurrentObj = (GameObject)assetBundleCreateRequest.assetBundle.LoadAsset(name, typeof(GameObject));;
                realObj    = Instantiate(CurrentObj);
#if UNITY_EDITOR
                MeshFilter[] filters = null;
                filters = realObj.GetComponentsInChildren <MeshFilter>(true);
                int topCount  = 0;
                int triCount  = 0;
                int meshCount = 0;
                if (filters != null)
                {
                    for (int j = 0; j < filters.Length; j++)
                    {
                        MeshFilter f = filters[j];
                        topCount += f.sharedMesh.vertexCount;
                        triCount += f.sharedMesh.triangles.Length / 3;
                        meshCount++;
                    }
                }
                LoadResult += string.Format("{0,20}\t{1,20}\t{2,20}", name, topCount, topCount / 8881.123208f) + "\n";
                //Debug.LogError(name + "总共Mesh=" + meshCount + "   总共顶点=" + topCount + "   总共三角形=" + triCount);
                //Debug.LogError(string.Format("{0,20}\t{1,20}\t{2,20}M", name, topCount, topCount / 8881.123208f));
                // Debug.LogError(name + " 总共顶点=" + topCount +" 占用内存:" + topCount / 8881.123208f + "M");
#endif
            }
            catch (Exception ex)
            {
                load_error_flag = true;
                vesal_log.vesal_write_log("assetbundle load error in :" + name);
                vesal_log.vesal_write_log("error message:" + ex.Message);
            }

            //yield return abr;
            //if (abr != null && abr.asset != null)
            //{
            //    CurrentObj = (GameObject)abr.asset;
            //    realObj = Instantiate(CurrentObj);
            //}
            //else
            //{
            //    load_error_flag = true;
            //    vesal_log.vesal_write_log("assetbundle load error in :" + name);
            //}

            if (CurrentObj != null && realObj != null && load_error_flag == false)
            {
                yield return(realObj);

                realObj.name = realObj.name.Replace("(Clone)", "");
                realObj.transform.SetParent(PublicClass.Transform_parent);
                assetBundleCreateRequest.assetBundle.Unload(false);

                load_list[count].source   = CurrentObj;
                load_list[count].instance = realObj;
                if (File.Exists(temp_path))
                {
                    try
                    {
                        Vesal_DirFiles.DelFile(temp_path);
                    }
                    catch { }
                }
            }
        }
        if (count_load != null)
        {
            count_load();
        }
    }