mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-28 20:32:10 +01:00
add gruid buildingsystem
This commit is contained in:
@@ -11,6 +11,7 @@ GameObject:
|
||||
- component: {fileID: 5852600358559839619}
|
||||
- component: {fileID: 2080657515599704299}
|
||||
- component: {fileID: 95789179383567876}
|
||||
- component: {fileID: 3089461975269771136}
|
||||
m_Layer: 0
|
||||
m_Name: House
|
||||
m_TagString: Untagged
|
||||
@@ -111,3 +112,16 @@ BoxCollider2D:
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 3, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &3089461975269771136
|
||||
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: a7737d4424cb89b4caa8dc00101053f9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
isPlaced: 0
|
||||
|
||||
@@ -29653,8 +29653,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 8c4997c1e7757ea49a7ea73e46e528c2, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
placeableObject: {fileID: 11400000, guid: 40437410555fcda43ab2ec4c9a4c2807, type: 2}
|
||||
TESTPO: {fileID: 11400000, guid: 40437410555fcda43ab2ec4c9a4c2807, type: 2}
|
||||
collisionTm: {fileID: 1579890810}
|
||||
occupiedTile: {fileID: 11400000, guid: 4815673d17e2b7246b5812e51b47cd6d, type: 2}
|
||||
--- !u!1 &1579890809
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -29686,7 +29687,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29696,7 +29697,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29706,7 +29707,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29716,7 +29717,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29726,7 +29727,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29736,7 +29737,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29746,7 +29747,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29756,7 +29757,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29766,7 +29767,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29776,7 +29777,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29786,7 +29787,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29796,7 +29797,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29806,7 +29807,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29816,7 +29817,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29826,7 +29827,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29836,7 +29837,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29846,7 +29847,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29856,7 +29857,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29866,7 +29867,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29876,7 +29877,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29886,7 +29887,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29896,7 +29897,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29906,7 +29907,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29916,7 +29917,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29926,7 +29927,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29936,7 +29937,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29946,7 +29947,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29956,7 +29957,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29966,7 +29967,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29976,7 +29977,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29986,7 +29987,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -29996,7 +29997,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30006,7 +30007,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30016,7 +30017,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30026,7 +30027,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30036,7 +30037,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30046,7 +30047,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30056,7 +30057,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30066,7 +30067,7 @@ Tilemap:
|
||||
second:
|
||||
serializedVersion: 2
|
||||
m_TileIndex: 0
|
||||
m_TileSpriteIndex: 0
|
||||
m_TileSpriteIndex: 1
|
||||
m_TileMatrixIndex: 0
|
||||
m_TileColorIndex: 0
|
||||
m_TileObjectToInstantiateIndex: 65535
|
||||
@@ -30077,8 +30078,10 @@ Tilemap:
|
||||
- m_RefCount: 39
|
||||
m_Data: {fileID: 11400000, guid: 4815673d17e2b7246b5812e51b47cd6d, type: 2}
|
||||
m_TileSpriteArray:
|
||||
- m_RefCount: 0
|
||||
m_Data: {fileID: 0}
|
||||
- m_RefCount: 39
|
||||
m_Data: {fileID: 101721542, guid: 705252b03b9874148b86d73e7eb692ac, type: 3}
|
||||
m_Data: {fileID: 21300000, guid: 5c9374046d843f944922f6d98b38f750, type: 3}
|
||||
m_TileMatrixArray:
|
||||
- m_RefCount: 39
|
||||
m_Data:
|
||||
@@ -30100,10 +30103,12 @@ Tilemap:
|
||||
e33: 1
|
||||
m_TileColorArray:
|
||||
- m_RefCount: 39
|
||||
m_Data: {r: 1, g: 0, b: 0, a: 0.6117647}
|
||||
m_Data: {r: 1, g: 0, b: 0, a: 1}
|
||||
- m_RefCount: 0
|
||||
m_Data: {r: 3.8611e-41, g: 3.8611e-41, b: 3.8611e-41, a: 3.8611e-41}
|
||||
m_TileObjectToInstantiateArray: []
|
||||
m_AnimationFrameRate: 1
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 0.6039216}
|
||||
m_Origin: {x: -8, y: -3, z: 0}
|
||||
m_Size: {x: 13, y: 10, z: 1}
|
||||
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
|
||||
@@ -30241,6 +30246,10 @@ PrefabInstance:
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 3089461975269771136, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
||||
propertyPath: isPlaced
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5852600358559839619, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3}
|
||||
propertyPath: m_RootOrder
|
||||
value: 5
|
||||
|
||||
25
Assets/Scripts/Building.cs
Normal file
25
Assets/Scripts/Building.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Building : MonoBehaviour
|
||||
{
|
||||
public bool isPlaced = false;
|
||||
public PlaceableObject placeableObject;
|
||||
|
||||
public void Place()
|
||||
{
|
||||
isPlaced = true;
|
||||
BuildingManager.buildings.Add(this);
|
||||
}
|
||||
|
||||
public void Demolish()
|
||||
{
|
||||
isPlaced = false;
|
||||
BuildingManager.buildings.Remove(this);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public Vector3Int GetGridPosition()
|
||||
{
|
||||
return new Vector3Int(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y), 0);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Building.cs.meta
Normal file
11
Assets/Scripts/Building.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7737d4424cb89b4caa8dc00101053f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/BuildingManager.cs
Normal file
25
Assets/Scripts/BuildingManager.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Tilemaps;
|
||||
public class BuildingManager : MonoBehaviour
|
||||
{
|
||||
public static List<Building> buildings { get; private set; } = new List<Building>();
|
||||
|
||||
public static Building GetBuildingByGridPosition(Vector3Int tilePosition)
|
||||
{
|
||||
foreach (Building building in buildings)
|
||||
{
|
||||
PlaceableObject po = building.placeableObject;
|
||||
Vector3Int buildingPosition = building.GetGridPosition();
|
||||
BoundsInt area = new BoundsInt(buildingPosition, po.GetSizeVector());
|
||||
if (area.Contains(tilePosition))
|
||||
{
|
||||
return building;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/BuildingManager.cs.meta
Normal file
11
Assets/Scripts/BuildingManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f6b0f7d7d44d8a4c9fa79d01ee4ec53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,45 +5,135 @@ using UnityEngine.Tilemaps;
|
||||
|
||||
public class GridBuildingSystem : MonoBehaviour
|
||||
{
|
||||
public PlaceableObject placeableObject;
|
||||
|
||||
|
||||
public PlaceableObject TESTPO; //! DEBUG
|
||||
public Tilemap collisionTm;
|
||||
public TileBase occupiedTile;
|
||||
|
||||
GameObject newBuilding;
|
||||
private PlaceableObject placeableObject;
|
||||
private GameObject newBuildingObject;
|
||||
private bool isDemolishing = false;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
newBuilding = Instantiate(placeableObject.prefab, Vector3.zero, Quaternion.identity);
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (newBuilding)
|
||||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
int snappedX = Mathf.RoundToInt(mousePosition.x);
|
||||
int snappedY = Mathf.RoundToInt(mousePosition.y);
|
||||
Vector3Int snappedMousePosition = new Vector3Int(snappedX, snappedY, 0);
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.N))
|
||||
{
|
||||
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);
|
||||
isDemolishing = !isDemolishing;
|
||||
Debug.Log(isDemolishing);
|
||||
}
|
||||
|
||||
newBuilding.transform.position = snappedPosition;
|
||||
|
||||
// TODO change to red if occupied
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && !IsOccupied(snappedPosition, placeableObject))
|
||||
if (!isDemolishing)
|
||||
{
|
||||
//! DEBUG
|
||||
if (Input.GetKeyDown(KeyCode.B))
|
||||
{
|
||||
placeableObject.Place();
|
||||
// TODO mark tiles as occupied
|
||||
// TODO unselect
|
||||
SelectBuilding(TESTPO);
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
UnselectBuilding();
|
||||
}
|
||||
|
||||
if (newBuildingObject)
|
||||
{
|
||||
Cursor.visible = false;
|
||||
|
||||
newBuildingObject.transform.position = snappedMousePosition;
|
||||
bool isOccupied = IsOccupied(snappedMousePosition, placeableObject.GetSizeVector());
|
||||
|
||||
if (isOccupied)
|
||||
{
|
||||
newBuildingObject.GetComponent<SpriteRenderer>().color = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
newBuildingObject.GetComponent<SpriteRenderer>().color = Color.white;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && !isOccupied)
|
||||
{
|
||||
newBuildingObject.GetComponent<Building>().Place();
|
||||
newBuildingObject.GetComponent<Building>().placeableObject = placeableObject;
|
||||
OccupyTiles(snappedMousePosition, placeableObject.GetSizeVector());
|
||||
newBuildingObject = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.visible = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Building demoBuilding = BuildingManager.GetBuildingByGridPosition(snappedMousePosition);
|
||||
|
||||
if (demoBuilding)
|
||||
{
|
||||
demoBuilding.Demolish();
|
||||
UnOccupyTiles(demoBuilding.GetGridPosition(), demoBuilding.placeableObject.GetSizeVector());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool IsOccupied(Vector3Int startPos, PlaceableObject po)
|
||||
public void SelectBuilding(PlaceableObject newPo)
|
||||
{
|
||||
Vector3Int poSize = new Vector3Int(po.width, po.height, 1);
|
||||
if (newBuildingObject)
|
||||
{
|
||||
Destroy(newBuildingObject);
|
||||
}
|
||||
|
||||
placeableObject = newPo;
|
||||
newBuildingObject = Instantiate(placeableObject.prefab, Vector3.zero, Quaternion.identity);
|
||||
}
|
||||
|
||||
public void UnselectBuilding()
|
||||
{
|
||||
if (newBuildingObject)
|
||||
{
|
||||
Destroy(newBuildingObject);
|
||||
}
|
||||
newBuildingObject = null;
|
||||
placeableObject = null;
|
||||
}
|
||||
|
||||
private void OccupyTiles(Vector3Int startPos, Vector3Int poSize)
|
||||
{
|
||||
BoundsInt area = new BoundsInt(startPos, poSize);
|
||||
TileBase[] tileArray = new TileBase[area.size.x * area.size.y * area.size.z];
|
||||
for (int index = 0; index < tileArray.Length; index++)
|
||||
{
|
||||
tileArray[index] = occupiedTile;
|
||||
}
|
||||
|
||||
collisionTm.SetTilesBlock(area, tileArray);
|
||||
|
||||
}
|
||||
|
||||
private void UnOccupyTiles(Vector3Int startPos, Vector3Int poSize)
|
||||
{
|
||||
BoundsInt area = new BoundsInt(startPos, poSize);
|
||||
TileBase[] tileArray = new TileBase[area.size.x * area.size.y * area.size.z];
|
||||
for (int index = 0; index < tileArray.Length; index++)
|
||||
{
|
||||
tileArray[index] = null;
|
||||
}
|
||||
|
||||
collisionTm.SetTilesBlock(area, tileArray);
|
||||
}
|
||||
|
||||
private bool IsOccupied(Vector3Int startPos, Vector3Int poSize)
|
||||
{
|
||||
|
||||
|
||||
BoundsInt area = new BoundsInt(startPos, poSize);
|
||||
TileBase[] tileArray = collisionTm.GetTilesBlock(area);
|
||||
|
||||
@@ -9,8 +9,8 @@ public class PlaceableObject : ScriptableObject
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public void Place()
|
||||
public Vector3Int GetSizeVector()
|
||||
{
|
||||
Debug.Log("PLACE");
|
||||
return new Vector3Int(width, height, 1);
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ public class TimeManager : MonoBehaviour
|
||||
{
|
||||
Day++;
|
||||
Hour = 0;
|
||||
OnDayChanged();
|
||||
OnDayChanged?.Invoke();
|
||||
}
|
||||
|
||||
OnHourChanged();
|
||||
OnHourChanged?.Invoke();
|
||||
}
|
||||
|
||||
timer = minuteToRealTime;
|
||||
|
||||
BIN
Assets/Sprites/red.png
Normal file
BIN
Assets/Sprites/red.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 B |
135
Assets/Sprites/red.png.meta
Normal file
135
Assets/Sprites/red.png.meta
Normal file
@@ -0,0 +1,135 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c9374046d843f944922f6d98b38f750
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 12
|
||||
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
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMasterTextureLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 16
|
||||
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
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Server
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 5e97eb03825dee720800000000000000
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,10 +10,10 @@ MonoBehaviour:
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 13312, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_Name: TakenTile
|
||||
m_Name: occupiedTile
|
||||
m_EditorClassIdentifier:
|
||||
m_Sprite: {fileID: 101721542, guid: 705252b03b9874148b86d73e7eb692ac, type: 3}
|
||||
m_Color: {r: 1, g: 0, b: 0, a: 0.6117647}
|
||||
m_Sprite: {fileID: 21300000, guid: 5c9374046d843f944922f6d98b38f750, type: 3}
|
||||
m_Color: {r: 1, g: 0, b: 0, a: 1}
|
||||
m_Transform:
|
||||
e00: 1
|
||||
e01: 0
|
||||
Reference in New Issue
Block a user