mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 04:42:08 +01:00
add grid building system
This commit is contained in:
8
Assets/PlaceableObjects.meta
Normal file
8
Assets/PlaceableObjects.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d7dca3d9e70abff4c98a2913b1182060
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
18
Assets/PlaceableObjects/house.asset
Normal file
18
Assets/PlaceableObjects/house.asset
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
%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: 66971ee377514a046acbb1e1c0b45d44, type: 3}
|
||||||
|
m_Name: house
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
objectName: house
|
||||||
|
prefab: {fileID: 6244317213382018835, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
||||||
|
width: 4
|
||||||
|
height: 5
|
||||||
8
Assets/PlaceableObjects/house.asset.meta
Normal file
8
Assets/PlaceableObjects/house.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 40437410555fcda43ab2ec4c9a4c2807
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -11,7 +11,6 @@ GameObject:
|
|||||||
- component: {fileID: 5852600358559839619}
|
- component: {fileID: 5852600358559839619}
|
||||||
- component: {fileID: 2080657515599704299}
|
- component: {fileID: 2080657515599704299}
|
||||||
- component: {fileID: 95789179383567876}
|
- component: {fileID: 95789179383567876}
|
||||||
- component: {fileID: 6347999927300409482}
|
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: House
|
m_Name: House
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -85,7 +84,7 @@ SpriteRenderer:
|
|||||||
m_SpriteTileMode: 0
|
m_SpriteTileMode: 0
|
||||||
m_WasSpriteAssigned: 1
|
m_WasSpriteAssigned: 1
|
||||||
m_MaskInteraction: 0
|
m_MaskInteraction: 0
|
||||||
m_SpriteSortPoint: 0
|
m_SpriteSortPoint: 1
|
||||||
--- !u!61 &95789179383567876
|
--- !u!61 &95789179383567876
|
||||||
BoxCollider2D:
|
BoxCollider2D:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -99,31 +98,16 @@ BoxCollider2D:
|
|||||||
m_IsTrigger: 0
|
m_IsTrigger: 0
|
||||||
m_UsedByEffector: 0
|
m_UsedByEffector: 0
|
||||||
m_UsedByComposite: 0
|
m_UsedByComposite: 0
|
||||||
m_Offset: {x: 0, y: 0}
|
m_Offset: {x: 2, y: 0}
|
||||||
m_SpriteTilingProperty:
|
m_SpriteTilingProperty:
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
pivot: {x: 0.5, y: 0.5}
|
pivot: {x: 0, y: 0}
|
||||||
oldSize: {x: 4, y: 4.5625}
|
oldSize: {x: 4, y: 5}
|
||||||
newSize: {x: 4, y: 4.5625}
|
newSize: {x: 4, y: 4.5625}
|
||||||
adaptiveTilingThreshold: 0.5
|
adaptiveTilingThreshold: 0.5
|
||||||
drawMode: 0
|
drawMode: 0
|
||||||
adaptiveTiling: 0
|
adaptiveTiling: 0
|
||||||
m_AutoTiling: 0
|
m_AutoTiling: 0
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Size: {x: 4, y: 4.5625}
|
m_Size: {x: 3, y: 1}
|
||||||
m_EdgeRadius: 0
|
m_EdgeRadius: 0
|
||||||
--- !u!114 &6347999927300409482
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 6244317213382018835}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: b98c0e6f554197e4281920fafc6bab25, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
area:
|
|
||||||
m_Position: {x: 0, y: 0, z: 0}
|
|
||||||
m_Size: {x: 4, y: 5, z: 1}
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 224768186}
|
m_GameObject: {fileID: 224768186}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: -5.5101213, y: 0.036043525, z: 0}
|
m_LocalPosition: {x: -7.45, y: 4.21, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children:
|
m_Children:
|
||||||
@@ -29650,12 +29650,11 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 1507699183}
|
m_GameObject: {fileID: 1507699183}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 2e90c7a6153f1b345a7aa678ca6b61cd, type: 3}
|
m_Script: {fileID: 11500000, guid: 8c4997c1e7757ea49a7ea73e46e528c2, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
gridLayout: {fileID: 1507699184}
|
placeableObject: {fileID: 11400000, guid: 40437410555fcda43ab2ec4c9a4c2807, type: 2}
|
||||||
mainTilemap: {fileID: 1579890810}
|
collisionTm: {fileID: 1579890810}
|
||||||
takenTile: {fileID: 11400000, guid: 4815673d17e2b7246b5812e51b47cd6d, type: 2}
|
|
||||||
--- !u!1 &1579890809
|
--- !u!1 &1579890809
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -29668,7 +29667,7 @@ GameObject:
|
|||||||
- component: {fileID: 1579890810}
|
- component: {fileID: 1579890810}
|
||||||
- component: {fileID: 1579890811}
|
- component: {fileID: 1579890811}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Buildings
|
m_Name: Occupied
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
@@ -30166,7 +30165,7 @@ TilemapRenderer:
|
|||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 99
|
||||||
m_ChunkSize: {x: 32, y: 32, z: 32}
|
m_ChunkSize: {x: 32, y: 32, z: 32}
|
||||||
m_ChunkCullingBounds: {x: 0, y: 0, z: 0}
|
m_ChunkCullingBounds: {x: 0, y: 0, z: 0}
|
||||||
m_MaxChunkCount: 16
|
m_MaxChunkCount: 16
|
||||||
@@ -30248,11 +30247,11 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5852600358559839619, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
- target: {fileID: 5852600358559839619, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
value: 0
|
value: 2
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5852600358559839619, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
- target: {fileID: 5852600358559839619, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
||||||
propertyPath: m_LocalPosition.y
|
propertyPath: m_LocalPosition.y
|
||||||
value: 0
|
value: 15
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5852600358559839619, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
- target: {fileID: 5852600358559839619, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
||||||
propertyPath: m_LocalPosition.z
|
propertyPath: m_LocalPosition.z
|
||||||
|
|||||||
61
Assets/Scripts/GridBuildingSystem.cs
Normal file
61
Assets/Scripts/GridBuildingSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Tilemaps;
|
||||||
|
|
||||||
|
public class GridBuildingSystem : MonoBehaviour
|
||||||
|
{
|
||||||
|
public PlaceableObject placeableObject;
|
||||||
|
|
||||||
|
|
||||||
|
public Tilemap collisionTm;
|
||||||
|
|
||||||
|
GameObject newBuilding;
|
||||||
|
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
newBuilding = Instantiate(placeableObject.prefab, Vector3.zero, Quaternion.identity);
|
||||||
|
}
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (newBuilding)
|
||||||
|
{
|
||||||
|
Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||||
|
//* Cursor.visible = false;
|
||||||
|
int snappedX = Mathf.RoundToInt(newPosition.x);
|
||||||
|
int snappedY = Mathf.RoundToInt(newPosition.y);
|
||||||
|
Vector3Int snappedPosition = new Vector3Int(snappedX, snappedY, 0);
|
||||||
|
|
||||||
|
newBuilding.transform.position = snappedPosition;
|
||||||
|
|
||||||
|
// TODO change to red if occupied
|
||||||
|
|
||||||
|
if (Input.GetMouseButtonDown(0) && !IsOccupied(snappedPosition, placeableObject))
|
||||||
|
{
|
||||||
|
placeableObject.Place();
|
||||||
|
// TODO mark tiles as occupied
|
||||||
|
// TODO unselect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsOccupied(Vector3Int startPos, PlaceableObject po)
|
||||||
|
{
|
||||||
|
Vector3Int poSize = new Vector3Int(po.width, po.height, 1);
|
||||||
|
|
||||||
|
BoundsInt area = new BoundsInt(startPos, poSize);
|
||||||
|
TileBase[] tileArray = collisionTm.GetTilesBlock(area);
|
||||||
|
|
||||||
|
foreach (TileBase tile in tileArray)
|
||||||
|
{
|
||||||
|
if (tile != null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/GridBuildingSystem.cs.meta
Normal file
11
Assets/Scripts/GridBuildingSystem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8c4997c1e7757ea49a7ea73e46e528c2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
16
Assets/Scripts/PlaceableObject.cs
Normal file
16
Assets/Scripts/PlaceableObject.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[CreateAssetMenu(fileName = "New PlacableObject", menuName = "Harvestdale/PlaceableObjects", order = 0)]
|
||||||
|
public class PlaceableObject : ScriptableObject
|
||||||
|
{
|
||||||
|
public string objectName;
|
||||||
|
// public Sprite icon;
|
||||||
|
public GameObject prefab;
|
||||||
|
public int width;
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
public void Place()
|
||||||
|
{
|
||||||
|
Debug.Log("PLACE");
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/PlaceableObject.cs.meta
Normal file
11
Assets/Scripts/PlaceableObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 66971ee377514a046acbb1e1c0b45d44
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user