- Home /
 
Modal Dialog
Hello, everyone! I wanna to write a function that show a dialog window, the only method i thought about is that defining a global boolean variable to record whether we are showing a gui, if so, i must maintain its value when i or my partner is showing a gui! Are there any other method? i find a way here : link text
but it is in javascript version, can anybody translate it into C# version? Thanks in advance! static function ModalWindow(rect:Rect,title:String,windowFunction:Function)
{
 return GUILayout.Window(GUIUtility.GetControlID(FocusType.Passive),rect,function(id:int)
 {
     GUI.depth=0;
     //first get a control id. every subsequent call to GUI control function will get a larger id
     var min=GUIUtility.GetControlID(FocusType.Native);
     //we can use the id to check if current control is inside our window
     if(GUIUtility.hotControl<min)
         setHotControl(0);//if it's not - set hot control to 0, to allow window controls to become hot
     //if it is, we can't change it, because mouseover effect would not be there
     
     //draw our window
     windowFunction();
     
     //get max control id in our window
     var max=GUIUtility.GetControlID(FocusType.Native);
     //once again check current hot control
     //if it's outside our window - set it to -1 - it prevent's clicks!
     //we can't block clicks inside our window, so we have to check max!=-1
     //max equals -1 if a control inside our window has taken focus in this frame, because
     //we can't get a valid id in this frame any more
     if(GUIUtility.hotControl<min || (GUIUtility.hotControl>max && max!=-1))
         setHotControl(-1);
     
     //focus the window and bring it to front
     GUI.FocusWindow(id);
     GUI.BringWindowToFront(id);
 },title);
 
               }
static function setHotControl(id:int)
{
 //don't block events if mousePointer is outside "Screen", otherwise if we run the game in editor
 //we would block the editor GUI as well.
 if(Rect(0,0,Screen.width,Screen.height).Contains(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)))
     GUIUtility.hotControl=id;        
 
               }
               Comment
              
 
               
              Your answer