// 处理其他没有 EntityData 的物体 private static void EntityOnAdded(On.Monocle.Entity.orig_Added orig, Entity self, Scene scene) { orig(self, scene); Type type = self.GetType(); if (!(scene is Level)) { return; } if (self.IsGlobalButNotCassetteManager()) { return; } if (self.HasEntityId2()) { return; } if (ExcludeTypes.Contains(type)) { return; } string entityIdParam = self.Position.ToString(); if (type.IsNestedPrivate) { if (!SpecialNestedPrivateTypes.Contains(type.FullName)) { return; } entityIdParam = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Where(info => info.FieldType.IsSimple() && info.DeclaringType.IsNestedPrivate).Aggregate( entityIdParam, (current, fieldInfo) => current + (fieldInfo.GetValue(self)?.ToString() ?? "null")); } EntityId2 entityId2 = self.CreateEntityId2(entityIdParam); self.SetEntityId2(entityId2); self.SetStartPosition(self.Position); }
public static void SetEntityId2(this Entity entity, EntityId2 entityId2) { entity.SetExtendedDataValue(EntityId2Key, entityId2); }