Toolbar!
This commit is contained in:
@@ -83,9 +83,9 @@ public class Chunk
|
||||
|
||||
AddUV(textures[f]);
|
||||
}
|
||||
else if(world.GetBlockID(new Vector3(x + Data.faceChecks[f].x + chunkPosition.x * Data.chunkWidth,
|
||||
else if(world.IsBlockTransparent(world.GetBlockID(new Vector3(x + Data.faceChecks[f].x + chunkPosition.x * Data.chunkWidth,
|
||||
y + Data.faceChecks[f].y,
|
||||
z + Data.faceChecks[f].z + chunkPosition.z * Data.chunkWidth)) == 6)
|
||||
z + Data.faceChecks[f].z + chunkPosition.z * Data.chunkWidth))))
|
||||
{
|
||||
for (int v = 0; v < 6; v++)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Hotbar : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image[] itemSlots;
|
||||
[SerializeField] private Sprite[] itemIcons; //id always: -1 to get item icon
|
||||
[SerializeField] private GameObject highlight;
|
||||
|
||||
private byte[] hotBarItems = new byte[9];
|
||||
private byte selectedSlot = 0;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//change later:
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
itemSlots[i].sprite = itemIcons[i];
|
||||
hotBarItems[i] = (byte)(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectSlot(byte idx)
|
||||
{
|
||||
selectedSlot = idx;
|
||||
highlight.transform.position = itemSlots[idx].transform.position;
|
||||
}
|
||||
|
||||
public byte GetSelectedSlot()
|
||||
{
|
||||
return selectedSlot;
|
||||
}
|
||||
|
||||
public byte GetSelectedItemID()
|
||||
{
|
||||
return hotBarItems[selectedSlot];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53c4d26baf11ca64697efb3490cfdb51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -13,6 +13,7 @@ public class Player : MonoBehaviour
|
||||
private float walkSpeed;
|
||||
[SerializeField] private float jumpForce;
|
||||
[SerializeField] private World world;
|
||||
[SerializeField] private Hotbar hotbar;
|
||||
private float playerWidth = 0.15f;
|
||||
private float playerOffsetWidth = 0.1f;
|
||||
private float horizontal;
|
||||
@@ -150,32 +151,38 @@ public class Player : MonoBehaviour
|
||||
|
||||
lastTriggerR = Input.GetAxis("Right Trigger");
|
||||
|
||||
if (currentBlock == 1)
|
||||
{
|
||||
if (Input.GetAxisRaw("Mouse ScrollWheel") < 0)
|
||||
{
|
||||
currentBlock = (byte)(world.blockData.Length - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentBlock += (byte)(Input.GetAxisRaw("Mouse ScrollWheel") * 10);
|
||||
}
|
||||
}
|
||||
else if (currentBlock == world.blockData.Length - 1)
|
||||
{
|
||||
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0)
|
||||
{
|
||||
currentBlock = (byte)(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentBlock += (byte)(Input.GetAxisRaw("Mouse ScrollWheel") * 10);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentBlock += (byte)(Input.GetAxisRaw("Mouse ScrollWheel") * 10);
|
||||
}
|
||||
// if (currentBlock == 1)
|
||||
// {
|
||||
// if (Input.GetAxisRaw("Mouse ScrollWheel") < 0)
|
||||
// {
|
||||
// currentBlock = (byte)(8);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentBlock += (byte)(Input.GetAxisRaw("Mouse ScrollWheel") * 10);
|
||||
// }
|
||||
// }
|
||||
// else if (currentBlock == 8)
|
||||
// {
|
||||
// if (Input.GetAxisRaw("Mouse ScrollWheel") > 0)
|
||||
// {
|
||||
// currentBlock = (byte)(1);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentBlock += (byte)(Input.GetAxisRaw("Mouse ScrollWheel") * 10);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentBlock += (byte)(Input.GetAxisRaw("Mouse ScrollWheel") * 10);
|
||||
// }
|
||||
|
||||
int currentSlot = (int)hotbar.GetSelectedSlot();
|
||||
currentSlot += (int)(-Input.GetAxisRaw("Mouse ScrollWheel") * 10);
|
||||
if (currentSlot > 8) currentSlot = 0;
|
||||
if (currentSlot < 0) currentSlot = 8;
|
||||
hotbar.SelectSlot((byte)currentSlot);
|
||||
|
||||
//send build block request to server
|
||||
if(Time.timeScale > 0)
|
||||
@@ -185,7 +192,7 @@ public class Player : MonoBehaviour
|
||||
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit, 8))
|
||||
{
|
||||
hit.point -= camera.transform.forward / 10;
|
||||
client.EditBlock(hit.point, currentBlock);
|
||||
client.EditBlock(hit.point, hotbar.GetSelectedItemID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,6 +251,11 @@ public class World : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsBlockTransparent(byte id)
|
||||
{
|
||||
return blockData[id].transparent;
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
client.Disconnect();
|
||||
@@ -267,6 +272,7 @@ public class World : MonoBehaviour
|
||||
{
|
||||
public string name;
|
||||
public byte[] textures = new byte[6];
|
||||
public bool transparent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user