Skip to content

Commit

Permalink
Output invalid materials
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Williams committed Jan 18, 2025
1 parent c178062 commit 777780c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Components/VRCQuestifyerSwitchMaterials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public struct MaterialSwitch {
public bool addQuestSuffix = true;
public bool useToonShader = false;

public void Init() {
var transformToUse = this.overrideTarget != null ? this.overrideTarget : this.transform;
var renderer = transformToUse.GetComponent<Renderer>();

materialSwitches = new MaterialSwitch[renderer.sharedMaterials.Length];
}

public override void Apply() {
Debug.Log("VRCQuestifyer :: Switch materials - apply");

Expand Down
58 changes: 57 additions & 1 deletion Editor/ComponentEditors/VRCQuestifyerAvatarEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public override void RenderGUI() {

EditorGUI.BeginDisabledGroup(!canOverrideTarget);
EditorGUILayout.ObjectField("Target", vrcAvatarDescriptor, typeof(VRCAvatarDescriptor));
CustomGUI.ItalicLabel("Leave blank to use this object");

if (canOverrideTarget) {
CustomGUI.ItalicLabel("Leave blank to use this object");
} else {
CustomGUI.ItalicLabel("You cannot override this target");
}

EditorGUI.EndDisabledGroup();

CustomGUI.LineGap();
Expand Down Expand Up @@ -158,6 +164,55 @@ void RenderComponentValidationIssues() {
}
}

void RenderMaterialIssues() {
var component = target as VRCQuestifyerAvatar;
var vrcAvatarDescriptor = Utils.FindComponentInAncestor<VRCAvatarDescriptor>(component.transform);

List<Renderer> renderers = Utils.FindAllComponents<Renderer>(vrcAvatarDescriptor.transform);

foreach (var renderer in renderers) {
var materials = renderer.sharedMaterials;
var isInvalid = true;

var switchMaterialsComponent = renderer.gameObject.GetComponent<VRCQuestifyerSwitchMaterials>();

if (switchMaterialsComponent != null) {
continue;
}

foreach (var material in materials) {
if (material == null || Common.GetIsMaterialUsingWhitelistedShader(material)) {
continue;
}

isInvalid = true;
}

if (!isInvalid) {
continue;
}

EditorGUILayout.BeginHorizontal();

if (CustomGUI.TinyButton("Ping")) {
Utils.Ping(renderer.gameObject);
}

if (CustomGUI.TinyButton("View")) {
Utils.Inspect(renderer.gameObject);
}

if (CustomGUI.TinyButton("+Swi")) {
switchMaterialsComponent = renderer.gameObject.AddComponent<VRCQuestifyerSwitchMaterials>();
switchMaterialsComponent.Init();
}

CustomGUI.Label($"Renderer \"{renderer.gameObject.name}\" has at least one invalid material");

EditorGUILayout.EndHorizontal();
}
}

void RenderConstraintIssues() {
var component = target as VRCQuestifyerAvatar;
var vrcAvatarDescriptor = Utils.FindComponentInAncestor<VRCAvatarDescriptor>(component.transform);
Expand Down Expand Up @@ -326,6 +381,7 @@ void RenderIssues() {
CustomGUI.MediumLabel("Issues");

RenderComponentValidationIssues();
RenderMaterialIssues();
RenderConstraintIssues();
RenderPhysBoneIssues();
RenderContactIssues();
Expand Down

0 comments on commit 777780c

Please sign in to comment.