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); }
/// <summary> /// 遍历解析每个物体上用户自己添加的脚本 /// </summary> /// <param name="root"></param> /// <param name="transform"></param> /// <param name="scriptList"></param> private static void DecompressionBinding(Transform root, Transform transform, List <PrefabBindingInfo.ScriptItem> scriptList) { if (transform != null) { var behaivers = GetCustomMonoBehaivers(transform); for (int i = 0; i < behaivers.Length; i++) { var behaiver = behaivers[i]; var scriptItem = new PrefabBindingInfo.ScriptItem(); var fields = GetAllSupportedFieldInfos(behaivers[i]); for (int j = 0; j < fields.Length; j++) { var field = fields[j]; var fieldValue = field.GetValue(behaiver); if (fieldValue != null) { var value = GetStringValue(field.FieldType, root, fieldValue); if (!string.IsNullOrEmpty(value)) { scriptItem.resources.Add(field.Name, value); } } } if (scriptItem.resources.Count > 0) { scriptItem.path = GetChildPath(root, transform); scriptItem.type = behaiver.GetType(); scriptList.Add(scriptItem); } } } if (transform.childCount > 0) { for (int i = 0; i < transform.childCount; i++) { var childTransform = transform.GetChild(i); DecompressionBinding(root, childTransform, scriptList); } } }