mirror of
				https://github.com/DerTyp7/grow-ai-unity.git
				synced 2025-10-30 12:57:09 +01:00 
			
		
		
		
	added pathfinding
This commit is contained in:
		
							
								
								
									
										49
									
								
								Assets/Scripts/Grid/PlacedObject.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Assets/Scripts/Grid/PlacedObject.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.Tilemaps; | ||||
|  | ||||
| public class PlacedObject : MonoBehaviour | ||||
| { | ||||
|     public static PlacedObject Create(Vector3 worldPosition, Vector2Int origin, PlacedObjectTypeSO.Dir dir, PlacedObjectTypeSO placedObjectTypeSO) | ||||
|     { | ||||
|         Transform placeObjectTransform = Instantiate(placedObjectTypeSO.prefab, worldPosition, Quaternion.identity); | ||||
|  | ||||
|         PlacedObject placedObject = placeObjectTransform.GetComponent<PlacedObject>(); | ||||
|         placedObject.placedObjectTypeSO = placedObjectTypeSO; | ||||
|         placedObject.origin = origin; | ||||
|         placedObject.dir = dir; | ||||
|  | ||||
|         if (placedObjectTypeSO.isWalkable)  | ||||
|         { | ||||
|             foreach(Vector2Int position in placedObject.GetGridPositionList()) | ||||
|             { | ||||
|                 Pathfinding.Instance.GetNode(position.x, position.y).SetIsWalkable(true); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return placedObject; | ||||
|     } | ||||
|  | ||||
|     PlacedObjectTypeSO placedObjectTypeSO; | ||||
|     Vector2Int origin; | ||||
|     PlacedObjectTypeSO.Dir dir; | ||||
|  | ||||
|     public List<Vector2Int> GetGridPositionList() | ||||
|     { | ||||
|         return placedObjectTypeSO.GetGridPositionList(origin, PlacedObjectTypeSO.Dir.Down); | ||||
|     } | ||||
|  | ||||
|     public void DestroySelf() | ||||
|     { | ||||
|         if (placedObjectTypeSO.isWalkable) | ||||
|         { | ||||
|             foreach (Vector2Int position in GetGridPositionList()) | ||||
|             { | ||||
|                 Pathfinding.Instance.GetNode(position.x, position.y).SetIsWalkable(false); | ||||
|             } | ||||
|         } | ||||
|         Destroy(gameObject); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Janis M
					Janis M