mirror of
				https://github.com/DerTyp7/industrialize-unity.git
				synced 2025-10-31 05:17:10 +01:00 
			
		
		
		
	demolish playercontroller
This commit is contained in:
		| @@ -239,6 +239,9 @@ public class GridBuildingSystem : MonoBehaviour | ||||
|     #region PlacedObjectsTypeSO Methods | ||||
|     public void DemolishPlacedObjectTypeSO(Vector3 position) | ||||
|     { | ||||
|         if (selectedPlacedObjectTypeSO != null) | ||||
|             return; | ||||
|  | ||||
|         GridObject gridObject = buildingGrid.GetGridObject(position); // Camera.main.ScreenToWorldPoint(Input.mousePosition) | ||||
|         PlacedObject placedObject = gridObject.GetPlacedObject(); | ||||
|  | ||||
|   | ||||
| @@ -18,7 +18,8 @@ public class BuildingMenu : Menu | ||||
|  | ||||
|         foreach (PlacedObjectTypeSO p in placedObectTypeSOList) | ||||
|         { | ||||
|             GameObject item = Instantiate(itemPrefab, Vector3.zero, Quaternion.identity, itemListParent); | ||||
|             BuildingMenuItem item = Instantiate(itemPrefab, Vector3.zero, Quaternion.identity, itemListParent).GetComponent<BuildingMenuItem>(); | ||||
|             item.SetPlacedObjectType(p); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
							
								
								
									
										34
									
								
								Assets/Scripts/Menus/BuildingMenu/BuildingMenuItem.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Assets/Scripts/Menus/BuildingMenu/BuildingMenuItem.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| using TMPro; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class BuildingMenuItem : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] PlacedObjectTypeSO placedObjectType; | ||||
|  | ||||
|     [SerializeField] TextMeshProUGUI nameText; | ||||
|     [SerializeField] Image image; | ||||
|  | ||||
|     public void SelectPlacedObjectType() | ||||
|     { | ||||
|         MenuManager.CloseAllMenus(); | ||||
|         GridBuildingSystem.instance.SelectPlacedObjectTypeSO(placedObjectType); | ||||
|     } | ||||
|  | ||||
|     private void UpdateItem() | ||||
|     { | ||||
|         nameText.text = placedObjectType.name; | ||||
|         image.sprite = placedObjectType.iconSprite; | ||||
|     } | ||||
|  | ||||
|     public void SetPlacedObjectType(PlacedObjectTypeSO newPlacedObjectType) | ||||
|     { | ||||
|         placedObjectType = newPlacedObjectType; | ||||
|         UpdateItem(); | ||||
|     } | ||||
|  | ||||
|     public PlacedObjectTypeSO GetPlacedObjectType() | ||||
|     { | ||||
|         return placedObjectType; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/Menus/BuildingMenu/BuildingMenuItem.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Menus/BuildingMenu/BuildingMenuItem.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 7e64f31dcc5389143bfbd503c79ebaee | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
| @@ -146,6 +146,8 @@ GameObject: | ||||
|   - component: {fileID: 1001252664493678504} | ||||
|   - component: {fileID: 1001252664493678510} | ||||
|   - component: {fileID: 1001252664493678505} | ||||
|   - component: {fileID: -6979517058801678543} | ||||
|   - component: {fileID: 6909281088584444976} | ||||
|   m_Layer: 5 | ||||
|   m_Name: Item | ||||
|   m_TagString: Untagged | ||||
| @@ -213,6 +215,77 @@ MonoBehaviour: | ||||
|   m_FillOrigin: 0 | ||||
|   m_UseSpriteMesh: 0 | ||||
|   m_PixelsPerUnitMultiplier: 1 | ||||
| --- !u!114 &-6979517058801678543 | ||||
| MonoBehaviour: | ||||
|   m_ObjectHideFlags: 0 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_GameObject: {fileID: 1001252664493678507} | ||||
|   m_Enabled: 1 | ||||
|   m_EditorHideFlags: 0 | ||||
|   m_Script: {fileID: 11500000, guid: 7e64f31dcc5389143bfbd503c79ebaee, type: 3} | ||||
|   m_Name:  | ||||
|   m_EditorClassIdentifier:  | ||||
|   placedObjectType: {fileID: 0} | ||||
|   nameText: {fileID: 1001252663500297332} | ||||
|   image: {fileID: 1001252664626742490} | ||||
| --- !u!114 &6909281088584444976 | ||||
| MonoBehaviour: | ||||
|   m_ObjectHideFlags: 0 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_GameObject: {fileID: 1001252664493678507} | ||||
|   m_Enabled: 1 | ||||
|   m_EditorHideFlags: 0 | ||||
|   m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} | ||||
|   m_Name:  | ||||
|   m_EditorClassIdentifier:  | ||||
|   m_Navigation: | ||||
|     m_Mode: 3 | ||||
|     m_WrapAround: 0 | ||||
|     m_SelectOnUp: {fileID: 0} | ||||
|     m_SelectOnDown: {fileID: 0} | ||||
|     m_SelectOnLeft: {fileID: 0} | ||||
|     m_SelectOnRight: {fileID: 0} | ||||
|   m_Transition: 1 | ||||
|   m_Colors: | ||||
|     m_NormalColor: {r: 1, g: 1, b: 1, a: 1} | ||||
|     m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} | ||||
|     m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} | ||||
|     m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} | ||||
|     m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} | ||||
|     m_ColorMultiplier: 1 | ||||
|     m_FadeDuration: 0.1 | ||||
|   m_SpriteState: | ||||
|     m_HighlightedSprite: {fileID: 0} | ||||
|     m_PressedSprite: {fileID: 0} | ||||
|     m_SelectedSprite: {fileID: 0} | ||||
|     m_DisabledSprite: {fileID: 0} | ||||
|   m_AnimationTriggers: | ||||
|     m_NormalTrigger: Normal | ||||
|     m_HighlightedTrigger: Highlighted | ||||
|     m_PressedTrigger: Pressed | ||||
|     m_SelectedTrigger: Selected | ||||
|     m_DisabledTrigger: Disabled | ||||
|   m_Interactable: 1 | ||||
|   m_TargetGraphic: {fileID: 1001252664493678505} | ||||
|   m_OnClick: | ||||
|     m_PersistentCalls: | ||||
|       m_Calls: | ||||
|       - m_Target: {fileID: -6979517058801678543} | ||||
|         m_TargetAssemblyTypeName: BuildingMenuItem, Assembly-CSharp | ||||
|         m_MethodName: SelectPlacedObjectType | ||||
|         m_Mode: 1 | ||||
|         m_Arguments: | ||||
|           m_ObjectArgument: {fileID: 0} | ||||
|           m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine | ||||
|           m_IntArgument: 0 | ||||
|           m_FloatArgument: 0 | ||||
|           m_StringArgument:  | ||||
|           m_BoolArgument: 0 | ||||
|         m_CallState: 2 | ||||
| --- !u!1 &1001252664626742484 | ||||
| GameObject: | ||||
|   m_ObjectHideFlags: 0 | ||||
|   | ||||
| @@ -24,6 +24,18 @@ public class MenuManager : MonoBehaviour | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static bool AllMenusClosed() | ||||
|     { | ||||
|         foreach (Menu menu in MenuDictionary.instance.entries) | ||||
|         { | ||||
|             if (menu.isOpen) | ||||
|             { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         CloseAllMenus(); | ||||
|   | ||||
							
								
								
									
										27
									
								
								Assets/Scripts/Player/PlayerController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Assets/Scripts/Player/PlayerController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| using UnityEngine; | ||||
|  | ||||
| public class PlayerController : MonoBehaviour | ||||
| { | ||||
|     Camera cam; | ||||
|  | ||||
|     bool demolishMode = false; | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         cam = gameObject.GetComponent<Camera>(); | ||||
|     } | ||||
|  | ||||
|     void Update() | ||||
|     { | ||||
|         if (Input.GetButtonDown("Demolish")) | ||||
|         { | ||||
|             demolishMode = !demolishMode; | ||||
|         } | ||||
|  | ||||
|         if (demolishMode && Input.GetMouseButton(0) && MenuManager.AllMenusClosed()) | ||||
|         { | ||||
|             Vector3 postion = cam.ScreenToWorldPoint(Input.mousePosition); | ||||
|             GridBuildingSystem.instance.DemolishPlacedObjectTypeSO(postion); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/Player/PlayerController.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Player/PlayerController.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: f6238252f2005474e93f24acf68a7409 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
		Reference in New Issue
	
	Block a user
	 Janis
					Janis