Jump to content

Editor Scene: What Part is user Mousing Over in Bin?


Recommended Posts

Hey all,

Is there a way I can in the Editor scene, tell what part the user has their mouse over, not in the 3D view, but in the parts bin on the left? Or if that can't be done, maybe a way to tell what part it is if they right click it?

Link to comment
Share on other sites

I'm trying something along the lines of this:


VABCamera cam = Camera.main.GetComponent<VABCamera>();
GUILayer editorLayer = cam.GetComponent<GUILayer>();
if (editorLayer.HitTest(Input.mousePosition) != null)
Debug.Log(editorLayer.HitTest(Input.mousePosition).name);

But the hit test always comes back null, so either I have the wrong camera, the wrong GUILayer, or something. Not sure.

Link to comment
Share on other sites

You could repurpose this snippet:

[KSPAddon(KSPAddon.Startup.EditorAny, false)]
class EditPartListPrefab : MonoBehaviour
{
class ClickListener : MonoBehaviour
{
AvailablePart myPart;
EditorPartIcon icon;
bool mouseFlag = false;

void Start()
{
GetComponent<UIButton>().AddValueChangedDelegate(OnClick);
GetComponent<UIButton>().AddInputDelegate(OnInput);
myPart = GetComponent<EditorPartIcon>().partInfo;
icon = GetComponent<EditorPartIcon>();
}

void OnClick(IUIObject obj)
{
print("User clicked " + myPart.partPrefab.name);
}

void OnInput(ref POINTER_INFO ptr)
{
switch (ptr.evt)
{
case POINTER_INFO.INPUT_EVENT.MOVE:
if (!mouseFlag)
{
mouseFlag = true;
print("User moused over " + myPart.partPrefab.name);
}
break;
case POINTER_INFO.INPUT_EVENT.MOVE_OFF:
mouseFlag = false;
break;
}
}
}

void Start()
{
EditorPartList.Instance.iconPrefab.gameObject.AddComponent<ClickListener>();
}
}

The PartIcons are EzGUI buttons, not Unity GUI, so if you really want to manually cast a ray instead you'll want to do it on the EzGUI_UI layer using one of the EzGUI UI cameras

Link to comment
Share on other sites

The PartIcons are EzGUI buttons, not Unity GUI, so if you really want to manually cast a ray instead you'll want to do it on the EzGUI_UI layer using one of the EzGUI UI cameras

Well that would explain it! Thank you so much!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...