Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to run a method in Unity after rendering the GUI (void OnGUI () {})? in EditorWindow

Discussion in 'Scripting' started by ivantriumphov, Jun 19, 2020.

  1. ivantriumphov

    ivantriumphov

    Joined:
    Jun 24, 2019
    Posts:
    5
    Here I found the order of execution of the functions of events. But I still did not understand how to start the method, after the GUI rendering event (void OnGUI () {}).
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. public class Main : EditorWindow {
    3.     [MenuItem ("Window/Panorama Terrain Tools")]
    4.     public static void ShowWindow () {
    5.         m_WindowMain = (Main) GetCustomWindow (true);
    6.         // if(Main.m_WindowMain == null) { Main.m_WindowMain = (Main) Main.GetCustomWindow (true); }
    7.         m_WindowMain.Show ();
    8.     }
    9.  
    10.     public static Main GetCustomWindow (bool focus) {
    11.         return GetWindow<Main> (" ", focus);
    12.     }
    13.  
    14.  
    15.     void OnEnable () {
    16.  
    17.     }
    18.     void OnGUI () {
    19.      ...
    20.     }
    21.  
    22.     void SomeMethod(){
    23.      Debug.Log("method to call after the method void OnGUI () {}");
    24.     }
    25. }
    26. #endif
     
  2. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
  3. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Besides the EditorApplication.delayCall that is called only once (but you can keep registering every time it is called), you can use this:
    Code (CSharp):
    1. void OnGUI()
    2. {
    3.     if (Event.current.type == EventType.Repaint)
    4.     {
    5.         // this will be processed after all others EventType
    6.     }
    7. }
     
    Garrafote likes this.
  4. ivantriumphov

    ivantriumphov

    Joined:
    Jun 24, 2019
    Posts:
    5
  5. ivantriumphov

    ivantriumphov

    Joined:
    Jun 24, 2019
    Posts:
    5
    I need to call the method once .... And not after each redraw
     
  6. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    It's pretty simple, anytime you need a method to be called after all GUI calls you can just add that method to to the delegate, like so:
    Code (CSharp):
    1.  EditorApplication.delayCall += SomeMethod;