Skip to content

Commit 78edee3

Browse files
committed
重构代码,增加EditorCommon命名空间
1 parent a9450d6 commit 78edee3

Some content is hidden

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

57 files changed

+1677
-1363
lines changed

Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetDepend.cs renamed to Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetDepot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace BundleManager
66
{
7-
public static class AssetDepend
7+
public static class AssetDepot
88
{
99
public static string[] GetDependenciesCache(string assetPath)
1010
{

Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetDepend.cs.meta renamed to Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetDepot.cs.meta

File renamed without changes.

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

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using UnityEditor;
55
using System.Collections.Generic;
6+
using EditorCommon;
67

78
namespace BundleManager
89
{
@@ -18,49 +19,15 @@ public static void RegisterFilter(FilterDelegate filterDelegate)
1819
{
1920
m_filterList.Add(filterDelegate);
2021
}
21-
public static List<UnityEngine.Object> FilterObjectByType(UnityEngine.Object[] assetsAtPath, BundleType bundleType, string assetPath)
22+
public static List<UnityEngine.Object> FilterObjectByType(UnityEngine.Object[] assets, BundleType bundleType, string assetPath)
2223
{
2324
List<UnityEngine.Object> ret = new List<UnityEngine.Object>();
24-
switch (bundleType)
25+
foreach (UnityEngine.Object asset in assets)
2526
{
26-
case BundleType.FBX:
27-
foreach (UnityEngine.Object obj in assetsAtPath)
27+
if (FilterObject(asset, bundleType))
2828
{
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-
}
29+
ret.Add(asset);
4030
}
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);
6431
}
6532

6633
for (int i = 0; i < m_filterList.Count; ++i)
@@ -71,6 +38,32 @@ public static void RegisterFilter(FilterDelegate filterDelegate)
7138
return ret;
7239
}
7340

41+
private static bool FilterObject(UnityEngine.Object asset, BundleType bundleType)
42+
{
43+
if (asset == null)
44+
{
45+
return false;
46+
}
47+
48+
switch (bundleType)
49+
{
50+
case BundleType.FBX:
51+
return !(asset.GetType() == typeof(AnimationClip) && asset.name == EditorConst.EDITOR_ANICLIP_NAME);
52+
case BundleType.Controller:
53+
string typeName = asset.GetType().ToString();
54+
for (int i = 0 ; i < EditorConst.EDITOR_CONTROL_NAMES.Length; ++i)
55+
{
56+
if (typeName.Contains(EditorConst.EDITOR_CONTROL_NAMES[i]))
57+
{
58+
return false;
59+
}
60+
}
61+
return true;
62+
default:
63+
return true;
64+
}
65+
}
66+
7467
private static List<FilterDelegate> m_filterList = new List<FilterDelegate>();
7568
}
7669
}

Assets/BundleBuildTool/Src/Editor/AssetHelper/AssetSize.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,48 @@
33
using UnityEngine.Profiling;
44
using UnityEditor;
55
using System.Collections.Generic;
6+
using EditorCommon;
67

78
namespace BundleManager
89
{
910
public class AssetSize
1011
{
11-
public static long CalcAssetSize(string path, BundleType type)
12+
public static long CalcAssetSize(string assetPath, BundleType type)
1213
{
13-
path = PathConfig.FormatAssetPath(path);
14-
path = PathConfig.NormalizePathSplash(path);
14+
assetPath = EditorPath.FormatAssetPath(assetPath);
15+
assetPath = EditorPath.NormalizePathSplash(assetPath);
1516

1617
long ret = 0;
17-
if (m_pathFileSize.TryGetValue(path, out ret))
18+
if (m_pathFileSize.TryGetValue(assetPath, out ret))
1819
{
1920
return ret;
2021
}
2122

22-
UnityEngine.Object[] objs = null;
23+
UnityEngine.Object[] assets = null;
2324

2425
switch (type)
2526
{
2627
case BundleType.Texture:
27-
objs = AssetDatabase.LoadAllAssetsAtPath(path);
28-
for (int i = 0; i < objs.Length; ++i)
28+
assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
29+
for (int i = 0; i < assets.Length; ++i)
2930
{
30-
if (objs[i] is Texture)
31+
if (assets[i] is Texture)
3132
{
32-
#pragma warning disable 0618
33-
ret += Profiler.GetRuntimeMemorySize(objs[i]);
34-
#pragma warning restore 0618
33+
ret += EditorTool.GetRuntimeMemorySize(assets[i]);
3534
}
3635
}
3736

3837
break;
3938
case BundleType.Material:
40-
string[] deps = AssetDepend.GetDependenciesCache(path);
39+
string[] deps = AssetDepot.GetDependenciesCache(assetPath);
4140
for (int i = 0; i < deps.Length; ++i)
4241
{
43-
if (PathConfig.IsTexture(deps[i]))
42+
if (EditorPath.IsTexture(deps[i]))
4443
{
4544
BundleImportData data = BundleDataControl.Instance.GetPathImportData(deps[i]);
4645
if (data == null || data.SkipData)
4746
{
48-
ret += EditorCommon.CalculateTextureSizeBytes(deps[i]);
47+
ret += EditorTool.CalculateTextureSizeBytes(deps[i]);
4948
}
5049
}
5150
}
@@ -54,30 +53,28 @@ public static long CalcAssetSize(string path, BundleType type)
5453
case BundleType.FBX:
5554
case BundleType.Controller:
5655
case BundleType.Animation:
57-
objs = AssetDatabase.LoadAllAssetsAtPath(path);
58-
List<UnityEngine.Object> list = AssetFilter.FilterObjectByType(objs, type, path);
56+
assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
57+
List<UnityEngine.Object> list = AssetFilter.FilterObjectByType(assets, type, assetPath);
5958
for (int i = 0; i < list.Count; ++i)
6059
{
61-
#pragma warning disable 0618
62-
ret += Profiler.GetRuntimeMemorySize(list[i]);
63-
#pragma warning restore 0618
60+
ret += EditorTool.GetRuntimeMemorySize(list[i]);
6461
}
6562
break;
6663
default:
67-
FileInfo fileInfo = new FileInfo(path);
64+
FileInfo fileInfo = new FileInfo(assetPath);
6865
ret = fileInfo.Length;
6966
break;
7067
}
7168

72-
for (int i = 0; objs != null && i < objs.Length; ++i)
69+
for (int i = 0; assets != null && i < assets.Length; ++i)
7370
{
74-
if ((!(objs[i] is GameObject)) && (!(objs[i] is Component)))
71+
if ((!(assets[i] is GameObject)) && (!(assets[i] is Component)))
7572
{
76-
Resources.UnloadAsset(objs[i]);
73+
Resources.UnloadAsset(assets[i]);
7774
}
7875
}
7976

80-
m_pathFileSize.Add(path, ret);
77+
m_pathFileSize.Add(assetPath, ret);
8178
return ret;
8279
}
8380
public static void Clear()

Assets/BundleBuildTool/Src/Editor/BuildConfig.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using UnityEditor;
3+
using EditorCommon;
34

45
namespace BundleManager
56
{
@@ -12,7 +13,7 @@ public static class BuildConfig
1213
public static string InterpretedRootPath = "Assets/BundleBuildTool/Bundle/";
1314
public static string ResourceRootPath = "Assets";
1415
public static string BundleDataPath = InterpretedRootPath + "BundleData.txt";
15-
public static string BundleStatePath = InterpretedRootPath + "BundleStatePath.txt";
16+
public static string BundleStatePath = InterpretedRootPath + "BundleState.txt";
1617
public static string BundleImportDataPath = InterpretedRootPath + "BundleImportData.txt";
1718

1819
public static BuildAssetBundleOptions CurrentBuildAssetOpts

Assets/BundleBuildTool/Src/Editor/BundleDefine/BundleDict.cs renamed to Assets/BundleBuildTool/Src/Editor/BundleDefine/BundleNexus.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,49 @@
44

55
namespace BundleManager
66
{
7-
public class BundleDict
7+
public class BundleNexus
88
{
9-
public void AddPathWithBundleName(string path, string bundleName)
9+
public void AddPathToBundle(string path, string bundleName)
1010
{
11-
if (!m_pathToBundleName.ContainsKey(path))
11+
if (!m_pathToBundle.ContainsKey(path))
1212
{
13-
m_pathToBundleName.Add(path, bundleName);
13+
m_pathToBundle.Add(path, bundleName);
1414
}
1515
else
1616
{
17-
m_pathToBundleName[path] = bundleName;
17+
m_pathToBundle[path] = bundleName;
1818
}
1919
}
2020

21-
public void AddBundleDepend(string bundleName, string depBundleName)
21+
public void AddBundleRely(string bundleName, string relyBundle)
2222
{
2323
List<string> list = null;
24-
if (!m_bundleDependDict.TryGetValue(bundleName, out list))
24+
if (!m_bundleRely.TryGetValue(bundleName, out list))
2525
{
2626
list = new List<string>();
27-
m_bundleDependDict.Add(bundleName, list);
27+
m_bundleRely.Add(bundleName, list);
2828
}
2929

30-
if (!list.Contains(depBundleName))
30+
if (!list.Contains(relyBundle))
3131
{
32-
list.Add(depBundleName);
32+
list.Add(relyBundle);
3333
}
3434
}
3535

3636
public void Clear()
3737
{
38-
m_bundleDependDict.Clear();
39-
m_pathToBundleName.Clear();
38+
m_bundleRely.Clear();
39+
m_pathToBundle.Clear();
4040
}
4141

4242
public bool SaveBytes(string path)
4343
{
4444
FileStream file = File.Open(path, FileMode.Create);
4545
BinaryWriter binaryWriter = new BinaryWriter(file);
4646

47-
binaryWriter.Write(m_pathToBundleName.Count);
47+
binaryWriter.Write(m_pathToBundle.Count);
4848

49-
using (var iterator = m_pathToBundleName.GetEnumerator())
49+
using (var iterator = m_pathToBundle.GetEnumerator())
5050
{
5151
while (iterator.MoveNext())
5252
{
@@ -58,8 +58,8 @@ public bool SaveBytes(string path)
5858
}
5959
}
6060

61-
binaryWriter.Write(m_bundleDependDict.Count);
62-
using (var iterator = m_bundleDependDict.GetEnumerator())
61+
binaryWriter.Write(m_bundleRely.Count);
62+
using (var iterator = m_bundleRely.GetEnumerator())
6363
{
6464
while (iterator.MoveNext())
6565
{
@@ -81,7 +81,7 @@ public bool SaveBytes(string path)
8181
return true;
8282
}
8383

84-
Dictionary<string, string> m_pathToBundleName = new Dictionary<string, string>();
85-
Dictionary<string, List<string>> m_bundleDependDict = new Dictionary<string, List<string>>();
84+
private Dictionary<string, string> m_pathToBundle = new Dictionary<string, string>();
85+
private Dictionary<string, List<string>> m_bundleRely = new Dictionary<string, List<string>>();
8686
}
8787
}

Assets/BundleBuildTool/Src/Editor/BundleDefine/BundleDict.cs.meta renamed to Assets/BundleBuildTool/Src/Editor/BundleDefine/BundleNexus.cs.meta

File renamed without changes.

Assets/BundleBuildTool/Src/Editor/BundleHelper/BundleBuildHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using UnityEditor;
55
using System.Collections.Generic;
6+
using EditorCommon;
67

78
namespace BundleManager
89
{
@@ -35,7 +36,7 @@ public static bool BuildSingleBundle(BundleData bundle, BundleState state)
3536
return false;
3637

3738
string outputPath = BuildConfig.GetBuildOutputPath(bundle.name);
38-
EditorCommon.CreateDirectory(outputPath);
39+
EditorTool.CreateDirectory(outputPath);
3940
uint crc = 0;
4041

4142
string[] assetPaths = bundle.includs.ToArray();
@@ -100,7 +101,7 @@ public static bool BuildShaderBundle(BundleData bundle, BundleState state)
100101

101102
uint crc = 0;
102103
string outputPath = BuildConfig.GetBuildOutputPath(bundle.name);
103-
EditorCommon.CreateDirectory(outputPath);
104+
EditorTool.CreateDirectory(outputPath);
104105

105106
bool succeed = BuildAssetBundle(list.ToArray(), outputPath, out crc);
106107
succeed = UpdateBundleState(bundle, state, outputPath, succeed, crc);

Assets/BundleBuildTool/Src/Editor/BundleHelper/BundleDataAccessor.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using EditorCommon;
23

34
namespace BundleManager
45
{
@@ -10,7 +11,7 @@ public static List<BundleData> Datas
1011
{
1112
if (m_datas == null)
1213
{
13-
m_datas = EditorCommon.LoadJsonData<List<BundleData>>(BuildConfig.BundleDataPath);
14+
m_datas = EditorTool.LoadJsonData<List<BundleData>>(BuildConfig.BundleDataPath);
1415
}
1516
if (m_datas == null)
1617
{
@@ -26,7 +27,7 @@ public static List<BundleState> States
2627
{
2728
if (m_states == null)
2829
{
29-
m_states = EditorCommon.LoadJsonData<List<BundleState>>(BuildConfig.BundleStatePath);
30+
m_states = EditorTool.LoadJsonData<List<BundleState>>(BuildConfig.BundleStatePath);
3031
}
3132
if (m_states == null)
3233
{
@@ -42,7 +43,7 @@ public static List<BundleImportData> ImportDatas
4243
{
4344
if (m_importDatas == null)
4445
{
45-
m_importDatas = EditorCommon.LoadJsonData<List<BundleImportData>>(BuildConfig.BundleImportDataPath);
46+
m_importDatas = EditorTool.LoadJsonData<List<BundleImportData>>(BuildConfig.BundleImportDataPath);
4647
}
4748
if (m_importDatas == null)
4849
{
@@ -62,20 +63,20 @@ public static void SaveData()
6263
{
6364
if (m_datas != null)
6465
{
65-
EditorCommon.SaveJsonData<List<BundleData>>(m_datas, BuildConfig.BundleDataPath);
66+
EditorTool.SaveJsonData<List<BundleData>>(m_datas, BuildConfig.BundleDataPath);
6667
}
6768

6869
if (m_states != null)
6970
{
70-
EditorCommon.SaveJsonData<List<BundleState>>(m_states, BuildConfig.BundleStatePath);
71+
EditorTool.SaveJsonData<List<BundleState>>(m_states, BuildConfig.BundleStatePath);
7172
}
7273
}
7374

7475
public static void SaveImportData()
7576
{
7677
if (m_importDatas != null)
7778
{
78-
EditorCommon.SaveJsonData<List<BundleImportData>>(m_importDatas, BuildConfig.BundleImportDataPath);
79+
EditorTool.SaveJsonData<List<BundleImportData>>(m_importDatas, BuildConfig.BundleImportDataPath);
7980
}
8081
}
8182

0 commit comments

Comments
 (0)