Esempio n. 1
0
    void Awake()
    {
#if !UNITY_EDITOR || ASSETBUNDLE_ENABLE
        dictAssetBundleRefs = new Dictionary <string, AssetBundleData>();
        dicAbName           = new Dictionary <string, string>();
        m_DependencyTable   = new Dictionary <string, List <string> >();
        m_dicSpriteAtlas    = new Dictionary <string, Dictionary <string, Sprite> >();
        AssetBundle mainBundle = null;
        // 获得更新包路径
        string strPersistentDataPath = string.Empty;
        if (Application.isMobilePlatform)
        {
            strPersistentDataPath = Application.persistentDataPath;
        }
        // 获得原始数据路径
        string strRawPath = string.Empty;
        switch (Application.platform)
        {
        case RuntimePlatform.Android:
            strRawPath = "jar:file://" + Application.dataPath + "!/assets";
            break;

        case RuntimePlatform.IPhonePlayer:
            strRawPath = Application.dataPath + "/Raw";
            break;

        default:
            strRawPath = Application.streamingAssetsPath;
            break;
        }
        if (strPersistentDataPath != string.Empty && File.Exists(Application.persistentDataPath + "/StreamingAssets"))
        {
            mainBundle = AssetBundle.LoadFromFile(strPersistentDataPath + "/StreamingAssets");
        }
        else
        {
            // 没有新版的bundle主文件,则加载安装包里的bundle主文件
            mainBundle = AssetBundle.LoadFromFile(strRawPath + "/StreamingAssets");
        }
        // 构建资源依赖关系
        AssetBundleManifest manifest     = mainBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
        string[]            arrStrBundle = manifest.GetAllAssetBundles();
        foreach (string strBundleName in arrStrBundle)
        {
            AssetBundleRef  abRef           = new AssetBundleRef(strBundleName);
            AssetBundleData assetBundleData = new AssetBundleData();
            assetBundleData.listUseBundleName = new List <string>();
            assetBundleData.assetBundleRef    = abRef;
            if (strPersistentDataPath != string.Empty && File.Exists(Application.persistentDataPath + "/" + strBundleName))
            {
                assetBundleData.strAssetPath = strPersistentDataPath + "/" + strBundleName;
            }
            else
            {
                // 没有新版的bundle主文件,则加载安装包里的bundle主文件
                assetBundleData.strAssetPath = strRawPath + "/" + strBundleName;
            }
            abRef.assetBundle = AssetBundle.LoadFromFile(assetBundleData.strAssetPath);

            string[] arrStrName          = abRef.assetBundle.GetAllAssetNames();
            string[] arrDependenciesName = manifest.GetAllDependencies(abRef.assetBundle.name);
            assetBundleData.arrDependenciesName = new string[arrDependenciesName.Length];
            for (int i = 0; i < arrDependenciesName.Length; i++)
            {
                assetBundleData.arrDependenciesName[i] = arrDependenciesName[i];
            }

            foreach (string strAssetName in arrStrName)
            {
                if (!dicAbName.ContainsKey(abRef.assetBundle.name))
                {
                    dicAbName.Add(abRef.assetBundle.name, strAssetName);
                }
                dictAssetBundleRefs.Add(strAssetName, assetBundleData);
            }
            abRef.assetBundle.Unload(false);
        }
        mainBundle.Unload(false);
#endif
    }
Esempio n. 2
0
 public XAssetBundle(AssetBundleData data)
 {
     Init(data);
 }
Esempio n. 3
0
    public static Sprite GetAssetSprite(string strAssetUrl, string strAssetAtlas = "")
    {
        string keyName = "assets/" + strAssetUrl.ToLower();

        if (strAssetAtlas != "")
        {
            keyName = "assets/" + strAssetAtlas.ToLower();
        }

#if UNITY_EDITOR && !ASSETBUNDLE_ENABLE
        if (strAssetAtlas != "")
        {
            Dictionary <string, Sprite> dicSprite = null;
            m_dicSpriteAtlas.TryGetValue(keyName, out dicSprite);
            if (dicSprite == null)
            {
                dicSprite = new Dictionary <string, Sprite>();
                UnityEngine.Object[] arrObj = AssetDatabase.LoadAllAssetsAtPath(keyName);
                for (int i = 0; i < arrObj.Length; i++)
                {
                    if (arrObj[i].GetType() == typeof(UnityEngine.Sprite))
                    {
                        dicSprite[arrObj[i].name] = arrObj[i] as Sprite;
                    }
                }
                m_dicSpriteAtlas[keyName] = dicSprite;
            }
            Sprite sprite = null;
            dicSprite.TryGetValue(strAssetUrl, out sprite);
            return(sprite);
        }

        return(AssetDatabase.LoadAssetAtPath <Sprite>(keyName));
#else
        AssetBundleData assetBundleData = GetAssetBundleDataByPath(keyName);
        if (assetBundleData == null)
        {
            return(null);
        }
        if (assetBundleData.assetBundle == null)
        {
            assetBundleData.assetBundle = AssetBundle.LoadFromFile(assetBundleData.strAssetPath);
        }
        if (strAssetAtlas != "")
        {
            Dictionary <string, Sprite> dicSprite = null;
            m_dicSpriteAtlas.TryGetValue(keyName, out dicSprite);
            if (dicSprite == null)
            {
                dicSprite = new Dictionary <string, Sprite>();
                Sprite[] arrSprites = assetBundleData.assetBundle.LoadAllAssets <Sprite>();
                for (int i = 0; i < arrSprites.Length; i++)
                {
                    dicSprite[arrSprites[i].name] = arrSprites[i];
                }
                m_dicSpriteAtlas[keyName] = dicSprite;
            }
            Sprite sprite = null;
            dicSprite.TryGetValue(strAssetUrl, out sprite);
            return(sprite);
        }
        return(assetBundleData.assetBundle.LoadAsset <Sprite>(keyName));
#endif
    }
Esempio n. 4
0
            private bool GetBuildLightmapParams(AssetBundleData assetBundleData, string filePath, List<Object> assetObjectList, List<string> assetObjectNameList, List<string> savePathList, string lightmapScene)
            {
                if (string.IsNullOrEmpty(lightmapScene))
                {
                    return true;
                }

                string currentScene = EditorApplication.currentScene;
                if (!AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(URL.assets + "/" + lightmapScene)))
                {
                    Debug.LogError("Cannot open the scene:" + filePath);
                    return false;
                }

                if (LightmapSettings.lightmaps == null || LightmapSettings.lightmaps.Length == 0)
                {
                    Debug.LogWarning("There is no lightmap data in the scene:" + filePath);
                    return true;
                }

                LightMapAsset lightmapAsset = ScriptableObject.CreateInstance<LightMapAsset>();
                int count = LightmapSettings.lightmaps.Length;
                lightmapAsset.lightmapFar = new Texture2D[count];
                lightmapAsset.lightmapNear = new Texture2D[count];
                for (int i = 0; i < count; ++i)
                {
                    lightmapAsset.lightmapFar[i] = LightmapSettings.lightmaps[i].lightmapFar;
                    lightmapAsset.lightmapNear[i] = LightmapSettings.lightmaps[i].lightmapNear;
                }
                string assetPath = URL.assets + "/" + filePath + ".lightmap.asset";
                assetBundleData.garbageAssetList.Add(assetPath);
                AssetDatabase.CreateAsset(lightmapAsset, assetPath);
                assetObjectList.Add(AssetDatabase.LoadAssetAtPath(assetPath, typeof(LightMapAsset)));
                assetObjectNameList.Add(filePath + ".lightmap");
                savePathList.Add(filePath + ".lightmap.unity3d");

                if (string.IsNullOrEmpty(currentScene))
                {
                    EditorApplication.NewScene();
                }
                else
                {
                    AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(currentScene));
                }

                return true;
            }
Esempio n. 5
0
 public static AssetBundleLoadAssetOperation LoadAllAssetAsync(
     AssetBundleData data,
     System.Type type)
 {
     return(AssetBundleManager.LoadAllAssetAsync(data.bundle, type, (string)null));
 }
Esempio n. 6
0
            private bool GetBuildDirectoryParams(AssetBundleData assetBundleData, string dirPath, List<Object> assetObjectList, List<string> assetObjectNameList, List<string> savePathList)
            {
                if (assetBundleData.IsIgnoreExtension(dirPath))
                {
                    return true;
                }

                // files
                string[] fileFullPathList = Directory.GetFiles(URL.dataPath + "/" + dirPath);
                if (fileFullPathList != null && fileFullPathList.Length != 0)
                {
                    foreach (string fileFullPath in fileFullPathList)
                    {
                        string filePath = fileFullPath.Replace('\\', '/').Substring(URL.dataPath.Length + 1);
                        if (!GetBuildFileParams(assetBundleData, filePath, assetObjectList, assetObjectNameList, savePathList, null))
                        {
                            return false;
                        }
                    }
                }

                // sub directory
                if (recursive)
                {
                    string[] subDirFullPathList = Directory.GetDirectories(URL.dataPath + "/" + dirPath);
                    if (subDirFullPathList != null && subDirFullPathList.Length != 0)
                    {
                        foreach (string subDirFullPath in subDirFullPathList)
                        {
                            string subDirPath = subDirFullPath.Replace('\\', '/').Substring(URL.dataPath.Length + 1);
                            if (!GetBuildDirectoryParams(assetBundleData, subDirPath, assetObjectList, assetObjectNameList, savePathList))
                            {
                                return false;
                            }
                        }
                    }
                }

                return true;
            }
Esempio n. 7
0
            private bool GetBuildSceneParams(AssetBundleData assetBundleData, string filePath, List<Object> assetObjectList, List<string> assetObjectNameList, List<string> savePathList)
            {
                if (assetBundleData.IsIgnoreExtension(filePath))
                {
                    return true;
                }

                assetObjectList.Add(null);
                assetObjectNameList.Add(filePath);
                savePathList.Add(filePath + ".unity3d");
                return true;
            }
Esempio n. 8
0
    /*
     *
     * static void Main (string[] args)
     * {
     *      // Excelのブックを作成
     *      var book = new HSSFWorkbook ();
     *
     *      // シートを作成
     *      var sheet = book.CreateSheet ("何とかレポート");
     *
     *      // ヘッダーにあたる行を作成
     *      CreateHeaderRow (book, sheet);
     *
     *
     *      //`AssetBudleDataChecker.CreateHeaderRow(NPOI.HSSF.UserModel.HSSFWorkbook, NPOI.HSSF.UserModel.HSSFSheet)' has some invalid arguments
     *
     *
     *      // とりあえず10行くらいデータ作成
     *      foreach (var index in Enumerable.Range(1, 10)) {
     *              CreateRow (book, sheet, index);
     *      }
     *
     *      // 2列目と3列目は、そのままだと幅が足りないので広げる(256で1文字ぶんの幅らしい)
     *      sheet.SetColumnWidth (1, 256 * 12);
     *      sheet.SetColumnWidth (2, 256 * 15);
     *
     *      // output.xlsに保存
     *      using (var fs = new FileStream ("otuput.xls", FileMode.OpenOrCreate, FileAccess.Write)) {
     *              book.Write (fs);
     *      }
     * }
     *
     *
     * // ヘッダー行を作成する
     * private static void CreateHeaderRow (HSSFWorkbook book, HSSFSheet sheet)
     * {
     *      var row = sheet.CreateRow (0);
     *
     *      // 0列目はIDの列
     *      var idCell = row.CreateCell (0);
     *      idCell.SetCellValue ("ID");
     *
     *      // 1列目は名前の列
     *      var nameCell = row.CreateCell (1);
     *      nameCell.SetCellValue ("名前");
     *
     *      // 3列目は誕生日の列
     *      var birthdayCell = row.CreateCell (2);
     *      birthdayCell.SetCellValue ("誕生日");
     *
     *      // 4方に罫線
     *      var style = book.CreateCellStyle ();
     *      style.BorderTop = HSSFBorderFormatting.BORDER_THIN;
     *      style.BorderLeft = HSSFBorderFormatting.BORDER_THIN;
     *      style.BorderBottom = HSSFBorderFormatting.BORDER_THIN;
     *      style.BorderRight = HSSFBorderFormatting.BORDER_THIN;
     *
     *      // 薄いグリーンの背景色で塗りつぶす
     *      style.FillForegroundColor = HSSFColor.LIGHT_GREEN.index;
     *      style.FillPattern = HSSFCellStyle.SOLID_FOREGROUND;
     *      // テキストはセンタリング
     *      style.Alignment = HSSFCellStyle.ALIGN_CENTER;
     *
     *      // 太字
     *      var font = book.CreateFont ();
     *      font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
     *      style.SetFont (font);
     *
     *      // 全てのヘッダー用のセルに、上で作ったスタイルを適用する
     *      foreach (var cell in new[] { idCell, nameCell, birthdayCell }) {
     *              cell.CellStyle = style;
     *      }
     *
     * }
     *
     * private static System.Random r = new System.Random ();
     *
     * // index行目のデータを作る
     * private static void CreateRow (HSSFWorkbook book, HSSFSheet sheet, int index)
     * {
     *      // 行を作って
     *      var row = sheet.CreateRow (index);
     *
     *      // id列を作る
     *      var idCell = row.CreateCell (0);
     *      idCell.SetCellValue (index);
     *
     *      // 名前も適当に入れて
     *      var nameCell = row.CreateCell (1);
     *      nameCell.SetCellValue ("田中 太郎" + index);
     *
     *      // 誕生日も適当に
     *      var birthdayCell = row.CreateCell (2);
     *      birthdayCell.SetCellValue (DateTime.Now.AddYears (r.Next (10)));
     *
     *      // 全ての列に4方に罫線のあるスタイルを作って適用する
     *      // あえて別々のスタイルを設定してるのは、誕生日セルにフォーマットを入れるため
     *      foreach (var cell in new[] { idCell, nameCell, birthdayCell }) {
     *              var style = book.CreateCellStyle ();
     *              style.BorderTop = HSSFBorderFormatting.BORDER_THIN;
     *              style.BorderRight = HSSFBorderFormatting.BORDER_THIN;
     *              style.BorderLeft = HSSFBorderFormatting.BORDER_THIN;
     *              style.BorderBottom = HSSFBorderFormatting.BORDER_THIN;
     *
     *              cell.CellStyle = style;
     *      }
     *      // 日付用yyyy年mm月dd日のフォーマットで誕生日は表示するようにする
     *      var format = book.CreateDataFormat ();
     *      birthdayCell.CellStyle.DataFormat = format.GetFormat ("yyyy年mm月dd日");
     * }
     *
     *
     */


    //##################################################
    // Loading
    //##################################################

    //private static readonly string filePath = "Assets/00_AssetBundleData/Resources/Admini/AssetBundleData.xls";
    //private static readonly string exportPath = "Assets/00_AssetBundleData/Resources/Admini/AssetBundleData.asset";


    static AssetBundleData LoadCheckData()
    {
        //	if (!filePath.Equals (asset))
        //		continue;

        AssetBundleData data = (AssetBundleData)AssetDatabase.LoadAssetAtPath(SystemSetting.GetAdminAssetPath(), typeof(AssetBundleData));

        Debug.LogWarning("###### SystemSetting.GetAdminAssetPath() :" + SystemSetting.GetAdminAssetPath());

        return(data);


        //AssetBundleData data = (AssetBundleData)AssetDatabase.LoadAssetAtPath (SystemSetting.GetAdminAssetPath(), typeof(AssetBundleData));

        if (data == null)
        {
            data = ScriptableObject.CreateInstance <AssetBundleData> ();
            AssetDatabase.CreateAsset((ScriptableObject)data, SystemSetting.GetAdminAssetPath());
            data.hideFlags = HideFlags.NotEditable;
        }

        data.list.Clear();

        using (FileStream stream = File.Open(SystemSetting.GetAdminExcelPath(), FileMode.Open, FileAccess.Read)) {
            IWorkbook book = new HSSFWorkbook(stream);

            ISheet sheet = book.GetSheet("AssetList");

            ////Debug.Log (sheet.SheetName);

            for (int i = 1; i < sheet.LastRowNum; i++)
            {
                IRow row = sheet.GetRow(i);

                AssetBundleData.Param p = new AssetBundleData.Param();



                p.assetbundleName = row.GetCell(0).StringCellValue;
                p.version         = (int)row.GetCell(1).NumericCellValue;
                p.type            = (int)row.GetCell(2).NumericCellValue;


                int tmpUpdate = (int)row.GetCell(3).NumericCellValue;

                if (tmpUpdate == 1)
                {
                    p.update = true;
                }
                else
                {
                    p.update = false;
                }

                p.folderName = row.GetCell(5).StringCellValue;
                data.list.Add(p);


                //data.waveParamlist.Add (p);
            }


            return(data);
        }



//		ScriptableObject obj = AssetDatabase.LoadAssetAtPath (exportPath, typeof(ScriptableObject)) as ScriptableObject;
//		EditorUtility.SetDirty (obj);//
        //	}
    }
Esempio n. 9
0
    static void MakeData()
    {
        AssetBundleData data = LoadCheckData();

        //const Int32 MAX_COL = 9;
        int maxRow = data.list.Count;
        //Int32 iCol = 0;
        Int32 iRow = 0;
        IRow  row;
        ICell cell;

        // ワークブックオブジェクト生成
        HSSFWorkbook workbook = new HSSFWorkbook();

        // シートオブジェクト生成
        ISheet sheet1 = workbook.CreateSheet("DataChecker");

        makeCellLow = 0;

        // セルスタイル(黒線)
        ICellStyle blackBorder = workbook.CreateCellStyle();

        blackBorder.BorderBottom      = BorderStyle.THIN;
        blackBorder.BorderLeft        = BorderStyle.THIN;
        blackBorder.BorderRight       = BorderStyle.THIN;
        blackBorder.BorderTop         = BorderStyle.THIN;
        blackBorder.BottomBorderColor = HSSFColor.BLACK.index;
        blackBorder.LeftBorderColor   = HSSFColor.BLACK.index;
        blackBorder.RightBorderColor  = HSSFColor.BLACK.index;
        blackBorder.TopBorderColor    = HSSFColor.BLACK.index;


        // セルスタイル(黒線)
        HSSFCellStyle hStyle = (HSSFCellStyle)workbook.CreateCellStyle();

        hStyle.FillForegroundColor = IndexedColors.AQUA.Index;
        hStyle.FillPattern         = FillPatternType.SOLID_FOREGROUND;

        hStyle.BorderBottom      = BorderStyle.THIN;
        hStyle.BorderLeft        = BorderStyle.THIN;
        hStyle.BorderRight       = BorderStyle.THIN;
        hStyle.BorderTop         = BorderStyle.THIN;
        hStyle.BottomBorderColor = HSSFColor.BLACK.index;
        hStyle.LeftBorderColor   = HSSFColor.BLACK.index;
        hStyle.RightBorderColor  = HSSFColor.BLACK.index;
        hStyle.TopBorderColor    = HSSFColor.BLACK.index;


        // セルスタイル(黒線)
        HSSFCellStyle hStyleRed = (HSSFCellStyle)workbook.CreateCellStyle();

        hStyleRed.FillForegroundColor = IndexedColors.DARK_RED.Index;
        hStyleRed.FillPattern         = FillPatternType.SOLID_FOREGROUND;

        hStyleRed.BorderBottom      = BorderStyle.THIN;
        hStyleRed.BorderLeft        = BorderStyle.THIN;
        hStyleRed.BorderRight       = BorderStyle.THIN;
        hStyleRed.BorderTop         = BorderStyle.THIN;
        hStyleRed.BottomBorderColor = HSSFColor.BLACK.index;
        hStyleRed.LeftBorderColor   = HSSFColor.BLACK.index;
        hStyleRed.RightBorderColor  = HSSFColor.BLACK.index;
        hStyleRed.TopBorderColor    = HSSFColor.BLACK.index;



        HSSFCellStyle headStyle = (HSSFCellStyle)workbook.CreateCellStyle();

        headStyle.FillForegroundColor = IndexedColors.BRIGHT_GREEN.Index;
        headStyle.FillPattern         = FillPatternType.SOLID_FOREGROUND;


        HSSFCellStyle headStylePrefab = (HSSFCellStyle)workbook.CreateCellStyle();

        headStylePrefab.FillForegroundColor = IndexedColors.LEMON_CHIFFON.Index;
        headStylePrefab.FillPattern         = FillPatternType.SOLID_FOREGROUND;

        HSSFCellStyle headStyleBundle = (HSSFCellStyle)workbook.CreateCellStyle();

        headStyleBundle.FillForegroundColor = IndexedColors.GOLD.Index;
        headStyleBundle.FillPattern         = FillPatternType.SOLID_FOREGROUND;


        // IWorkbook doc
        IFont font = workbook.CreateFont();

        font.FontHeightInPoints = 12;
        font.FontName           = "Arial";
        font.Boldweight         = (short)FontBoldWeight.BOLD;


        headStyle.SetFont(font);

        string[]        titleText     = { "■■■ EXCELシート ■■■", "", "", "■■■ プレハブ ■■■", "", "■■■ アセットバンドル ■■■", "" };
        int[]           columnWidth   = { 35, 12, 20, 30, 12, 30, 12 };
        HSSFCellStyle[] hssfCellStyle =
        {
            headStyle,
            headStyle,
            headStyle,
            headStylePrefab,
            headStylePrefab,
            headStyleBundle,
            headStyleBundle
        };

        CellMake(sheet1, titleText, hssfCellStyle, columnWidth);


        string[]        titleTextB     = { "アセットバンドル名:", "バージョン", "フォルダ名", "プレハブ最終出力時間", "プレハブVer", "アセットバンドル最終出力時間", "アセットVer" };
        int[]           columnWidthB   = { 35, 12, 20, 30, 12, 30, 12 };
        HSSFCellStyle[] hssfCellStyleB =
        {
            headStyle,
            headStyle,
            headStyle,
            headStylePrefab,
            headStylePrefab,
            headStyleBundle,
            headStyleBundle
        };

        CellMake(sheet1, titleTextB, hssfCellStyleB, columnWidthB);

        int countDataListIndex = 0;

        // セルを作成する(垂直方向)
        for (iRow = (makeCellLow); iRow < (maxRow + makeCellLow); iRow++)
        {
            int cellIndex = 0;

            //	Debug.Log ("Cell :" + cellIndex);
            Debug.Log("iRow :" + iRow);

            string assebundlename = data.list [countDataListIndex].assetbundleName;
            string folderName     = data.list [countDataListIndex].folderName;

            Debug.Log("読み込みアセットバンドル数 :" + data.list.Count);
            Debug.Log("読み込みアセットバンドル名 :" + assebundlename);

            row = sheet1.CreateRow(iRow);



            //アセットバンドル名
            cell = row.CreateCell(cellIndex++);
            string objName = assebundlename;
            cell.SetCellValue(objName);
            cell.CellStyle = hStyle;

            //バージョン名
            cell = row.CreateCell(cellIndex++);
            int version = data.list [countDataListIndex].version;
            cell.SetCellValue(version);
            cell.CellStyle = hStyle;


            //フォルダ名
            cell = row.CreateCell(cellIndex++);
            cell.SetCellValue(folderName);
            cell.CellStyle = hStyle;


            //プレハブ最終出力時間
            string returnString = GetFileInfo(assebundlename, folderName, AssetBundleInfo.InfoType.MAKETIME);

            string prefTime = returnString;

            cell = row.CreateCell(cellIndex++);
            cell.SetCellValue(returnString);
            cell.CellStyle = hStyle;

            //プレハブバージョン
            returnString = GetFileInfo(assebundlename, folderName, AssetBundleInfo.InfoType.VERID);
            cell         = row.CreateCell(cellIndex++);
            cell.SetCellValue(returnString);
            cell.CellStyle = hStyle;


            //アセットバンドル最終出力時間
            returnString = GetAssetBundleFileInfo(assebundlename, folderName, AssetBundleInfo.InfoType.MAKETIME);

            cell = row.CreateCell(cellIndex++);
            cell.SetCellValue(returnString);

            if (prefTime != returnString)
            {
                cell.CellStyle = hStyleRed;
            }
            else
            {
                cell.CellStyle = hStyle;
            }

            returnString = GetAssetBundleFileInfo(assebundlename, folderName, AssetBundleInfo.InfoType.VERID);

            cell = row.CreateCell(cellIndex++);
            cell.SetCellValue(returnString);
            cell.CellStyle = hStyle;

            countDataListIndex++;
        }


        string dataURL = SystemSetting.GetBundleVerUrl() + SystemSetting.GetBundleVerName();


        // Excelファイル出力
        OutputExcelFile(dataURL, workbook);
        AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
    }
        protected IEnumerable <ITranslationDumper> GetCustomListDumpers()
        {
            TranslationDumper <IDictionary <string, string> > .TranslationCollector BuildDumper(ExcelData asset,
                                                                                                string assetName = null)
            {
                if (string.IsNullOrEmpty(assetName))
                {
                    assetName = asset.name;
                }

                // cache results, only process once
                OrderedDictionary <string, string> results = null;

                IDictionary <string, string> Dumper()
                {
                    if (results != null)
                    {
                        return(results);
                    }

                    results = new OrderedDictionary <string, string>();
                    if (asset == null)
                    {
                        return(results);
                    }
                    var firstRow  = 0;
                    var colToDump = -1;

                    if (asset.list[0].list.Count == 0 || asset.list[0].list[0].IsNullOrEmpty())
                    {
                        var i = 0;
                        while (i < asset.list.Count && asset.list[i].list.Count == 0)
                        {
                            i++;
                        }
                        if (i < asset.list.Count)
                        {
                            firstRow = i;
                            var row = asset.GetRow(i);

                            if (asset.name.Contains("_pose") && row.Count >= 7)
                            {
                                colToDump = 3;
                            }
                            else if (row.Count >= 9)
                            {
                                colToDump = 2;
                            }
                            else if (row.Count > 2)
                            {
                                colToDump = 1;
                            }
                        }
                    }
                    else
                    {
                        var header = ResourceHelper.GetExcelHeaderRow(asset, out firstRow);
                        colToDump = header.IndexOf("デフォルト");
                    }

                    if (colToDump == -1)
                    {
                        return(results);
                    }

                    var mapIdx = -1;

                    if (asset.name.StartsWith("cus_eb_ptn"))
                    {
                        mapIdx = 0;
                    }
                    else if (asset.name.StartsWith("cus_e_ptn"))
                    {
                        mapIdx = 1;
                    }
                    else if (asset.name.StartsWith("cus_m_ptn"))
                    {
                        mapIdx = 2;
                    }
                    else if (asset.name.StartsWith("cus_eyeslook"))
                    {
                        mapIdx = 3;
                    }
                    else if (asset.name.StartsWith("cus_necklook"))
                    {
                        mapIdx = 4;
                    }
                    else if (asset.name.StartsWith("cus_pose"))
                    {
                        mapIdx = 5;
                    }
                    else if (asset.name.StartsWith("cus_filelist"))
                    {
                        mapIdx = 6;
                    }
                    else if (asset.name.StartsWith("cus_selectlist"))
                    {
                        mapIdx = 7;
                    }


                    // CUSTOM_LIST2 = 3
                    var processor = GetTranslateManagerRowProcessor(3, mapIdx, colToDump);
                    var items     = GetExcelEntries(asset, assetName).ToList();

                    for (var i = firstRow; i < items.Count; i++)
                    {
                        try
                        {
                            foreach (var entry in processor(items[i].list))
                            {
                                if (entry.Key.Contains("unity3d"))
                                {
                                    continue;
                                }
                                AddLocalizationToResults(results, entry);
                            }
                        }
                        catch (Exception err)
                        {
                            Logger.LogFatal($"GetCustomListDumpers: {err}\n{err.StackTrace}");
                            throw;
                        }
                    }

                    return(results);
                }

                return(Dumper);
            }

            var assetBundleNames = GetAssetBundleNameListFromPath("custom/", true);

            foreach (var assetBundleName in assetBundleNames)
            {
                foreach (var assetName in GetAssetNamesFromBundle(assetBundleName).Where(n => n.StartsWith("cus_")))
                {
                    var asset  = ManualLoadAsset <ExcelData>(assetBundleName, assetName, null);
                    var dumper = BuildDumper(asset, assetName);
                    foreach (var filePath in BuildCustomListDumperAssetFilePaths(assetBundleName, assetName))
                    {
                        yield return(new StringTranslationDumper(filePath, dumper));
                    }
                }

                // some custom lists have multiple assets with the same name in the same bundle, so also get them this way
                var assetBundleData = new AssetBundleData(assetBundleName, null);
                foreach (var asset in assetBundleData.GetAllAssets <ExcelData>())
                {
                    var assetName = asset.name;
                    var dumper    = BuildDumper(asset, assetName);
                    foreach (var filePath in BuildCustomListDumperAssetFilePaths(assetBundleName, assetName))
                    {
                        yield return(new StringTranslationDumper(filePath, dumper));
                    }
                }
            }
        }
Esempio n. 11
0
 public AudioSource CreateCache(Manager.Sound.Type type, AssetBundleData data)
 {
     return(this.CreateCache(type, data.bundle, data.asset, (string)null));
 }
Esempio n. 12
0
            public static bool ParseAssetBundleData(string configString, out AssetBundleData assetBundleData)
            {
                assetBundleData = null;

                XmlDocument doc = new XmlDocument();

                try
                {
                    doc.LoadXml(configString);
                }
                catch (System.Exception exception)
                {
                    Debug.LogError("Cannot parse config file");
                    return(false);
                }

                assetBundleData = new AssetBundleData();

                XmlNode buildAssetBundleNode = doc.SelectSingleNode("buildAssetBundle");

                if (buildAssetBundleNode == null)
                {
                    Debug.LogError("Cannot parse node(buildAssetBundle)");
                    return(false);
                }

                // ignoreExtention
                XmlNode ignoreExtentionNode = buildAssetBundleNode.Attributes.GetNamedItem("ignoreExtention");

                if (ignoreExtentionNode != null)
                {
                    string[] blocks = ignoreExtentionNode.Value.Split(';');
                    if (blocks != null && blocks.Length > 0)
                    {
                        assetBundleData.ignoreExtentionList = new List <string>();
                        foreach (string block in blocks)
                        {
                            assetBundleData.ignoreExtentionList.Add(block);
                        }
                    }
                }

                // platform
#if UNITY_EDITOR
                XmlNode platformNode = buildAssetBundleNode.Attributes.GetNamedItem("platform");
                if (platformNode != null)
                {
                    try
                    {
                        assetBundleData.platform = (BuildTarget)System.Enum.Parse(typeof(BuildTarget), platformNode.Value);
                    }
                    catch (System.Exception exception)
                    {
                        Debug.LogError("Cannot parse node(platform)" + ":" + platformNode.Value);
                        return(false);
                    }
                }
#endif

                // saveRoot
                XmlNode saveRootNode = doc.SelectSingleNode("buildAssetBundle/saveRoot");
                if (saveRootNode == null)
                {
                    Debug.LogError("Cannot parse node(saveRoot)");
                    return(false);
                }
                assetBundleData.saveRoot = saveRootNode.InnerText;

                // asset
                XmlNodeList assetNodeList = doc.SelectNodes("buildAssetBundle/asset");
                if (assetNodeList == null || assetNodeList.Count == 0)
                {
                    Debug.LogError("Nothing asset");
                    return(false);
                }
                assetBundleData.assetDataMap = new Dictionary <string, AssetData>();
                foreach (XmlNode assetNode in assetNodeList)
                {
                    AssetData assetData = new AssetData();
                    assetData.enabled = true;
                    assetData.itemDataCollectionList = new List <ItemDataCollection>();

                    // id
                    XmlNode idNode = assetNode.Attributes.GetNamedItem("id");
                    if (idNode == null)
                    {
                        Debug.LogError("Missing asset id");
                        return(false);
                    }
                    if (assetBundleData.assetDataMap.ContainsKey(idNode.Value))
                    {
                        Debug.LogError("Repeated id:" + idNode.Value);
                        return(false);
                    }
                    if (string.IsNullOrEmpty(idNode.Value))
                    {
                        Debug.LogError("Missing asset id:" + idNode.Value);
                        return(false);
                    }
                    assetData.id = idNode.Value;
                    assetBundleData.assetDataMap.Add(assetData.id, assetData);

                    // dependence
                    XmlNode dependenceNode = assetNode.Attributes.GetNamedItem("dependence");
                    if (dependenceNode != null)
                    {
                        assetData.dependence = dependenceNode.Value;
                    }

                    // item
                    XmlNodeList itemNodeList = assetNode.SelectNodes("item");
                    if (itemNodeList != null && itemNodeList.Count > 0)
                    {
                        foreach (XmlNode itemNode in itemNodeList)
                        {
                            ItemDataCollection itemDataCollection = new ItemDataCollection();
                            assetData.itemDataCollectionList.Add(itemDataCollection);
                            itemDataCollection.bind         = false;
                            itemDataCollection.itemDataList = new List <ItemData>();

                            ItemData itemData = null;
                            if (!ParseItemNode(itemNode, assetData.id, out itemData))
                            {
                                return(false);
                            }
                            itemDataCollection.itemDataList.Add(itemData);
                        }
                    }

                    // bind
                    XmlNodeList bindNodeList = assetNode.SelectNodes("bind");
                    if (bindNodeList != null)
                    {
                        foreach (XmlNode bindNode in bindNodeList)
                        {
                            ItemDataCollection itemDataCollection = new ItemDataCollection();
                            assetData.itemDataCollectionList.Add(itemDataCollection);
                            itemDataCollection.bind         = true;
                            itemDataCollection.itemDataList = new List <ItemData>();

                            // savePath
                            XmlNode savePathNode = bindNode.Attributes.GetNamedItem("savePath");
                            if (savePathNode == null)
                            {
                                Debug.LogError("Cannot parse node(bind.savePath)" + ":" + assetData.id);
                                return(false);
                            }
                            itemDataCollection.savePath = savePathNode.Value;

                            // item
                            XmlNodeList itemNodeList2 = bindNode.SelectNodes("item");
                            if (itemNodeList2 != null && itemNodeList2.Count > 0)
                            {
                                foreach (XmlNode itemNode in itemNodeList2)
                                {
                                    ItemData itemData = null;
                                    if (!ParseItemNode(itemNode, assetData.id, out itemData))
                                    {
                                        return(false);
                                    }
                                    itemDataCollection.itemDataList.Add(itemData);
                                }
                            }

                            // empty test
                            if (itemDataCollection.IsEmpty())
                            {
                                Debug.LogWarning("Empty asset config:" + assetData.id);
                            }
                        }
                    }

                    // empty test
                    if (assetData.IsEmpty())
                    {
                        Debug.LogWarning("Empty asset config:" + assetData.id);
                    }
                }

                return(true);
            }
Esempio n. 13
0
 public static AudioSource Get(int voiceNo, AssetBundleData data)
 {
     return(!Singleton <Manager.Voice> .IsInstance() ? (AudioSource)null : Singleton <Manager.Voice> .Instance.CreateCache(voiceNo, data));
 }
Esempio n. 14
0
 public static AudioSource Get(Manager.Sound.Type type, AssetBundleData data)
 {
     return(!Singleton <Manager.Sound> .IsInstance() ? (AudioSource)null : Singleton <Manager.Sound> .Instance.CreateCache(type, data));
 }
Esempio n. 15
0
            public bool GetBuildParams(AssetBundleData assetBundleData, List<Object> assetObjectList, List<string> assetObjectNameList, List<string> savePathList)
            {
                if (IsEmpty())
                {
                    return true;
                }

                foreach (ItemData itemData in itemDataList)
                {
                    if (!itemData.GetBuildParams(assetBundleData, assetObjectList, assetObjectNameList, savePathList))
                    {
                        return false;
                    }
                }
                return true;
            }
Esempio n. 16
0
 public LoaderBase(AssetBundleData d)
 {
     data    = d;
     mono    = GameEnine.entrance;
     depsCnt = data.dependencies.Length;
 }
Esempio n. 17
0
 public bool GetBuildParams(AssetBundleData assetBundleData, List<Object> assetObjectList, List<string> assetObjectNameList, List<string> savePathList)
 {
     if (isScene)
     {
         return GetBuildSceneParams(assetBundleData, path, assetObjectList, assetObjectNameList, savePathList);
     }
     else
     {
         if (type == ItemType.File)
         {
             return GetBuildFileParams(assetBundleData, path, assetObjectList, assetObjectNameList, savePathList, lightmapScene);
         }
         else if (type == ItemType.Directory)
         {
             return GetBuildDirectoryParams(assetBundleData, path, assetObjectList, assetObjectNameList, savePathList);
         }
         else
         {
             Debug.LogError("Undefined Error" + type);
             return false;
         }
     }
 }
Esempio n. 18
0
 public Loader(AssetBundleData d) : base(d)
 {
 }
Esempio n. 19
0
            private bool GetBuildFileParams(AssetBundleData assetBundleData, string filePath, List<Object> assetObjectList, List<string> assetObjectNameList, List<string> savePathList, string lightmapScene)
            {
                if (assetBundleData.IsIgnoreExtension(filePath))
                {
                    return true;
                }

                Object assetObject = AssetDatabase.LoadMainAssetAtPath(URL.assets + "/" + filePath);
                if (assetObject == null)
                {
                    Debug.LogError("Read asset file fail:" + filePath);
                    return false;
                }

                assetObjectList.Add(assetObject);
                assetObjectNameList.Add(filePath);
                savePathList.Add(filePath + ".unity3d");

                if (!GetBuildLightmapParams(assetBundleData, filePath, assetObjectList, assetObjectNameList, savePathList, lightmapScene))
                {
                    return false;
                }

                return true;
            }
Esempio n. 20
0
    private UnityEngine.Object LoadFromBundle(AssetBundleData data)
    {
        XAssetBundle bundle = ab.GetBundle(data);

        return(bundle.LoadAsset(data.loadName));
    }
Esempio n. 21
0
            public static bool ParseAssetBundleData(string configString, out AssetBundleData assetBundleData)
            {
                assetBundleData = null;

                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.LoadXml(configString);
                }
                catch (System.Exception exception)
                {
                    Debug.LogError("Cannot parse config file");
                    return false;
                }

                assetBundleData = new AssetBundleData();

                XmlNode buildAssetBundleNode = doc.SelectSingleNode("buildAssetBundle");
                if (buildAssetBundleNode == null)
                {
                    Debug.LogError("Cannot parse node(buildAssetBundle)");
                    return false;
                }

                // ignoreExtention
                XmlNode ignoreExtentionNode = buildAssetBundleNode.Attributes.GetNamedItem("ignoreExtention");
                if (ignoreExtentionNode != null)
                {
                    string[] blocks = ignoreExtentionNode.Value.Split(';');
                    if (blocks != null && blocks.Length > 0)
                    {
                        assetBundleData.ignoreExtentionList = new List<string>();
                        foreach (string block in blocks)
                        {
                            assetBundleData.ignoreExtentionList.Add(block);
                        }
                    }
                }

                // platform
#if UNITY_EDITOR
                XmlNode platformNode = buildAssetBundleNode.Attributes.GetNamedItem("platform");
                if (platformNode != null)
                {
                    try
                    {
                        assetBundleData.platform = (BuildTarget)System.Enum.Parse(typeof(BuildTarget), platformNode.Value);
                    }
                    catch (System.Exception exception)
                    {
                        Debug.LogError("Cannot parse node(platform)" + ":" + platformNode.Value);
                        return false;
                    }
                }
#endif

                // saveRoot
                XmlNode saveRootNode = doc.SelectSingleNode("buildAssetBundle/saveRoot");
                if (saveRootNode == null)
                {
                    Debug.LogError("Cannot parse node(saveRoot)");
                    return false;
                }
                assetBundleData.saveRoot = saveRootNode.InnerText;

                // asset
                XmlNodeList assetNodeList = doc.SelectNodes("buildAssetBundle/asset");
                if (assetNodeList == null || assetNodeList.Count == 0)
                {
                    Debug.LogError("Nothing asset");
                    return false;
                }
                assetBundleData.assetDataMap = new Dictionary<string, AssetData>();
                foreach (XmlNode assetNode in assetNodeList)
                {
                    AssetData assetData = new AssetData();
                    assetData.enabled = true;
                    assetData.itemDataCollectionList = new List<ItemDataCollection>();

                    // id
                    XmlNode idNode = assetNode.Attributes.GetNamedItem("id");
                    if (idNode == null)
                    {
                        Debug.LogError("Missing asset id");
                        return false;
                    }
                    if (assetBundleData.assetDataMap.ContainsKey(idNode.Value))
                    {
                        Debug.LogError("Repeated id:" + idNode.Value);
                        return false;
                    }
                    if (string.IsNullOrEmpty(idNode.Value))
                    {
                        Debug.LogError("Missing asset id:" + idNode.Value);
                        return false;
                    }
                    assetData.id = idNode.Value;
                    assetBundleData.assetDataMap.Add(assetData.id, assetData);

                    // dependence
                    XmlNode dependenceNode = assetNode.Attributes.GetNamedItem("dependence");
                    if (dependenceNode != null)
                    {
                        assetData.dependence = dependenceNode.Value;
                    }

                    // item
                    XmlNodeList itemNodeList = assetNode.SelectNodes("item");
                    if (itemNodeList != null && itemNodeList.Count > 0)
                    {
                        foreach (XmlNode itemNode in itemNodeList)
                        {
                            ItemDataCollection itemDataCollection = new ItemDataCollection();
                            assetData.itemDataCollectionList.Add(itemDataCollection);
                            itemDataCollection.bind = false;
                            itemDataCollection.itemDataList = new List<ItemData>();

                            ItemData itemData = null;
                            if (!ParseItemNode(itemNode, assetData.id, out itemData))
                            {
                                return false;
                            }
                            itemDataCollection.itemDataList.Add(itemData);
                        }
                    }

                    // bind
                    XmlNodeList bindNodeList = assetNode.SelectNodes("bind");
                    if (bindNodeList != null)
                    {
                        foreach (XmlNode bindNode in bindNodeList)
                        {
                            ItemDataCollection itemDataCollection = new ItemDataCollection();
                            assetData.itemDataCollectionList.Add(itemDataCollection);
                            itemDataCollection.bind = true;
                            itemDataCollection.itemDataList = new List<ItemData>();

                            // savePath
                            XmlNode savePathNode = bindNode.Attributes.GetNamedItem("savePath");
                            if (savePathNode == null)
                            {
                                Debug.LogError("Cannot parse node(bind.savePath)" + ":" + assetData.id);
                                return false;
                            }
                            itemDataCollection.savePath = savePathNode.Value;

                            // item
                            XmlNodeList itemNodeList2 = bindNode.SelectNodes("item");
                            if (itemNodeList2 != null && itemNodeList2.Count > 0)
                            {
                                foreach (XmlNode itemNode in itemNodeList2)
                                {
                                    ItemData itemData = null;
                                    if (!ParseItemNode(itemNode, assetData.id, out itemData))
                                    {
                                        return false;
                                    }
                                    itemDataCollection.itemDataList.Add(itemData);
                                }
                            }

                            // empty test
                            if (itemDataCollection.IsEmpty())
                            {
                                Debug.LogWarning("Empty asset config:" + assetData.id);
                            }
                        }
                    }

                    // empty test
                    if (assetData.IsEmpty())
                    {
                        Debug.LogWarning("Empty asset config:" + assetData.id);
                    }
                }

                return true;
            }
Esempio n. 22
0
 public static void UnloadAssetBundle(AssetBundleData data, bool isUnloadForceRefCount, bool unloadAllLoadedObjects = false)
 {
     UnloadAssetBundle(data.bundle, isUnloadForceRefCount, null, unloadAllLoadedObjects);
 }
Esempio n. 23
0
    AssetBundleData CreateBundleData(string bundleName, AssetBundle bundle, eBundleLoadType loadtype)
    {
        AssetBundleData bundleData = new AssetBundleData(bundleName, bundle, loadtype);

        return(bundleData);
    }
Esempio n. 24
0
 public static AssetBundleLoadOperation LoadLevel(AssetBundleData data, bool isAdditive)
 {
     return(LoadLevel(data.bundle, data.asset, isAdditive, null));
 }
Esempio n. 25
0
 public static AssetBundleLoadOperation LoadLevelAsync(
     AssetBundleData data,
     bool isAdditive)
 {
     return(AssetBundleManager.LoadLevelAsync(data.bundle, data.asset, isAdditive, (string)null));
 }
Esempio n. 26
0
 public static AssetBundleLoadAssetOperation LoadAsset(AssetBundleData data, Type type)
 {
     return(LoadAsset(data.bundle, data.asset, type, null));
 }
Esempio n. 27
0
    //加载lua文件
    public static byte[] GetLuaScript(string fileName)
    {
#if UNITY_EDITOR && !ASSETBUNDLE_ENABLE
        string path = LuaFileUtils.Instance.FindFile(fileName);
        byte[] str  = null;

        if (!string.IsNullOrEmpty(path) && File.Exists(path))
        {
            str = File.ReadAllBytes(path);
        }
        if (str != null)
        {
            return(str);
        }
#endif
        AssetBundle assetBundle = null;
        byte[]      buffer      = null;

        using (CString.Block())
        {
            string strBundleName = "";
            if (fileName.IndexOf("message/") != -1)
            {
                strBundleName = "lua/lua_message.unity3d";
            }
            else if (fileName.IndexOf("Template/") != -1)
            {
                strBundleName = "lua/lua_template.unity3d";
            }
            else
            {
                strBundleName = "lua/lua_script.unity3d";
            }
            int pos = fileName.LastIndexOf('/');
            if (pos > 0)
            {
                fileName = fileName.Substring(pos + 1);
            }
            if (!fileName.EndsWith(".lua"))
            {
                fileName += ".lua";
            }

#if UNITY_5 || UNITY_2017
            fileName += ".bytes";
#endif
            AssetBundleData assetBundleData = null;
            if (m_dicAssetBundle.TryGetValue(strBundleName, out assetBundleData))
            {
                string keyName = "assets/" + fileName.ToLower();
                if (assetBundleData != null)
                {
                    if (assetBundleData.assetBundle == null)
                    {
                        assetBundleData.assetBundle = AssetBundle.LoadFromFile(assetBundleData.strAssetPath);
                    }
                    assetBundle = assetBundleData.assetBundle;
                }
            }
        }

        if (assetBundle != null)
        {
#if UNITY_5 || UNITY_2017
            TextAsset luaCode = assetBundle.LoadAsset <TextAsset>(fileName);
#else
            TextAsset luaCode = assetBundle.Load(fileName, typeof(TextAsset)) as TextAsset;
#endif
            if (luaCode != null)
            {
                buffer = luaCode.bytes;
                Resources.UnloadAsset(luaCode);
            }
        }
        return(buffer);
    }
Esempio n. 28
0
 public AudioSource CreateCache(int voiceNo, AssetBundleData data)
 {
     return(this.CreateCache(voiceNo, data.bundle, data.asset, (string)null));
 }
Esempio n. 29
0
    void Awake()
    {
        m_assetManager   = this;
        dictAbName       = new Dictionary <string, string>();
        m_dicAssetBundle = new Dictionary <string, AssetBundleData>();

        AssetBundle mainBundle = null;
        // 获得更新包路径
        string strPersistentDataPath = string.Empty;

        if (Application.isMobilePlatform)
        {
            strPersistentDataPath = Application.persistentDataPath;
        }
        // 获得原始数据路径
        string strRawPath = string.Empty;

        switch (Application.platform)
        {
        case RuntimePlatform.Android:
            strRawPath = Application.streamingAssetsPath;
            break;

        case RuntimePlatform.IPhonePlayer:
            strRawPath = Application.dataPath + "/Raw";
            break;

        default:
            strRawPath = Application.streamingAssetsPath;
            break;
        }
        if (strPersistentDataPath != string.Empty && File.Exists(Application.persistentDataPath + "/StreamingAssets"))
        {
            mainBundle = AssetBundle.LoadFromFile(strPersistentDataPath + "/StreamingAssets");
        }
        else
        {
            // 没有新版的bundle主文件,则加载安装包里的bundle主文件
            mainBundle = AssetBundle.LoadFromFile(strRawPath + "/StreamingAssets");
        }
        // 构建资源依赖关系
        manifest = mainBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

        string strAssetRelateUrl = "";

        if (strPersistentDataPath != string.Empty && File.Exists(Application.persistentDataPath + "/AssetRelateData"))
        {
            strAssetRelateUrl = strPersistentDataPath + "/AssetRelateData";
        }
        else
        {
            // 没有新版的bundle主文件,则加载安装包里的bundle主文件
            strAssetRelateUrl = strRawPath + "/AssetRelateData";
        }

        string content = File.ReadAllText(strAssetRelateUrl);

        string[] strArr = content.Split('\n');
        foreach (string nameData in strArr)
        {
            string[] arr           = nameData.Split('|');
            string[] assetNameList = arr[0].Split(',');
            string   strBundleName = arr[1];

            AssetBundleData assetBundleData = new AssetBundleData();
            if (strPersistentDataPath != string.Empty && File.Exists(Application.persistentDataPath + "/" + strBundleName))
            {
                assetBundleData.strAssetPath = strPersistentDataPath + "/" + strBundleName;
            }
            else
            {
                // 没有新版的bundle主文件,则加载安装包里的bundle主文件
                assetBundleData.strAssetPath = strRawPath + "/" + strBundleName;
            }
            assetBundleData.listUseBundleName = new List <string>();

            foreach (string strAssetName in assetNameList)
            {
                if (string.IsNullOrEmpty(strAssetName))
                {
                    continue;
                }
                dictAbName.Add(strAssetName, strBundleName);
            }
            m_dicAssetBundle.Add(strBundleName, assetBundleData);
        }
        mainBundle.Unload(false);
//#endif
    }
Esempio n. 30
0
    /// <summary>
    /// 加载资源
    /// </summary>
    /// <param name="assetPath"></param>
    /// <param name="callBack"></param>
    /// <param name="assetBundleName"></param>
    /// <returns></returns>
    public IEnumerator LoadAsset(string assetPath, LoadABCallBack loadABCallBack, string assetBundleName)
    {
        while (IsLoading(assetPath))
        {
            yield return(new WaitForEndOfFrame());
        }

        {
            // 从管理器中获取加载数据
            AssetBundleData assetBundleData = AssetBundleManager.Instance.GetAssetBundleData(assetPath);
            // 获取到的数据不为空就不再重新加载了
            if (assetBundleData != null)
            {
                // 引用 +1
                assetBundleData.Retain();
                if (loadABCallBack != null)
                {
                    loadABCallBack(assetBundleData);
                }

                yield break;  // 已经有了直接返回
            }
        }

        if (assetBundleManifest == null)
        {
            yield return(Game.Instance.StartCoroutine(LoadManifest()));
        }

        if (assetBundleManifest == null)
        {
            Debug.LogError("assetBundlManifest is");
            yield break;
        }

        AddLoading(assetPath);

        // 加载依赖资源
        // 获取依赖资源数据
        string[] depends = assetBundleManifest.GetAllDependencies(assetBundleName);
        int      count   = depends.Length;

        if (count > 0)
        {
            AssetBundleManager.Instance.SetDepends(assetBundleName, depends);
        }

        List <string> urlList = new List <string>();

        for (int i = 0; i < count; ++i)
        {
            string url = ResourcePathManager.Instance.CheckFilePath(ResourcePathManager.Instance.GetPersistentDataPath, "AssetBundle/" + depends[i]);
            url = url.ToLower();

            AssetBundleData assetBundleData = AssetBundleManager.Instance.GetAssetBundleData(url);
            // 获取到的数据不为空就不再重新加载了
            if (assetBundleData != null)
            {
                continue;
            }

            Game.Instance.StartCoroutine(LoadAB(url, null, true));

            urlList.Add(url);
            AddLoading(url);
        }

        int index = 0;

        while (urlList.Count > 0)
        {
            index %= urlList.Count;
            if (!IsLoading(urlList[index]))
            {
                urlList.RemoveAt(index);
            }

            ++index;
            yield return(new WaitForEndOfFrame());
        }

        LoadABCallBack CallBack = delegate(AssetBundleData assetBundleData)
        {
            loadABCallBack(assetBundleData);
        };

        yield return(Game.Instance.StartCoroutine(LoadAB(assetPath, CallBack)));
    }