I need to be clear: is the original issue of items becoming selected at the wrong time now resolved, such that the only remaining issue your following request?
If heldTime equals or is greater than, let's say, 0.15, the item cannot be selected, otherwise if heldTime is less than 0.15, you can select the item.
using UnityEngine;
using System.Collections;
using AC;
public class VerbCoin : MonoBehaviour
{
public float maxHoldTime = 0.5f;
public float selectTime = 0.15f;
private float heldTime;
private void Update ()
{
if (heldTime < 0f && !Input.GetMouseButton (0)) heldTime = 0f;
if (heldTime >= 0f &&
Input.GetMouseButton (0) &&
(KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
KickStarter.stateHandler.IsInGameplay () &&
!KickStarter.playerMenus.IsInteractionMenuOn ())
{
// LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
heldTime += Time.deltaTime;
if (heldTime >= maxHoldTime)
{
// Open the Interaction menu
if (KickStarter.runtimeInventory.hoverItem != null)
{
// For an inventory item
KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
}
else
{
// For a Hotspot
KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
}
heldTime = -1f;
}
else if (heldTime < selectTime)
{
KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.hoverItem);
heldTime = -1f;
}
}
else if (!Input.GetMouseButton (0) &&
(KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
KickStarter.stateHandler.IsInGameplay () &&
KickStarter.playerMenus.IsInteractionMenuOn ())
{
KickStarter.playerMenus.CloseInteractionMenus ();
heldTime = 0f;
}
}
}
That didn't work but I had a better idea, too bad I couldn't execute it correctly
If the game detects that the mouse button was lifted before maxHoldTime was elapsed then the element will be selected, otherwise the interactions menu will be displayed and the item will not be selected. This is what I tried to do, without success because it didn't work
using UnityEngine;
using System.Collections;
using AC;
public class VerbCoin : MonoBehaviour
{
public float maxHoldTime = 0.5f;
private float heldTime;
private void Update ()
{
if (Input.GetMouseButton (0) &&
(KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
KickStarter.stateHandler.IsInGameplay () &&
!KickStarter.playerMenus.IsInteractionMenuOn ())
{
// LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
if (KickStarter.runtimeInventory.SelectedItem != null) return;
heldTime += Time.deltaTime;
if (heldTime >= maxHoldTime)
{
// Open the Interaction menu
if (KickStarter.runtimeInventory.hoverItem != null)
{
// For an inventory item
KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
}
else
{
// For a Hotspot
KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
}
heldTime = 0f;
}
Made a FREAKING oopsie, I happened to update to 1.8 today to see if I could expand my options for fixing the bugs that still occur nowadays, and I found myself getting the following message:
Assets\VerbCoin.cs(44,54): error CS1503: Argument 1: cannot convert from 'AC.InvItem' to 'AC.InvInstance'.
Fortunately, not all is lost, because I would like to know if there is any way that if you hold down the left mouse button over an Inventory Item, you could activate the boolean: "Prevent Selection?"
Assets\VerbCoin.cs(44,54): error CS1503: Argument 1: cannot convert from 'AC.InvItem' to 'AC.InvInstance'.
The Inventory system's API was changed in v1.72 - you can find details about it here.
If you'd like to share the VerbCoin script, I can make the necessary amendment.
is any way that if you hold down the left mouse button over an Inventory Item, you could activate the boolean: "Prevent Selection?"
You can alter the field through script. As with any Manager field, right-click its label to get an API reference you can copy to the text buffer.
I'd say that altering this field at runtime, however, would be easy to create errors and knock-on effects elsewhere. If you want to heavily customise the behaviour of Inventory menus, the best way is to set the Inventory box type to Custom Script, and then hook into the OnMenuElementClickcustom event to dictate the intended behaviour:
void OnMenuElementClick (Menu _menu, MenuElement _element, int _slot, int buttonPressed)
{
if (_menu.title == "Inventory" && _element.title == "InventoryBox")
{
MenuInventoryBox inventoryBox = _element as MenuInventoryBox;
InvInstance clickedInstance = inventoryBox.GetInstance (_slot);
//
}
}
Comments
Uncheck Prevent interactions? in your InventoryBox element.
This feature is available in the current release.
Define an input named "SkipSpeech" in the Input Manager, and set "." (no quotes) in its Positive Button field.
Unchecked it. Since it doesn't allow to interact with inventory items, nothing was written in the log
So, what's next now?
I need to be clear: is the original issue of items becoming selected at the wrong time now resolved, such that the only remaining issue your following request?
That didn't work but I had a better idea, too bad I couldn't execute it correctly
If the game detects that the mouse button was lifted before maxHoldTime was elapsed then the element will be selected, otherwise the interactions menu will be displayed and the item will not be selected. This is what I tried to do, without success because it didn't work
using UnityEngine;
using System.Collections;
using AC;
public class VerbCoin : MonoBehaviour
{
if (KickStarter.runtimeInventory.SelectedItem != null) return;
heldTime += Time.deltaTime;
if (heldTime >= maxHoldTime)
{
// Open the Interaction menu
if (KickStarter.runtimeInventory.hoverItem != null)
{
// For an inventory item
KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
}
else
{
// For a Hotspot
KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
}
heldTime = 0f;
}
}
It may be something more along these lines:
Made a FREAKING oopsie, I happened to update to 1.8 today to see if I could expand my options for fixing the bugs that still occur nowadays, and I found myself getting the following message:
Assets\VerbCoin.cs(44,54): error CS1503: Argument 1: cannot convert from 'AC.InvItem' to 'AC.InvInstance'.
Fortunately, not all is lost, because I would like to know if there is any way that if you hold down the left mouse button over an Inventory Item, you could activate the boolean: "Prevent Selection?"
The Inventory system's API was changed in v1.72 - you can find details about it here.
If you'd like to share the VerbCoin script, I can make the necessary amendment.
You can alter the field through script. As with any Manager field, right-click its label to get an API reference you can copy to the text buffer.
I'd say that altering this field at runtime, however, would be easy to create errors and knock-on effects elsewhere. If you want to heavily customise the behaviour of Inventory menus, the best way is to set the Inventory box type to Custom Script, and then hook into the OnMenuElementClick custom event to dictate the intended behaviour:
using UnityEngine;
using AC;
public class VerbCoin : MonoBehaviour
{
}
Here is the code, thank you
Replace:
with: