Search Unity

Drag and Drop component into EditorWindow field

Discussion in 'Immediate Mode GUI (IMGUI)' started by cybie, Jan 24, 2015.

  1. cybie

    cybie

    Joined:
    Sep 17, 2010
    Posts:
    91
    In PlayMaker, if your game object contains multiple of a type of component (say contains several PlayerMakerFSM component), you can drag and drop a specific one of those components into a field of an EditorWindow. How is that achieved?

    I only know how to select and drop a game object into a field, not how to drag and drop a specific component.

    Any hints would be appreciated.
    David
     
  2. tango209

    tango209

    Joined:
    Feb 23, 2011
    Posts:
    379
    Typically you only have one 'thing' on a component, unless you are talking about specific scripts. In any case, the editor field will usually accept the object type it is expecting (for example; Transform, Texture, etc.).

    What specifically is the field expecting? Can you post a screenshot of the editor window?
     
  3. cybie

    cybie

    Joined:
    Sep 17, 2010
    Posts:
    91
    In PlayMakerFSM component, an GO can contain multiples of them. You can assign anyone of these to a field (within the PlayMaker editor window) by dragging the component (start by mouse holding the top of the desire component) and dropping into the field box.

    So there are 2 things I want to achieve:
    1) Editor window field accepting a reference to specific type of component of another game object.
    2) Like 1), but the source game object has multiples of the component, and I want editor window to accept a specific one of them.

    Thanks
    David
     
  4. Immanuel-Scholz

    Immanuel-Scholz

    Joined:
    Jun 8, 2013
    Posts:
    221
    Are you asking how to do this in the editor? You can drag the heading of the component in the inspector view. So select your game object, and start dragging the component name.


    (Or are you asking how to initiate a drag operation in editor code that contains a specific component instead of a gameObject? If so, you simply just set the component to DragAndDrop.objectReferences instead of the gameObject.)
     
  5. cybie

    cybie

    Joined:
    Sep 17, 2010
    Posts:
    91
    Hi Immanuel,

    I am asking how to achieve this in code. I think you answered my question. Thanks!