mirror of
				https://github.com/DerTyp7/grow-ai-unity.git
				synced 2025-10-31 05:17:08 +01:00 
			
		
		
		
	a
This commit is contained in:
		
							
								
								
									
										64
									
								
								Assets/Scripts/Managers/AreaManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								Assets/Scripts/Managers/AreaManager.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class AreaManager : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] int areaHeight; | ||||
|     [SerializeField] int areaWidth; | ||||
|     List<AreaObject> areaObjects; | ||||
|     [SerializeField] GameObject testPrefab; | ||||
|     void Start() | ||||
|     { | ||||
|         //int gridWidth = GridBuildingSystem.instance.buildingGrid.GetWidth(); | ||||
|         //int gridHeight = GridBuildingSystem.instance.buildingGrid.GetWidth(); | ||||
|  | ||||
|         int areaWidthCount = GridBuildingSystem.instance.buildingGrid.GetWidth() / areaWidth; | ||||
|         int areaHeightCount = GridBuildingSystem.instance.buildingGrid.GetHeight() / areaHeight; | ||||
|  | ||||
|         for(int heightCounter = 0; heightCounter < areaHeightCount; heightCounter++) | ||||
|         { | ||||
|             Debug.Log("---- New Row -----"); | ||||
|             for (int widthCounter = 0; widthCounter < areaWidthCount; widthCounter++) | ||||
|             { | ||||
|                 Debug.Log("---- New Area -----"); | ||||
|  | ||||
|                 List<GameObject> testGameObjs = new List<GameObject>(); | ||||
|                 for (int x = 0; x < areaWidth; x++) | ||||
|                 { | ||||
|                     for (int y = 0; y < areaHeight; y++) | ||||
|                     { | ||||
|                          | ||||
|                         Debug.Log((x + widthCounter * areaWidth).ToString() + "," + (y + heightCounter * areaHeight).ToString()); | ||||
|                         GameObject testObj = Instantiate(testPrefab); | ||||
|                         testObj.transform.position = GridBuildingSystem.instance.buildingGrid.GetWorldPosition((x + widthCounter * areaWidth), (y + heightCounter * areaHeight)); | ||||
|                         testObj.transform.name = widthCounter + " - " + heightCounter; | ||||
|                         testGameObjs.Add(testObj); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 Color color = Random.ColorHSV(); | ||||
|                 foreach (GameObject testObj in testGameObjs) | ||||
|                 { | ||||
|                     testObj.GetComponent<SpriteRenderer>().color = color; | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     public class AreaObject | ||||
|     { | ||||
|         public int[,] tileArray; | ||||
|  | ||||
|         public AreaObject(int[,] _tileArray) { | ||||
|             tileArray = _tileArray; | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/Managers/AreaManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Managers/AreaManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 2be9f8a208335fe43bb797bec633e029 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										36
									
								
								Assets/Scripts/Managers/PersonManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Assets/Scripts/Managers/PersonManager.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class PersonManager : MonoBehaviour | ||||
| { | ||||
|     City city; | ||||
|     [SerializeField] GameObject personPrefab; | ||||
|     void Start() | ||||
|     { | ||||
|         city = GetComponent<City>(); | ||||
|         TimeManager.OnDayUpdate += OnDayUpdate; | ||||
|     } | ||||
|  | ||||
|     void OnDayUpdate() | ||||
|     { | ||||
|         int avaiableSpace = city.GetAvaiableHousingSpace(); | ||||
|         if (avaiableSpace > 5) | ||||
|         { | ||||
|             SpawnPerson(5); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             SpawnPerson(avaiableSpace); | ||||
|         } | ||||
|          | ||||
|     } | ||||
|  | ||||
|     public void SpawnPerson(int count = 1) | ||||
|     { | ||||
|         for(int i = 0; i < count; i++) | ||||
|         { | ||||
|             Instantiate(personPrefab); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/Managers/PersonManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Managers/PersonManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 7a66523eed61c5b44af39762a8d6e476 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
| @@ -31,7 +31,7 @@ public class TimeManager : MonoBehaviour | ||||
|     int minutesPerInterval = 1; | ||||
|  | ||||
|     public CultureInfo cultureInfo = new CultureInfo("en-us"); | ||||
|     DateTime dateTime = new DateTime(1, 1, 1, 0, 0, 0); | ||||
|     DateTime dateTime = new DateTime(1, 1, 1, 23, 0, 0); | ||||
|     DateTime prevDateTime; | ||||
|     float timer; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 j.mei7
					j.mei7