Skip to content

Commit a73291c

Browse files
committed
commit
1 parent d791483 commit a73291c

29 files changed

+2291
-2223
lines changed

Assets/Editor/EditorMenu.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ static void GetMeshData()
5555
}
5656
GameObject go = Selection.activeObject as GameObject;
5757
if (go == null)
58+
{
5859
return;
60+
}
5961
MeshFilter filter = go.GetComponent<MeshFilter>();
6062
if (filter == null || filter.sharedMesh == null)
6163
{
@@ -167,7 +169,10 @@ static void ReplaceFont()
167169
for (int i = 0; i < objs.Count; i++)
168170
{
169171
UnityEngine.GameObject go = (GameObject)objs[i];
170-
if (go == null) return;
172+
if (go == null)
173+
{
174+
return;
175+
}
171176
GameObject clone = GameObject.Instantiate(go);
172177
UILabel[] labels = clone.GetComponentsInChildren<UILabel>(true);
173178
foreach (var current in labels)
@@ -282,7 +287,7 @@ static void ChangeLayerStateName()
282287
}
283288

284289
if (name.Contains("_") &&
285-
name.Contains("_0") == false)
290+
name.Contains("_0") == false)
286291
{
287292
layer.stateMachine.states[k].state.name = name.Replace("_", "_0");
288293
}
@@ -293,7 +298,7 @@ static void ChangeLayerStateName()
293298
{
294299
string paramName = ac.parameters[i].name;
295300
if (paramName.Contains("_") &&
296-
paramName.Contains("_0") == false)
301+
paramName.Contains("_0") == false)
297302
{
298303
Debug.LogError(paramName.Replace("_", "_0"));
299304

@@ -307,7 +312,7 @@ static void ChangeLayerStateName()
307312
AssetDatabase.Refresh();
308313
}
309314

310-
[MenuItem("Assets/提取新动画")]
315+
[MenuItem("工具/提取新动画")]
311316
static void GetFilteredtoNewAnim()
312317
{
313318
UnityEngine.Object[] selectionAsset = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Unfiltered);

Assets/Editor/EditorResourceBuild.cs

+139-127
Original file line numberDiff line numberDiff line change
@@ -8,164 +8,176 @@
88

99
namespace EDT
1010
{
11-
public class EditorResourceBuild
11+
public class EditorResourceBuild
12+
{
13+
static public Dictionary<string, string> m_mapAssetList = new Dictionary<string, string>();
14+
15+
public static string ASSET_PATH_KEY = "fzgdhks";
16+
17+
static string GetPlatformName(BuildTarget buildTarget)
1218
{
13-
static string OUTPUTPATH = Application.dataPath.Replace("/Assets", string.Empty) + "/AssetBundles";
19+
string szFolerName = "Windows";
20+
switch (buildTarget)
21+
{
22+
case BuildTarget.Android:
23+
szFolerName = "Android";
24+
break;
1425

15-
static void DelBundles()
26+
case BuildTarget.iOS:
27+
szFolerName = "iOS";
28+
break;
29+
}
30+
return szFolerName;
31+
}
32+
33+
static string GetAssetBundleOutPutPath(BuildTarget buildTarget)
34+
{
35+
return Application.dataPath.Replace("/Assets", string.Empty) + "/AssetBundles" + "/" + GetPlatformName(buildTarget) + "/";
36+
}
37+
static bool DeleteBundles()
38+
{
39+
if (Directory.Exists(GetAssetBundleOutPutPath(EditorUserBuildSettings.activeBuildTarget)))
1640
{
17-
if (Directory.Exists(OUTPUTPATH))
18-
{
19-
Directory.Delete(OUTPUTPATH, true);
20-
}
21-
Directory.CreateDirectory(OUTPUTPATH);
41+
Directory.Delete(GetAssetBundleOutPutPath(EditorUserBuildSettings.activeBuildTarget), true);
2242
}
2343

24-
static void DelBundleNames()
44+
Directory.CreateDirectory(GetAssetBundleOutPutPath(EditorUserBuildSettings.activeBuildTarget));
45+
46+
return true;
47+
}
48+
49+
static bool DeleteBundleNames()
50+
{
51+
string[] oldAssetBundleNames = AssetDatabase.GetAllAssetBundleNames();
52+
if(oldAssetBundleNames.Length <= 0)
2553
{
26-
var length = AssetDatabase.GetAllAssetBundleNames().Length;
27-
var oldAssetBundleNames = new string[length];
28-
for (var i = 0; i < length; i++)
29-
{
30-
oldAssetBundleNames[i] = AssetDatabase.GetAllAssetBundleNames()[i];
31-
}
32-
for (var j = 0; j < oldAssetBundleNames.Length; j++)
33-
{
34-
AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[j], true);
35-
}
54+
return true;
3655
}
3756

38-
static void SetBundleConfig()
57+
for (var i = 0; i < oldAssetBundleNames.Length; i++)
3958
{
40-
List<GTResourceData> list = new List<GTResourceData>();
41-
UnityEngine.Object[] assets = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
42-
for (int i = 0; i < assets.Length; i++)
59+
AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[i], true);
60+
}
61+
62+
return true;
63+
}
64+
65+
static bool SetBundleConfig()
66+
{
67+
UnityEngine.Object[] assets = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
68+
for (int i = 0; i < assets.Length; i++)
69+
{
70+
UnityEngine.Object obj = assets[i];
71+
string assetPath = AssetDatabase.GetAssetPath(obj);
72+
string extenName = System.IO.Path.GetExtension(assetPath).ToLower();
73+
if (string.IsNullOrEmpty(extenName) || extenName == ".meta")
74+
{
75+
continue;
76+
}
77+
switch (extenName)
4378
{
44-
UnityEngine.Object obj = assets[i];
45-
string assetPath = AssetDatabase.GetAssetPath(obj);
46-
string extenName = System.IO.Path.GetExtension(assetPath).ToLower();
47-
if (string.IsNullOrEmpty(extenName) || extenName == ".meta")
79+
case ".xml":
80+
case ".txt":
4881
{
49-
continue;
82+
EditorResourceBuild.m_mapAssetList[assetPath] = obj.name + extenName + ".assetbundle";
5083
}
51-
GTResourceData bundle = new GTResourceData();
52-
switch (extenName)
84+
break;
85+
case ".prefab":
5386
{
54-
case ".xml":
55-
case ".txt":
56-
{
57-
bundle.AssetName = obj.name + extenName;
58-
bundle.AssetBundleName = obj.name + extenName + ".assetbundle";
59-
bundle.Path = assetPath;
60-
bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path);
61-
}
62-
break;
63-
case ".prefab":
64-
{
65-
bundle.AssetName = obj.name + extenName;
66-
bundle.AssetBundleName = GTTools.GetParentPathName(assetPath) + ".pre.assetbundle";
67-
bundle.Path = assetPath;
68-
bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path);
69-
}
70-
break;
71-
case ".mp3":
72-
{
73-
bundle.AssetName = obj.name + extenName;
74-
bundle.AssetBundleName = obj.name + extenName + ".assetbundle";
75-
bundle.Path = assetPath;
76-
bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path);
77-
}
78-
break;
79-
case ".png":
80-
{
81-
if (assetPath.Contains("Image"))
82-
{
83-
bundle.AssetName = obj.name + extenName;
84-
bundle.AssetBundleName = GTTools.GetParentPathName(assetPath) + ".atlas.assetbundle";
85-
bundle.Path = assetPath;
86-
bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path);
87-
}
88-
if (assetPath.Contains("T_Background"))
89-
{
90-
bundle.AssetName = obj.name + extenName;
91-
bundle.AssetBundleName = obj.name + ".tex.assetbundle";
92-
bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path);
93-
}
94-
}
95-
break;
87+
EditorResourceBuild.m_mapAssetList[assetPath] = GTTools.GetParentPathName(assetPath) + ".pre.assetbundle";
9688
}
97-
98-
if (string.IsNullOrEmpty(bundle.AssetName))
89+
break;
90+
case ".mp3":
91+
{
92+
EditorResourceBuild.m_mapAssetList[assetPath] = obj.name + extenName + ".assetbundle";
93+
}
94+
break;
95+
case ".png":
9996
{
100-
continue;
97+
if (assetPath.Contains("Textures"))
98+
{
99+
EditorResourceBuild.m_mapAssetList[assetPath] = GTTools.GetParentPathName(assetPath) + ".atlas.assetbundle";
100+
}
101101
}
102-
bundle.AssetBundleName = bundle.AssetBundleName.ToLower();
103-
list.Add(bundle);
102+
break;
104103
}
104+
}
105105

106-
list.Sort((a1, a2) => { return a1.AssetName.CompareTo(a2.AssetName); });
107-
GTResourceManager.Instance.Data.Clear();
108-
foreach (var current in list)
109-
{
110-
GTResourceManager.Instance.Data[current.Path] = current;
111-
}
106+
XmlDocument doc = new XmlDocument();
107+
XmlNode root = doc.CreateElement("root");
108+
doc.AppendChild(root);
109+
foreach (var current in EditorResourceBuild.m_mapAssetList)
110+
{
111+
XmlElement child = doc.CreateElement("row");
112+
root.AppendChild(child);
113+
child.SetAttribute("AssetName", current.Key);
114+
child.SetAttribute("AssetBundleName", current.Value.ToLower());
115+
}
112116

113-
XmlDocument doc = new XmlDocument();
114-
XmlNode root = doc.CreateElement("root");
115-
doc.AppendChild(root);
116-
foreach (var current in list)
117-
{
118-
GTResourceData bundle = current;
119-
XmlElement child = doc.CreateElement("row");
120-
root.AppendChild(child);
121-
child.SetAttribute("AssetName", bundle.AssetName);
122-
child.SetAttribute("AssetBundleName", bundle.AssetBundleName);
123-
child.SetAttribute("Path", bundle.Path);
124-
child.SetAttribute("GUID", bundle.GUID);
125-
}
117+
string fileName = GetAssetBundleOutPutPath(EditorUserBuildSettings.activeBuildTarget) + "/assetlist.xml";
118+
doc.Save(fileName);
119+
return true;
120+
}
126121

127-
string fileName = Application.streamingAssetsPath + "/Asset.xml";
128-
FileStream fs = null;
129-
if (!File.Exists(fileName))
130-
{
131-
fs = File.Create(fileName);
132-
}
133-
doc.Save(fileName);
134-
if (fs != null)
122+
static bool SetBundleNames()
123+
{
124+
foreach (var current in EditorResourceBuild.m_mapAssetList)
125+
{
126+
var assetImporter = AssetImporter.GetAtPath(current.Key);
127+
if (assetImporter != null)
135128
{
136-
fs.Flush();
137-
fs.Dispose();
138-
fs.Close();
129+
assetImporter.assetBundleName = current.Value.ToLower();
139130
}
140131
}
141132

142-
static void SetBundleNames()
133+
return true;
134+
}
135+
public static string GetMD5(byte[] src)
136+
{
137+
var md5 = System.Security.Cryptography.MD5.Create();
138+
byte[] bytes = md5.ComputeHash(src);
139+
md5.Clear();
140+
141+
var sb = new System.Text.StringBuilder();
142+
for (int i = 0; i < bytes.Length; i++)
143143
{
144-
Dictionary<string, GTResourceData> units = GTResourceManager.Instance.Data;
145-
foreach (var current in units)
146-
{
147-
GTResourceData bundle = current.Value;
148-
var assetImporter = AssetImporter.GetAtPath(bundle.Path);
149-
if (assetImporter != null)
150-
{
151-
assetImporter.assetBundleName = bundle.AssetBundleName.ToLower();
152-
}
153-
}
144+
sb.Append(bytes[i].ToString("x2"));
154145
}
155146

156-
static void BuildBundles()
147+
return sb.ToString();
148+
}
149+
public static string GetAssetPathMd5(string path)
150+
{
151+
string tmp = path + EditorResourceBuild.ASSET_PATH_KEY;
152+
byte[] data = System.Text.Encoding.UTF8.GetBytes(tmp);
153+
return GetMD5(data);
154+
}
155+
156+
static void BuildBundles()
157+
{
158+
BuildPipeline.BuildAssetBundles(GetAssetBundleOutPutPath(EditorUserBuildSettings.activeBuildTarget), BuildAssetBundleOptions.UncompressedAssetBundle, EditorUserBuildSettings.activeBuildTarget);
159+
}
160+
161+
public static void Build()
162+
{
163+
if(!DeleteBundles())
157164
{
158-
BuildPipeline.BuildAssetBundles(OUTPUTPATH, BuildAssetBundleOptions.UncompressedAssetBundle,
159-
EditorUserBuildSettings.activeBuildTarget);
165+
return;
160166
}
161167

162-
public static void Build()
168+
169+
//if (!DeleteBundleNames())
170+
//{
171+
// return;
172+
//}
173+
174+
//return;
175+
if (!SetBundleConfig())
163176
{
164-
DelBundles();
165-
DelBundleNames();
166-
SetBundleConfig();
167-
SetBundleNames();
168-
BuildBundles();
177+
return;
169178
}
179+
SetBundleNames();
180+
BuildBundles();
170181
}
171182
}
183+
}

0 commit comments

Comments
 (0)