public override void Update(GameTime gameTime) { base.Update(gameTime); BoundingBox.X = (int)(Transform.X); BoundingBox.Y = (int)(Transform.Y); var mouse = Engine.Input.Mouse; if (BoundingBox.Contains(mouse.X, mouse.Y)) { if (mouse.LeftClick) { OnMouseClick(mouse.MouseData); OnMouseClickEvent?.Invoke(mouse.MouseData); } else { _mouseHovering = true; OnMouseHover(mouse.MouseData); OnMouseHoverEvent?.Invoke(mouse.MouseData); } } else { if (_mouseHovering) { _mouseHovering = false; OnMouseExit(mouse.MouseData); OnMouseExitEvent?.Invoke(mouse.MouseData); } } }
///<summary> /// When called checks if he is the GameObject hovered on and change its material. ///</summary> ///<param name="e">The event's instance</param> private void OnMouseHover(OnMouseHoverEvent e) { if (GameManager.gm.focus.Count > 0 && (!transform.parent || GameManager.gm.focus[GameManager.gm.focus.Count - 1] != transform.parent.gameObject)) { return; } if (e.obj.Equals(gameObject) && !isSelected && !isFocused) { Color temp = transform.GetChild(0).GetComponent <Renderer>().material.color; SetMaterial(mouseHoverMaterial); isHovered = true; transform.GetChild(0).GetComponent <Renderer>().material.color = Utils.InvertColor(temp); } }
// If the mouse position is negative or larger than the length/width of the screen resolution it means the mouse is out of bounds of the gamescreen. private void OnMouseHover(Vector2 myMousePosition) { OnMouseHoverEvent?.Invoke(this, myMousePosition); }