diff --git a/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs b/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs index 19b8fb3..2f46bd8 100644 --- a/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs +++ b/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs @@ -271,13 +271,39 @@ public class ModelBehaviour : MonoBehaviour, IResettable //model clicked void OnSelect() { - Debug.Log($"Selected portIndex {Index}"); + Debug.Log($"OnClick model {name} {Index}"); if (Index == -1) { - Debug.LogWarning($"Clicked on Initialized"); + Debug.LogWarning($"Clicked on Initialized/BaseModel, doing nothing"); return; } - PortSelector.mapPSB[Index].OnClick(); + if (this is ChildModelBehaviour cmb) + { + if (cmb.Parent is BaseModelBehaviour) + { + 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()