少年修仙传客户端基础资源
client_Wu Xijin
2019-01-16 d53a782e2fd91ffc47dad0dd5a080ee451a351b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
 
public class AssetBundleBuildExtersion
{
    public static void Build(string _output, string _category, BuildAssetBundleOptions _bundleOption, BuildTarget _buildTarget)
    {
        var assetBundles = AssetDatabase.GetAllAssetBundleNames();
 
        List<string> targetAssetBundles = new List<string>();
        for (int i = 0; i < assetBundles.Length; i++)
        {
            var bundleName = assetBundles[i];
            if (bundleName.StartsWith(_category))
            {
                targetAssetBundles.Add(bundleName);
            }
        }
 
        var assets = new List<AssetBundleBuild>();
 
        for (int i = 0; i < targetAssetBundles.Count; i++)
        {
            var assetBundleBuild = new AssetBundleBuild();
            assetBundleBuild.assetBundleName = targetAssetBundles[i];
            assetBundleBuild.assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(targetAssetBundles[i]);
            assets.Add(assetBundleBuild);
        }
 
        var rootPath = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, _category);
        var mainFile = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, GetMainFestFileName(_buildTarget));
        var mainFileRename = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, _category, "_assetbundle");
        var manifest = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, GetMainFestFileName(_buildTarget), ".manifest");
        var manifestRename = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, _category, "_assetbundle.manifest");
 
        if (Directory.Exists(rootPath))
        {
            Directory.Delete(rootPath, true);
        }
 
        Directory.CreateDirectory(rootPath);
 
        if (File.Exists(mainFileRename))
        {
            File.Delete(mainFileRename);
        }
 
        if (File.Exists(manifestRename))
        {
            File.Delete(manifestRename);
        }
 
        BuildPipeline.BuildAssetBundles(_output, assets.ToArray(), _bundleOption, _buildTarget);
 
        File.Move(mainFile, mainFileRename);
        File.Move(manifest, manifestRename);
 
    }
 
    static string GetMainFestFileName(BuildTarget _target)
    {
        switch (_target)
        {
            case BuildTarget.StandaloneWindows:
                return "standalone";
            case BuildTarget.Android:
                return "android";
            case BuildTarget.iOS:
                return "ios";
            default:
                return string.Empty;
        }
    }
 
    [MenuItem("Assets/BuildAssetBundle ( Test )")]
    public static void BuildTest()
    {
        if (Selection.activeObject != null)
        {
            var path = AssetDatabase.GetAssetPath(Selection.activeObject);
            var importer = AssetImporter.GetAtPath(path);
 
            if (importer != null)
            {
                var ab = importer.assetBundleName;
                if (!string.IsNullOrEmpty(ab))
                {
 
                    var assetBundles = AssetDatabase.GetAllAssetBundleNames();
 
                    List<string> targetAssetBundles = new List<string>();
                    for (int i = 0; i < assetBundles.Length; i++)
                    {
                        var bundleName = assetBundles[i];
                        if (bundleName == ab)
                        {
                            targetAssetBundles.Add(bundleName);
                        }
                    }
 
                    var assets = new List<AssetBundleBuild>();
                    for (int i = 0; i < targetAssetBundles.Count; i++)
                    {
                        var assetBundleBuild = new AssetBundleBuild();
                        assetBundleBuild.assetBundleName = targetAssetBundles[i];
                        assetBundleBuild.assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(targetAssetBundles[i]);
                        assets.Add(assetBundleBuild);
                    }
 
                    var opt = BuildAssetBundleOptions.None
                        | BuildAssetBundleOptions.ChunkBasedCompression
                        | BuildAssetBundleOptions.DeterministicAssetBundle;
 
                    var dirctory = Application.dataPath + "/BundleTest";
                    if (!Directory.Exists(dirctory))
                    {
                        Directory.CreateDirectory(dirctory);
                    }
                    BuildPipeline.BuildAssetBundles(dirctory, assets.ToArray(), opt, BuildTarget.Android);
                }
            }
 
        }
    }
 
}