static void BuildExcels(PlatformType platform, BuildTarget target)
    {
        //0 clean directory
        BuildAssetBundleHelper.DeleteAllFilesInDir(_buildOutputPath);

        //1 build
        foreach (string name in _allExcelFileNames)
        {
            for (int i = 0; i < (int)ExcelDirType.Count; i++)
            {
                ExcelDirType dirType = (ExcelDirType)i;
                BuildSingleExcel(platform, target, name, _buildOutputPath, dirType);
            }
        }

        //2 encrypt and copy
        foreach (string name in _allExcelFileNames)
        {
            for (int i = 0; i < (int)ExcelDirType.Count; i++)
            {
                ExcelDirType dirType = (ExcelDirType)i;
                EncryptAndCopyFile(name, dirType);
            }
        }
    }
    static void EncryptAndCopyFile(string excelName, ExcelDirType dirType)
    {
        string name       = excelName.ToLower();
        string bundleName = ExcelConfig.GetBundleName(dirType, name);
        string src        = Path.Combine(Path.Combine(Application.dataPath, _buildOutputPath), bundleName);
        string dest       = Path.Combine(Path.Combine(Application.dataPath, _streamingPath), bundleName);

        if (File.Exists(src))
        {
            byte[] originalBytes  = File.ReadAllBytes(src);
            byte[] encryptedBytes = null;
            if (AssetConfig.IsExcelAssetBundleEncrypted)
            {
                encryptedBytes = EncryptUtility.AES_Encrypt(originalBytes);
            }
            else
            {
                encryptedBytes = originalBytes;
            }
            File.WriteAllBytes(dest, encryptedBytes);
        }
        else
        {
            //Debug.LogError("EncryptAndCopyFile fail: file doesn't exist: " + src);
        }
    }
    static void CopyBetweenProjectAndAB(string versionName, ExcelDirType dirType, bool isABToProject)
    {
        string excelTopDir = ExcelConfig.GetTopDir(dirType);

        string abDir = GetCurrentVersionPath(versionName);

        if (!Directory.Exists(abDir))
        {
            Debug.LogError("Error: directory doesn't exist:" + abDir);
            return;
        }

        List <FileInfo> abInfos = BuildAssetBundleHelper.GetUsefulFileInfosFromDir(abDir);

        string          projectPath = Application.dataPath;
        List <FileInfo> allInfos    = BuildAssetBundleHelper.GetUsefulFileInfosFromDir(projectPath);

        foreach (FileInfo abInfo in abInfos)
        {
            bool isExcel = abInfo.Name.EndsWith(".xls");

            FileInfo projectInfo = ListUtility.FindFirstOrDefault(allInfos, (FileInfo i) => {
                //Debug.Log("name:" + i.Name);
                bool result = abInfo.Name == i.Name;
                if (result && isExcel)
                {
                    result = IsContainDirectory(i.FullName, excelTopDir);
                }
                return(result);
            });

            if (projectInfo == null)
            {
                string errStr = "Can't find corresponding project file:" + abInfo.Name;
                Debug.LogError(errStr);
            }
            else
            {
                if (isABToProject)
                {
                    Debug.Log("copy from " + abInfo.FullName);
                    Debug.Log("copy to " + projectInfo.FullName);

                    File.Copy(abInfo.FullName, projectInfo.FullName, true);

                    string relativePath = BuildAssetBundleHelper.TrimToRelativePath(projectInfo.FullName);
                    AssetDatabase.ImportAsset(relativePath);
                }
                else
                {
                    File.Copy(projectInfo.FullName, abInfo.FullName, true);
                }
            }
        }
    }
Exemple #4
0
    public static List <string> GetAllExcelResourcePaths(ExcelDirType dirType, List <string> excelNames)
    {
        List <string> result = new List <string>();

        foreach (var name in excelNames)
        {
            List <string> paths = GetSingleExcelResourcePaths(dirType, name);
            result.AddRange(paths);
        }
        return(result);
    }
Exemple #5
0
    public static ExcelDirType GetExcelDirType(BuildTarget target)
    {
        ExcelDirType result = ExcelDirType.Default;

        switch (target)
        {
        case BuildTarget.Android:
            result = ExcelDirType.Default;
            break;

        case BuildTarget.iOS:
            result = ExcelDirType.IOS;
            break;

        default:
            Debug.Assert(false);
            break;
        }
        return(result);
    }
Exemple #6
0
    static bool BuildLiveUpdateAssets()
    {
        bool        result = false;
        BuildTarget target = BuildAssetBundleHelper.GetBuildTarget(_liveUpdateConfig._platformType);

        if (target != BuildTarget.NoTarget)
        {
            //Note: Important fix. If don't switch platform, everytime before building AssetBundle,
            //it will take much time to switch to the particular platform.
            PerformBuild.SwitchBuildPlatform(target);

            string path = BuildAssetBundleHelper.GetAssetBundlePath(_liveUpdateConfig._platformType);
            BuildAssetBundleHelper.DeleteAllFilesInDir(path);

            ExcelDirType  dirType     = BuildAssetBundleHelper.GetExcelDirType(target);
            List <string> allResPaths = BuildAssetBundleHelper.GetAllExcelResourcePaths(dirType, _liveUpdateConfig._excelFileNames);
            allResPaths.AddRange(_liveUpdateConfig._resourcePaths);

            result = BuildAssetBundles.BuildBundlesFromMap(path, _liveUpdateConfig._version, _liveUpdateConfig._platformType, target,
                                                           true, _liveUpdateConfig._bundleName, allResPaths);
        }
        return(result);
    }
    static bool BuildABTestAssets()
    {
        bool        result = false;
        BuildTarget target = BuildAssetBundleHelper.GetBuildTarget(_abTestConfig._platformType);

        if (target != BuildTarget.NoTarget)
        {
            //Note: Important fix. If don't switch platform, everytime before building AssetBundle,
            //it will take much time to switch to the particular platform.
            PerformBuild.SwitchBuildPlatform(target);

            ExcelDirType dirType = BuildAssetBundleHelper.GetExcelDirType(target);
            result = true;
            foreach (string abVersion in _abTestConfig._abVersions)
            {
                string path = BuildAssetBundleHelper.GetAssetBundlePath(_abTestConfig._platformType);
                BuildAssetBundleHelper.DeleteAllFilesInDir(path);

                BuildABTestHelper.CopyABToProject(abVersion, dirType);

                string version = _abTestConfig._version + "." + abVersion;

                List <string> allResPaths = BuildAssetBundleHelper.GetAllExcelResourcePaths(dirType, _abTestConfig._excelFileNames);
                allResPaths.AddRange(_abTestConfig._resourcePaths);

                bool r = BuildAssetBundles.BuildBundlesFromMap(path, version, _abTestConfig._platformType, target,
                                                               true, _abTestConfig._bundleName, allResPaths);

                if (!r)
                {
                    result = false;
                }
            }
        }
        return(result);
    }
Exemple #8
0
    public static List <string> GetSingleExcelResourcePaths(ExcelDirType dirType, string excelName)
    {
        string          resourcePath = _resourceDir + ExcelConfig.GetTopDir(dirType);
        string          excelPath    = Path.Combine(Application.dataPath, resourcePath);
        List <FileInfo> fileInfos    = GetUsefulFileInfosFromDir(excelPath);
        List <string>   paths        = new List <string>();
        string          prefix       = excelName + "_";

        foreach (var info in fileInfos)
        {
            if (info.Name.Contains(prefix) && !info.Name.Contains(".meta"))
            {
                string p = TrimToRelativePath(info.FullName);
                paths.Add(p);
            }
        }

        if (paths.Count == 0)
        {
            Debug.Log("Warning: GetSingleExcelResourcePaths is empty: " + excelName);
        }

        return(paths);
    }
 static public void CopyABToProject(string versionName, ExcelDirType dirType)
 {
     CopyBetweenProjectAndAB(versionName, dirType, true);
 }
 static public void CopyProjectToAB(string versionName, ExcelDirType dirType)
 {
     CopyBetweenProjectAndAB(versionName, dirType, false);
 }
    static bool BuildSingleExcel(PlatformType platform, BuildTarget target, string excelName, string outputPath, ExcelDirType dirType)
    {
        List <string> allResPaths = BuildAssetBundleHelper.GetSingleExcelResourcePaths(dirType, excelName);
        string        bundleName  = ExcelConfig.GetBundleName(dirType, excelName);
        bool          result      = BuildAssetBundles.BuildBundlesFromMap(outputPath, "", platform, target, false, bundleName, allResPaths);

        if (!result)
        {
            Debug.Log("Warn: Fail to build excel: " + excelName);
        }

        return(result);
    }
    void OnGUI()
    {
        _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true);

        GUILayout.Label("*********************************************************************");
        GUILayout.Label("*                           AB Test                                 *");
        GUILayout.Label("*********************************************************************");

        _abTestConfig._platformType = (PlatformType)EditorGUILayout.EnumPopup("PlatformType", _abTestConfig._platformType);
        _abTestConfig._bundleName   = EditorGUILayout.TextField("BundleName", _abTestConfig._bundleName);
        _abTestConfig._version      = EditorGUILayout.TextField("Version", _abTestConfig._version);

        GUILayout.Space(20);

        GUILayout.Label("AB Versions:");
        for (int i = 0; i < _abTestConfig._abVersions.Count; i++)
        {
            GUILayout.BeginHorizontal();

            _abTestConfig._abVersions[i] = EditorGUILayout.TextField("Version:", _abTestConfig._abVersions[i]);
            string versionName = _abTestConfig._abVersions[i];

            GUILayout.Space(10);

            if (GUILayout.Button("AB -> Project", GUILayout.Width(90)))
            {
                BuildTarget target = BuildAssetBundleHelper.GetBuildTarget(_abTestConfig._platformType);
                if (target != BuildTarget.NoTarget)
                {
                    ExcelDirType dirType = BuildAssetBundleHelper.GetExcelDirType(target);
                    BuildABTestHelper.CopyABToProject(versionName, dirType);
                }
                else
                {
                    Debug.LogError("Can't copy since platformType is wrong");
                }
            }

            GUILayout.Space(10);

            if (GUILayout.Button("-", GUILayout.Width(30)))
            {
                _abTestConfig._abVersions.RemoveAt(i);
                i--;
            }

            GUILayout.EndHorizontal();
        }

        if (GUILayout.Button("+", GUILayout.Width(30)))
        {
            _abTestConfig._abVersions.Insert(_abTestConfig._abVersions.Count, "");
        }

        GUILayout.Space(20);

        GUILayout.Label("Excel File Names:");
        for (int i = 0; i < _abTestConfig._excelFileNames.Count; i++)
        {
            GUILayout.BeginHorizontal();

            _abTestConfig._excelFileNames[i] = EditorGUILayout.TextField("Name:", _abTestConfig._excelFileNames[i]);

            GUILayout.Space(10);

            if (GUILayout.Button("-", GUILayout.Width(30)))
            {
                _abTestConfig._excelFileNames.RemoveAt(i);
                i--;
            }

            GUILayout.EndHorizontal();
        }

        if (GUILayout.Button("+", GUILayout.Width(30)))
        {
            _abTestConfig._excelFileNames.Insert(_abTestConfig._excelFileNames.Count, "");
        }

        GUILayout.Space(20);

        GUILayout.Label("Resource Paths:");
        for (int i = 0; i < _abTestConfig._resourcePaths.Count; i++)
        {
            GUILayout.BeginHorizontal();

            string path = _abTestConfig._resourcePaths[i];
            path = EditorGUILayout.TextField(path, GUILayout.Width(300));
            if (string.IsNullOrEmpty(path))
            {
                if (!string.IsNullOrEmpty(_lastResourcePath))
                {
                    path = _lastResourcePath;
                }
                else
                {
                    path = BuildAssetBundleHelper.GetDefaultResourcePath();
                }
            }

            if (GUILayout.Button("...", GUILayout.Width(30)))
            {
                string selectPath = BuildAssetBundleHelper.OpenFilePanel(path);

                if (selectPath.Length != 0)
                {
                    // the path should be relative not absolute one to make it work on any platform.
                    string trimPath = BuildAssetBundleHelper.TrimToRelativePath(selectPath);
                    if (!string.IsNullOrEmpty(trimPath))
                    {
                        // set relative path
                        _abTestConfig._resourcePaths[i] = trimPath;
                        _lastResourcePath = trimPath;
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Error", "Folder should be under 'Assets' folder", "OK");
                        return;
                    }
                }
            }

            if (GUILayout.Button("-", GUILayout.Width(30)))
            {
                _abTestConfig._resourcePaths.RemoveAt(i);
            }

            if (GUILayout.Button("+", GUILayout.Width(30)))
            {
                _abTestConfig._resourcePaths.Insert(i + 1, "");
            }

            GUILayout.EndHorizontal();
        }

        if (GUILayout.Button("+", GUILayout.Width(30)))
        {
            _abTestConfig._resourcePaths.Insert(_abTestConfig._resourcePaths.Count, "");
        }

        GUILayout.Space(20);

        if (GUILayout.Button("Build ABTest AssetBundles", GUILayout.Width(180.0f)))
        {
            BuildABTestButtonDown();
        }

        GUILayout.Space(20);

        if (GUILayout.Button("Save config", GUILayout.Width(100)))
        {
            BuildAssetBundleHelper.SaveConfigButtonDown(_abTestConfig);
        }

        GUILayout.EndScrollView();
    }