Exemplo n.º 1
0
    //-------------------------------------------------------------------------
    void _copyDir(Casinos._eEditorRunSourcePlatform platform, string path_src, string path_dst)
    {
        DirectoryInfo dir = new DirectoryInfo(path_src);

        FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();// 获取目录下(不包含子目录)的文件和子目录
        foreach (FileSystemInfo i in fileinfo)
        {
            if (i is DirectoryInfo)// 判断是否文件夹
            {
                if (!Directory.Exists(path_dst + "\\" + i.Name))
                {
                    Directory.CreateDirectory(path_dst + "\\" + i.Name);
                }
                _copyDir(platform, i.FullName, path_dst + "\\" + i.Name);// 递归调用复制子文件夹
            }
            else
            {
                string file_extension = Path.GetExtension(i.FullName);
                if (DoNotPackFileExtention.Contains(file_extension))
                {
                    continue;
                }

                File.Copy(i.FullName, path_dst + "\\" + i.Name, true);// 不是文件夹即复制文件,true表示可以覆盖同名文件
            }
        }
    }
Exemplo n.º 2
0
    //-------------------------------------------------------------------------
    void _clearRawDataAndLua(Casinos._eEditorRunSourcePlatform platform)
    {
        string path_rawdata = string.Empty;
        string path_lua     = string.Empty;

        switch (platform)
        {
        case Casinos._eEditorRunSourcePlatform.Android:
            path_rawdata = EditorContext.Instance.PathStreamingAssets + "ANDROID\\Resources.KingTexasRaw\\";
            path_lua     = EditorContext.Instance.PathStreamingAssets + "ANDROID\\Script.Lua\\";
            break;

        case Casinos._eEditorRunSourcePlatform.IOS:
            path_rawdata = EditorContext.Instance.PathStreamingAssets + "IOS\\Resources.KingTexasRaw\\";
            path_lua     = EditorContext.Instance.PathStreamingAssets + "IOS\\Script.Lua\\";
            break;

        case Casinos._eEditorRunSourcePlatform.PC:
            path_rawdata = EditorContext.Instance.PathStreamingAssets + "PC\\Resources.KingTexasRaw\\";
            path_lua     = EditorContext.Instance.PathStreamingAssets + "PC\\Script.Lua\\";
            break;
        }

        if (Directory.Exists(path_rawdata))
        {
            Directory.Delete(path_rawdata, true);
        }
        if (Directory.Exists(path_lua))
        {
            Directory.Delete(path_lua, true);
        }
    }
Exemplo n.º 3
0
    //-------------------------------------------------------------------------
    bool _pakAbLuaEx(List <string> list_file, string ab_name, Casinos._eEditorRunSourcePlatform platform, BuildTarget build_target)
    {
        AssetBundleBuild abb = new AssetBundleBuild();

        abb.assetBundleName    = ab_name;
        abb.assetBundleVariant = "";
        abb.addressableNames   = null;

        int asset_index = 0;

        abb.assetNames = new string[list_file.Count];
        foreach (var j in list_file)
        {
            string j1 = j.Replace('\\', '/');
            int    n  = j1.IndexOf("Assets");
            string j2 = j1.Substring(n);// AssetBundle中的资源路径必须起始于Assets
            abb.assetNames[asset_index++] = j2;
        }

        AssetBundleBuild[] arr_abb = new AssetBundleBuild[1];
        arr_abb[0] = abb;

        string dir_dataoss = EditorContext.Instance.PathDataOss;
        AssetBundleManifest ab_manifest = BuildPipeline.BuildAssetBundles(dir_dataoss + "Common\\Lua",
                                                                          arr_abb,
                                                                          BuildAssetBundleOptions.ForceRebuildAssetBundle, build_target);

        if (ab_manifest == null)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 4
0
    //-------------------------------------------------------------------------
    void _buildAssetBundleLua(Casinos._eEditorRunSourcePlatform platform)
    {
        BuildTarget      build_target       = BuildTarget.Android;
        BuildTargetGroup build_target_group = BuildTargetGroup.Android;

        switch (platform)
        {
        case Casinos._eEditorRunSourcePlatform.Android:
            build_target       = BuildTarget.Android;
            build_target_group = BuildTargetGroup.Android;
            break;

        case Casinos._eEditorRunSourcePlatform.IOS:
            build_target       = BuildTarget.iOS;
            build_target_group = BuildTargetGroup.iOS;
            break;

        case Casinos._eEditorRunSourcePlatform.PC:
            build_target       = BuildTarget.StandaloneWindows64;
            build_target_group = BuildTargetGroup.Standalone;
            break;
        }
        EditorUserBuildSettings.SwitchActiveBuildTarget(build_target_group, build_target);

        string dir_assets = EditorContext.Instance.PathAssets;

        List <string> list_file    = new List <string>();
        var           ignore_files = new HashSet <string> {
            "CommonFileList.txt", "Bundle.txt", "Context.txt"
        };

        _getDataFileList2(list_file, ignore_files, dir_assets + "Script.Lua\\");

        string ab_name1 = "lua_android.ab";
        bool   b        = _pakAbLuaEx(list_file, ab_name1, platform, build_target);

        if (!b)
        {
            Debug.LogError("BuildAssetBundle失败!");
            return;
        }

        list_file.Clear();
        _getDataFileList2(list_file, ignore_files, dir_assets + "Script.Lua\\Launch\\");
        ab_name1 = "lua_launch_android.ab";
        b        = _pakAbLuaEx(list_file, ab_name1, platform, build_target);
        if (!b)
        {
            Debug.LogError("BuildAssetBundle失败!");
            return;
        }

        ShowNotification(new GUIContent("BuildAssetBundle Finished!"));
    }
Exemplo n.º 5
0
    //-------------------------------------------------------------------------
    void _changeDataVersion(Casinos._eEditorRunSourcePlatform platform, bool add)
    {
        var settings = EditorContext.Instance.Config.CfgProjectSettings;

        string current_data_version = settings.InitDataVersion;

        switch (platform)
        {
        case Casinos._eEditorRunSourcePlatform.Android:
            current_data_version = settings.CurrentDataVersionANDROID;
            break;

        case Casinos._eEditorRunSourcePlatform.IOS:
            current_data_version = settings.CurrentDataVersionIOS;
            break;

        case Casinos._eEditorRunSourcePlatform.PC:
            current_data_version = settings.CurrentDataVersionANDROID;
            break;
        }

        int data = int.Parse(current_data_version.Replace(".", ""));

        if (add)
        {
            data += 1;
        }
        else
        {
            data -= 1;
        }
        string data_version = data.ToString();

        data_version         = data_version.Insert(1, ".").Insert(4, ".");
        current_data_version = data_version;

        switch (platform)
        {
        case Casinos._eEditorRunSourcePlatform.Android:
            settings.CurrentDataVersionANDROID = current_data_version;
            break;

        case Casinos._eEditorRunSourcePlatform.IOS:
            settings.CurrentDataVersionIOS = current_data_version;
            break;

        case Casinos._eEditorRunSourcePlatform.PC:
            settings.CurrentDataVersionANDROID = current_data_version;
            break;
        }

        EditorContext.Instance.Config.SaveProjectSettings();
    }
Exemplo n.º 6
0
    //-------------------------------------------------------------------------
    void _copyLua(Casinos._eEditorRunSourcePlatform platform)
    {
        string path_src = EditorContext.Instance.PathAssets + "Script.Lua\\";
        string path_dst = string.Empty;

        switch (platform)
        {
        case Casinos._eEditorRunSourcePlatform.Android:
            path_dst = EditorContext.Instance.PathStreamingAssets + "ANDROID\\Script.Lua\\";
            break;

        case Casinos._eEditorRunSourcePlatform.IOS:
            path_dst = EditorContext.Instance.PathStreamingAssets + "IOS\\Script.Lua\\";
            break;

        case Casinos._eEditorRunSourcePlatform.PC:
            path_dst = EditorContext.Instance.PathStreamingAssets + "PC\\Script.Lua\\";
            break;
        }

        _copyDir(platform, path_src, path_dst);
    }
Exemplo n.º 7
0
    //-------------------------------------------------------------------------
    void _genDataFileList(Casinos._eEditorRunSourcePlatform platform)
    {
        string path_dst = string.Empty;

        switch (platform)
        {
        case Casinos._eEditorRunSourcePlatform.Android:
            path_dst = EditorContext.Instance.PathDataOss + "ANDROID\\";
            break;

        case Casinos._eEditorRunSourcePlatform.IOS:
            path_dst = EditorContext.Instance.PathDataOss + "IOS\\";
            break;

        case Casinos._eEditorRunSourcePlatform.PC:
            path_dst = EditorContext.Instance.PathDataOss + "PC\\";
            break;
        }
        path_dst = path_dst.Replace(@"\", "/");

        string file_datafilelist = path_dst + EditorStringDef.FileDataFileList;

        if (File.Exists(file_datafilelist))
        {
            File.Delete(file_datafilelist);
        }

        using (StreamWriter sw = File.CreateText(file_datafilelist))
        {
            var ignore_files = new HashSet <string> {
                "DataFileList.txt", "LaunchInfo.json"
            };
            _genDataFileList2(sw, ignore_files, path_dst, path_dst);
        }

        ShowNotification(new GUIContent("GenDataFileList Finished!"));
    }
Exemplo n.º 8
0
    //-------------------------------------------------------------------------
    //void _clearRawDataAndLua(Casinos._eEditorRunSourcePlatform platform)
    //{
    //    string path_rawdata = string.Empty;
    //    string path_lua = string.Empty;
    //    switch (platform)
    //    {
    //        case Casinos._eEditorRunSourcePlatform.Android:
    //            path_rawdata = EditorContext.Instance.PathStreamingAssets + "ANDROID\\Resources.KingTexasRaw\\";
    //            path_lua = EditorContext.Instance.PathStreamingAssets + "ANDROID\\Script.Lua\\";
    //            break;
    //        case Casinos._eEditorRunSourcePlatform.IOS:
    //            path_rawdata = EditorContext.Instance.PathStreamingAssets + "IOS\\Resources.KingTexasRaw\\";
    //            path_lua = EditorContext.Instance.PathStreamingAssets + "IOS\\Script.Lua\\";
    //            break;
    //        case Casinos._eEditorRunSourcePlatform.PC:
    //            path_rawdata = EditorContext.Instance.PathStreamingAssets + "PC\\Resources.KingTexasRaw\\";
    //            path_lua = EditorContext.Instance.PathStreamingAssets + "PC\\Script.Lua\\";
    //            break;
    //    }

    //    if (Directory.Exists(path_rawdata)) Directory.Delete(path_rawdata, true);
    //    if (Directory.Exists(path_lua)) Directory.Delete(path_lua, true);
    //}

    //-------------------------------------------------------------------------
    //void _copyRawData(Casinos._eEditorRunSourcePlatform platform)
    //{
    //    string path_src = EditorContext.Instance.PathAssets + "Resources.KingTexasRaw\\";
    //    string path_dst = string.Empty;
    //    switch (platform)
    //    {
    //        case Casinos._eEditorRunSourcePlatform.Android:
    //            path_dst = EditorContext.Instance.PathStreamingAssets + "ANDROID\\Resources.KingTexasRaw\\";
    //            break;
    //        case Casinos._eEditorRunSourcePlatform.IOS:
    //            path_dst = EditorContext.Instance.PathStreamingAssets + "IOS\\Resources.KingTexasRaw\\";
    //            break;
    //        case Casinos._eEditorRunSourcePlatform.PC:
    //            path_dst = EditorContext.Instance.PathStreamingAssets + "PC\\Resources.KingTexasRaw\\";
    //            break;
    //    }

    //    _copyDir(platform, path_src, path_dst);
    //}

    //-------------------------------------------------------------------------
    //void _copyLua(Casinos._eEditorRunSourcePlatform platform)
    //{
    //    string path_src = EditorContext.Instance.PathAssets + "Script.Lua\\";
    //    string path_dst = string.Empty;
    //    switch (platform)
    //    {
    //        case Casinos._eEditorRunSourcePlatform.Android:
    //            path_dst = EditorContext.Instance.PathStreamingAssets + "ANDROID\\Script.Lua\\";
    //            break;
    //        case Casinos._eEditorRunSourcePlatform.IOS:
    //            path_dst = EditorContext.Instance.PathStreamingAssets + "IOS\\Script.Lua\\";
    //            break;
    //        case Casinos._eEditorRunSourcePlatform.PC:
    //            path_dst = EditorContext.Instance.PathStreamingAssets + "PC\\Script.Lua\\";
    //            break;
    //    }

    //    _copyDir(platform, path_src, path_dst);
    //}

    //-------------------------------------------------------------------------
    void _copyDir(Casinos._eEditorRunSourcePlatform platform, string path_src, string path_dst)
    {
        var path_dst1 = path_dst.Replace("\\", "/");
        var path_src1 = path_src.Replace("\\", "/");

        DirectoryInfo dir = new DirectoryInfo(path_src1);

        FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();// 获取目录下(不包含子目录)的文件和子目录
        foreach (FileSystemInfo i in fileinfo)
        {
            if (i is DirectoryInfo)// 判断是否文件夹
            {
                if (i.Name == ".idea" || i.Name == ".ideadictionaries")
                {
                    continue;
                }

                if (!Directory.Exists(path_dst1 + i.Name))
                {
                    Directory.CreateDirectory(path_dst1 + i.Name);
                }
                _copyDir(platform, i.FullName, path_dst1 + i.Name);// 递归调用复制子文件夹
            }
            else
            {
                string file_extension = Path.GetExtension(i.FullName);
                if (DoNotPackFileExtention.Contains(file_extension) ||
                    i.Name == "Context.lua" ||
                    i.Name == "Bundle.lua")
                {
                    continue;
                }

                File.Copy(i.FullName, path_dst1 + "/" + i.Name, true);// 不是文件夹即复制文件,true表示可以覆盖同名文件
            }
        }
    }
Exemplo n.º 9
0
    //-------------------------------------------------------------------------
    bool _pakABSingleEx(Dictionary <string, List <string> > map_single_pkg,
                        Casinos._eEditorRunSourcePlatform platform, BuildTarget build_target)
    {
        string path_assetex = "";

        foreach (var i in map_single_pkg)
        {
            path_assetex = i.Value[0];
            path_assetex = path_assetex.Replace("Assets/", "");
            path_assetex = path_assetex.Replace(AssetBundleSingleFoldName + "/", "");
            path_assetex = EditorContext.Instance.PathDataOss + platform.ToString() + "/" + path_assetex;
            string file_name      = Path.GetFileName(path_assetex);
            string file_extension = Path.GetExtension(path_assetex);
            string obj_dir        = path_assetex.Replace(file_name, "");

            if (!Directory.Exists(obj_dir))
            {
                Directory.CreateDirectory(obj_dir);
            }

            AssetBundleBuild[] arr_abb = new AssetBundleBuild[i.Value.Count];
            for (int n = 0; n < i.Value.Count; n++)
            {
                string f       = i.Value[n];
                string ab_name = Path.GetFileNameWithoutExtension(f);

                AssetBundleBuild abb;
                abb.assetBundleName    = ab_name + ".ab";
                abb.assetBundleVariant = "";
                abb.addressableNames   = null;

                var           dependences             = AssetDatabase.GetDependencies(f);
                List <string> list_needbuildassetname = new List <string>(dependences.Length);
                foreach (var j in dependences)
                {
                    if (j.EndsWith(".cs") || j.EndsWith(".ttf"))
                    {
                        continue;
                    }
                    list_needbuildassetname.Add(j);
                }

                int asset_index = 0;
                abb.assetNames = new string[list_needbuildassetname.Count];
                foreach (var j in list_needbuildassetname)
                {
                    abb.assetNames[asset_index++] = j;
                }

                arr_abb[n] = abb;
            }

            if (file_extension == ".prefab")
            {
                foreach (var k in arr_abb)
                {
                    AssetBundleBuild[] arr_abb1 = new AssetBundleBuild[1] {
                        k
                    };
                    AssetBundleManifest ab_manifest = BuildPipeline.BuildAssetBundles(obj_dir, arr_abb1,
                                                                                      BuildAssetBundleOptions.ForceRebuildAssetBundle, build_target);
                    if (ab_manifest == null)
                    {
                        Debug.LogError("BuildAssetBundle失败!");
                        return(false);
                    }
                }
            }
            else
            {
                AssetBundleManifest ab_manifest = BuildPipeline.BuildAssetBundles(obj_dir, arr_abb,
                                                                                  BuildAssetBundleOptions.ForceRebuildAssetBundle, build_target);
                if (ab_manifest == null)
                {
                    Debug.LogError("BuildAssetBundle失败!");
                    return(false);
                }
            }
        }

        return(true);
    }
Exemplo n.º 10
0
    //-------------------------------------------------------------------------
    void _buildAssetBundle(Casinos._eEditorRunSourcePlatform platform, bool selected_or_all)
    {
        BuildTarget      build_target       = BuildTarget.Android;
        BuildTargetGroup build_target_group = BuildTargetGroup.Android;

        switch (platform)
        {
        case Casinos._eEditorRunSourcePlatform.Android:
            build_target       = BuildTarget.Android;
            build_target_group = BuildTargetGroup.Android;
            break;

        case Casinos._eEditorRunSourcePlatform.IOS:
            build_target       = BuildTarget.iOS;
            build_target_group = BuildTargetGroup.iOS;
            break;

        case Casinos._eEditorRunSourcePlatform.PC:
            build_target       = BuildTarget.StandaloneWindows64;
            build_target_group = BuildTargetGroup.Standalone;
            break;
        }
        EditorUserBuildSettings.SwitchActiveBuildTarget(build_target_group, build_target);

        UnityEngine.Object[] select_objs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);

        Dictionary <string, List <string> > map_single_pkg  = new Dictionary <string, List <string> >();
        Dictionary <string, List <string> > map_fold_pkg    = new Dictionary <string, List <string> >();
        Dictionary <string, List <string> > map_fold_launch = new Dictionary <string, List <string> >();

        foreach (var i in select_objs)
        {
            string path_asset = AssetDatabase.GetAssetPath(i);

            string extension = Path.GetExtension(path_asset);
            if (DoNotPackFileExtention.Contains(extension) || string.IsNullOrEmpty(extension))
            {
                continue;
            }

            string file_name = Path.GetFileName(path_asset);

            if (path_asset.Contains(AssetBundleSingleFoldName))
            {
                string key = Directory.GetParent(path_asset).Name;

                List <string> list_directory = null;
                map_single_pkg.TryGetValue(key, out list_directory);
                if (list_directory == null)
                {
                    list_directory      = new List <string>();
                    map_single_pkg[key] = list_directory;
                }

                list_directory.Add(path_asset);
            }
            else if (path_asset.Contains(AssetBundlePkgFoldFoldName))
            {
                string fold = path_asset;
                fold = fold.Replace("Assets/", "");
                fold = fold.Replace(AssetBundlePkgFoldFoldName + "/", "");
                fold = EditorContext.Instance.PathDataOss + platform.ToString() + "/" + fold;
                fold = fold.Replace(file_name, "");

                List <string> list_directory = null;
                map_fold_pkg.TryGetValue(fold, out list_directory);
                if (list_directory == null)
                {
                    list_directory     = new List <string>();
                    map_fold_pkg[fold] = list_directory;
                }

                list_directory.Add(path_asset);
            }
            else if (path_asset.Contains(AssetBundleLaunchFoldName))
            {
                string fold = path_asset;
                fold = fold.Replace("Assets/", "");
                fold = EditorContext.Instance.PathDataOss + platform.ToString() + "/" + fold;
                fold = fold.Replace(file_name, "");

                List <string> list_directory = null;
                map_fold_launch.TryGetValue(fold, out list_directory);
                if (list_directory == null)
                {
                    list_directory        = new List <string>();
                    map_fold_launch[fold] = list_directory;
                }

                list_directory.Add(path_asset);
            }
        }

        bool b = _pakABSingleEx(map_single_pkg, platform, build_target);

        if (!b)
        {
            Debug.LogError("BuildAssetBundle失败!");
            return;
        }

        foreach (var i in map_fold_pkg)
        {
            List <string>       list_samefold_file = i.Value;
            AssetBundleManifest ab_manifest        = _pakABFoldEx(i.Key, list_samefold_file, build_target);

            if (ab_manifest == null)
            {
                Debug.LogError("BuildAssetBundle失败!");
                return;
            }
        }

        foreach (var i in map_fold_launch)
        {
            List <string>       list_samefold_file = i.Value;
            AssetBundleManifest ab_manifest        = _pakABFoldEx(i.Key, list_samefold_file, build_target);

            if (ab_manifest == null)
            {
                Debug.LogError("BuildAssetBundle失败!");
                return;
            }
        }

        ShowNotification(new GUIContent("BuildAssetBundle Finished!"));
    }