added Gridinfo

This commit is contained in:
j.mei7
2022-03-09 19:02:26 +01:00
parent 5a680495ce
commit 25ce88501d
7 changed files with 59 additions and 19 deletions

17
Assets/GridInfo.cs Normal file
View File

@@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridInfo : MonoBehaviour
{
public static GridInfo instance;
public int gridWidth = 20;
public int gridHeight = 20;
public float cellSize = 1f;
private void Awake()
{
instance = this;
}
}

11
Assets/GridInfo.cs.meta Normal file
View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9ff0826ad15d5c43859748285744c87
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,7 +12,11 @@ public class PathfindingSystem : MonoBehaviour
void Start()
{
instance = this;
pathfinding = new Pathfinding(20, 10);
int gridWidth = GridInfo.instance.gridWidth;
int gridHeight = GridInfo.instance.gridHeight;
float cellSize = GridInfo.instance.cellSize;
pathfinding = new Pathfinding(gridWidth, gridHeight, cellSize);
}
void Update()

View File

@@ -313,6 +313,10 @@ PrefabInstance:
propertyPath: city
value:
objectReference: {fileID: 0}
- target: {fileID: 3391280458837659705, guid: 4b478a82c8aed4e4e9f09083bf6afa01, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3391280458837659708, guid: 4b478a82c8aed4e4e9f09083bf6afa01, type: 3}
propertyPath: m_Name
value: Person
@@ -377,6 +381,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1522634446}
- component: {fileID: 1522634448}
- component: {fileID: 1522634445}
- component: {fileID: 1522634447}
m_Layer: 0
@@ -427,6 +432,21 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: db134add0ff65f04aa54ed5edf6d6df2, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1522634448
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1522634444}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a9ff0826ad15d5c43859748285744c87, type: 3}
m_Name:
m_EditorClassIdentifier:
gridWidth: 100
gridHeight: 100
cellSize: 1
--- !u!1001 &1762203019
PrefabInstance:
m_ObjectHideFlags: 0

View File

@@ -15,9 +15,9 @@ public class GridBuildingSystem : MonoBehaviour
if (instance == null)
instance = this;
int gridWidth = 20;
int gridHeight = 20;
float cellSize = 1f;
int gridWidth = GridInfo.instance.gridWidth;
int gridHeight = GridInfo.instance.gridHeight;
float cellSize = GridInfo.instance.cellSize;
buildingGrid = new Grid<GridObject>(gridWidth, gridHeight, cellSize, Vector3.zero, (Grid<GridObject> g, int x, int y) => new GridObject(g, x, y));
placedObjectTypeSO = placedObjectTypeSOList[0];

View File

@@ -1,16 +1,4 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading this package
I hope you find it useful in your projects
If you have any questions let me know
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View File

@@ -13,9 +13,9 @@ public class Pathfinding {
private List<PathNode> openList;
private List<PathNode> closedList;
public Pathfinding(int width, int height) {
public Pathfinding(int width, int height, float cellSize) {
Instance = this;
grid = new Grid<PathNode>(width, height, 1f, Vector3.zero, (Grid<PathNode> g, int x, int y) => new PathNode(g, x, y));
grid = new Grid<PathNode>(width, height, cellSize, Vector3.zero, (Grid<PathNode> g, int x, int y) => new PathNode(g, x, y));
}
public Grid<PathNode> GetGrid() {