add basic inventory, fading walls

This commit is contained in:
2026-02-17 15:26:34 -06:00
parent 6baa6956bf
commit 7123238daa
30 changed files with 6594 additions and 255 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ Material:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
m_CustomRenderQueue: 2000
stringTagMap:
RenderType: Opaque
disabledShaderPasses:
+147
View File
@@ -0,0 +1,147 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-2389587588549404042
MonoBehaviour:
m_ObjectHideFlags: 11
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: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 10
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: CheckerFade
m_Shader: {fileID: 4800000, guid: 8d2bb70cbf9db8d4da26e15b26e74248, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _ALPHAPREMULTIPLY_ON
- _SURFACE_TYPE_TRANSPARENT
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- MOTIONVECTORS
- DepthOnly
- SHADOWCASTER
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 10309, guid: 0000000000000000f000000000000000, type: 0}
m_Scale: {x: 10, y: 10}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 10309, guid: 0000000000000000f000000000000000, type: 0}
m_Scale: {x: 10, y: 10}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _DstBlendAlpha: 10
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossinessSource: 0
- _GlossyReflections: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Shininess: 0
- _Smoothness: 0.5
- _SmoothnessSource: 0
- _SmoothnessTextureChannel: 1
- _SpecSource: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 1
- _UVSec: 0
- _WorkflowMode: 0
- _XRMotionVectorsPass: 1
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6132d09ee32c7df42bc151d035606725
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
-138
View File
@@ -1,138 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
public ItemSlot[] itemSlots;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// we'll set this up to only try to add one item to the inventory at a time for now
// there won't be stacked items in the wild for right now
public bool AddItem(Item item)
{
// first try to stack
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i] != null)
{
if (itemSlots[i].item == item.id && itemSlots[i].quantity < item.maxStack)
{
itemSlots[i].quantity += 1;
return true;
}
}
}
// no stack to add to, try to find an empty slot
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i] == null)
{
itemSlots[i] = new ItemSlot();
itemSlots[i].quantity = 1;
itemSlots[i].item = item.id;
return true;
}
}
// no open slots, no open stacks, we can't add the item
return false;
}
public bool RemoveItemQuantity(ItemIdEnum itemId, int quantity)
{
if (GetItemQuantity(itemId) >= quantity)
{
int currentQuantity = quantity;
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i] != null && itemSlots[i].item == itemId)
{
// we are trying to remove less items than what exists in the current
// stack, so just subtract from the stack
if (currentQuantity < itemSlots[i].quantity)
{
itemSlots[i].quantity -= currentQuantity;
break;
}
else if (currentQuantity == itemSlots[i].quantity)
{
// we have exactly enough in the current slot, so nullify it and
// exit
itemSlots[i] = null;
break;
}
else
{
// we don't have enough in the stack, but we DO have enough in our
// inventory. nullify the stack, subtract that number from the current
// count, and move to the next item
currentQuantity -= itemSlots[i].quantity;
itemSlots[i] = null;
}
}
}
return true;
}
else
{
return false;
}
}
public int GetItemQuantity(ItemIdEnum itemId)
{
int itemCount = 0;
foreach (ItemSlot slot in itemSlots)
{
if (slot != null && slot.item == itemId)
{
itemCount += slot.quantity;
}
}
return itemCount;
}
#region Inventory Save/Load
public void SaveInventory(ref InventorySaveData data)
{
data.itemSlots = itemSlots;
}
public void LoadInventory(InventorySaveData data)
{
if (data.itemSlots != null)
{
itemSlots = data.itemSlots;
}
else
{
Debug.Log("new slots");
itemSlots = new ItemSlot[8];
}
}
#endregion
}
[System.Serializable]
public class ItemSlot
{
public int quantity;
public ItemIdEnum item;
}
[System.Serializable]
public struct InventorySaveData
{
public ItemSlot[] itemSlots;
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 076e174c9be31b547812dc69fe5636e7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2585db9850317154bbf6220ac979d78a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,117 @@
fileFormatVersion: 2
guid: 7230a06d2f8f71a4bb44ffd6617e89de
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,117 @@
fileFormatVersion: 2
guid: 314f3ac8c89c6764882eb1a2efd2f404
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
+55 -8
View File
@@ -1,12 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private float moveSpeed = 50.0f;
private float zoomSpeed = 20.0f;
private bool isTracking = false; // don't track when parented
private bool returningHome = false; // cam is on its way home
private float baseCamSize = 5; // this is how "zoomed" the ortho cam is
private float baseCamSize = 7; // this is how "zoomed" the ortho cam is
private float camMovementTime = 0.9f; // how much time to switch cam positions
private float moveSpeed;
private float zoomSpeed;
public Transform playerCamHome; // camera's home base
public GameObject cameraObj;
@@ -14,29 +18,72 @@ public class CameraController : MonoBehaviour
private Vector3 currentCamPosition;
private float desiredCamSize;
private int positionsSet = 0; // this keeps track of how many cam zones we're in
private List<StaticCamRoom> roomsActive;
public void SetCurrentPosition(Vector3 currentCamPosition, float desiredCamSize)
{
positionsSet++; // we have entered a cam zone
cameraObj.transform.parent = null;
float distanceToMove = Vector3.Distance(this.currentCamPosition, currentCamPosition);
float amountToZoom = Mathf.Abs(this.desiredCamSize - desiredCamSize);
moveSpeed = distanceToMove / camMovementTime;
zoomSpeed = amountToZoom / camMovementTime;
isTracking = true;
returningHome = false;
cameraObj.transform.parent = null;
this.currentCamPosition = currentCamPosition;
this.desiredCamSize = desiredCamSize;
}
public void ReturnCameraToHome()
{
isTracking = false;
returningHome = true;
positionsSet--; // we have exited a cam zone
currentCamPosition = playerCamHome.position;
desiredCamSize = baseCamSize;
// if this number is greater than 1, we have left a zone but are still in another
if (positionsSet <= 0)
{
positionsSet = 0;
float distanceToMove = Vector3.Distance(this.currentCamPosition, playerCamHome.position);
float amountToZoom = Mathf.Abs(this.desiredCamSize - baseCamSize);
moveSpeed = distanceToMove / camMovementTime;
zoomSpeed = amountToZoom / camMovementTime;
isTracking = false;
returningHome = true;
currentCamPosition = playerCamHome.position;
desiredCamSize = baseCamSize;
}
}
public void AddToRoomsActive(StaticCamRoom room)
{
roomsActive.Add(room);
room.RoomEnter();
}
public void RemoveFromRoomsActive(StaticCamRoom room)
{
List<Transform> wallsToKeep = new List<Transform>();
roomsActive.Remove(room);
foreach (StaticCamRoom staticCamRoom in roomsActive)
{
wallsToKeep.AddRange(staticCamRoom.objectsToHide);
}
room.RoomExit(wallsToKeep);
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
cameraComponent = cameraObj.GetComponent<Camera>();
roomsActive = new List<StaticCamRoom>();
ReturnCameraToHome();
}
+7 -6
View File
@@ -19,13 +19,14 @@ private void Awake()
else
{
Instance = this;
DontDestroyOnLoad(gameObject);
DialogueManager = GetComponent<DialogueManager>();
Inventory = GetComponent<Inventory>();
SaveSystem.Load();
}
DontDestroyOnLoad(gameObject);
DialogueManager = GetComponent<DialogueManager>();
Inventory = GetComponent<Inventory>();
SaveSystem.Load();
SaveSystem.Save(); // save off any corruption fixes
}
#region Storybool Save/Load
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c43e00cda947506459d64184fe41f882
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+220
View File
@@ -0,0 +1,220 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Inventory : MonoBehaviour
{
public ItemSlot[] itemSlots;
public BackPackType ownedBackpackType;
InventorySlotUI inventoryDisplay;
private bool showingInventory = false;
private void Update()
{
if (inventoryDisplay == null)
{
inventoryDisplay = GameObject.FindWithTag("InventorySlots").GetComponent<InventorySlotUI>();
inventoryDisplay.gameObject.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.Tab))
{
if (showingInventory)
{
inventoryDisplay.HideSlots();
Time.timeScale = 1;
}
else
{
inventoryDisplay.ShowSlots();
Time.timeScale = 0;
}
showingInventory = !showingInventory;
}
}
// we'll set this up to only try to add one item to the inventory at a time for now
// there won't be stacked items in the wild for right now
public bool AddItem(Item item, int quantity)
{
// first try to stack
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i].item == item.id && itemSlots[i].quantity < item.maxStack)
{
itemSlots[i].quantity += 1;
return true;
}
}
// no stack to add to, try to find an empty slot
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i].item == ItemIdEnum.NONE)
{
itemSlots[i] = new ItemSlot();
itemSlots[i].quantity = 1;
itemSlots[i].item = item.id;
return true;
}
}
// no open slots, no open stacks, we can't add the item
return false;
}
public bool RemoveItemQuantity(ItemIdEnum itemId, int quantity)
{
if (GetItemQuantity(itemId) >= quantity)
{
int currentQuantity = quantity;
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i].item == itemId)
{
// we are trying to remove less items than what exists in the current
// stack, so just subtract from the stack
if (currentQuantity < itemSlots[i].quantity)
{
itemSlots[i].quantity -= currentQuantity;
break;
}
else if (currentQuantity == itemSlots[i].quantity)
{
// we have exactly enough in the current slot, so nullify it and
// exit
itemSlots[i].item = ItemIdEnum.NONE;
break;
}
else
{
// we don't have enough in the stack, but we DO have enough in our
// inventory. nullify the stack, subtract that number from the current
// count, and move to the next item
currentQuantity -= itemSlots[i].quantity;
itemSlots[i].item = ItemIdEnum.NONE;
}
}
}
return true;
}
else
{
return false;
}
}
public int GetItemQuantity(ItemIdEnum itemId)
{
int itemCount = 0;
foreach (ItemSlot slot in itemSlots)
{
if (slot.item == itemId)
{
itemCount += slot.quantity;
}
}
return itemCount;
}
private int GetItemSlotNum()
{
switch (ownedBackpackType)
{
case BackPackType.Pockets:
return 8;
case BackPackType.SmallBag:
return 16;
case BackPackType.LargeBag:
return 32;
}
return 0;
}
#region Inventory Save/Load
public void SaveInventory(ref InventorySaveData data)
{
data.itemSlots = itemSlots;
data.ownedBackpack = ownedBackpackType;
}
public void LoadInventory(InventorySaveData data)
{
ownedBackpackType = data.ownedBackpack;
if (data.itemSlots != null && data.itemSlots.Length > 0)
{
itemSlots = data.itemSlots;
// list is somehow corrupted, fill in the rest of the slots
if (itemSlots.Length < GetItemSlotNum())
{
ItemSlot[] newSlots = new ItemSlot[GetItemSlotNum()];
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i] != null)
newSlots[i] = itemSlots[i];
else
newSlots[i] = new ItemSlot();
}
itemSlots = newSlots;
}
}
else if (data.itemSlots != null && data.itemSlots.Length > GetItemSlotNum())
{
// list is bigger than it should be, generate new slots of the proper size
// and save just the items in the slots we SHOULD have. (shouldn't ever happen)
ItemSlot[] newSlots = new ItemSlot[GetItemSlotNum()];
for (int i = 0; i < newSlots.Length; i++)
{
if (itemSlots[i] != null)
newSlots[i] = itemSlots[i];
else
newSlots[i] = new ItemSlot();
}
itemSlots = newSlots;
}
else
{
itemSlots = new ItemSlot[GetItemSlotNum()];
for (int i = 0; i < itemSlots.Length; i++)
{
itemSlots[i] = new ItemSlot();
}
}
}
#endregion
}
public enum BackPackType
{
Pockets = 0,
SmallBag = 1,
LargeBag = 2
}
[System.Serializable]
public class ItemSlot
{
public int quantity;
public ItemIdEnum item;
}
[System.Serializable]
public struct InventorySaveData
{
public ItemSlot[] itemSlots;
public BackPackType ownedBackpack;
}
@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
// This is the container for the inventory UI slots
public class InventorySlotUI : MonoBehaviour
{
public ItemSlotUI[] slots;
ItemNameUI itemNameUI;
ItemDescriptionUI itemDescriptionUI;
private void Start()
{
slots = GetComponentsInChildren<ItemSlotUI>();
itemNameUI = GetComponentInChildren<ItemNameUI>();
itemDescriptionUI = GetComponentInChildren<ItemDescriptionUI>();
}
public void ShowSlots()
{
gameObject.SetActive(true);
for (int i = 0; i < slots.Length; i++)
{
if (GameManager.Instance.Inventory.itemSlots[i] != null)
{
slots[i].SetItem(GameManager.Instance.Inventory.itemSlots[i]);
}
}
foreach (ItemSlotUI slot in slots)
{
slot.LoadImage(itemNameUI, itemDescriptionUI);
}
}
public void HideSlots()
{
itemNameUI.nameText = "";
itemDescriptionUI.descriptionText = "";
gameObject.SetActive(false);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6035a8fed1049624f8d8077553b85847
@@ -0,0 +1,20 @@
using TMPro;
using UnityEngine;
public class ItemDescriptionUI : MonoBehaviour
{
public string descriptionText = "";
TextMeshProUGUI text;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
text = GetComponent<TextMeshProUGUI>();
}
// Update is called once per frame
void Update()
{
text.text = descriptionText;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bd581500fc7211347bbe165c6ea8d780
+20
View File
@@ -0,0 +1,20 @@
using TMPro;
using UnityEngine;
public class ItemNameUI : MonoBehaviour
{
public string nameText = "";
TextMeshProUGUI text;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
text = GetComponent<TextMeshProUGUI>();
}
// Update is called once per frame
void Update()
{
text.text = nameText;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 798c4437c91e97b43893dcdfeb918617
+53
View File
@@ -0,0 +1,53 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ItemSlotUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
// Kind of confusing here... ItemSlot refers to the class that is the DATA for a
// "slot". It is used for serialization and keeping track of the inventory in data.
// ItemSlot simply has an item ID and a quantity. ItemSlotUI is the visual represenation of this.
private ItemSlot slotData;
private int quantity;
private Image image;
private Item itemObj;
// (I hate this approach) passed in from InventorySlotUI
private ItemNameUI itemNameUI;
private ItemDescriptionUI itemDescriptionUI;
private void Start()
{
image = GetComponentsInChildren<Image>()[1]; //ignore parent
}
public void LoadImage(ItemNameUI itemNameUI, ItemDescriptionUI itemDescriptionUI)
{
if (this.itemNameUI == null) this.itemNameUI = itemNameUI;
if (this.itemDescriptionUI == null) this.itemDescriptionUI = itemDescriptionUI;
itemObj = new Item(slotData.item);
image.sprite = Resources.Load<Sprite>(itemObj.itemImagePath);
}
public void SetItem(ItemSlot itemSlot)
{
this.slotData = itemSlot;
}
public void OnPointerEnter(PointerEventData pointerEventData)
{
if (itemObj != null && itemObj.id != ItemIdEnum.NONE)
{
itemNameUI.nameText = itemObj.itemName;
itemDescriptionUI.descriptionText = itemObj.description;
}
}
public void OnPointerExit(PointerEventData pointerEventData)
{
itemNameUI.nameText = "";
itemDescriptionUI.descriptionText = "";
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 26900fa2242c1514fb991ab59cf5f883
+45 -1
View File
@@ -1,14 +1,58 @@
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
// This is the actual ITEM data structure for keeping track of inventory/item actions
public class Item : MonoBehaviour
public class Item
{
public string itemName;
public ItemIdEnum id;
public int maxStack = 10;
public string description = "";
public string itemImagePath = "";
public Item(string itemName, ItemIdEnum id, int maxStack, string description, string itemImagePath)
{
this.itemName = itemName;
this.id = id;
this.maxStack = maxStack;
this.description = description;
this.itemImagePath = itemImagePath;
}
public Item(ItemIdEnum id)
{
Item newItem = ItemUtilities.GetItemFromId(id);
this.itemName = newItem.itemName;
this.id = newItem.id;
this.maxStack = newItem.maxStack;
this.description = newItem.description;
this.itemImagePath= newItem.itemImagePath;
}
}
public enum ItemIdEnum
{
NONE = 0,
STAR_SHARD = 1
}
public static class ItemUtilities
{
// THIS IS WHERE ALL THE ITEMS ARE DEFINED
public static Item GetItemFromId(ItemIdEnum itemId)
{
switch (itemId)
{
case ItemIdEnum.STAR_SHARD:
return new Item(
itemName: "Star Shard",
id: itemId,
maxStack: 10,
description: "A rare material that can only be found here in the valley.",
itemImagePath: "ItemSprites/starShard");
}
return new Item("", itemId, 0, "", "ItemSprites/noneItem"); ;
}
}
+12 -4
View File
@@ -3,13 +3,21 @@
// this class is specifically referring to items in the world that can be picked up
public class PickupableItem : Interactable
{
public Item item;
public ItemIdEnum itemId;
public int quantity;
private Item itemObj;
private void Start()
{
itemObj = new Item(itemId);
Debug.Log(itemObj.itemName);
}
public override void Interact()
{
if (GameManager.Instance.Inventory.AddItem(item))
if (GameManager.Instance.Inventory.AddItem(itemObj, quantity))
{
Debug.Log("Picked up " + item.itemName + "!");
MoveOutsideRange(); // I don't love this but if we destroy the object we probably need to do this first
Destroy(gameObject);
}
@@ -17,7 +25,7 @@ public override void Interact()
public override void MoveInsideRange()
{
GameManager.Instance.DialogueManager.ShowItemText(item.itemName);
GameManager.Instance.DialogueManager.ShowItemText(itemObj.itemName);
}
public override void MoveOutsideRange()
+21 -5
View File
@@ -11,11 +11,14 @@ public class PlayerController : MonoBehaviour
bool isDigging = false;
Interactable nearestInteractable;
private CharacterController characterController;
private Vector3 moveDir;
private float gravity = 10;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
characterController = GetComponent<CharacterController>();
}
// Update is called once per frame
@@ -24,17 +27,30 @@ void Update()
if (!isDigging)
{
RotatePlayerTowardMouse();
Walk();
TryInteract();
}
Walk();
DigDetector();
}
void Walk()
{
transform.position += DougBody.transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
transform.position += DougBody.transform.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime;
moveDir = Vector3.zero;
if (!characterController.isGrounded)
{
moveDir.y -= gravity * Time.deltaTime;
}
if (!isDigging)
{
Vector3 verticalMovement = DougBody.transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
Vector3 horizontalMovement = DougBody.transform.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime;
moveDir += verticalMovement + horizontalMovement;
}
characterController.Move(moveDir);
}
void DigDetector()
@@ -93,7 +109,7 @@ private void OnTriggerExit(Collider other)
Interactable interactable = other.GetComponent<Interactable>();
// store nearest interactable if it exists
if (interactable != null)
if (interactable != null && nearestInteractable != null)
{
nearestInteractable.MoveOutsideRange();
nearestInteractable = null;
+42 -6
View File
@@ -1,3 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class StaticCamRoom : MonoBehaviour
@@ -7,19 +10,22 @@ public class StaticCamRoom : MonoBehaviour
public Transform[] objectsToHide;
public float camZoom = 5f;
private void RoomEnter()
public void RoomEnter()
{
StopAllCoroutines();
foreach (var obj in objectsToHide)
{
obj.gameObject.SetActive(false);
StartCoroutine(FadeOutMaterial(0.5f, obj.gameObject));
}
}
private void RoomExit()
public void RoomExit(List<Transform> wallsToKeep)
{
StopAllCoroutines();
foreach (var obj in objectsToHide)
{
obj.gameObject.SetActive(true);
if (!wallsToKeep.Contains(obj))
StartCoroutine(FadeInMaterial(0.5f, obj.gameObject));
}
}
@@ -30,7 +36,7 @@ private void OnTriggerEnter(Collider other)
if (controller != null)
{
controller.SetCurrentPosition(camPosition.position, camZoom);
RoomEnter();
controller.AddToRoomsActive(this);
}
}
@@ -41,7 +47,37 @@ private void OnTriggerExit(Collider other)
if (controller != null)
{
controller.ReturnCameraToHome();
RoomExit();
controller.RemoveFromRoomsActive(this);
}
}
private IEnumerator FadeOutMaterial(float fadeSpeed, GameObject wallObj)
{
Renderer rend = wallObj.GetComponent<Renderer>();
Color matColor = rend.material.color;
if (matColor.a > 1f)
matColor = new Color(matColor.r, matColor.g, matColor.b, 1f);
while (rend.material.color.a > 0f)
{
matColor.a -= Time.deltaTime / fadeSpeed;
rend.material.color = matColor;
yield return null;
}
rend.material.color = new Color(matColor.r, matColor.g, matColor.b, 0f);
}
private IEnumerator FadeInMaterial(float fadeSpeed, GameObject wallObj)
{
Renderer rend = wallObj.GetComponent<Renderer>();
Color matColor = rend.material.color;
while (rend.material.color.a < 1f)
{
matColor.a += Time.deltaTime / fadeSpeed;
rend.material.color = matColor;
yield return null;
}
rend.material.color = new Color(matColor.r, matColor.g, matColor.b, 1f);
}
}
+3 -17
View File
@@ -12,7 +12,6 @@ GameObject:
- component: {fileID: 4819581479575965518}
- component: {fileID: 1199667423908831825}
- component: {fileID: 3187412546555382564}
- component: {fileID: 7967411503437802021}
- component: {fileID: 7654873247549649761}
m_Layer: 0
m_Name: TestItem
@@ -91,6 +90,7 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &3187412546555382564
MonoBehaviour:
@@ -104,22 +104,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e3bb397f7c2c8ee47bc71df7f8d491bf, type: 3}
m_Name:
m_EditorClassIdentifier:
item: {fileID: 7967411503437802021}
--- !u!114 &7967411503437802021
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9072044991579024645}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa43c795f1a58fa4785593558036d0b3, type: 3}
m_Name:
m_EditorClassIdentifier:
itemName: Star Shard
id: 1
maxStack: 10
itemId: 1
quantity: 1
--- !u!135 &7654873247549649761
SphereCollider:
m_ObjectHideFlags: 0
+1
View File
@@ -5,6 +5,7 @@ TagManager:
serializedVersion: 3
tags:
- Shovel
- InventorySlots
layers:
- Default
- TransparentFX