Skip to content

Commit 8dd9d2b

Browse files
authored
Merge 1.1.0 to main (#59)
* To be able to test folders. (#51) * To be able to test folders. * Fix points reviewed. * Add DependentObjectBasedAssetFilter. (#52) * To be able to test folders. * Fix points reviewed. * Add DependentObjectBasedAssetFilter. * fix a point reviewd. * Add AssetTypeConstraint. (#53) * To be able to test folders. * Fix points reviewed. * Add DependentObjectBasedAssetFilter. * Add AssetTypeConstraint. * Fix a point reviewed. * Add FolderTexelCountConstraint. (#54) * To be able to test folders. * Fix points reviewed. * Add DependentObjectBasedAssetFilter. * Add AssetTypeConstraint. * Fix a point reviewed. * Add FolderTexelCountConstraint. * Feature/shader keyword constraint (#56) * To be able to test folders. * Fix points reviewed. * Add DependentObjectBasedAssetFilter. * Add AssetTypeConstraint. * Fix a point reviewed. * Add FolderTexelCountConstraint. * Add MaterialShaderKeywordConstraint. * Fix Bugs (#57) * Fixed that a presenter is not disposed correctly. * Make CheckCondition always enabled. * Update docs for 1.1.0. (#58) * Update docs for 1.1.0. * Fix a point reviewed. * bump
1 parent ed6d220 commit 8dd9d2b

File tree

72 files changed

+1537
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1537
-302
lines changed

Assets/AssetRegulationManager/Editor/Core/Model/AssetRegulationTestGenerateService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ public void Run(IReadOnlyList<string> assetPathFilters,
8686
private void RunInternal(IEnumerable<string> assetPaths, IReadOnlyList<string> regulationNameFilters = null)
8787
{
8888
_testStore.ClearTests();
89-
90-
// Exclude folders.
91-
assetPaths = assetPaths.Where(x => !AssetDatabase.IsValidFolder(x));
9289

9390
var regulations = _regulationRepository.GetAllRegulations().ToArray();
9491

@@ -118,7 +115,8 @@ private void RunInternal(IEnumerable<string> assetPaths, IReadOnlyList<string> r
118115
.Select(assetPathGroup =>
119116
{
120117
var assetTypeGroup = assetPathGroup.Select(AssetDatabase.GetMainAssetTypeAtPath).ToArray();
121-
return CreateTestsAsync(assetPathGroup, assetTypeGroup, regulations, _assetDatabaseAdapter);
118+
var folderFlagGroup = assetPathGroup.Select(AssetDatabase.IsValidFolder).ToArray();
119+
return CreateTestsAsync(assetPathGroup, assetTypeGroup, folderFlagGroup, regulations, _assetDatabaseAdapter);
122120
});
123121

124122
var tests = Task.WhenAll(createTestsTasks).Result;
@@ -138,7 +136,7 @@ private static Task<string[]> GetMatchedAssetPathsAsync(IList<string> assetPaths
138136
}
139137

140138
private static Task<AssetRegulationTest[]> CreateTestsAsync(IReadOnlyList<string> assetPaths,
141-
IReadOnlyList<Type> assetTypes, IList<AssetRegulation> regulations,
139+
IReadOnlyList<Type> assetTypes, IReadOnlyList<bool> folderFlags, IList<AssetRegulation> regulations,
142140
IAssetDatabaseAdapter assetDatabaseAdapter)
143141
{
144142
return Task.Run(() =>
@@ -148,10 +146,12 @@ private static Task<AssetRegulationTest[]> CreateTestsAsync(IReadOnlyList<string
148146
{
149147
var assetPath = assetPaths[i];
150148
var assetType = assetTypes[i];
149+
var folderFlag = folderFlags[i];
151150
var test = new AssetRegulationTest(assetPath, assetDatabaseAdapter);
152151
foreach (var regulation in regulations)
153152
{
154-
if (!regulation.IsTargetAsset(assetPath, assetType)) continue;
153+
if (!regulation.IsTargetAsset(assetPath, assetType, folderFlag))
154+
continue;
155155

156156
foreach (var constraint in regulation.Constraints.Values) test.AddEntry(constraint);
157157
}

Assets/AssetRegulationManager/Editor/Core/Model/AssetRegulations/AssetConstraintImpl/AssetPathConstraint.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public override string GetDescription()
7070
case AssetPathType.AssetNameWithoutExtensions:
7171
label = "Asset Name (Without Extensions)";
7272
break;
73-
case AssetPathType.FolderName:
74-
label = "Folder Name";
73+
case AssetPathType.ParentFolderName:
74+
label = "Parent Folder Name";
7575
break;
76-
case AssetPathType.FolderPath:
77-
label = "Folder Path";
76+
case AssetPathType.ParentFolderPath:
77+
label = "Parent Folder Path";
7878
break;
7979
default:
8080
throw new ArgumentOutOfRangeException();

Assets/AssetRegulationManager/Editor/Core/Model/AssetRegulations/AssetConstraintImpl/AssetPathType.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public enum AssetPathType
99
AssetPath,
1010
AssetName,
1111
AssetNameWithoutExtensions,
12-
FolderName,
13-
FolderPath
12+
ParentFolderName,
13+
ParentFolderPath
1414
}
1515

1616
public static class AssetPathModeExtensions
@@ -30,9 +30,9 @@ public static string ConvertAssetPath(this AssetPathType assetPathType, string a
3030
return Path.GetFileName(assetPath);
3131
case AssetPathType.AssetNameWithoutExtensions:
3232
return Path.GetFileNameWithoutExtension(assetPath);
33-
case AssetPathType.FolderName:
33+
case AssetPathType.ParentFolderName:
3434
return AssetPathUtility.GetFolderName(assetPath);
35-
case AssetPathType.FolderPath:
35+
case AssetPathType.ParentFolderPath:
3636
return AssetPathUtility.GetFolderPath(assetPath);
3737
default:
3838
throw new ArgumentOutOfRangeException(nameof(assetPathType), assetPathType, null);
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
using System.Text;
3+
using UnityEngine;
4+
using UnityEngine.Assertions;
5+
using Object = UnityEngine.Object;
6+
7+
namespace AssetRegulationManager.Editor.Core.Model.AssetRegulations.AssetConstraintImpl
8+
{
9+
[Serializable]
10+
[AssetConstraint("File/Asset Type", "Asset Type")]
11+
public sealed class AssetTypeConstraint : AssetConstraint<Object>
12+
{
13+
[SerializeField] private TypeReferenceListableProperty _type = new TypeReferenceListableProperty();
14+
[SerializeField] private bool _matchWithDerivedTypes = true;
15+
16+
private string _latestValue;
17+
18+
/// <summary>
19+
/// Type.
20+
/// </summary>
21+
public TypeReferenceListableProperty Type => _type;
22+
23+
public bool MatchWithDerivedTypes
24+
{
25+
get => _matchWithDerivedTypes;
26+
set => _matchWithDerivedTypes = value;
27+
}
28+
29+
public override string GetDescription()
30+
{
31+
var types = new StringBuilder();
32+
var typeCount = 0;
33+
foreach (var type in _type)
34+
{
35+
if (type == null)
36+
continue;
37+
38+
if (typeCount >= 1) types.Append(" || ");
39+
40+
types.Append(type.Name);
41+
typeCount++;
42+
}
43+
44+
if (typeCount >= 2)
45+
{
46+
types.Insert(0, "( ");
47+
types.Append(" )");
48+
}
49+
50+
var result = $"Type: {types}";
51+
if (MatchWithDerivedTypes)
52+
result += " and derived types";
53+
return result;
54+
}
55+
56+
public override string GetLatestValueAsText()
57+
{
58+
return string.IsNullOrEmpty(_latestValue) ? "None" : _latestValue;
59+
}
60+
61+
/// <inheritdoc />
62+
protected override bool CheckInternal(Object asset)
63+
{
64+
Assert.IsNotNull(asset);
65+
66+
var assetType = asset.GetType();
67+
_latestValue = assetType.ToString();
68+
69+
foreach (var typeRef in _type)
70+
{
71+
if (typeRef == null)
72+
continue;
73+
74+
var type = System.Type.GetType(typeRef.AssemblyQualifiedName);
75+
76+
if (type == null)
77+
continue;
78+
79+
if (type == assetType)
80+
return true;
81+
82+
if (_matchWithDerivedTypes && assetType.IsSubclassOf(type))
83+
return true;
84+
}
85+
86+
return false;
87+
}
88+
}
89+
}

Assets/AssetRegulationManager/Editor/Core/Model/AssetRegulations/AssetConstraintImpl/AssetTypeConstraint.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using AssetRegulationManager.Editor.Foundation.ListableProperty;
5+
using UnityEngine;
6+
using UnityEngine.Assertions;
7+
8+
namespace AssetRegulationManager.Editor.Core.Model.AssetRegulations.AssetConstraintImpl
9+
{
10+
[Serializable]
11+
[AssetConstraint("Material/Shader Keyword", "Shader Keyword")]
12+
public sealed class MaterialShaderKeywordConstraint : AssetConstraint<Material>
13+
{
14+
public enum CheckCondition
15+
{
16+
EnabledAll,
17+
EnabledAny,
18+
DisabledAll,
19+
DisabledAny
20+
}
21+
22+
[SerializeField] private CheckCondition _checkCondition = CheckCondition.EnabledAll;
23+
[SerializeField] private StringListableProperty _keywords = new StringListableProperty();
24+
25+
private string[] _latestValues;
26+
27+
public CheckCondition Condition
28+
{
29+
get => _checkCondition;
30+
set => _checkCondition = value;
31+
}
32+
33+
public StringListableProperty Keywords => _keywords;
34+
35+
public override string GetDescription()
36+
{
37+
var result = new StringBuilder();
38+
var elementCount = 0;
39+
foreach (var keyword in _keywords)
40+
{
41+
if (string.IsNullOrEmpty(keyword))
42+
continue;
43+
44+
if (elementCount >= 1)
45+
{
46+
var delimiter =
47+
_checkCondition == CheckCondition.EnabledAll || _checkCondition == CheckCondition.DisabledAll
48+
? " && "
49+
: " || ";
50+
result.Append(delimiter);
51+
}
52+
53+
result.Append(keyword);
54+
elementCount++;
55+
}
56+
57+
if (result.Length >= 1)
58+
{
59+
if (elementCount >= 2)
60+
{
61+
result.Insert(0, "( ");
62+
result.Append(" )");
63+
}
64+
65+
var prefix = _checkCondition == CheckCondition.EnabledAll ||
66+
_checkCondition == CheckCondition.EnabledAny
67+
? "Enabled Shader Keyword: "
68+
: "Disabled Shader Keyword: ";
69+
result.Insert(0, prefix);
70+
}
71+
72+
return result.ToString();
73+
}
74+
75+
public override string GetLatestValueAsText()
76+
{
77+
return string.Join(", ", _latestValues);
78+
}
79+
80+
protected override bool CheckInternal(Material asset)
81+
{
82+
Assert.IsNotNull(asset);
83+
84+
_latestValues = asset.shaderKeywords;
85+
switch (_checkCondition)
86+
{
87+
case CheckCondition.EnabledAny:
88+
return _keywords.Any(keyword => asset.shaderKeywords.Contains(keyword));
89+
case CheckCondition.EnabledAll:
90+
return _keywords.All(keyword => asset.shaderKeywords.Contains(keyword));
91+
case CheckCondition.DisabledAny:
92+
return _keywords.Any(keyword => !asset.shaderKeywords.Contains(keyword));
93+
case CheckCondition.DisabledAll:
94+
return _keywords.All(keyword => !asset.shaderKeywords.Contains(keyword));
95+
default:
96+
throw new ArgumentOutOfRangeException();
97+
}
98+
}
99+
}
100+
}

Assets/AssetRegulationManager/Editor/Core/Model/AssetRegulations/AssetConstraintImpl/MaterialShaderKeywordConstraint.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Linq;
3+
using AssetRegulationManager.Editor.Core.Shared;
4+
using UnityEditor;
5+
using UnityEngine;
6+
using UnityEngine.Assertions;
7+
8+
namespace AssetRegulationManager.Editor.Core.Model.AssetRegulations.AssetConstraintImpl
9+
{
10+
[Serializable]
11+
[AssetConstraint("Texture/Max Texel Count in Folder", "Max Texel Count in Folder")]
12+
public sealed class MaxFolderTexelCountConstraint : AssetConstraint<DefaultAsset>
13+
{
14+
[SerializeField] private int _maxCount;
15+
[SerializeField] private bool _topFolderOnly;
16+
17+
private int _latestValue;
18+
19+
public int MaxCount
20+
{
21+
get => _maxCount;
22+
set => _maxCount = value;
23+
}
24+
25+
public bool TopFolderOnly
26+
{
27+
get => _topFolderOnly;
28+
set => _topFolderOnly = value;
29+
}
30+
31+
public override string GetDescription()
32+
{
33+
var desc = $"Max Texel Count in Folder: {_maxCount}";
34+
return desc;
35+
}
36+
37+
public override string GetLatestValueAsText()
38+
{
39+
return _latestValue.ToString();
40+
}
41+
42+
protected override bool CheckInternal(DefaultAsset asset)
43+
{
44+
Assert.IsNotNull(asset);
45+
46+
var assetPath = AssetDatabase.GetAssetPath(asset);
47+
if (!AssetDatabase.IsValidFolder(assetPath))
48+
throw new ArgumentException($"Invalid Type: {asset.GetType()} is not folder.");
49+
50+
var textures = AssetDatabase.FindAssets("t:Texture", new[] { assetPath })
51+
.Select(AssetDatabase.GUIDToAssetPath)
52+
.Where(x =>
53+
{
54+
if (_topFolderOnly)
55+
{
56+
var parentFolderPath = AssetPathUtility.GetFolderPath(x);
57+
return parentFolderPath == assetPath;
58+
}
59+
60+
return true;
61+
})
62+
.Select(AssetDatabase.LoadAssetAtPath<Texture>);
63+
64+
var texelCount = 0;
65+
foreach (var texture in textures)
66+
texelCount += texture.width * texture.height;
67+
68+
_latestValue = texelCount;
69+
return texelCount <= _maxCount;
70+
}
71+
}
72+
}

Assets/AssetRegulationManager/Editor/Core/Model/AssetRegulations/AssetConstraintImpl/MaxFolderTexelCountConstraint.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)