Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Event.current not defined [SOLVED]

Discussion in 'Immediate Mode GUI (IMGUI)' started by monokilho, Mar 18, 2016.

  1. monokilho

    monokilho

    Joined:
    Oct 31, 2014
    Posts:
    2
    I seem to be having a bit of a stupid issue most likely to missing some namespace call. When i try to use Event.current I get "Error CS0117 'Event' does not contain a definition for 'current' Custom Editors.CSharp.Editor " though current is suposedly a static method according to documentation.Can anyone give me some insight on this or just tell the stupid mistake I did somewhere?

    Code of the file: (line 20 and 23 contain the method calls)
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4.  
    5. public class Popuptest
    6. {
    7.   static int popupListHash = "PopupList".GetHashCode();
    8.  
    9.   public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, GUIContent[] listContent,
    10.   GUIStyle listStyle)
    11.   {
    12.   return List(position, ref showList, ref listEntry, buttonContent, listContent, "button", "box", listStyle);
    13.   }
    14.  
    15.   public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, GUIContent[] listContent,
    16.   GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle)
    17.   {
    18.   int controlID = GUIUtility.GetControlID(popupListHash, FocusType.Passive);
    19.   bool done = false;
    20.   switch (Event.current.GetTypeForControl(controlID))
    21.   {
    22.   case EventType.mouseDown:
    23.   if (position.Contains(Event.current.mousePosition))
    24.   {
    25.   GUIUtility.hotControl = controlID;
    26.   showList = true;
    27.   }
    28.   break;
    29.   case EventType.mouseUp:
    30.   if (showList)
    31.   {
    32.   done = true;
    33.   }
    34.   break;
    35.   }
    36.  
    37.   GUI.Label(position, buttonContent, buttonStyle);
    38.   if (showList)
    39.   {
    40.   Rect listRect = new Rect(position.x, position.y, position.width, listStyle.CalcHeight(listContent[0], 1.0f) * listContent.Length);
    41.   GUI.Box(listRect, "", boxStyle);
    42.   listEntry = GUI.SelectionGrid(listRect, listEntry, listContent, 1, listStyle);
    43.   }
    44.   if (done)
    45.   {
    46.   showList = false;
    47.   }
    48.   return done;
    49.   }
    50. }
    51.  
    [SOLVED] Aparently there was a custom class on that project also called Event
     
    Last edited: Mar 18, 2016
    Westland likes this.
  2. Westland

    Westland

    Joined:
    Jan 26, 2015
    Posts:
    25
    Really glad you came back and left the solution, saved me - Mucho graciases!
     
  3. batvink

    batvink

    Joined:
    Sep 26, 2019
    Posts:
    53
    7 years later...just resolved my problem :)