CustomGetMouseButtonDown

From Unify Community Wiki
Revision as of 21:34, 7 November 2018 by Isaiah Kelly (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If you need to use the likes of Input.OnMouseButtonDown(0), but when your user clicks on buttons and text fields need it to not shoot whatever happens to be behind the window.... just use this class. It's written so you can simply replace "Input." with "YourGUIClass." and it will just work.

You do, however, need to customize the last function per game - it needs to check each window manually, as there doesn't seem to be an automated way of looping through all the windows.

static function GetMouseButtonDown(btn : int) : boolean {
	if (!Input.GetMouseButtonDown(btn)) return false;
	if (CursorIsOverAnyWindow()) return false;
	return true;
}
static function GetMouseButton(btn :int) : boolean {
	if (!Input.GetMouseButton(btn)) return false;
	if (CursorIsOverAnyWindow()) return false;
	return true;
}
 
static function CursorIsOverAnyWindow() : boolean {
	var guiCursorPos : Vector2 = Vector2(Input.mousePosition.x, Screen.height-Input.mousePosition.y);
//TODO: check all your windows here
	if (GUIScriptClass1.main.window.Contains(guiCursorPos)) return true;
	if (GUIScriptClass2.main.window.Contains(guiCursorPos)) return true;
//etcetera
	return false;
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox