Fix Child OnClicks

This commit is contained in:
Tim
2025-07-12 13:08:50 +02:00
parent 4dee4d3862
commit e1ec13dda8

View File

@@ -271,14 +271,40 @@ public class ModelBehaviour : MonoBehaviour, IResettable
//model clicked //model clicked
void OnSelect() void OnSelect()
{ {
Debug.Log($"Selected portIndex {Index}"); Debug.Log($"OnClick model {name} {Index}");
if (Index == -1) if (Index == -1)
{ {
Debug.LogWarning($"Clicked on Initialized"); Debug.LogWarning($"Clicked on Initialized/BaseModel, doing nothing");
return; return;
} }
if (this is ChildModelBehaviour cmb)
{
if (cmb.Parent is BaseModelBehaviour)
{
PortSelector.mapPSB[Index].OnClick(); PortSelector.mapPSB[Index].OnClick();
} }
else //subchild
{
var parent = cmb;
while (parent)
{
if (parent.Parent is BaseModelBehaviour)
{
Debug.Log($"Parent {parent.name} is root, clicking on him");
PortSelector.mapPSB[parent.Index].OnClick();
return;
}
if (parent.Parent is ChildModelBehaviour cmbParent)
{
parent = cmbParent;
continue;
}
Debug.LogWarning($"Skipping {parent.name}, weird");
break;
}
}
}
}
public void ResetThis() public void ResetThis()
{ {