예제 #1
0
    // 유틸 : 번들 패킹 시작 및 아웃풋
    static bool MakeAssetBundle(BuildTarget eTarget, string strOutputPath, Dictionary <string, AssetBundleInfo> dicBundles)
    {
        // 디렉토리 정리
        SHUtils.DeleteDirectory(strOutputPath);
        SHUtils.CreateDirectory(strOutputPath);

        // 번들 빌드 정보 만들기
        List <AssetBundleBuild> pBuildList = new List <AssetBundleBuild>();

        SHUtils.ForToDic(dicBundles, (pKey, pValue) =>
        {
            List <string> pAssets = new List <string>();
            SHUtils.ForToDic(pValue.m_dicResources, (pResKey, pResValue) =>
            {
                pAssets.Add(string.Format("{0}/{1}{2}", "Assets/Resources", pResValue.m_strPath, pResValue.m_strExtension));
            });

            AssetBundleBuild pAssetInfo = new AssetBundleBuild();
            pAssetInfo.assetBundleName  = string.Format("{0}.unity3d", pValue.m_strBundleName);
            pAssetInfo.assetNames       = pAssets.ToArray();
            pBuildList.Add(pAssetInfo);
        });

        // 빌드할 번들이 없으면 종료
        if (0 == pBuildList.Count)
        {
            return(true);
        }

        // 번들 빌드하기
        AssetBundleManifest pManifest = BuildPipeline.BuildAssetBundles(strOutputPath, pBuildList.ToArray(), BuildAssetBundleOptions.DeterministicAssetBundle, eTarget);

        if (null == pManifest)
        {
            Debug.LogErrorFormat("Error!!! Make Assets Bundle : {0}", strOutputPath);
            return(false);
        }

        // 후 처리
        SHUtils.ForToList(pBuildList, (pBundle) =>
        {
            // 번들 크기와 해시코드 기록
            string strKey = pBundle.assetBundleName.Substring(0, pBundle.assetBundleName.Length - ".unity3d".Length).ToLower();
            if (true == dicBundles.ContainsKey(strKey))
            {
                dicBundles[strKey].m_pHash128    = pManifest.GetAssetBundleHash(pBundle.assetBundleName);
                dicBundles[strKey].m_lBundleSize = (new FileInfo(string.Format("{0}/{1}", strOutputPath, pBundle.assetBundleName))).Length;
            }

            // Manifest제거 ( 사용하지 않는 불필요한 파일이라 그냥 제거시킴 )
            SHUtils.DeleteFile(string.Format("{0}/{1}.manifest", strOutputPath, pBundle.assetBundleName));
        });
        SHUtils.DeleteFile(string.Format("{0}/{1}", strOutputPath, SHHard.GetStrToPlatform(eTarget)));
        SHUtils.DeleteFile(string.Format("{0}/{1}.manifest", strOutputPath, SHHard.GetStrToPlatform(eTarget)));

        return(true);
    }
예제 #2
0
    // 유틸 : 원본 리소스 모두 제거
    static void DeleteOriginalResource(SHTableData pTableData)
    {
        var pBundleInfo = GetBundleTable(pTableData);

        SHUtils.ForToDic(pBundleInfo.GetContainer(), (pKey, pValue) =>
        {
            SHUtils.ForToDic(pValue.m_dicResources, (pResKey, pResValue) =>
            {
                SHUtils.DeleteFile(string.Format("{0}/{1}{2}", SHPath.GetPathToResources(), pResValue.m_strPath, pResValue.m_strExtension));
                SHUtils.DeleteFile(string.Format("{0}/{1}{2}", SHPath.GetPathToResources(), pResValue.m_strPath, ".meta"));
            });
        });
    }