private void CheckHover() { //can only hover on things within FOV if (lightingSystem.enabled && !lightingSystem.IsScreenPointVisible(CommonInput.mousePosition)) { if (lastHoveredThing) { lastHoveredThing.transform.SendMessageUpwards("OnHoverEnd", SendMessageOptions.DontRequireReceiver); } lastHoveredThing = null; return; } var hit = MouseUtils.GetOrderedObjectsUnderMouse(layerMask).FirstOrDefault(); if (hit != null) { if (lastHoveredThing != hit) { if (lastHoveredThing) { lastHoveredThing.transform.SendMessageUpwards("OnHoverEnd", SendMessageOptions.DontRequireReceiver); } hit.transform.SendMessageUpwards("OnHoverStart", SendMessageOptions.DontRequireReceiver); lastHoveredThing = hit; } hit.transform.SendMessageUpwards("OnHover", SendMessageOptions.DontRequireReceiver); } }
private bool CheckAltClick() { if (KeyboardInputManager.IsAltPressed()) { //Check for items on the clicked position, and display them in the Item List Tab, if they're in reach //and not FOV occluded Vector3 position = MousePosition; position.z = 0f; if (lightingSystem.IsScreenPointVisible(Input.mousePosition)) { if (PlayerManager.LocalPlayerScript.IsInReach(position)) { List <GameObject> objects = UITileList.GetItemsAtPosition(position); //remove hidden wallmounts objects.RemoveAll(obj => obj.GetComponent <WallmountBehavior>() != null && obj.GetComponent <WallmountBehavior>().IsHiddenFromLocalPlayer()); LayerTile tile = UITileList.GetTileAtPosition(position); ControlTabs.ShowItemListTab(objects, tile, position); } } UIManager.SetToolTip = $"clicked position: {Vector3Int.RoundToInt(position)}"; return(true); } return(false); }
private void OnDragEnd() { UIManager.IsMouseInteractionDisabled = false; Destroy(shadowObject); shadowObject = null; if (lightingSystem.enabled && !lightingSystem.IsScreenPointVisible(CommonInput.mousePosition)) { //do nothing, the point is not visible. return; } //check what we dropped on, which may or may not have mousedrop interaction components //can only drop on things that have a RegisterTile var dropTargets = MouseUtils.GetOrderedObjectsUnderMouse(); //go through the stack of objects and call any drop components we find foreach (GameObject dropTarget in dropTargets) { MouseDrop info = MouseDrop.ByLocalPlayer(gameObject, dropTarget.gameObject); //call this object's mousedrop interaction methods if it has any, for each object we are dropping on if (InteractionUtils.ClientCheckAndTrigger(mouseDrops, info) != null) { return; } var targetComps = dropTarget.GetComponents <IBaseInteractable <MouseDrop> >() .Where(mb => mb != null && (mb as MonoBehaviour).enabled); if (InteractionUtils.ClientCheckAndTrigger(targetComps, info) != null) { return; } } }
void Update() { // Get right mouse click and check if mouse point occluded by FoV system. if (Input.GetMouseButtonDown(1) && lightingSystem.IsScreenPointVisible(Input.mousePosition)) { //gets Items on the position of the mouse that are able to be right clicked List <GameObject> objects = GetRightClickableObjects(); //Generates menus Generate(objects); //Logger.Log ("yo", Category.UI); if (options.Count > 0) { RadialMenuSpawner.ins.SpawnRadialMenu(options); } } }
private void OnDragEnd() { UIManager.IsMouseInteractionDisabled = false; Destroy(shadowObject); shadowObject = null; if (lightingSystem.enabled && !lightingSystem.IsScreenPointVisible(CommonInput.mousePosition)) { //do nothing, the point is not visible. return; } //check what we dropped on, which may or may not have mousedrop interaction components //can only drop on things that have a RegisterTile var dropTargets = MouseUtils.GetOrderedObjectsUnderMouse(dropLayers, go => go.GetComponent <RegisterTile>() != null) //get the root gameobject of the dropped-on sprite renderer .Select(sr => sr.GetComponentInParent <RegisterTile>().gameObject) //only want distinct game objects even if we hit multiple renderers on one object. .Distinct(); //go through the stack of objects and call any drop components we find foreach (GameObject dropTarget in dropTargets) { MouseDrop info = new MouseDrop(PlayerManager.LocalPlayer, gameObject, dropTarget.gameObject); //call this object's mousedrop interaction methods if it has any, for each object we are dropping on foreach (IInteractable <MouseDrop> mouseDrop in mouseDrops) { var result = mouseDrop.Interact(info); if (result.SomethingHappened) { //we're done checking, something happened return; } } //call the mousedrop interaction methods on the dropped-on object if it has any foreach (IInteractable <MouseDrop> mouseDropTarget in dropTarget.GetComponents <IInteractable <MouseDrop> >()) { var result = mouseDropTarget.Interact(info); if (result.SomethingHappened) { //something happened, done checking return; } } } }
private List <GameObject> GetRightClickableObjects(Vector3 mousePosition) { if (lightingSystem.enabled && !lightingSystem.IsScreenPointVisible(mousePosition)) { return(null); } var position = MouseUtils.MouseToWorldPos(); var objects = UITileList.GetItemsAtPosition(position); //special case, remove wallmounts that are transparent objects.RemoveAll(IsHiddenWallmount); //Objects that are under a floor tile should not be available objects.RemoveAll(IsUnderFloorTile); return(objects); }
void Update() { // Get right mouse click if (CommonInput.GetMouseButtonDown(1)) { List <GameObject> objects = null; // Check if mouse point occluded by FoV system. if (!lightingSystem.enabled || lightingSystem.IsScreenPointVisible(CommonInput.mousePosition)) { // Gets Items on the position of the mouse that are able to be right clicked objects = GetRightClickableObjects(); } else { objects = new List <GameObject>(); } // Gets UI elements var pointerData = new PointerEventData(EventSystem.current) { pointerId = -1, // Mouse position = CommonInput.mousePosition, }; EventSystem.current.RaycastAll(pointerData, raycastResults); #pragma warning disable UEA0005 // Ignore warning about using GetComponent() inside Update() // Searching for UI_ItemSwap instead of UI_ItemSlot for the larger and more consistent hitbox. objects.AddRange(raycastResults.Select(rc => { // Verbose workaround since you should not use null propagation on Unity objects. Thanks, Unity. var itemSwap = rc.gameObject.GetComponent <UI_ItemSwap>(); var itemSlot = itemSwap == null ? null : itemSwap.GetComponentInChildren <UI_ItemSlot>(); return(itemSlot == null ? null : itemSlot.ItemObject); }).Where(go => go != null)); #pragma warning restore UEA0005 //Generates menus var options = Generate(objects); //Logger.Log ("yo", Category.UI); if (options != null && options.Count > 0) { RadialMenuSpawner.ins.SpawnRadialMenu(options); } } }
private void OnDragEnd() { UIManager.IsMouseInteractionDisabled = false; Destroy(shadowObject); shadowObject = null; if (lightingSystem.enabled && !lightingSystem.IsScreenPointVisible(CommonInput.mousePosition)) { //do nothing, the point is not visible. return; } //check what we dropped on, which may or may not have mousedrop interaction components //can only drop on things that have a RegisterTile var dropTargets = MouseUtils.GetOrderedObjectsUnderMouse(dropLayers); //go through the stack of objects and call any drop components we find foreach (GameObject dropTarget in dropTargets) { MouseDrop info = MouseDrop.ByLocalPlayer(gameObject, dropTarget.gameObject); //call this object's mousedrop interaction methods if it has any, for each object we are dropping on foreach (IInteractable <MouseDrop> mouseDrop in mouseDrops) { var interacted = mouseDrop.Interact(info); if (interacted) { //we're done checking, something happened return; } } //call the mousedrop interaction methods on the dropped-on object if it has any foreach (IInteractable <MouseDrop> mouseDropTarget in dropTarget.GetComponents <IInteractable <MouseDrop> >() .Where(mb => mb != null && (mb as MonoBehaviour).enabled)) { var interacted = mouseDropTarget.Interact(info); if (interacted) { //something happened, done checking return; } } } }