Search Unity

Draw Gizmo for selected (list) property?

Discussion in 'Immediate Mode GUI (IMGUI)' started by lowins, Oct 18, 2018.

  1. lowins

    lowins

    Joined:
    Mar 16, 2013
    Posts:
    1
    Is it possible to draw gizmos for selected properties?
    For example, in the image below i have an element of a list selected. I would like to draw a gizmo for the outline selected in this list.
    At the bottom i included some snippets that show how this specific case is structured. The list contains Outline objects (which do not implement MonoBehaviour). I would assume i have to draw gizmos in the ItemGenerator, but it needs to be able to somehow detect what element in the list is selected.
    Is this possible, and how would i have to go about it?




    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(ItemGenerator))]
    7. public class ItemGeneratorEditor : Editor {
    8.  
    9.     public override void OnInspectorGUI()
    10.     {
    11.         DrawDefaultInspector();
    12.         if (GUILayout.Button ("Generate"))
    13.         {
    14.             // do stuff
    15.         }
    16.     }
    17. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ItemGenerator: MonoBehaviour {
    6.  
    7.     public List<Outline> outlines;
    8.  
    9.     public void Generate()
    10.     {
    11.         // Generate
    12.         // Assign outlines
    13.     }
    14. }
    15.  
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]
    6. public class Outline {
    7.  
    8.     private List<Vector3> _points;
    9.  
    10.     public Outline()
    11.     {
    12.         _points = new List<Vector3>();
    13.     }
    14. }