Пример #1
0
    /// <summary>
    /// 把制定打包的AB文件移动到streamingAssets文件夹中适当的位置,要先清空文件夹后移动
    /// </summary>
    /// <param name="bt">BuildTarget的类型,一般都是打目标版本的类型</param>
    public static void MoveAssetBundleToStreamingAssets(BuildTarget bt)
    {
        RuntimePlatform runtimePlatform = AssetBundleSettingHelperEditor.BuildTargetToRuntimePlatform(bt);
        string          versionName     = GetABSH().RuntimePlatformToSimplifyName(runtimePlatform);

        //string streamingAssetsPath = AssetBundleHelper.GetStreamingAssetsPath();
        //清理三个文件夹
        ABPInfo[] deleteABPIs = new ABPInfo[3];
        deleteABPIs[0] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.WindowsEditor));
        deleteABPIs[1] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.OSXEditor));
        deleteABPIs[2] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.Android));
        foreach (var abpiTmp in deleteABPIs)
        {
            if (Directory.Exists(abpiTmp.Dir_Relative))
            {
                Directory.Delete(abpiTmp.Dir_Relative, true);
            }
        }
        var abpiTar = GetABSH().GetStreamingAssetABPath(versionName);

        Directory.CreateDirectory(abpiTar.Dir_Relative);
        var abpi = GetABSH().GetAssetBundleOutputPath(versionName);

        CopyFolder(abpi.Dir_Relative, abpiTar.Dir_Relative);

        AssetDatabase.Refresh();
    }
    //绘制窗口时调用
    void OnGUI()
    {
        //***************************************************************************
        GUILayout.BeginArea(new Rect(0, 0, position.width, LayoutOneHeight));
        GUILayout.Label("编辑器模式运行的过程中:", titleSytle);
        //是否使用bundle
        {
            GUILayout.BeginHorizontal();
            {
                SetTab(2);
                GUILayout.Label("编辑器模式下是否使用AssetBundle:", NormalSytle, GUILayout.Width(260));
                if (ABSH.UseAssetBundle)
                {
                    //GUI.enabled = false;
                    GUILayout.Label("使用AB", RedTextFieldSytle, GUILayout.Width(100));
                    //GUI.enabled = true;
                }
                else
                {
                    GUI.enabled = false;
                    GUILayout.Label("不使用AB", RedTextFieldSytle, GUILayout.Width(100));
                    GUI.enabled = true;
                }
                if (GUILayout.Button("更改", ResetButtonSytle, GUILayout.Width(100)))
                {
                    ABSH.UseAssetBundle = !ABSH.UseAssetBundle;
                    bDirty = true;
                }
                //AssetBundleHelper.UseAssetBundle = GUILayout.Toggle(AssetBundleHelper.UseAssetBundle, "", ToggleSytle, GUILayout.ExpandWidth(false));
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndArea();
        //**************************************************************************
        GUILayout.BeginArea(new Rect(0, LayoutOneHeight, position.width, position.height));
        GUILayout.Label("Build AssetBundle的时候:", titleSytle);
        GUILayout.Label("本打包脚本会将制定目录下所有的资源单独打包,被引用的资源如果被共享则单独打包,未共享的被一同打包:", titleSytle);

        //输出目录
        {
            GUILayout.BeginHorizontal();
            {
                SetTab(1);
                GUILayout.Label("AssetBundle输出的目录(相对与Assets目录上一层的相对目录,修改前请思考一下):", NormalSytle);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            {
                SetTab(2);
                var EditString = (GUILayout.TextField(ABSH.ABOutputPath, TextFieldSytle, GUILayout.Width(700)));
                if (!EditString.Equals(ABSH.ABOutputPath))               //BuildBundleManager.AssetBundlePath
                {
                    ABSH.ABOutputPath = EditString;
                    bDirty            = true;
                }
                //防止不小心修改,可以重置为默认值
                if (GUILayout.Button("重置为默认", ResetButtonSytle, GUILayout.Width(100)))
                {
                    //BuildBundleManager.AssetBundlePath = AssetBundleHelper.Ins.ABSettingHelper.ABOutputPath;
                }
            }
            GUILayout.EndHorizontal();
        }
        //打包目录
        {
            GUILayout.BeginHorizontal();
            {
                SetTab(1);
                GUILayout.Label("需要build assetbundle的目录(相对与Assets目录上一层的相对目录,修改前请思考一下):", NormalSytle);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            {
                SetTab(1);
                GUILayout.Label("如果真的要改这个,请记得把AssetBundleHelper.AssetBundlePrefixPath一同修改,这样游戏内才能正确找到bundle位置:", RedNormalSytle);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            {
                SetTab(2);
                var EditString = (GUILayout.TextField(ABSH.NeedBuildABPath, TextFieldSytle, GUILayout.Width(700)));                //BuildBundleManager.NeedBuildAssetBundlePath
                if (!EditString.Equals(ABSH.NeedBuildABPath))
                {
                    ABSH.NeedBuildABPath = EditString;
                    bDirty = true;
                }
                //防止不小心修改,可以重置为默认值
                if (GUILayout.Button("重置为默认", ResetButtonSytle, GUILayout.Width(100)))
                {
                    //BuildBundleManager.NeedBuildAssetBundlePath = BuildBundleManager.needBuildAssetBundlePath;
                }
            }
            GUILayout.EndHorizontal();
        }
        //xml信息
        {
            //AB信息
            {
                GUILayout.BeginHorizontal();
                {
                    SetTab(1);
                    GUILayout.Label("ABInfo 的xml文件路径(相对与Assets目录上一层的相对目录,这个并不准备让你修改,但是让你看一下在哪):", NormalSytle);
                }
                GUILayout.EndHorizontal();
                //ios系列
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUILayout.Label("iOS系列:", NormalSytle);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUI.enabled = false;
                    var abpi = ABSH.GetABInfoXmlPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.OSXEditor));
                    GUILayout.Label(abpi.FullName_RelativePath, TextFieldSytle, GUILayout.Width(700));
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                //android系列
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUILayout.Label("android系列:", NormalSytle);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUI.enabled = false;
                    var abpi = ABSH.GetABInfoXmlPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.Android));
                    GUILayout.Label(abpi.FullName_RelativePath, TextFieldSytle, GUILayout.Width(700));
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                //Windows系列
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUILayout.Label("Windows系列:", NormalSytle);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUI.enabled = false;
                    var abpi = ABSH.GetABInfoXmlPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.WindowsEditor));
                    GUILayout.Label(abpi.FullName_RelativePath, TextFieldSytle, GUILayout.Width(700));
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
            }
            //ABDiffer信息
            {
                GUILayout.BeginHorizontal();
                {
                    SetTab(1);
                    GUILayout.Label("ABInfo 的xml文件路径(相对与Assets目录上一层的相对目录,这个并不准备让你修改,但是让你看一下在哪):", NormalSytle);
                }
                GUILayout.EndHorizontal();
                //ios系列
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUILayout.Label("iOS系列:", NormalSytle);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUI.enabled = false;
                    var abpi = ABSH.GetDifferXmlPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.OSXEditor));
                    GUILayout.Label(abpi.FullName_RelativePath, TextFieldSytle, GUILayout.Width(700));
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                //android系列
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUILayout.Label("android系列:", NormalSytle);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUI.enabled = false;
                    var abpi = ABSH.GetDifferXmlPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.Android));
                    GUILayout.Label(abpi.FullName_RelativePath, TextFieldSytle, GUILayout.Width(700));
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                //Windows系列
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUILayout.Label("Windows系列:", NormalSytle);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    SetTab(2);
                    GUI.enabled = false;
                    var abpi = ABSH.GetDifferXmlPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.WindowsEditor));
                    GUILayout.Label(abpi.FullName_RelativePath, TextFieldSytle, GUILayout.Width(700));
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
            }
        }
        GUILayout.EndArea();
        //*****************************************************************************
    }