x


Select object by selecting gizmo or handle?

Is it possible to select a gameobject by selecting the gizmo in the Scene View? I have a line (Gizmos.DrawLine) between object A and object B and I want to be able to select the line and have it select object A.

That then leads on to my second question to grab a MouseOver event from gizmos, but maybe i'll leave that for another Question.

more ▼

asked Oct 23 '10 at 09:51 AM

George gravatar image

George
285 10 11 19

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

This question is old, so I don't know if I will be of help anymore, still I'm going to answer.

I don't know if gizmos are meant to be selectable, but on the other hand there is the possebility of extending the Unity Editor itself (refer Extending the Editor). There you get the idea of how to use handles to easily modify certain aspects of your object A.

That doesn't help you on your specific question, as basically to see the handles you would have to have your object selected allready. So as another straw for to hold on here is a small editor script that automatically selects the parent of something selected in the scene or hierachy view:

using UnityEditor;
using UnityEngine;    
[@CustomEditor(typeof(AutoSelectParent))]
public class AutoSelectParentEditor : Editor {
    public override void OnInspectorGUI()
    {
        EditorGUILayout.TextArea("You should not see this text unless this script doesn't work");
    }

    public void OnSceneGUI()
    {
        MonoBehaviour handle = (MonoBehaviour)target;
        GameObject[] selection = new GameObject[1];
        selection[0] = handle.transform.parent.gameObject;
        Selection.objects =  selection;
    }
}

put that script in an Editor folder for it to work. The following script is rather a marker to objects that shall not be selected. Put it outside an Editor folder and attach it to an object. Whenever you try to select object C that is a child of object A, you will instead select A immediatly. This can become a nuisance if you DO want to select object C again. To do that type the name ob object C in the search filter of the scene view to exclude the parent and you CAN select object C again.

using UnityEngine; public class AutoSelectParent : MonoBehaviour { }

Maybe you get some different ideas from the hints I gave you - if you do ponder this problem anymore, anyhow :-)

more ▼

answered Apr 19 '11 at 01:12 PM

Tom 17 gravatar image

Tom 17
269 5 7 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1665
x84
x69
x45
x37

asked: Oct 23 '10 at 09:51 AM

Seen: 2225 times

Last Updated: Oct 23 '10 at 09:51 AM