/// <summary> /// 创建临时绑定对象 /// </summary> /// <param name="bindingInfo"></param> /// <returns></returns> public static GameObject CreateBindingTemplate(PrefabBindingInfo bindingInfo) { var pathDic = new Dictionary <string, Transform>(); var root = new GameObject(bindingInfo.name); for (int i = 0; i < bindingInfo.scriptItems.Count; i++) { var scriptItem = bindingInfo.scriptItems[i]; var transform = CompleteTransform(root.transform, scriptItem.path, pathDic); var behaiver = MustMonobeahvier(transform.gameObject, scriptItem.type); if (behaiver != null && scriptItem.resources != null) { using (var enumerator = scriptItem.resources.GetEnumerator()) { while (enumerator.MoveNext()) { var current = enumerator.Current; SetValueToMemeberRuntime(behaiver, current.Key, current.Value, root.transform, pathDic); } } } else { Debug.LogErrorFormat("【装置失败】路径:{0},类型:{1},资源:{2}", scriptItem.path, scriptItem.type, scriptItem.resources); } } return(root); }
/// <summary> /// 解析关联信息 /// </summary> /// <param name="scripts"></param> /// <param name="objHolds"></param> public static PrefabBindingInfo DecompressionBindingInfo(Transform root) { var info = new PrefabBindingInfo(root.name); DecompressionBinding(root, root, info.scriptItems); return(info); }
public static PrefabBindingInfo LoadPrefabBindingInfo(this CsvTable table) { if (table == null) { return(null); } if (table.Columns.Count < 4) { Debug.LogErrorFormat("表列数和需求不一致,请目标表{0}检查是否为绑定信息!", table.name); return(null); } var prefabBindingInfo = new PrefabBindingInfo(table.name); var count = table.Rows.Count; for (int i = 0; i < count; i++) { var row = table.Rows[i]; var scriptItem = new PrefabBindingInfo.ScriptItem(); scriptItem.path = row[0]; var assemble = Assembly.Load(row[1]); if (assemble != null) { scriptItem.type = assemble.GetType(row[2]); } scriptItem.resources = ParamAnalysisTool.ToDictionary(row[3]); prefabBindingInfo.scriptItems.Add(scriptItem); } return(prefabBindingInfo); }
private static void CopyBininding() { bindingInfo = DecompressionBindingInfo(Selection.activeTransform); if (bindingInfo != null && bindingInfo.scriptItems != null && bindingInfo.scriptItems.Count > 0) { EditorUtility.DisplayDialog("小提示", "复制信息成功,可选中目标后,使用粘贴功能!", "确认"); } else { EditorUtility.DisplayDialog("小提示", "复制信息失败,未成功解析到非引擎自带的Monobehaiver信息!", "确认"); } }
///// <summary> ///// 加载记录的信息 ///// </summary> ///// <param name="obj"></param> ///// <param name="scripts"></param> public static void InstallInfomation(PrefabBindingInfo bindingInfo, Transform root) { var pathDic = new Dictionary <string, Transform>(); for (int i = 0; i < root.childCount; i++) { MakeTransfomDicDeep(root.GetChild(i), "", pathDic); } for (int i = 0; i < bindingInfo.scriptItems.Count; i++) { var scriptItem = bindingInfo.scriptItems[i]; Transform currentTransform = null; if (string.IsNullOrEmpty(scriptItem.path)) { currentTransform = root; } else { if (pathDic.ContainsKey(scriptItem.path)) { currentTransform = pathDic[scriptItem.path]; } } if (currentTransform != null) { var behaiver = MustMonobeahvier(currentTransform.gameObject, scriptItem.type); if (behaiver != null && scriptItem.resources != null) { using (var enumerator = scriptItem.resources.GetEnumerator()) { while (enumerator.MoveNext()) { var current = enumerator.Current; SetValueToMemeber(behaiver, current.Key, current.Value, pathDic); } } } else { Debug.LogErrorFormat("【装置失败】路径:{0},类型:{1},资源:{2}", scriptItem.path, scriptItem.type, scriptItem.resources); } } else { Debug.LogErrorFormat("【装置失败】路径:{0}", scriptItem.path); } } }
public static CsvTable CreateTable(this PrefabBindingInfo bindingInfo) { var table = new CsvTable(bindingInfo.name); table.Columns = new List <string>(titles); for (int i = 0; i < bindingInfo.scriptItems.Count; i++) { var scriptItem = bindingInfo.scriptItems[i]; var infos = new string[titles.Length]; infos[0] = scriptItem.path; infos[1] = scriptItem.type.Assembly.FullName; infos[2] = scriptItem.type.FullName; infos[3] = ParamAnalysisTool.FromDictionary(scriptItem.resources); table.Rows.Add(infos); } return(table); }