提交 6733e3c7 编写于 作者: unityLR's avatar unityLR

替换第一版

上级 b94efa82

要显示的变更太多。

To preserve performance only 1000 of 1000+ files are displayed.
fileFormatVersion: 2
guid: 19864418aecd9304a962111ebfaaa135
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a730e3f543354fb458cf017d1205c0d5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class BuildApp : EditorWindow
{
[MenuItem("Build/打包APP")]
public static void ShowWin()
{
var win = GetWindow<BuildApp>();
win.Show();
}
private void Awake()
{
m_versionGUI = new VersionGUI();
m_versionGUI.Awake();
}
private void OnGUI()
{
m_versionGUI.DrawVersion();
DrawBuildApp();
}
private void DrawBuildApp()
{
if(GUILayout.Button("Build APP"))
{
// 生成原始lua全量文件的md5
BuildUtils.GenOriginalLuaFrameworkMD5File();
// 打AssetBundle
BuildAssetBundle.Build();
// 打包APP
BuildUtils.BuildApp();
}
}
private VersionGUI m_versionGUI;
}
fileFormatVersion: 2
guid: d9f4a1765020ccc47a60ad7bd5dc8289
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEditor;
public class BuildAssetBundle
{
public static void Build()
{
string targetPath = Application.streamingAssetsPath + "/res";
BuildUtils.BuildLuaBundle(targetPath);
BuildUtils.BuildNormalCfgBundle(targetPath);
BuildUtils.BuildGameResBundle(targetPath);
GameLogger.Log("BuildAssetBundle Done");
}
}
fileFormatVersion: 2
guid: cbea85053b739d14897b492e9306406f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Ionic.Zip;
using System.IO;
using LitJson;
using UObject = UnityEngine.Object;
using System.Text.RegularExpressions;
public class BuildUpdateZip : EditorWindow
{
[MenuItem("Build/ȸ")]
public static void ShowWindow()
{
var win = GetWindow<BuildUpdateZip>();
win.Show();
}
private void Awake()
{
m_versionGUI = new VersionGUI();
m_versionGUI.Awake();
m_luaFrameworkFilesVersion = TryGetLuaFrameworkFilesVersion();
}
private void OnGUI()
{
m_versionGUI.DrawVersion();
GUILayout.BeginHorizontal();
GUILayout.Label("LuaFrameworkFiles.json");
m_luaFrameworkFilesVersion = EditorGUILayout.TextField(m_luaFrameworkFilesVersion);
GUILayout.EndHorizontal();
if (GUILayout.Button("ȸ"))
{
var zipDir = BuildUtils.CreateTmpDir("updateZip");
BuildUtils.BuildNormalCfgBundle(zipDir);
BuildLuaUpdateBundle(zipDir);
var contionsObj = BuildObjBundle(zipDir);
ZipUpdateDir(zipDir, contionsObj);
BuildUtils.DeleteDir(zipDir);
AssetDatabase.Refresh();
}
DrawObjList();
}
private void DrawObjList()
{
m_scrollViewPos = GUILayout.BeginScrollView(m_scrollViewPos);
if (GUILayout.Button("+"))
{
m_objList.Add(null);
}
for (int i = 0, cnt = m_objList.Count; i < cnt; ++i)
{
GUILayout.BeginHorizontal();
m_objList[i] = EditorGUILayout.ObjectField(m_objList[i], typeof(UObject), false);
if (GUILayout.Button("-"))
{
m_objList.RemoveAt(i);
break;
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
}
private string TryGetLuaFrameworkFilesVersion()
{
if (!Directory.Exists(BuildUtils.BIN_PATH))
return null;
var fs = Directory.GetFiles(BuildUtils.BIN_PATH);
foreach (var f in fs)
{
if (f.Contains("LuaFrameworkFiles_"))
{
var result = Regex.Match(f, ".*LuaFrameworkFiles_(.*).json");
if (null != result)
{
return result.Groups[1].Value;
}
}
}
return null;
}
private void ZipUpdateDir(string zipDir, bool contionsObj)
{
var zipFilePath = BuildUtils.BIN_PATH + "/" + (contionsObj ? "res_" : "script_") + VersionMgr.instance.resVersion + ".zip";
if (File.Exists(zipFilePath))
{
File.Delete(zipFilePath);
}
ZipFile zipFile = new ZipFile();
var fs = Directory.GetFiles(zipDir);
foreach (var f in fs)
{
if (f.EndsWith("meta") || f.EndsWith(".manifest"))
continue;
zipFile.AddFile(f, "");
}
zipFile.Save(zipFilePath);
zipFile.Dispose();
}
private void BuildLuaUpdateBundle(string zipDir)
{
var needUpdateLuaFiles = GetNeedUpdateLuaList();
GameLogger.Log("needUpdateLuaFiles.Count:" + needUpdateLuaFiles.Count);
var luaBundleDir = BuildUtils.CreateTmpDir("luabundle");
BuildUtils.CopyLuaToBundleDir(needUpdateLuaFiles, luaBundleDir);
// AssetBundle
Hashtable tb = new Hashtable();
tb["lua_update.bundle"] = "luabundle";
AssetBundleBuild[] buildArray = BuildUtils.MakeAssetBundleBuildArray(tb);
BuildUtils.BuildBundles(buildArray, zipDir);
BuildUtils.DeleteDir(luaBundleDir);
AssetDatabase.Refresh();
}
private bool BuildObjBundle(string zipDir)
{
if (0 == m_objList.Count) return false;
AssetBundleBuild[] bundleBuilds = new AssetBundleBuild[m_objList.Count];
bool contionsObj = false;
for (int i = 0, cnt = m_objList.Count; i < cnt; ++i)
{
var obj = m_objList[i];
if (null == obj) continue;
var assetPath = AssetDatabase.GetAssetPath(obj);
var fileName = Path.GetFileName(assetPath);
bundleBuilds[i].assetBundleName = fileName;
bundleBuilds[i].assetNames = new string[] { assetPath };
contionsObj = true;
}
BuildUtils.BuildBundles(bundleBuilds, zipDir);
return contionsObj;
}
private List<string> GetNeedUpdateLuaList()
{
var localLuaMD5 = BuildUtils.GetOriginalLuaframeworkMD5Json();
var originalLuaMD5FilePath = BuildUtils.BIN_PATH + "/LuaFrameworkFiles_" + m_luaFrameworkFilesVersion + ".json";
var originalLuaMD5File = File.OpenRead(originalLuaMD5FilePath);
StreamReader sr = new StreamReader(originalLuaMD5File);
var jsonStr = sr.ReadToEnd();
sr.Close();
var originalLuaMD5 = JsonMapper.ToObject(jsonStr);
List<string> needUpdateLuaFiles = new List<string>();
foreach (var key in localLuaMD5.Keys)
{
if (!originalLuaMD5.ContainsKey(key) || originalLuaMD5[key].ToString() != localLuaMD5[key].ToString())
{
needUpdateLuaFiles.Add(key);
}
}
return needUpdateLuaFiles;
}
private VersionGUI m_versionGUI;
private string m_luaFrameworkFilesVersion;
private List<UObject> m_objList = new List<UObject>();
private Vector2 m_scrollViewPos;
}
fileFormatVersion: 2
guid: bca23174dce23564c87a92c47791dbca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using LitJson;
public class BuildUtils
{
/// <summary>
/// 递归遍历获取目标目录中的所有文件
/// </summary>
/// <param name="sourceDir">目标目录</param>
/// <param name="splitAssetPath">是否要切割目录,以Assets目录为根</param>
public static List<string> GetFiles(string sourceDir, bool splitAssetPath)
{
List<string> fileList = new List<string>();
string[] fs = Directory.GetFiles(sourceDir);
string[] ds = Directory.GetDirectories(sourceDir);
for (int i = 0, len = fs.Length; i < len; ++i)
{
var index = splitAssetPath ? fs[i].IndexOf("Assets") : 0;
fileList.Add(fs[i].Substring(index));
}
for (int i = 0, len = ds.Length; i < len; ++i)
{
fileList.AddRange(GetFiles(ds[i], splitAssetPath));
}
return fileList;
}
public static List<string> GetFiles(string[] sourceDirs, bool splitAssetPath)
{
List<string> fileList = new List<string>();
foreach (var sourceDir in sourceDirs)
{
fileList.AddRange(GetFiles(sourceDir, splitAssetPath));
}
return fileList;
}
/// <summary>
/// 根据哈希表构建AssetBundleBuild列表
/// </summary>
/// <param name="tb">哈希表,key为assetBundleName,value为目录</param>
/// <returns></returns>
public static AssetBundleBuild[] MakeAssetBundleBuildArray(Hashtable tb)
{
AssetBundleBuild[] buildArray = new AssetBundleBuild[tb.Count];
int index = 0;
foreach (string key in tb.Keys)
{
buildArray[index].assetBundleName = key;
List<string> fileList = new List<string>();
fileList = GetFiles(Application.dataPath + "/" + tb[key], true);
buildArray[index].assetNames = fileList.ToArray();
++index;
}
return buildArray;
}
/// <summary>
/// 打包常规配置表AssetBundle
/// </summary>
public static void BuildNormalCfgBundle(string targetPath)
{
Hashtable tb = new Hashtable();
tb["normal_cfg.bundle"] = "GameRes/Config";
AssetBundleBuild[] buildArray = BuildUtils.MakeAssetBundleBuildArray(tb);
BuildUtils.BuildBundles(buildArray, targetPath);
}
/// <summary>
/// 打包Lua的AssetBundle
/// </summary>
public static void BuildLuaBundle(string targetPath)
{
// 创建Lua的Bundle临时目录
var luabundleDir = BuildUtils.CreateTmpDir("luabundle");
// 将Lua代码拷贝到Bundle临时目录(做加密处理)
var luaFiles = BuildUtils.GetFiles(new string[] {
Application.dataPath + "/LuaFramework/Lua",
Application.dataPath + "/LuaFramework/ToLua/Lua",
}, true);
BuildUtils.CopyLuaToBundleDir(luaFiles, luabundleDir);
// 构建AssetBundleBuild列表
Hashtable tb = new Hashtable();
tb["lua.bundle"] = "luabundle";
AssetBundleBuild[] buildArray = MakeAssetBundleBuildArray(tb);
// 打包AssetBundle
BuildBundles(buildArray, targetPath);
// 删除Lua的Bundle临时目录
DeleteDir(luabundleDir);
AssetDatabase.Refresh();
}
/// <summary>
/// 打包游戏资源AssetBundle
/// </summary>
public static void BuildGameResBundle(string targetPath)
{
Hashtable tb = new Hashtable();
tb["baseres.bundle"] = "GameRes/BaseRes";
tb["uiprefabs.bundle"] = "GameRes/UIPrefabs";
AssetBundleBuild[] buildArray = MakeAssetBundleBuildArray(tb);
BuildBundles(buildArray, targetPath);
}
/// <summary>
/// 打AssetBundle
/// </summary>
/// <param name="buildArray">AssetBundleBuild列表</param>
public static void BuildBundles(AssetBundleBuild[] buildArray, string targetPath)
{
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
BuildPipeline.BuildAssetBundles(targetPath, buildArray, BuildAssetBundleOptions.ChunkBasedCompression, GetBuildTarget());
}
public static void BuildApp()
{
string[] scenes = new string[] { "Assets/Scenes/Main.unity" };
string appName = PlayerSettings.productName + "_" + VersionMgr.instance.appVersion + GetTargetPlatfromAppPostfix();
string outputPath = Application.dataPath + "/../Bin/";
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
string appPath = Path.Combine(outputPath, appName);
// 根据你的需求设置各种版本号
// PlayerSettings.Android.bundleVersionCode
// PlayerSettings.bundleVersion
// PlayerSettings.iOS.buildNumber
BuildPipeline.BuildPlayer(scenes, appPath, GetBuildTarget(), BuildOptions.None);
GameLogger.Log("Build APP Done");
}
/// <summary>
/// 生成原始lua代码的md5
/// </summary>
public static void GenOriginalLuaFrameworkMD5File()
{
VersionMgr.instance.Init();
JsonData jd = GetOriginalLuaframeworkMD5Json();
var jsonStr = JsonMapper.ToJson(jd);
jsonStr = jsonStr.Replace(",", ",\n");
if (!Directory.Exists(BIN_PATH))
{
Directory.CreateDirectory(BIN_PATH);
}
using (StreamWriter sw = new StreamWriter(BIN_PATH + "LuaFrameworkFiles_" + VersionMgr.instance.appVersion + ".json"))
{
sw.Write(jsonStr);
}
GameLogger.Log("GenLuaframeworkMd5 Done");
}
public static JsonData GetOriginalLuaframeworkMD5Json()
{
var sourceDirs = new string[] {
Application.dataPath + "/LuaFramework/Lua",
Application.dataPath + "/LuaFramework/ToLua/Lua",
};
JsonData jd = new JsonData();
foreach (var sourceDir in sourceDirs)
{
List<string> fileList = new List<string>();
fileList = GetFiles(sourceDir, false);
foreach (var luaFile in fileList)
{
if (!luaFile.EndsWith(".lua")) continue;
var md5 = LuaFramework.Util.md5file(luaFile);
var key = luaFile.Substring(luaFile.IndexOf("Assets/"));
jd[key] = md5;
}
}
return jd;
}
/// <summary>
/// 创建临时目录
/// </summary>
/// <returns></returns>
public static string CreateTmpDir(string dirName)
{
var tmpDir = string.Format(Application.dataPath + "/{0}/", dirName);
if (Directory.Exists(tmpDir))
{
Directory.Delete(tmpDir, true);
}
Directory.CreateDirectory(tmpDir);
return tmpDir;
}
/// <summary>
/// 删除目录
/// </summary>
public static void DeleteDir(string targetDir)
{
if (Directory.Exists(targetDir))
{
Directory.Delete(targetDir, true);
}
AssetDatabase.Refresh();
}
/// <summary>
/// 拷贝Lua到目标目录,并做加密处理
/// </summary>
/// <param name="sourceDirs">源目录列表</param>
/// <param name="luabundleDir">母包目录</param>
public static void CopyLuaToBundleDir(List<string> luaFiles, string luabundleDir)
{
foreach (var luaFile in luaFiles)
{
if (luaFile.EndsWith(".meta")) continue;
var luaFileFullPath = Application.dataPath + "/../" + luaFile;
// 由于Build AssetBundle不识别.lua文件,所以拷贝一份到临时目录,统一加上.bytes结尾
var targetFile = luaFile.Replace("Assets/LuaFramework/Lua", "");
targetFile = targetFile.Replace("Assets/LuaFramework/ToLua/Lua", "");
targetFile = luabundleDir + targetFile + ".bytes";
var targetDir = Path.GetDirectoryName(targetFile);
if (!Directory.Exists(targetDir))
Directory.CreateDirectory(targetDir);
// 做下加密
byte[] bytes = File.ReadAllBytes(luaFileFullPath);
byte[] encryptBytes = AESEncrypt.Encrypt(bytes);
File.WriteAllBytes(targetFile, encryptBytes);
}
AssetDatabase.Refresh();
}
public void BuildLuaUpdateBundle(List<string> luaFileList)
{
}
/// <summary>
/// 获取当前平台
/// </summary>
public static BuildTarget GetBuildTarget()
{
#if UNITY_STANDALONE
return BuildTarget.StandaloneWindows;
#elif UNITY_ANDROID
return BuildTarget.Android;
#else
return BuildTarget.iOS;
#endif
}
/// <summary>
/// 获取目标平台APP后缀
/// </summary>
/// <returns></returns>
public static string GetTargetPlatfromAppPostfix(bool useAAB = false)
{
#if UNITY_STANDALONE
return ".exe";
#elif UNITY_ANDROID
if(useAAB)
{
return ".aab";
}
else
{
return ".apk";
}
#else
return ".ipa";
#endif
}
public static string BIN_PATH
{
get { return Application.dataPath + "/../Bin/"; }
}
}
fileFormatVersion: 2
guid: 1f8f12a57955dba4988e152c8e3f7246
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEditor;
using LitJson;
using System.IO;
public class VersionGUI
{
public void Awake()
{
VersionMgr.instance.Init();
m_appVersion = VersionMgr.instance.appVersion;
}
public void DrawVersion()
{
GUILayout.BeginHorizontal();
m_appVersion = EditorGUILayout.TextField("version", m_appVersion);
JsonData jd = new JsonData();
jd["app_version"] = m_appVersion;
jd["res_version"] = m_appVersion;
if (GUILayout.Button("Save"))
{
using (StreamWriter sw = new StreamWriter(Application.dataPath + "/Resources/version.bytes"))
{
sw.Write(jd.ToJson());
}
AssetDatabase.Refresh();
Debug.Log("Save Version OK: " + m_appVersion);
VersionMgr.instance.DeleteCacheResVersion();
VersionMgr.instance.Init();
}
GUILayout.EndHorizontal();
}
private string m_appVersion;
}
fileFormatVersion: 2
guid: 09417d263b36c404dacbf8da14d68a1a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4713dc4a92bf750408ff085522a4fe1f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
// PrefabObjBinder编辑器
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
public class PrefabObjBinderEditor : EditorWindow
{
private GameObject m_prefabObjBinderObj;
private PrefabObjBinder m_binder;
private List<PrefabObjBinder.Item> m_itemList;
private List<PrefabObjBinder.Item> m_searchMatchItemList = new List<PrefabObjBinder.Item>();
private Vector2 m_scrollViewPos;
private List<Component> m_comList = new List<Component>();
private string m_itemName;
private string m_itemNameSearch;
private string m_selectedItemName;
private string m_lockBtnName;
private Object m_itemObj;
private bool m_lock;
private string m_componentStr;
enum ItemOption
{
AddItem,
RemoveItem,
ClearItems,
SearchItems
}
private GUIStyle m_labelSytleYellow;
private GUIStyle m_labelStyleNormal;
public static void ShowWindow()
{
var window = GetWindow<PrefabObjBinderEditor>();
window.titleContent = new GUIContent("预设对象绑定", AssetPreview.GetMiniTypeThumbnail(typeof(UnityEngine.EventSystems.EventSystem)), "decent");
window.Init();
}
[MenuItem("GameObject/PrefabObjBinder Window", priority = 0)]
public static void PrefabObjBinderWindow()
{
if (Selection.activeGameObject.GetComponent<PrefabObjBinder>())
ShowWindow();
else
Debug.LogError("no PrefabObjBinder on this GameObject");
}
void Awake()
{
m_labelStyleNormal = new GUIStyle(EditorStyles.miniButton);
m_labelStyleNormal.fontSize = 12;
m_labelStyleNormal.normal.textColor = Color.white;
m_labelSytleYellow = new GUIStyle(EditorStyles.miniButton);
m_labelSytleYellow.fontSize = 12;
m_labelSytleYellow.normal.textColor = Color.yellow;
}
void OnEnable()
{
EditorApplication.update += Repaint;
}
void OnDisable()
{
EditorApplication.update -= Repaint;
}
void Init()
{
m_itemList = new List<PrefabObjBinder.Item>();
m_comList = new List<Component>();
m_lockBtnName = "锁定item组件列表";
m_componentStr = string.Empty;
m_lock = false;
if (Selection.activeGameObject.GetComponent<PrefabObjBinder>())
{
m_prefabObjBinderObj = Selection.activeGameObject;
OnRefreshBtnClicked();
}
}
void OnGUI()
{
BeginBox(new Rect(0, 0, 3 * Screen.width / 10f, Screen.height));
DrawSearchBtn();
DrawSearchItemList();
EndBox();
BeginBox(new Rect(3 * Screen.width / 10f, 0, 3 * Screen.width / 10f, Screen.height));
DrawLockBtn();
GUILayout.Space(2);
DrawComponentList();
EndBox();
BeginBox(new Rect(6 * Screen.width / 10f, 0, 4 * Screen.width / 10f, Screen.height));
DrawPrefabObjBinderField();
GUILayout.Space(2);
DrawItemField();
EndBox();
}
private void DrawSearchBtn()
{
GUILayout.BeginHorizontal();
string before = m_itemNameSearch;
string after = EditorGUILayout.TextField("", before, "SearchTextField");
if (before != after) m_itemNameSearch = after;
if (GUILayout.Button("", "SearchCancelButton"))
{
m_itemNameSearch = "";
GUIUtility.keyboardControl = 0;
}
ComponentOperation(m_binder, ItemOption.SearchItems, after);
GUILayout.EndHorizontal();
}
private void DrawPrefabObjBinderField()
{
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
GUILayout.Label("prefab");
var oldObj = m_prefabObjBinderObj;
m_prefabObjBinderObj = EditorGUILayout.ObjectField(m_prefabObjBinderObj, typeof(GameObject), true) as GameObject;
EditorGUILayout.EndHorizontal();
if (!m_prefabObjBinderObj)
{
EditorGUILayout.HelpBox("Select a PrefabObjBinder Object", MessageType.Warning);
}
else if (oldObj != m_prefabObjBinderObj)
{
m_binder = m_prefabObjBinderObj.GetComponent<PrefabObjBinder>();
}
}
private void BeginBox(Rect rect)
{
rect.height -= 20;
GUILayout.BeginArea(rect);
GUILayout.Box("", GUILayout.Width(rect.width), GUILayout.Height(rect.height));
GUILayout.EndArea();
GUILayout.BeginArea(rect);
}
private void EndBox()
{
GUILayout.EndArea();
}
private void DrawSearchItemList()
{
if (null == m_prefabObjBinderObj || null == m_binder)
m_searchMatchItemList.Clear();
m_scrollViewPos = EditorGUILayout.BeginScrollView(m_scrollViewPos);
foreach (var item in m_searchMatchItemList)
{
GUILayout.BeginHorizontal();
item.name = EditorGUILayout.TextField(item.name);
item.obj = EditorGUILayout.ObjectField(item.obj, typeof(GameObject), true);
if (GUILayout.Button("-", GUILayout.Width(20)))
{
m_itemList.Remove(item);
m_binder.items = m_itemList.ToArray();
GUILayout.EndHorizontal();
break;
}
GUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
}
private void DrawItemField()
{
EditorGUILayout.BeginVertical();
GUILayout.Label(string.IsNullOrEmpty(m_componentStr) ? "null" : m_componentStr);
m_itemName = EditorGUILayout.TextField(m_itemName);
if (GUILayout.Button(new GUIContent("Add Item", "添加item"), GUILayout.Height(80)))
{
ComponentOperation(m_binder, ItemOption.AddItem);
}
if (GUILayout.Button(new GUIContent("Delete Item", "删除指定的item")))
{
if (m_prefabObjBinderObj != null)
{
if (string.IsNullOrEmpty(m_itemName))
Debug.LogWarning("请输入要删除的项目名称");
else
ComponentOperation(m_binder, ItemOption.RemoveItem);
}
}
if (GUILayout.Button(new GUIContent("Refresh", "刷新")))
{
OnRefreshBtnClicked();
}
ItemTip();
}
private void OnRefreshBtnClicked()
{
if (null != m_prefabObjBinderObj)
m_binder = m_prefabObjBinderObj.GetComponent<PrefabObjBinder>();
if (null == m_binder)
{
m_itemList.Clear();
m_comList.Clear();
}
}
private void DrawLockBtn()
{
if (GUILayout.Button(new GUIContent(m_lockBtnName, m_lockBtnName), EditorStyles.toolbarButton))
{
m_lock = !m_lock;
if (m_lock == false)
m_lockBtnName = "锁定item组件列表";
else
m_lockBtnName = "解锁item组件列表";
}
}
private void DrawComponentList()
{
var go = Selection.activeObject as GameObject; //获取选中对象
if (go && m_lock == false)
{
Component[] components = go.GetComponents<Component>();
m_comList.Clear();
m_comList.AddRange(components);
m_selectedItemName = go.name;
}
if (go == null)
{
m_comList.Clear();
m_selectedItemName = "无选中对象";
}
if (go && GUILayout.Button("GameObject", "GameObject" == m_componentStr ? m_labelSytleYellow : m_labelStyleNormal))
{
m_itemObj = go;
m_componentStr = "GameObject";
}
foreach (var com in m_comList)
{
GUILayout.Space(2);
var comType = com.GetType().ToString();
comType = comType.Replace("UnityEngine.UI.", "");
comType = comType.Replace("UnityEngine.", "");
if (GUILayout.Button(comType, comType == m_componentStr ? m_labelSytleYellow : m_labelStyleNormal))
{
m_itemObj = com;
m_componentStr = comType;
}
}
EditorGUILayout.EndVertical();
}
#region private method
private void ComponentOperation(PrefabObjBinder binder, ItemOption option, string name = " ")
{
if (null == binder) return;
PrefabObjBinder.Item item = new PrefabObjBinder.Item();
switch (option)
{
case ItemOption.AddItem:
AddItem(item, binder);
break;
case ItemOption.RemoveItem:
RemoveItem(item, binder);
break;
case ItemOption.ClearItems:
ClearItem(item, binder);
break;
case ItemOption.SearchItems:
SearchItem(item, binder, name);
break;
}
binder.items = m_itemList.ToArray();
// 这样enabled一下,才能触发预设的Override
binder.enabled = false;
binder.enabled = true;
}
private void AddItem(PrefabObjBinder.Item item, PrefabObjBinder binder)
{
item.name = m_itemName;
item.obj = m_itemObj;
m_itemList = binder.items.ToList();
List<string> nameList = new List<string>();
foreach (var obj in m_itemList)
{
nameList.Add(obj.name);
}
if (!string.IsNullOrEmpty(m_itemName) && m_itemObj != null)
{
if (nameList.Contains(m_itemName))
{
Debug.LogError("重复元素");
m_itemList.Add(item);
}
else
m_itemList.Add(item);
}
}
private void RemoveItem(PrefabObjBinder.Item item, PrefabObjBinder Ps)
{
item.name = m_itemName;
m_itemList = Ps.items.ToList();
for (int i = 0; i < m_itemList.Count; i++)
{
if (m_itemList[i].name.ToLower() == item.name.ToLower())
{
m_itemList.Remove(m_itemList[i]);
break;
}
}
}
private void ClearItem(PrefabObjBinder.Item item, PrefabObjBinder Ps)
{
item.name = m_itemName;
item.obj = m_itemObj;
m_itemList = Ps.items.ToList();
for (int i = 0; i < m_itemList.Count; i++)
{
if (m_itemList[i].obj == null || string.IsNullOrEmpty(m_itemList[i].name))
{
m_itemList.Remove(m_itemList[i]);
}
}
}
private void SearchItem(PrefabObjBinder.Item item, PrefabObjBinder binder, string name)
{
m_itemList = binder.items.ToList();
m_searchMatchItemList.Clear();
foreach (var o in m_itemList)
{
if (string.IsNullOrEmpty(name))
{
m_searchMatchItemList.Add(o);
}
else
{
if (o.name.ToLower().Contains(name.ToLower()))
{
m_searchMatchItemList.Add(o);
}
else if (null != o.obj)
{
var objName = o.obj.name;
if (objName.ToLower().Contains(name.ToLower()))
{
m_searchMatchItemList.Add(o);
}
}
}
}
}
private void ItemTip()
{
if (string.IsNullOrEmpty(m_itemName) || m_itemObj == null)
{
string msg = string.Empty;
if (m_itemObj == null)
{
msg = "请选择项目组件";
}
else if (string.IsNullOrEmpty(m_itemName))
{
msg = "请输入要添加的项的名字";
}
EditorGUILayout.HelpBox(msg, MessageType.Warning);
EditorGUILayout.Space();
}
}
#endregion
}
fileFormatVersion: 2
guid: 188c0adbe02f53b4ca36382d1757221e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PrefabObjBinder), true)]
public class PrefabObjBinderInspector : Editor
{
public override void OnInspectorGUI()
{
if (GUILayout.Button("Edit"))
{
PrefabObjBinderEditor.ShowWindow();
}
base.OnInspectorGUI();
}
}
fileFormatVersion: 2
guid: 89dcc076b9af0bf40a784931eeda48f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e7a83745da9587f4c8a4b10919d396a4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEditor;
public class PlayerPrefsTools
{
[MenuItem("Tools/ClearCache")]
private static void ClearCache()
{
PlayerPrefs.DeleteAll();
}
}
fileFormatVersion: 2
guid: 1413a3893acfe154fab3c1deb519bc9e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 5f90414665418a340a4989266e67fb8d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b121129f3c49c74438d3500e29ed5356
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: dc7f7f0b14777ec4f87cbb5a40d644a7
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4cf7bc58f25ad4d45984a7e39a57e3c0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
[
{ "id":1, "editor_path":"UIPrefabs/LoginPanel.prefab", "desc":"登录界面" },
{ "id":2, "editor_path":"UIPrefabs/PlazaPanel.prefab", "desc":"大厅界面" },
{ "id":3, "editor_path":"UIPrefabs/TipsFly.prefab", "desc":"提示语" }
]
\ No newline at end of file
fileFormatVersion: 2
guid: 905542cec90faf749af8720311a9a36b
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 98ed8ce323a50c8449efa82d29ca7007
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: a36dfe0665b06564c85d89874d8bdb0e
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: a76efc0193422e94a8c7ccd522fad8d5
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: 35d8e092974551b4e9625de602bb6531
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6e0bd67d664a3c7418742db812cb3644
folderAsset: yes
timeCreated: 1453125768
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a57bd8213452ba24ab5b93cc9d62fb15
folderAsset: yes
timeCreated: 1453127194
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: 86bf33513bdd8324985f8712180692d9
timeCreated: 1457265758
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d1ff240b0de4c2c4aa0bfa3805e7b880
folderAsset: yes
DefaultImporter:
userData:
fileFormatVersion: 2
guid: fef477624099d704ca56e26ccb995f63
folderAsset: yes
DefaultImporter:
userData:
fileFormatVersion: 2
guid: 1119c4407810743de86d01fa652b2374
folderAsset: yes
DefaultImporter:
userData:
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Mark up Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
fileFormatVersion: 2
guid: d6de770751412fd43a5fd1fe331dd761
TextScriptImporter:
userData:
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册