From 580cb2bfe9fa62142f0a42f30aecae71608998af Mon Sep 17 00:00:00 2001 From: nekobako Date: Sat, 31 Aug 2024 10:04:58 +0900 Subject: [PATCH] Fix material setter index (#1061) * fix: error when Material Setter has an invalid index * feat: warn by color when Material Setter has an invalid index --- .../MaterialSwitchObjectEditor.cs | 17 +++++++++++++++-- .../ReactiveObjectAnalyzer.LocateReactions.cs | 2 +- Editor/ReactiveObjects/MaterialSetterPreview.cs | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Editor/Inspector/MaterialSetter/MaterialSwitchObjectEditor.cs b/Editor/Inspector/MaterialSetter/MaterialSwitchObjectEditor.cs index 59c764a7..f789cc29 100644 --- a/Editor/Inspector/MaterialSetter/MaterialSwitchObjectEditor.cs +++ b/Editor/Inspector/MaterialSetter/MaterialSwitchObjectEditor.cs @@ -78,7 +78,7 @@ namespace nadena.dev.modular_avatar.core.editor.ShapeChanger var idx = int.Parse(idx_s); if (idx < 0 || idx >= sharedMaterials.Length) { - return $"Element {idx_s}: "; + return $"Element {idx_s}: "; } else if (sharedMaterials[idx] == null) { @@ -89,7 +89,20 @@ namespace nadena.dev.modular_avatar.core.editor.ShapeChanger return $"Element {idx_s}: {sharedMaterials[idx].name}"; } }; - f_material_index_dropdown.formatSelectedValueCallback = idx_s => $"Element {idx_s}"; + f_material_index_dropdown.formatSelectedValueCallback = idx_s => + { + if (string.IsNullOrWhiteSpace(idx_s)) return ""; + + var idx = int.Parse(idx_s); + if (idx < 0 || idx >= sharedMaterials.Length) + { + return $"Element {idx_s}"; + } + else + { + return $"Element {idx_s}"; + } + }; } else { diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs index 76ff96e5..63d33edd 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs @@ -171,7 +171,7 @@ namespace nadena.dev.modular_avatar.core.editor Enumerable.SequenceEqual)) { var renderer = _computeContext.GetComponent(obj.Object.Get(setter)); - if (renderer == null || renderer.sharedMaterials.Length < obj.MaterialIndex) continue; + if (renderer == null || renderer.sharedMaterials.Length <= obj.MaterialIndex) continue; var key = new TargetProp { diff --git a/Editor/ReactiveObjects/MaterialSetterPreview.cs b/Editor/ReactiveObjects/MaterialSetterPreview.cs index aea21a10..0889bfa8 100644 --- a/Editor/ReactiveObjects/MaterialSetterPreview.cs +++ b/Editor/ReactiveObjects/MaterialSetterPreview.cs @@ -129,7 +129,7 @@ namespace nadena.dev.modular_avatar.core.editor foreach (var mat in _materials) { - if (mat.Item1 <= mats.Length) + if (mat.Item1 < mats.Length) { mats[mat.Item1] = mat.Item2; }