Implement inventory slot switching in the inventory interface
This commit is contained in:
parent
7feff52f69
commit
c892218560
@ -541,6 +541,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
ID: 0
|
ID: 0
|
||||||
|
Character: {fileID: 114052379458543858}
|
||||||
--- !u!143 &143753897266899886
|
--- !u!143 &143753897266899886
|
||||||
CharacterController:
|
CharacterController:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
@ -4955,6 +4955,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
Character: {fileID: 114575501420754388}
|
Character: {fileID: 114575501420754388}
|
||||||
|
InventoryInterface: {fileID: 114383476058023772}
|
||||||
Camera: {fileID: 20678872378488080}
|
Camera: {fileID: 20678872378488080}
|
||||||
--- !u!114 &114390919699494652
|
--- !u!114 &114390919699494652
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -5162,6 +5163,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
ID: 0
|
ID: 0
|
||||||
|
Character: {fileID: 114575501420754388}
|
||||||
--- !u!114 &114741357428691828
|
--- !u!114 &114741357428691828
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
@ -555,6 +555,7 @@ Transform:
|
|||||||
- {fileID: 375619906}
|
- {fileID: 375619906}
|
||||||
- {fileID: 1610252930}
|
- {fileID: 1610252930}
|
||||||
- {fileID: 274219296}
|
- {fileID: 274219296}
|
||||||
|
- {fileID: 1785155275}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
@ -2353,6 +2354,46 @@ Transform:
|
|||||||
m_Father: {fileID: 310461192}
|
m_Father: {fileID: 310461192}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &1785155274
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 0}
|
||||||
|
serializedVersion: 5
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1785155275}
|
||||||
|
- component: {fileID: 1785155276}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Lerper
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1785155275
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1785155274}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 344272455}
|
||||||
|
m_RootOrder: 6
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &1785155276
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1785155274}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 33c8d5915d5e847eb9bbe018c2fdb457, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1 &1810916631
|
--- !u!1 &1810916631
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -98,12 +98,22 @@ namespace Cyber.Controls {
|
|||||||
private List<Transform> ItemGridCells;
|
private List<Transform> ItemGridCells;
|
||||||
private List<MeshFilter> ItemGridCellMeshes;
|
private List<MeshFilter> ItemGridCellMeshes;
|
||||||
private int ItemGridSelectedIndex;
|
private int ItemGridSelectedIndex;
|
||||||
|
private Transform GrabbedItem;
|
||||||
|
private int GrabbedItemIndex = -1;
|
||||||
|
|
||||||
private Color IconInventoryColor;
|
private Color IconInventoryColor;
|
||||||
private Color IconStatusColor;
|
private Color IconStatusColor;
|
||||||
private Color IconSocialColor;
|
private Color IconSocialColor;
|
||||||
private Color IconMapColor;
|
private Color IconMapColor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the inventory is currently open and interactible.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c> if this instance is open; otherwise, <c>false</c>.</returns>
|
||||||
|
public bool IsOpen() {
|
||||||
|
return InventoryOpen;
|
||||||
|
}
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
int ItemGridSize = (int) ItemGridDimensions.x * (int) ItemGridDimensions.y;
|
int ItemGridSize = (int) ItemGridDimensions.x * (int) ItemGridDimensions.y;
|
||||||
ItemGridCells = new List<Transform>(ItemGridSize);
|
ItemGridCells = new List<Transform>(ItemGridSize);
|
||||||
@ -138,11 +148,23 @@ namespace Cyber.Controls {
|
|||||||
if (ItemGridCells.Contains(LookedAt.collider.transform)) {
|
if (ItemGridCells.Contains(LookedAt.collider.transform)) {
|
||||||
// Interacting with the item list
|
// Interacting with the item list
|
||||||
CurrentIndex = int.Parse(LookedAt.collider.name.Split(' ')[1]);
|
CurrentIndex = int.Parse(LookedAt.collider.name.Split(' ')[1]);
|
||||||
|
if (GrabbedItem == null) {
|
||||||
|
// Nothing is currently being dragged, continue as normal
|
||||||
|
if (Input.GetButton("Activate") &&
|
||||||
|
(Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0) &&
|
||||||
|
ItemGridSelectedIndex == CurrentIndex) {
|
||||||
|
// This item has been selected for at least a frame,
|
||||||
|
// and the mouse is moving, this counts as dragging
|
||||||
|
Debug.Log("Grabbed!");
|
||||||
|
GrabbedItem = LookedAt.collider.transform;
|
||||||
|
GrabbedItemIndex = CurrentIndex;
|
||||||
|
}
|
||||||
if (Input.GetButtonDown("Activate") || Input.GetButtonDown("Equip")) {
|
if (Input.GetButtonDown("Activate") || Input.GetButtonDown("Equip")) {
|
||||||
|
// Select things
|
||||||
ItemGridSelectedIndex = CurrentIndex;
|
ItemGridSelectedIndex = CurrentIndex;
|
||||||
}
|
}
|
||||||
if (Input.GetButtonDown("Equip")) {
|
if (Input.GetButtonDown("Equip")) {
|
||||||
// Selected index was already this => equip (double-clicked)
|
// Equip things
|
||||||
Item SelectedItem = Inventory.Drive.GetItemAt(ItemGridSelectedIndex);
|
Item SelectedItem = Inventory.Drive.GetItemAt(ItemGridSelectedIndex);
|
||||||
if (SelectedItem != null) {
|
if (SelectedItem != null) {
|
||||||
Item Equipped = Inventory.Drive.GetSlot(SelectedItem.Slot);
|
Item Equipped = Inventory.Drive.GetSlot(SelectedItem.Slot);
|
||||||
@ -155,6 +177,26 @@ namespace Cyber.Controls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Something is grabbed, make things react to this
|
||||||
|
if (Input.GetButtonUp("Activate")) {
|
||||||
|
// Grab was released, drop item here
|
||||||
|
// Lerp things
|
||||||
|
ItemGridCellMeshes[GrabbedItemIndex].transform.position = ItemGridCells[CurrentIndex].position;
|
||||||
|
ItemGridCellMeshes[CurrentIndex].transform.position = ItemGridCells[GrabbedItemIndex].position;
|
||||||
|
Lerper.LerpTransformPosition(ItemGridCellMeshes[GrabbedItemIndex].transform, new Vector3(), 10f);
|
||||||
|
Lerper.LerpTransformPosition(ItemGridCellMeshes[CurrentIndex].transform, new Vector3(), 10f);
|
||||||
|
|
||||||
|
// Switch items
|
||||||
|
Inventory.Drive.SwitchSlots(GrabbedItemIndex, CurrentIndex);
|
||||||
|
|
||||||
|
// Reset grabbing
|
||||||
|
GrabbedItem = null;
|
||||||
|
GrabbedItemIndex = -1;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (Mesh != null) {
|
} else if (Mesh != null) {
|
||||||
float InvBrightness = 1.1f;
|
float InvBrightness = 1.1f;
|
||||||
float StsBrightness = 1f;
|
float StsBrightness = 1f;
|
||||||
|
@ -21,6 +21,11 @@ namespace Cyber.Controls {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Character Character;
|
public Character Character;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The inventory interface.
|
||||||
|
/// </summary>
|
||||||
|
public InventoryInterface InventoryInterface;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The camera the player is seeing the world through.
|
/// The camera the player is seeing the world through.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -77,7 +82,7 @@ namespace Cyber.Controls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Equipment actions
|
// Equipment actions
|
||||||
if (!Interacted) {
|
if (!Interacted && !InventoryInterface.IsOpen()) {
|
||||||
// Don't use equipment if you're interacting with something
|
// Don't use equipment if you're interacting with something
|
||||||
// (ie. don't shoot at the buttons)
|
// (ie. don't shoot at the buttons)
|
||||||
if (Input.GetButtonDown("Use Item (R)")) {
|
if (Input.GetButtonDown("Use Item (R)")) {
|
||||||
|
@ -104,6 +104,9 @@ namespace Cyber.Items {
|
|||||||
/// <param name="idx1">The first index.</param>
|
/// <param name="idx1">The first index.</param>
|
||||||
/// <param name="idx2">The second index.</param>
|
/// <param name="idx2">The second index.</param>
|
||||||
public void SwitchSlots(int idx1, int idx2) {
|
public void SwitchSlots(int idx1, int idx2) {
|
||||||
|
if (idx1 == idx2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Slot Slot1 = GetSlotAt(idx1);
|
Slot Slot1 = GetSlotAt(idx1);
|
||||||
Slot Slot2 = GetSlotAt(idx2);
|
Slot Slot2 = GetSlotAt(idx2);
|
||||||
SetSlotAt(idx1, Slot2);
|
SetSlotAt(idx1, Slot2);
|
||||||
|
59
Assets/Scripts/Util/Lerper.cs
Normal file
59
Assets/Scripts/Util/Lerper.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cyber.Util {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lerps stuff.
|
||||||
|
/// </summary>
|
||||||
|
public class Lerper : MonoBehaviour {
|
||||||
|
private struct PositionLerp {
|
||||||
|
public Vector3 Target;
|
||||||
|
public float Speed;
|
||||||
|
|
||||||
|
public PositionLerp(Vector3 target, float speed) {
|
||||||
|
Target = target;
|
||||||
|
Speed = speed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Lerper Singleton;
|
||||||
|
|
||||||
|
private Dictionary<Transform, PositionLerp> PositionLerps = new Dictionary<Transform, PositionLerp>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the singleton.
|
||||||
|
/// </summary>
|
||||||
|
public Lerper() {
|
||||||
|
Singleton = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lerps the transform local position.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="transform">Transform.</param>
|
||||||
|
/// <param name="to">To.</param>
|
||||||
|
/// <param name="speed">Speed.</param>
|
||||||
|
public static void LerpTransformPosition(Transform transform, Vector3 to, float speed) {
|
||||||
|
if (Singleton != null) {
|
||||||
|
Singleton.PositionLerps[transform] = new PositionLerp(to, speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update() {
|
||||||
|
List<Transform> RemoveThese = new List<Transform>();
|
||||||
|
foreach (Transform Transform in PositionLerps.Keys) {
|
||||||
|
Transform.localPosition = Vector3.Lerp(Transform.localPosition,
|
||||||
|
PositionLerps[Transform].Target, PositionLerps[Transform].Speed * Time.deltaTime);
|
||||||
|
if ((Transform.localPosition - PositionLerps[Transform].Target).magnitude < 0.001f) {
|
||||||
|
Transform.localPosition = PositionLerps[Transform].Target;
|
||||||
|
RemoveThese.Add(Transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (Transform Transform in RemoveThese) {
|
||||||
|
PositionLerps.Remove(Transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
Assets/Scripts/Util/Lerper.cs.meta
Normal file
12
Assets/Scripts/Util/Lerper.cs.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 33c8d5915d5e847eb9bbe018c2fdb457
|
||||||
|
timeCreated: 1494978322
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user