Skip to content

Commit

Permalink
basic inventory system
Browse files Browse the repository at this point in the history
  • Loading branch information
7ubi committed May 13, 2021
1 parent f103d26 commit e060b79
Show file tree
Hide file tree
Showing 89 changed files with 15,760 additions and 2,006 deletions.
1,536 changes: 1,497 additions & 39 deletions Assets/Scenes/Game.unity

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions Assets/Scripts/PlayerActionController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -7,7 +8,9 @@ public class PlayerActionController : MonoBehaviour
{
[SerializeField] private float Range;
[SerializeField] private worldCreation _worldCreation;

[SerializeField] private PlayerInventory _inventory;


private void Update()
{
var leftClick = Input.GetMouseButtonDown(0);
Expand All @@ -25,7 +28,10 @@ private void Update()
}
if(rightClick)
{
_worldCreation.PlaceBlock(hit.point + transform.forward * -.01f);
if (!_inventory.CanPlaceBlock(_inventory.Current + 1))
return;
_worldCreation.PlaceBlock(hit.point + transform.forward * -.01f, _inventory.Current + 1);
_inventory.AddItem(_inventory.Current + 1, -1);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class PlayerController : MonoBehaviour
{
[SerializeField] private float moveSpeed;
[SerializeField] private float sprintMult;
[SerializeField] private Camera _camera;
[SerializeField] private float speedH = 2.0f;
[SerializeField] private float speedV = 2.0f;
Expand All @@ -22,7 +23,7 @@ public class PlayerController : MonoBehaviour
private void Start()
{
_rb = GetComponent<Rigidbody>();
Cursor.lockState = CursorLockMode.Locked;
//Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}

Expand All @@ -33,7 +34,12 @@ private void Update()

var mouseRight = Input.GetAxis("Mouse X");
var mouseUp = Input.GetAxis("Mouse Y");


if (Input.GetKey(KeyCode.LeftShift))
{
forward *= sprintMult;
right *= sprintMult;
}

_yaw += speedH * Input.GetAxis("Mouse X");
_pitch -= speedV * Input.GetAxis("Mouse Y");
Expand Down
25 changes: 24 additions & 1 deletion Assets/Scripts/PlayerInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class PlayerInventory : MonoBehaviour
{
[SerializeField] private RectTransform selector;
private int _current = 0;

[SerializeField] private TMP_Text[] itemCountText;
private int[] itemCount = new int[9];

private void Update()
{
_current = (_current + (int)Input.mouseScrollDelta.y) % 9;
_current = (_current - (int)Input.mouseScrollDelta.y) % 9;
if (_current < 0)
_current = 8;

selector.localPosition = new Vector2(-400 + _current * 100, selector.localPosition.y);
}

public void AddItem(int id, int amount)
{
itemCount[id - 1] += amount;
UpdateText(id - 1);
}

public bool CanPlaceBlock(int id)
{
return itemCount[id - 1] > 0;
}

private void UpdateText(int i)
{
itemCountText[i].text = "" + itemCount[i];
}

public int Current => _current;
}
10 changes: 7 additions & 3 deletions Assets/Scripts/worldCreation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class worldCreation : MonoBehaviour

[SerializeField] private float renderDistance;
[SerializeField] private GameObject Player;
private PlayerInventory _playerInventory;
private List<GameObject> chuncks = new List<GameObject>();
private int _lastChunck = 0;

Expand All @@ -30,6 +31,7 @@ public class worldCreation : MonoBehaviour
private void Start()
{
_blocks = GetComponent<Blocks>();
_playerInventory = Player.GetComponent<PlayerInventory>();
StartCoroutine(GenerateChunck(true));
}

Expand Down Expand Up @@ -163,12 +165,14 @@ public void DestroyBlock(Vector3 block)
var bix = Mathf.FloorToInt(block.x) - chunkPosX;
var biy = Mathf.FloorToInt(block.y);
var biz = Mathf.FloorToInt(block.z) - chunkPosZ;
chunck.GetComponent<Chunck>().BlockIDs[bix, biy, biz] = 0;
var c = chunck.GetComponent<Chunck>();
_playerInventory.AddItem(c.BlockIDs[bix, biy, biz], 1);
c.BlockIDs[bix, biy, biz] = 0;
GenerateMesh(chunck);
}
}

public void PlaceBlock(Vector3 block)
public void PlaceBlock(Vector3 block, int id)
{
var chunkPosX = Mathf.FloorToInt(block.x / 16f) * 16;
var chunkPosZ = Mathf.FloorToInt(block.z / 16f) * 16;
Expand All @@ -184,7 +188,7 @@ public void PlaceBlock(Vector3 block)
var biz = Mathf.FloorToInt(block.z) - chunkPosZ;


chunck.GetComponent<Chunck>().BlockIDs[bix, biy, biz] = 1;
chunck.GetComponent<Chunck>().BlockIDs[bix, biy, biz] = (short) id;
GenerateMesh(chunck);
}
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/TextMesh Pro.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Documentation.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Fonts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans - OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Digitized data copyright (c) 2010 Google Corporation
with Reserved Font Arimo, Tinos and Cousine.
Copyright (c) 2012 Red Hat, Inc.
with Reserved Font Name Liberation.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the copyright statement(s).

"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.

5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans - OFL.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/TextMesh Pro/Fonts/LiberationSans.ttf
Binary file not shown.
19 changes: 19 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans.ttf.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/TextMesh Pro/Resources/Fonts & Materials.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: LiberationSans SDF - Drop Shadow
m_Shader: {fileID: 4800000, guid: fe393ace9b354375a9cb14cdbbc28be4, type: 3}
m_ShaderKeywords: OUTLINE_ON UNDERLAY_ON
m_LightmapFlags: 5
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Cube:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _FaceTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 28684132378477856, guid: 8f586378b4e144a9851e7b34d9b748ee,
type: 2}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OutlineTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Ambient: 0.5
- _Bevel: 0.5
- _BevelClamp: 0
- _BevelOffset: 0
- _BevelRoundness: 0
- _BevelWidth: 0
- _BumpFace: 0
- _BumpOutline: 0
- _ColorMask: 15
- _Diffuse: 0.5
- _DiffusePower: 1
- _FaceDilate: 0.1
- _FaceUVSpeedX: 0
- _FaceUVSpeedY: 0
- _GlowInner: 0.05
- _GlowOffset: 0
- _GlowOuter: 0.05
- _GlowPower: 0.75
- _GradientScale: 10
- _LightAngle: 3.1416
- _MaskSoftnessX: 0
- _MaskSoftnessY: 0
- _OutlineSoftness: 0
- _OutlineUVSpeedX: 0
- _OutlineUVSpeedY: 0
- _OutlineWidth: 0.1
- _PerspectiveFilter: 0.875
- _Reflectivity: 10
- _ScaleRatioA: 0.9
- _ScaleRatioB: 0.73125
- _ScaleRatioC: 0.64125
- _ScaleX: 1
- _ScaleY: 1
- _ShaderFlags: 0
- _Sharpness: 0
- _SpecularPower: 2
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _TextureHeight: 1024
- _TextureWidth: 1024
- _UnderlayDilate: 0
- _UnderlayOffsetX: 0.5
- _UnderlayOffsetY: -0.5
- _UnderlaySoftness: 0.05
- _VertexOffsetX: 0
- _VertexOffsetY: 0
- _WeightBold: 0.75
- _WeightNormal: 0
m_Colors:
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EnvMatrixRotation: {r: 0, g: 0, b: 0, a: 0}
- _FaceColor: {r: 1, g: 1, b: 1, a: 1}
- _GlowColor: {r: 0, g: 1, b: 0, a: 0.5}
- _MaskCoord: {r: 0, g: 0, b: 32767, a: 32767}
- _OutlineColor: {r: 0, g: 0, b: 0, a: 1}
- _ReflectFaceColor: {r: 0, g: 0, b: 0, a: 1}
- _ReflectOutlineColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecularColor: {r: 1, g: 1, b: 1, a: 1}
- _UnderlayColor: {r: 0, g: 0, b: 0, a: 0.5}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e060b79

Please sign in to comment.