mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 04:42:08 +01:00
sfdagsghds
This commit is contained in:
@@ -12,8 +12,8 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: ab99e668aa1ba5a469eef680f3bb4b45, type: 3}
|
m_Script: {fileID: 11500000, guid: ab99e668aa1ba5a469eef680f3bb4b45, type: 3}
|
||||||
m_Name: Hoe
|
m_Name: Hoe
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
uuid:
|
uuid: Dia Hoe
|
||||||
itemName:
|
itemName:
|
||||||
sprite: {fileID: 0}
|
sprite: {fileID: 0}
|
||||||
stackable: 1
|
stackable: 0
|
||||||
maxStackSize: 100
|
maxStackSize: 1
|
||||||
|
|||||||
@@ -495,8 +495,9 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: fd29210254821be4dab438ab0312df18, type: 3}
|
m_Script: {fileID: 11500000, guid: fd29210254821be4dab438ab0312df18, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
testItem1: {fileID: 11400000, guid: 601d7a33a6c338d49a35134d5c772940, type: 2}
|
testItem1: {fileID: 11400000, guid: 030984201821ba840872812944c9dc13, type: 2}
|
||||||
testItem2: {fileID: 11400000, guid: cbbbe8384f7ec2845b4145744d51ecf8, type: 2}
|
testItem2: {fileID: 11400000, guid: cbbbe8384f7ec2845b4145744d51ecf8, type: 2}
|
||||||
|
interactionDistance: 2
|
||||||
hotbarSlotCount: 9
|
hotbarSlotCount: 9
|
||||||
activeHotbarSlot: 0
|
activeHotbarSlot: 0
|
||||||
playerInventory: {fileID: 0}
|
playerInventory: {fileID: 0}
|
||||||
|
|||||||
@@ -6,6 +6,23 @@ using UnityEngine.Tilemaps;
|
|||||||
public class GridBuildingSystem : MonoBehaviour
|
public class GridBuildingSystem : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static GridBuildingSystem instance;
|
||||||
|
|
||||||
|
public static GridBuildingSystem Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = FindObjectOfType<GridBuildingSystem>();
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("No GridBuildingSystem found in the scene.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
public PlaceableObject TESTPO; //! DEBUG
|
public PlaceableObject TESTPO; //! DEBUG
|
||||||
|
|
||||||
public Tilemap collisionTm;
|
public Tilemap collisionTm;
|
||||||
@@ -16,12 +33,20 @@ public class GridBuildingSystem : MonoBehaviour
|
|||||||
private GameObject newBuildingObject;
|
private GameObject newBuildingObject;
|
||||||
private bool isDemolishing = false;
|
private bool isDemolishing = false;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (instance != null && instance != this)
|
||||||
|
{
|
||||||
|
Destroy(this.gameObject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
instance = this;
|
||||||
|
DontDestroyOnLoad(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
Vector3Int snappedMousePosition = GetSnappedMousePosition();
|
||||||
int snappedX = Mathf.FloorToInt(mousePosition.x);
|
|
||||||
int snappedY = Mathf.FloorToInt(mousePosition.y);
|
|
||||||
Vector3Int snappedMousePosition = new Vector3Int(snappedX, snappedY, 0);
|
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.N))
|
if (Input.GetKeyDown(KeyCode.N))
|
||||||
{
|
{
|
||||||
@@ -88,6 +113,17 @@ public class GridBuildingSystem : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public Vector3Int GetSnappedMousePosition()
|
||||||
|
{
|
||||||
|
return GetSnappedPosition(Camera.main.ScreenToWorldPoint(Input.mousePosition));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3Int GetSnappedPosition(Vector3 pos)
|
||||||
|
{
|
||||||
|
int snappedX = Mathf.FloorToInt(pos.x);
|
||||||
|
int snappedY = Mathf.FloorToInt(pos.y);
|
||||||
|
return new Vector3Int(snappedX, snappedY, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public void SelectBuilding(PlaceableObject newPo)
|
public void SelectBuilding(PlaceableObject newPo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ public class Hoe : Tool
|
|||||||
{
|
{
|
||||||
public override void OnUse()
|
public override void OnUse()
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
Debug.Log("Hoe on use");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Use()
|
public override void Use()
|
||||||
{
|
{
|
||||||
|
Debug.Log("Hoe use");
|
||||||
OnUse();
|
OnUse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ public class PlayerController : MonoBehaviour
|
|||||||
public static Action OnActiveSlotChanged;
|
public static Action OnActiveSlotChanged;
|
||||||
public Item testItem1;
|
public Item testItem1;
|
||||||
public Item testItem2;
|
public Item testItem2;
|
||||||
|
public float interactionDistance = 2.5f;
|
||||||
public int hotbarSlotCount = 9;
|
public int hotbarSlotCount = 9;
|
||||||
public int activeHotbarSlot = 0;
|
public int activeHotbarSlot = 0;
|
||||||
[SerializeField] private Inventory playerInventory;
|
[SerializeField] private Inventory playerInventory;
|
||||||
@@ -44,6 +44,26 @@ public class PlayerController : MonoBehaviour
|
|||||||
GuiManager.Instance.TogglePanel("Inventory");
|
GuiManager.Instance.TogglePanel("Inventory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
Vector3Int snappedMousePosition = GridBuildingSystem.Instance.GetSnappedMousePosition();
|
||||||
|
Vector3Int snappedPlayerPosition = GridBuildingSystem.Instance.GetSnappedPosition(gameObject.transform.position);
|
||||||
|
if (Vector3Int.Distance(snappedMousePosition, snappedPlayerPosition) <= interactionDistance)
|
||||||
|
{
|
||||||
|
if (playerInventory.items[activeHotbarSlot]?.item is Tool)
|
||||||
|
{
|
||||||
|
Tool tool = playerInventory.items[activeHotbarSlot].item as Tool;
|
||||||
|
tool.Use();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("Not in range");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//! DEBUG
|
//! DEBUG
|
||||||
if (Input.GetKeyDown(KeyCode.U))
|
if (Input.GetKeyDown(KeyCode.U))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user