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
This commit is contained in:
nekobako 2024-08-31 10:04:58 +09:00 committed by GitHub
parent 9d48ae4f65
commit 580cb2bfe9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 4 deletions

View File

@ -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 $"<color=\"red\">Element {idx_s}: <???></color>";
}
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 $"<color=\"red\">Element {idx_s}</color>";
}
else
{
return $"Element {idx_s}";
}
};
}
else
{

View File

@ -171,7 +171,7 @@ namespace nadena.dev.modular_avatar.core.editor
Enumerable.SequenceEqual))
{
var renderer = _computeContext.GetComponent<Renderer>(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
{

View File

@ -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;
}