private ValidationContext( Guid contentId, Guid schemaId, CheckContents checkContent, CheckContentsByIds checkContentByIds, CheckAssets checkAsset, ImmutableQueue <string> propertyPath, bool isOptional, ValidationMode mode = ValidationMode.Default) { Guard.NotNull(checkAsset); Guard.NotNull(checkContent); Guard.NotNull(checkContentByIds); this.propertyPath = propertyPath; this.checkContent = checkContent; this.checkContentByIds = checkContentByIds; this.checkAsset = checkAsset; this.contentId = contentId; this.schemaId = schemaId; Mode = mode; IsOptional = isOptional; }
public ValidationContext( Guid contentId, Guid schemaId, CheckContents checkContent, CheckAssets checkAsset) : this(contentId, schemaId, checkContent, checkAsset, ImmutableQueue <string> .Empty, false) { }
public AssetsValidator(AssetsFieldProperties properties, CheckAssets checkAssets) { Guard.NotNull(properties, nameof(properties)); Guard.NotNull(checkAssets, nameof(checkAssets)); this.properties = properties; this.checkAssets = checkAssets; }
public ValidationContext( Guid contentId, Guid schemaId, CheckContents checkContent, CheckContentsByIds checkContentsByIds, CheckAssets checkAsset, ValidationMode mode = ValidationMode.Default) : this(contentId, schemaId, checkContent, checkContentsByIds, checkAsset, ImmutableQueue <string> .Empty, false, mode) { }
public IEnumerable <IValidator> CreateValueValidators(ValidatorContext context, IField field, ValidatorFactory createFieldValidator) { if (context.Mode == ValidationMode.Optimized) { yield break; } var isRequired = IsRequired(context, field.RawProperties); if (field is IField <AssetsFieldProperties> assetsField) { var checkAssets = new CheckAssets(async ids => { return(await assetRepository.QueryAsync(context.AppId.Id, null, Q.Empty.WithIds(ids))); }); yield return(new AssetsValidator(isRequired, assetsField.Properties, checkAssets)); } if (field is IField <ReferencesFieldProperties> referencesField) { var checkReferences = new CheckContentsByIds(async ids => { return(await contentRepository.QueryIdsAsync(context.AppId.Id, ids, SearchScope.All)); }); yield return(new ReferencesValidator(isRequired, referencesField.Properties, checkReferences)); } if (field is IField <NumberFieldProperties> numberField && numberField.Properties.IsUnique) { var checkUniqueness = new CheckUniqueness(async filter => { return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter)); }); yield return(new UniqueValidator(checkUniqueness)); } if (field is IField <StringFieldProperties> stringField && stringField.Properties.IsUnique) { var checkUniqueness = new CheckUniqueness(async filter => { return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter)); }); yield return(new UniqueValidator(checkUniqueness)); } }
public AssetsValidator(bool isRequired, AssetsFieldProperties properties, CheckAssets checkAssets) { Guard.NotNull(properties, nameof(properties)); Guard.NotNull(checkAssets, nameof(checkAssets)); this.properties = properties; if (isRequired || properties.MinItems.HasValue || properties.MaxItems.HasValue) { collectionValidator = new CollectionValidator(isRequired, properties.MinItems, properties.MaxItems); } if (!properties.AllowDuplicates) { uniqueValidator = new UniqueValuesValidator <DomainId>(); } this.checkAssets = checkAssets; }
public IEnumerable <IValidator> CreateValueValidators(ValidationContext context, IField field, FieldValidatorFactory createFieldValidator) { if (field is IField <AssetsFieldProperties> assetsField) { var checkAssets = new CheckAssets(async ids => { return(await assetRepository.QueryAsync(context.AppId.Id, new HashSet <Guid>(ids))); }); yield return(new AssetsValidator(assetsField.Properties, checkAssets)); } if (field is IField <ReferencesFieldProperties> referencesField) { var checkReferences = new CheckContentsByIds(async ids => { return(await contentRepository.QueryIdsAsync(context.AppId.Id, ids, SearchScope.All)); }); yield return(new ReferencesValidator(referencesField.Properties.SchemaIds, checkReferences)); } if (field is IField <NumberFieldProperties> numberField && numberField.Properties.IsUnique) { var checkUniqueness = new CheckUniqueness(async filter => { return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter)); }); yield return(new UniqueValidator(checkUniqueness)); } if (field is IField <StringFieldProperties> stringField && stringField.Properties.IsUnique) { var checkUniqueness = new CheckUniqueness(async filter => { return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter)); }); yield return(new UniqueValidator(checkUniqueness)); } }
private ValidationContext( Guid contentId, Guid schemaId, CheckContents checkContent, CheckAssets checkAsset, ImmutableQueue <string> propertyPath, bool isOptional) { Guard.NotNull(checkAsset, nameof(checkAsset)); Guard.NotNull(checkContent, nameof(checkAsset)); this.propertyPath = propertyPath; this.checkContent = checkContent; this.checkAsset = checkAsset; this.contentId = contentId; this.schemaId = schemaId; IsOptional = isOptional; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); CheckAssets checkAssets = (CheckAssets)target; if (checkAssets.usefulPath == null) { checkAssets.usefulPath = new List <string>(); } if (checkAssets.checkPath == null) { checkAssets.checkPath = new List <string>(); } GUILayout.Label("场景/预制体路径:"); for (int i = 0; i < checkAssets.usefulPath.Count; i++) { string text = checkAssets.usefulPath[i]; GUILayout.BeginHorizontal(); if (GUILayout.Button(text, GUI.skin.label)) { } if (GUILayout.Button("-", GUILayout.Width(20))) { checkAssets.usefulPath.RemoveAt(i); } GUILayout.EndHorizontal(); } if (GUILayout.Button("+")) { string path = EditorUtility.OpenFolderPanel("Select", "Assets", ""); path = FullPathToAssetsPath(path); if (!string.IsNullOrEmpty(path) && !checkAssets.usefulPath.Contains(path)) { checkAssets.usefulPath.Add(path); } AssetDatabase.SaveAssets(); } GUILayout.Label("资源路径:"); for (int i = 0; i < checkAssets.checkPath.Count; i++) { GUILayout.BeginHorizontal(); string text = checkAssets.checkPath[i]; //text = "Assets" + text.Replace(Application.dataPath, ""); if (GUILayout.Button(text, GUI.skin.label)) { } if (GUILayout.Button("-", GUILayout.Width(20))) { checkAssets.checkPath.RemoveAt(i); } GUILayout.EndHorizontal(); } if (GUILayout.Button("+")) { string path = EditorUtility.OpenFolderPanel("Select", "Assets", ""); path = FullPathToAssetsPath(path); if (!string.IsNullOrEmpty(path) && !checkAssets.checkPath.Contains(path)) { checkAssets.checkPath.Add(path); } AssetDatabase.SaveAssets(); } if (GUILayout.Button("检查资源")) { var allFiles = GetAllFiles(checkAssets.checkPath); var dependences = GetDependences(checkAssets.usefulPath); checkResult = CheckAssets(allFiles, dependences); } GUILayout.BeginHorizontal(); bool flag = GUILayout.Toggle(checkAssets.showNormal, "显示非异常资源"); if (flag != checkAssets.showNormal) { checkAssets.showNormal = flag; AssetDatabase.SaveAssets(); } GUILayout.EndHorizontal(); if (checkResult != null && checkResult.Count != 0) { for (int i = 0; i < checkResult.Count; i++) { var r = checkResult[i]; int refCount = r.refSources.Count; //GUILayout.BeginVertical(refCount == 1 ? NormalStyle : AlertStyle); GUILayout.BeginVertical(); if (refCount == 1) { if (!checkAssets.showNormal) { continue; } } GUILayout.BeginHorizontal(); string assetPath = r.assetPath; Texture icon = AssetDatabase.GetCachedIcon(assetPath); GUILayout.Label(refCount.ToString(), GUILayout.MaxHeight(16), GUILayout.Width(20)); if (GUILayout.Button(icon, GUI.skin.label, GUILayout.MaxHeight(16), GUILayout.Width(20))) { EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(assetPath)); } GUILayout.Space(10); r.foldout = EditorGUILayout.Foldout(r.foldout, assetPath); GUILayout.EndHorizontal(); if (r.foldout) { foreach (var _ref in r.refSources) { GUILayout.BeginHorizontal(); GUILayout.Space(65); if (GUILayout.Button(_ref, GUI.skin.label)) { EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(_ref)); } GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); } //备份并删除引用零次的资源 if (GUILayout.Button("备份并删除多余文件")) { List <string> toDeleteFiles = new List <string>(); foreach (var v in checkResult) { if (v.refSources.Count == 0) { toDeleteFiles.Add(v.assetPath); } } if (toDeleteFiles.Count != 0) { string path = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length) + "Backup"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string suffix = "[" + System.DateTime.Now + "]"; suffix = suffix.Replace("/", "-"); suffix = suffix.Replace(":", "-"); string fileName = "CheckAsses" + suffix + ".unitypackage"; string fullPath = Path.Combine(path, fileName); AssetDatabase.ExportPackage(toDeleteFiles.ToArray(), fullPath); foreach (var v in toDeleteFiles) { AssetDatabase.DeleteAsset(v); } AssetDatabase.Refresh(); System.Diagnostics.Process.Start(path); } } } }