added inventory
Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (push) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled

This commit is contained in:
nlevin6 2025-03-29 21:27:24 -04:00
parent 1aa187a019
commit 930173c383
20 changed files with 1721 additions and 100 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
using UnityEngine;
using System.Collections.Generic;
public class Inventory : MonoBehaviour
{
// A fixed array of 10 slots
[Header("Exactly 10 Slots")]
public Item[] slots = new Item[10];
public int currentSlot = 0;
[SerializeField] private Transform handSlot;
private GameObject currentSpawnedItem;
void Update()
{
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll > 0f)
{
SelectPreviousSlot();
}
else if (scroll < 0f)
{
SelectNextSlot();
}
}
/// <summary>
/// Adds an item to the first available slot (if any).
/// </summary>
public void AddItem(Item newItem)
{
for (int i = 0; i < slots.Length; i++)
{
if (slots[i] == null)
{
slots[i] = newItem;
break;
}
}
// Optional: if no item is equipped yet, equip slot 0, etc.
// if (currentSpawnedItem == null) EquipSlot(0);
}
private void SelectNextSlot()
{
currentSlot = (currentSlot + 1) % slots.Length;
EquipSlot(currentSlot);
// Force the UI to re-check which slot is active
var ui = FindObjectOfType<InventoryUI>();
if (ui != null)
{
ui.RefreshUI();
}
}
private void SelectPreviousSlot()
{
currentSlot = (currentSlot - 1 + slots.Length) % slots.Length;
EquipSlot(currentSlot);
var ui = FindObjectOfType<InventoryUI>();
if (ui != null)
{
ui.RefreshUI();
}
}
public void EquipSlot(int slotIndex)
{
if (currentSpawnedItem != null)
{
Destroy(currentSpawnedItem);
}
Item itemInSlot = slots[slotIndex];
GameObject prefab = itemInSlot != null ? itemInSlot.GetPrefab() : null;
if (prefab != null && handSlot != null)
{
currentSpawnedItem = Instantiate(prefab, handSlot.position, handSlot.rotation, handSlot);
currentSpawnedItem.transform.localPosition = Vector3.zero;
currentSpawnedItem.transform.localRotation = Quaternion.identity;
}
else
{
currentSpawnedItem = null;
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b4448f3fbbe07214daca35863b8c4da4

View File

@ -0,0 +1,58 @@
using UnityEngine;
using UnityEngine.UI;
public class InventoryUI : MonoBehaviour
{
[SerializeField] private Image[] slotImages; // 10 UI Images
[SerializeField] private Inventory inventory; // The fixed-slot Inventory
// These let you pick highlight/normal colors in the Inspector
[SerializeField] private Color normalColor = Color.white;
[SerializeField] private Color highlightColor = Color.yellow;
void Start()
{
RefreshUI();
}
public void RefreshUI()
{
for (int i = 0; i < slotImages.Length; i++)
{
Item itemInSlot = inventory.slots[i];
if (itemInSlot != null && itemInSlot.itemIcon != null)
{
slotImages[i].sprite = itemInSlot.itemIcon;
slotImages[i].color = normalColor;
}
else
{
slotImages[i].sprite = null;
slotImages[i].color = new Color(1,1,1,0); // or Color.clear
}
}
HighlightSlot(inventory.currentSlot); // after we set sprites, highlight the active slot
}
private void HighlightSlot(int slotIndex)
{
// Make sure it's a valid index
if (slotIndex < 0 || slotIndex >= slotImages.Length)
return;
// Set all slots to normal color
for (int i = 0; i < slotImages.Length; i++)
{
// If the slot is empty, you might want to leave it "clear"
// but let's just do normalColor for demonstration:
if (slotImages[i].sprite == null)
slotImages[i].color = new Color(1,1,1,0); // keep empty slot invisible
else
slotImages[i].color = normalColor;
}
// Now highlight the active slot
slotImages[slotIndex].color = highlightColor;
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 04c5a8e0fda20d0428e7fc4099db147c

10
Assets/Scripts/Item.cs Normal file
View File

@ -0,0 +1,10 @@
using UnityEngine;
[CreateAssetMenu(fileName = "NewItem", menuName = "Inventory/Item")]
public class Item : ScriptableObject
{
public string itemName;
public Sprite itemIcon;
[SerializeField] public Object itemPrefab;
public GameObject GetPrefab() => itemPrefab as GameObject;
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9d572cf34af0fc14981c6699e965994d

View File

@ -1,5 +1,4 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class PickUpKeyCard : MonoBehaviour
@ -10,25 +9,24 @@ public class PickUpKeyCard : MonoBehaviour
[SerializeField] private Animator objectAnimator;
[SerializeField] private string animationName = "PickupAnimation";
[SerializeField] private AudioClip pickupSound = null;
[SerializeField] private string keyCardName = "Deck D key card";
[SerializeField] private KeyCardPlayer keyCardPlayer = null;
[SerializeField] private KeyCardPlayer keyCardPlayer = null;
[SerializeField] private float interactionDistance = 5.0f;
[SerializeField] private Item keyCardItem;
[SerializeField] private Inventory playerInventory;
private bool isPickedUp = false;
void Awake()
{
outline = GetComponent<Outline>();
if (outline != null)
{
outline.enabled = true;
}
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
void Update()
@ -49,43 +47,50 @@ public class PickUpKeyCard : MonoBehaviour
if (Input.GetMouseButtonDown(0))
{
isPickedUp = true;
// mark key card as picked up
// Mark key card as picked up in your custom script
if (keyCardPlayer != null)
{
keyCardPlayer.hasKeyCard = true;
// Add the keycard to player's inventory
if (playerInventory != null && keyCardItem != null)
{
playerInventory.AddItem(keyCardItem);
gameObject.SetActive(false);
// Refresh the UI
InventoryUI inventoryUI = FindObjectOfType<InventoryUI>();
if (inventoryUI != null)
{
inventoryUI.RefreshUI();
}
}
if (outline != null)
{
outline.enabled = false;
}
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
// Play pickup animation
if (objectAnimator != null)
{
objectAnimator.Play(animationName, 0, 0.0f);
}
// Play sound
if (pickupSound != null)
{
SoundFXManager.instance.PlaySound(pickupSound, transform, 1.5f);
}
}
}
else
{
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
}
else
{
if (interactionPrompt != null)
{
interactionPrompt.enabled = false;
}
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 55362fbe9e3d01c41a0afd8dcb3838fc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d572cf34af0fc14981c6699e965994d, type: 3}
m_Name: KeyCardItem
m_EditorClassIdentifier:
itemName: Red Card
itemIcon: {fileID: 21300000, guid: a93e077ba35a67049b715c183af5e346, type: 3}
itemPrefab: {fileID: 8924941041106658507, guid: 9978c9c43cf7bfb4ba426c30b5c569b2, type: 3}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b3e36ada447d99a498479618aeda7650
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d572cf34af0fc14981c6699e965994d, type: 3}
m_Name: USBStickItem
m_EditorClassIdentifier:
itemName: USB Stick
itemIcon: {fileID: 21300000, guid: 1d5d46cffb17f694987ced466c5888e3, type: 3}
itemPrefab: {fileID: 8988288550564699726, guid: 56a57c82158b9874eb02de81af87fcb1, type: 3}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a6b0d7faf8636114d8124eb4c966589b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 99173c697c5d848f79866d61b308a3f1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 91cc2e24d14a248aa89167fcd265678a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,75 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &8105838320280642335
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalScale.x
value: 4
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalScale.y
value: 4
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalScale.z
value: 4
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071067
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalRotation.x
value: -0.7071068
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_ConstrainProportionsScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}
propertyPath: m_Name
value: FlashDrive
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 91fca92ce7507a6f9af9cc7265b6cf76, type: 3}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 56a57c82158b9874eb02de81af87fcb1
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -61,7 +61,7 @@ Material:
m_Ints: []
m_Floats: []
m_Colors:
- _Color: {r: 0.38857278, g: 0.38857278, b: 0.38857278, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 128, g: 128, b: 128, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1

View File

@ -0,0 +1,187 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3839894878138069533
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2850537304662550584}
- component: {fileID: 190948566412933862}
- component: {fileID: 4691833975505319639}
m_Layer: 0
m_Name: Card_Mesh
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2850537304662550584
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3839894878138069533}
serializedVersion: 2
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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3101798197347461516}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &190948566412933862
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3839894878138069533}
m_Mesh: {fileID: 4821974255002996250, guid: 6945c9e5b5bb56266b0c5b76ef62b8aa, type: 3}
--- !u!23 &4691833975505319639
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3839894878138069533}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 518e8bed5d3d9060d935a6aa6dc5244d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &8924941041106658507
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3101798197347461516}
- component: {fileID: 6970733140935288315}
- component: {fileID: 318389086690240487}
- component: {fileID: 8402379286112444004}
m_Layer: 0
m_Name: Card_model_red
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3101798197347461516
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8924941041106658507}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0.23144493, z: -0, w: 0.97284806}
m_LocalPosition: {x: 2.29, y: 0.5528, z: -46.74}
m_LocalScale: {x: 3, y: 3, z: 3}
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 2850537304662550584}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: -26.764, z: 0}
--- !u!114 &6970733140935288315
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8924941041106658507}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 207aef9a0b351ba42a0551e2783bd236, type: 3}
m_Name:
m_EditorClassIdentifier:
interactionPrompt: {fileID: 0}
objectAnimator: {fileID: 8402379286112444004}
animationName: PickUpAnimation
pickupSound: {fileID: 8300000, guid: ed409be746b135887b4c63e3aa055282, type: 3}
keyCardName: Deck D key card
keyCardPlayer: {fileID: 0}
interactionDistance: 5
keyCardItem: {fileID: 0}
playerInventory: {fileID: 0}
--- !u!65 &318389086690240487
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8924941041106658507}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 0.13, y: 0.1, z: 0.16}
m_Center: {x: 0, y: 0, z: 0}
--- !u!95 &8402379286112444004
Animator:
serializedVersion: 7
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8924941041106658507}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: b1d17488fd8ca5d36a535e9f1770c2eb, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_AnimatePhysics: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9978c9c43cf7bfb4ba426c30b5c569b2
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: