using System; using System.Collections.Generic; using NBC; using Newtonsoft.Json.Linq; using UnityEngine; namespace NBF { public partial class ConfigAssets { private static readonly Type CustomType = typeof(ICustomParse); private static List ParseLine(JToken[] arr, TableNameAttribute tableNameAttribute) where T : ConfigBase { List list = new List(); var type = typeof(T); foreach (var jToken in arr) { T instance = null; try { if (CustomType.IsAssignableFrom(type)) //自定义解析 { instance = Activator.CreateInstance(); } else { instance = jToken.ToObject(); } } catch (Exception e) { Log.Error(e); } if (instance != null) { var key = jToken[tableNameAttribute.Key].ToInt(); if (key < 1) { if (instance.id > 0) { key = instance.id; } } try { if (key < 1) continue; if (instance is ICustomParse customParse) { customParse.Parse(jToken); } instance.id = key; list.Add(instance); } catch (Exception e) { Log.Error(e); } } } return list; } } }