Skip to content

Commit 9711fc8

Browse files
committed
AssetBundle打包工具提交
1 parent 8a2aab5 commit 9711fc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2626
-0
lines changed

Assets/BundleBuildTool.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/BundleBuildTool/Src.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/BundleBuildTool/Src/Editor.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/BundleBuildTool/Src/Editor/AssetHelper.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using System.Collections.Generic;
4+
5+
namespace BundleManager
6+
{
7+
public static class AssetDepend
8+
{
9+
public static string[] GetDependenciesCache(string assetPath)
10+
{
11+
string[] files = { assetPath };
12+
return GetDependenciesCache(files);
13+
}
14+
15+
public static string[] GetDependenciesCache(string[] files)
16+
{
17+
List<string> ret = new List<string>();
18+
for (int i = 0; i < files.Length; ++i)
19+
{
20+
DependData data = null;
21+
m_dict.TryGetValue(files[i], out data);
22+
23+
if (data == null)
24+
{
25+
string[] deps = GetDependencies(files[i]);
26+
data = new DependData();
27+
data.assetPath = files[i];
28+
data.dependPath = deps;
29+
data.InterString();
30+
m_dict.Add(data.assetPath, data);
31+
}
32+
ret.AddRange(data.dependPath);
33+
}
34+
return ret.ToArray();
35+
}
36+
37+
public static string[] GetDependencies(string file)
38+
{
39+
string[] files = { file };
40+
return GetDependencies(files);
41+
}
42+
43+
public static string[] GetDependencies(string[] files)
44+
{
45+
Dictionary<string, string> dict = new Dictionary<string, string>();
46+
for (int i = 0; i < files.Length; ++i)
47+
{
48+
if (!dict.ContainsKey(files[i]))
49+
{
50+
dict.Add(files[i], files[i]);
51+
}
52+
getDependencies(files[i], dict);
53+
}
54+
return new List<string>(dict.Keys).ToArray();
55+
}
56+
57+
private static void getDependencies(string file, Dictionary<string, string> dict)
58+
{
59+
string main_ext = System.IO.Path.GetExtension(file).ToLower();
60+
string[] dep = AssetDatabase.GetDependencies(file, false);
61+
62+
// dirty material has dirty texture dependencies
63+
if (main_ext == ".mat")
64+
{
65+
Material mat = AssetDatabase.LoadAssetAtPath<Material>(file);
66+
if (mat == null)
67+
{
68+
return;
69+
}
70+
MaterialProperty[] proTes = MaterialEditor.GetMaterialProperties(new Object[] {mat});
71+
for (int i = 0; i < proTes.Length; ++i)
72+
{
73+
if (proTes[i].type == MaterialProperty.PropType.Texture)
74+
{
75+
Texture tex = mat.GetTexture(proTes[i].name);
76+
string path = AssetDatabase.GetAssetPath(tex);
77+
if (!dict.ContainsKey(path))
78+
{
79+
dict.Add(path, path);
80+
}
81+
}
82+
}
83+
for (int i = 0; i < dep.Length; ++i)
84+
{
85+
// assume material only depencies Texture & Shader
86+
if (dep[i].EndsWith(".shader") && !dict.ContainsKey(dep[i]))
87+
{
88+
dict.Add(dep[i], dep[i]);
89+
}
90+
}
91+
Resources.UnloadAsset(mat);
92+
}
93+
else
94+
{
95+
for (int i = 0; i < dep.Length; ++i)
96+
{
97+
if (!dict.ContainsKey(dep[i]))
98+
{
99+
dict.Add(dep[i], dep[i]);
100+
getDependencies(dep[i], dict);
101+
}
102+
}
103+
}
104+
}
105+
106+
private class DependData
107+
{
108+
public string assetPath;
109+
public string[] dependPath;
110+
111+
public void InterString()
112+
{
113+
assetPath = string.Intern(assetPath);
114+
for (int i = 0; dependPath != null && i < dependPath.Length; ++i)
115+
{
116+
dependPath[i] = string.Intern(dependPath[i]);
117+
}
118+
}
119+
}
120+
121+
public static void Clear()
122+
{
123+
m_dict.Clear();
124+
}
125+
126+
private static Dictionary<string, DependData> m_dict = new Dictionary<string, DependData>();
127+
}
128+
}

Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetDepend.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.IO;
3+
using UnityEngine;
4+
using UnityEditor;
5+
using System.Collections.Generic;
6+
7+
namespace BundleManager
8+
{
9+
public delegate List<UnityEngine.Object> FilterDelegate(UnityEngine.Object[] assets, BundleType bundleType, string assetPath);
10+
11+
public class AssetFilter
12+
{
13+
public static void ClearFilter()
14+
{
15+
m_filterList.Clear();
16+
}
17+
public static void RegisterFilter(FilterDelegate filterDelegate)
18+
{
19+
m_filterList.Add(filterDelegate);
20+
}
21+
public static List<UnityEngine.Object> FilterObjectByType(UnityEngine.Object[] assetsAtPath, BundleType bundleType, string assetPath)
22+
{
23+
List<UnityEngine.Object> ret = new List<UnityEngine.Object>();
24+
switch (bundleType)
25+
{
26+
case BundleType.FBX:
27+
foreach (UnityEngine.Object obj in assetsAtPath)
28+
{
29+
if (obj == null)
30+
continue;
31+
Type type = obj.GetType();
32+
if (type == typeof(AnimationClip) && obj.name != EditorConst.EDITOR_ANICLIP_NAME)
33+
{
34+
ret.Add(obj);
35+
}
36+
else
37+
{
38+
ret.Add(obj);
39+
}
40+
}
41+
break;
42+
case BundleType.Controller:
43+
foreach (UnityEngine.Object obj in assetsAtPath)
44+
{
45+
46+
if (obj == null)
47+
continue;
48+
string typeName = obj.GetType().ToString();
49+
if (typeName.Contains("AnimatorStateMachine") || typeName.Contains("AnimatorStateTransition") ||
50+
typeName.Contains("AnimatorState") || typeName.Contains("AnimatorTransition") ||
51+
typeName.Contains("BlendTree"))
52+
continue;
53+
ret.Add(obj);
54+
}
55+
56+
break;
57+
default:
58+
ret.AddRange(assetsAtPath);
59+
break;
60+
}
61+
if (ret.Count == 0)
62+
{
63+
ret.AddRange(assetsAtPath);
64+
}
65+
66+
for (int i = 0; i < m_filterList.Count; ++i)
67+
{
68+
ret = m_filterList[i](ret.ToArray(), bundleType, assetPath);
69+
}
70+
71+
return ret;
72+
}
73+
74+
private static List<FilterDelegate> m_filterList = new List<FilterDelegate>();
75+
}
76+
}

Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetFilter.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using UnityEngine;
2+
using System.Collections.Generic;
3+
4+
namespace BundleManager
5+
{
6+
public class AssetPathInfo
7+
{
8+
public string Path = "Unknown";
9+
// Index Of BundleImportData
10+
public int Index = -1;
11+
12+
public static AssetPathInfo CreatePathInfo(string assetPath)
13+
{
14+
AssetPathInfo pathInfo = null;
15+
if (!m_dictPathInfo.TryGetValue(assetPath, out pathInfo))
16+
{
17+
pathInfo = new AssetPathInfo();
18+
pathInfo.Path = assetPath;
19+
m_dictPathInfo.Add(assetPath, pathInfo);
20+
}
21+
return pathInfo;
22+
}
23+
24+
private static Dictionary<string, AssetPathInfo> m_dictPathInfo = new Dictionary<string, AssetPathInfo>();
25+
}
26+
}

Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetPathInfo.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)