Is it possible to intercept from script mouse click? When the player presses the right or left mouse button I should do some actions. Later, however, I should not block the default mouse click activity.
For example, the player right-click to deselect item, I would need to do a script action and then let the item deselect.
I'm working in a custom event, GetItemClick, but I have to intercept the click also out of the inventory.
Comments
The "InputGetMouseButtonDown" override, when defined, causes AC to refer to this when checking for mouse clicks instead of Unity's Input.GetMouseButtonDown. You can then return Unity's function in normal circumstances, but then just return false if you want clicks to be ignored.
The input check, and hence your delegate override, is being asked if a given button index (int btnPressed) is being pressed.
Your override returns "true" in all cases, meaning you are telling AC that any mouse button click it is checking for (left and right) is being held down.
Replacing the "return true;" with:
return Input.GetMouseButtonDown (btnPressed);
Will have normal mouse-based behaviour return, but with the ability to detect if the RMB (button 1) is being clicked.
If you then wanted to override it, you could insert eg:
if (btnPressed == checkBtnPressed && someCondition)
{
// Don't accept RMB clicks at this time
return false;
}
return Input.GetMouseButtonDown (btnPressed);
Generally, you can have AC perform its default behaviour by returning the Unity Input function - as I showed above. As you're using coroutines and so on, though, I can't say for sure how appropriate that would be - but I don't imagine you need to use an Update function.
AC will check for the RMB every frame anyway, so you should be able to just put it all in the override function, e.g.:
if (KickStarter.runtimeInventory.SelectedItem != null)
{
if (btnPressed == 1)
{
// Do something
}
else if (btnPressed == 0)
{
// Do something else
}
return false; // Remove this to have AC always perform the default functionality
}
return Input.GetMouseButtonDown (btnPressed);
I don't feel like I have a clear picture of what it is you're actually trying to do as a result of all this - I think that's making it difficult to assist.
If your custom behaviour lasts several frames / update cycles, using a coroutine is fine - but then just add a bool check to the override that you can set in that coroutine, e.g.:
bool doNothing;
private bool CustomInputGetMouseButtonDownDelegate (int BtnPressed)
{
if (doNothing) return false;
// rest of function will not run if doNothing = True
}
private IENumerator execCursorBack ()
{
doNothing = true;
// other stuff over time
doNothing = false
}
So, the function is used to detect if a certain button is pressed - and the btnPressed parameter is merely used to determine which button is being checked. But since the function itself is used to determine if the input is pressed, it must also incorporate the Input function:
Change:
if (KickStarter.runtimeInventory.SelectedItem != null)
to:
if (KickStarter.runtimeInventory.SelectedItem != null && Input.GetMouseButtonDown (btnPressed))
That then makes the code only run if an item is selected, and that the requested button is indeed being held down. Otherwise, it doesn't care if it's clicked or not.
Apologies for not seeing that sooner.