/// <summary> /// Add list contains to ProtoSet /// </summary> private static void AddProtosToSet <T>(ProtoSet <T> protoSet, List <Proto> protos) where T : Proto { var array = protoSet.dataArray; protoSet.Init(array.Length + protos.Count); for (int i = 0; i < array.Length; i++) { protoSet.dataArray[i] = array[i]; } for (int i = 0; i < protos.Count; i++) { protoSet.dataArray[array.Length + i] = protos[i] as T; if (protos[i] is ItemProto item) { item.index = array.Length + i; } if (protos[i] is RecipeProto) { RecipeProto proto = protos[i] as RecipeProto; if (proto.preTech != null) { ArrayAddItem(ref proto.preTech.UnlockRecipes, proto.ID); ArrayAddItem(ref proto.preTech.unlockRecipeArray, proto); } } LDBToolPlugin.logger.LogInfo($"Add {protos[i].ID} {protos[i].Name.Translate()} to {protoSet.GetType().Name}."); } var dataIndices = new Dictionary <int, int>(); for (int i = 0; i < protoSet.dataArray.Length; i++) { protoSet.dataArray[i].sid = protoSet.dataArray[i].SID; dataIndices[protoSet.dataArray[i].ID] = i; } protoSet.dataIndices = dataIndices; if (protoSet is StringProtoSet stringProtoSet) { for (int i = array.Length; i < protoSet.dataArray.Length; i++) { stringProtoSet.nameIndices[protoSet.dataArray[i].Name] = i; } } }
/// <summary> /// 添加多个数据到数据表 /// </summary> private static void AddProtosToSet <T>(ProtoSet <T> protoSet, List <Proto> protos) where T : Proto { var array = protoSet.dataArray; protoSet.Init(array.Length + protos.Count); for (int i = 0; i < array.Length; i++) { protoSet.dataArray[i] = array[i]; } for (int i = 0; i < protos.Count; i++) { protoSet.dataArray[array.Length + i] = protos[i] as T; if (protos[i] is ItemProto) { Traverse.Create(protos[i]).Property("index").SetValue(array.Length + i); } if (protos[i] is RecipeProto) { RecipeProto proto = protos[i] as RecipeProto; if (proto.preTech != null) { ArrayAddItem <int>(ref proto.preTech.UnlockRecipes, proto.ID); ArrayAddItem <RecipeProto>(ref proto.preTech.unlockRecipeArray, proto); } } Debug.Log($"[LDBTool]Add {protos[i].ID} {protos[i].Name.Translate()} to {protoSet.GetType().Name}."); } var dataIndices = new Dictionary <int, int>(); for (int i = 0; i < protoSet.dataArray.Length; i++) { protoSet.dataArray[i].sid = protoSet.dataArray[i].SID; dataIndices[protoSet.dataArray[i].ID] = i; } Traverse.Create(protoSet).Field("dataIndices").SetValue(dataIndices); if (protoSet is ProtoSet <StringProto> ) { var nameIndices = Traverse.Create(protoSet).Field("nameIndices").GetValue <Dictionary <string, int> >(); for (int i = array.Length; i < protoSet.dataArray.Length; i++) { nameIndices[protoSet.dataArray[i].Name] = i; } Traverse.Create(protoSet).Field("nameIndices").SetValue(nameIndices); } }