Search Unity

Window info

Discussion in 'Immediate Mode GUI (IMGUI)' started by Omar Rojo, Jul 18, 2008.

  1. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Is there a way to know when a window becomes active ? or if its active at the moment ? both help me with my problem..

    .org
     
  2. imparare

    imparare

    Joined:
    Jun 24, 2008
    Posts:
    369
    here is what I do:


    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class moviePlay : MonoBehaviour {
    7.  
    8. private Rect WindowRect;
    9. private bool WindowActive;
    10. private MovieTexture videoTexture;
    11. public GUISkin videoController;
    12. public GUISkin blankSkin;
    13. public Texture2D playButton;
    14. public Texture2D stopButton;
    15. public Texture2D rewindButton;
    16.  
    17.     // Use this for initialization
    18.     void Start () {
    19.        
    20.     WindowRect = new Rect(20, 20, 160,86);
    21.     }
    22.    
    23.    
    24.     void OnGUI()
    25.     {
    26.        
    27.         if(WindowActive)
    28.         {
    29.             WindowRect = GUI.Window (1, WindowRect, VideoController, "Video Controller");
    30.             WindowActive = true;
    31.             videoTexture = (MovieTexture) renderer.material.mainTexture;           
    32.         }
    33.                
    34.     }  
    35.    
    36.     void VideoController(int WindowId)
    37.     {
    38.                            
    39.        
    40.         GUI.skin = videoController;
    41.        
    42.         GUILayout.BeginHorizontal();
    43.  
    44.         if(GUILayout.Button(playButton)) playVideo();
    45.         if(GUILayout.Button(stopButton)) stopVideo();
    46.         if(GUILayout.Button(rewindButton)) rewindVideo();
    47.        
    48.         GUILayout.EndHorizontal();
    49.        
    50.         GUI.skin = blankSkin;
    51.        
    52.         if(GUILayout.Button("hide panel"))
    53.         {
    54.            
    55.             videoTexture.Stop();
    56.             WindowActive = false;                      
    57.         }
    58.        
    59.             GUI.DragWindow();
    60.     }
    61.    
    62.     void playVideo()
    63.     {
    64.         videoTexture.Play();
    65.     }
    66.    
    67.     void stopVideo()
    68.     {
    69.         videoTexture.Stop();
    70.     }
    71.    
    72.     void rewindVideo()
    73.     {
    74.         videoTexture.Stop();
    75.         videoTexture.Play();   
    76.     }
    77.    
    78.     void OnMouseDown()
    79.     {
    80.         if(!WindowActive)   WindowActive = true;
    81.     }
    82.        
    83. }
    84.  
    85.  
    This is just a simple video controller GUI panel that appears when the video screen (plane with movieTexture) is clicked. It has a hide panel button to turn it off. Not sure if that's what you mean or not.
     
  3. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Not really, when i have more than 1 GUI.Window that are being rendered, i want to know which one is being rendered as Active, the GUI.Window becomes Active when the user clicks his area or any control inside it.

    .org
     
  4. imparare

    imparare

    Joined:
    Jun 24, 2008
    Posts:
    369
    just guessing but it is possible to check for FocusWindow somehow?
     
  5. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    I cant find anything like that, GUI.FocusWindow only lets you set the current GUI.Window with focus but does not return any value.

    Sounds like a wish

    .org