Skip to content

Commit

Permalink
Fix interaction keys (#364)
Browse files Browse the repository at this point in the history
* Fix weird interaction keys

* Fix Unity parent warning

* Fix in hand radial clipping
  • Loading branch information
Alainx277 authored May 31, 2020
1 parent 8796aef commit ea51dd1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
47 changes: 31 additions & 16 deletions Assets/Engine/Interactions/InteractionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,37 @@ public void Update()
Destroy(activeMenu.gameObject);
}

var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var viableInteractions = GetViableInteractions(ray, out InteractionEvent interactionEvent);
if (viableInteractions.Select(x => x.Interaction).ToList().Count > 0)
if (Input.GetButton("Alternate"))
{
//Debug.LogError(viableInteractions.Count);
// Create a menu that will run the given action when clicked
var obj = Instantiate(menuPrefab, transform.root.transform);
activeMenu = obj.GetComponentInChildren<UI.RadialInteractionMenuUI>();

activeMenu.Position = Input.mousePosition;
activeMenu.Event = interactionEvent;
activeMenu.Interactions = viableInteractions.Select(x => x.Interaction).ToList();
activeMenu.onSelect = interaction =>
Hands hands = GetComponent<Hands>();
if (hands != null )
{
CmdRunInteraction(ray, viableInteractions.FindIndex(x => x.Interaction == interaction),
Item item = hands.Container.GetItem(hands.HeldSlot);
if (item != null)
{
InteractInHand(item.gameObject, gameObject, true);
}
}
}
else
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var viableInteractions = GetViableInteractions(ray, out InteractionEvent interactionEvent);
if (viableInteractions.Select(x => x.Interaction).ToList().Count > 0)
{
// Create a menu that will run the given action when clicked
var obj = Instantiate(menuPrefab, transform.root.transform);
activeMenu = obj.GetComponentInChildren<UI.RadialInteractionMenuUI>();

activeMenu.Position = Input.mousePosition;
activeMenu.Event = interactionEvent;
activeMenu.Interactions = viableInteractions.Select(x => x.Interaction).ToList();
activeMenu.onSelect = interaction =>
{
CmdRunInteraction(ray, viableInteractions.FindIndex(x => x.Interaction == interaction),
interaction.GetName(interactionEvent));
};
};
}
}
}

Expand Down Expand Up @@ -116,11 +130,12 @@ public void InteractInHand(GameObject target, GameObject sourceObject, bool show
interactionEvent.Target = entries[0].Target;
if (showMenu && entries.Select(x => x.Interaction).ToList().Count > 0)
{
//Debug.LogError(entries[0]);
var obj = Instantiate(menuPrefab, transform.root.transform);
activeMenu = obj.GetComponentInChildren<UI.RadialInteractionMenuUI>();

activeMenu.Position = Input.mousePosition;
Vector3 mousePosition = Input.mousePosition;
mousePosition.y = Mathf.Max(obj.transform.GetChild(0).GetComponent<RectTransform>().rect.height, mousePosition.y);
activeMenu.Position = mousePosition;
activeMenu.Event = interactionEvent;
activeMenu.Interactions = entries.Select(x => x.Interaction).ToList();
activeMenu.onSelect = interaction =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Petal AddPetalToFolder(Sprite icon, string name)
Petal newPetal = Instantiate(petalPrefab, petalParent.transform).GetComponent<Petal>();
newPetal.iconImage.texture = icon.texture;
newPetal.name = name;
newPetal.transform.parent = petalParent.transform;
newPetal.transform.SetParent(petalParent.transform, false);
folder.AddPetal(newPetal);
folder.isDirty = true;
return (newPetal);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Engine/Inventory/UI/UIGroupedContainers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public override void OnPress(UIItemSlot slot, PointerEventData.InputButton butto

if (handler != null && hands != null && hands.GetActiveTool() != null && item != null && (slotType == Container.SlotType.LeftHand || slotType == Container.SlotType.RightHand))
{
handler.InteractInHand(item, playerObject);
handler.InteractInHand(item, playerObject, button == PointerEventData.InputButton.Right);
return;
}

Expand Down
18 changes: 17 additions & 1 deletion ProjectSettings/InputManager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ InputManager:
descriptiveName: Activate Item
descriptiveNegativeName:
negativeButton:
positiveButton: left alt
positiveButton:
altNegativeButton:
altPositiveButton: z
gravity: 1000
Expand All @@ -501,3 +501,19 @@ InputManager:
type: 0
axis: 5
joyNum: 0
- serializedVersion: 3
m_Name: Alternate
descriptiveName: Alternate action
descriptiveNegativeName:
negativeButton:
positiveButton: left alt
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 5
joyNum: 0

0 comments on commit ea51dd1

Please sign in to comment.