Search Unity

[Help] Hierarchy Editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by DoPie, Jun 16, 2015.

  1. DoPie

    DoPie

    Joined:
    Jun 20, 2013
    Posts:
    64
    Hi to All,

    can you help me on this part i try to make a textfield in Hierarchy Window. but this is could happen when i type a word or letter inside of textfield.

    Screen Shot 2015-06-16 at 5.16.02 PM.png
    The Textfield have same Word or text.



    Here's the Code:


    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4.  
    5. [InitializeOnLoad]
    6. class MyHierarchyIcon
    7. {
    8.     static List<int> markedObjects;
    9.  
    10.     static MyHierarchyIcon ()
    11.     {
    12.         // Init
    13.         EditorApplication.update += UpdateCB;
    14.         EditorApplication.hierarchyWindowItemOnGUI += HierarchyItemCB;
    15.     }
    16.  
    17.     static void UpdateCB ()
    18.     {
    19.         // Check here
    20.         GameObject[] go = Object.FindObjectsOfType (typeof(GameObject)) as GameObject[];
    21.         markedObjects = new List<int> ();
    22.         foreach (GameObject g in go)
    23.         {
    24.             if (g.GetComponent<Transform> () != null)
    25.             {
    26.                 markedObjects.Add (g.GetInstanceID ());
    27.             }
    28.         }
    29.     }
    30.     static string a = "";
    31.  
    32.     static void HierarchyItemCB (int instanceID, Rect selectionRect)
    33.     {
    34.         if (markedObjects.Contains (instanceID))
    35.         {
    36.             // Draw the GUI
    37.            a = GUILayout.TextField(a,25);
    38.         }
    39.     }
    40. }[/SIZE]
    41.  
    42.  
    43.  
    Thank you in Advance.
    Go Unity Dev
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Use GUI instead of GUILayout, the rect is passed as a parameter.

    Code (csharp):
    1. a = GUI.TextField( selectionRect, a );
    The reason they all have the same word is because you only have a single static string variable. if you want different text for each item then you need to use a different variable instead of a static string.