diff --git a/Assets/Entities/Structures/PowerPlant/PowerPlant.prefab b/Assets/Entities/Structures/PowerPlant/PowerPlant.prefab index ca5c8a5..b41ca6e 100644 --- a/Assets/Entities/Structures/PowerPlant/PowerPlant.prefab +++ b/Assets/Entities/Structures/PowerPlant/PowerPlant.prefab @@ -269,7 +269,7 @@ MeshRenderer: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5716373424675870408} - m_Enabled: 1 + m_Enabled: 0 m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 diff --git a/Assets/Entities/Structures/Tower/Turret.prefab b/Assets/Entities/Structures/Tower/Turret.prefab index 41d13eb..eb37bf2 100644 --- a/Assets/Entities/Structures/Tower/Turret.prefab +++ b/Assets/Entities/Structures/Tower/Turret.prefab @@ -646,7 +646,7 @@ MeshRenderer: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8385032484663529878} - m_Enabled: 1 + m_Enabled: 0 m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 @@ -748,9 +748,8 @@ MonoBehaviour: centerPosition: {fileID: 5103935544759496321} basePosition: {fileID: 8324879816836607384} cost: 20 + buildPlacementBlocked: 0 buildTimer: 1 - buildCollider: {fileID: 0} - _buildPlacementBlocked: 0 weaponRange: 40 damage: 1 fireRate: 1 diff --git a/Assets/Handlers/BuildingHandler.cs b/Assets/Handlers/BuildingHandler.cs index 74a7170..9a339f5 100644 --- a/Assets/Handlers/BuildingHandler.cs +++ b/Assets/Handlers/BuildingHandler.cs @@ -8,21 +8,28 @@ namespace AsteroidGame.Handlers { public class BuildingHandler : HandlerBase { - [Header("Connections")] [SerializeField] - private new Camera camera; + [Header("Config")] + [SerializeField] private Color colorGhost = new Color(1f, 1f, 1f, 0.12f); + [SerializeField] private Color colorBuildingBlocked = new Color(1f, 0f, 0f, 0.12f); + [SerializeField] private Material ghostStructureMaterial; - [Header("State")] [SerializeField] private bool isBuilding; + [Header("State")] + [SerializeField] private bool isBuilding; [SerializeField] private int buildingSelector; - [Header("Prefabs")] [SerializeField] private List buildings = new(); + [Header("Prefabs")] + [SerializeField] private List buildings = new(); #region Private + [SerializeField] private Color colorCurrent; + private Camera _camera; [SerializeField] private List activeBuildings; private Vector3 _tempVec; private Plane _buildPlane; - private StructureBase _tempSb; + private StructureBase _tempStructure; private StructureBase _ghostStructure; + private MeshRenderer[] _ghostStructureMeshRenderers; #endregion @@ -30,17 +37,27 @@ namespace AsteroidGame.Handlers protected override void OnEnable() { base.OnEnable(); + _camera = Camera.main; _buildPlane = new Plane(Vector3.up, Vector3.zero); activeBuildings.Clear(); - camera = Camera.main; } private void Update() { - if (isBuilding) + if (!isBuilding) return; + _ghostStructure.transform.position = GetPlanePoint(); + SetGhostColor(_ghostStructure.BuildPlacementBlocked ? colorBuildingBlocked : colorGhost); + } + + private void SetGhostColor(Color newColor) + { + if (newColor == colorCurrent) return; + foreach (var meshRenderer in _ghostStructureMeshRenderers) { - _ghostStructure.transform.position = GetPlanePoint(); + meshRenderer.material.color = newColor; } + + colorCurrent = newColor; } protected override void OnLeftClick(InputAction.CallbackContext context) @@ -50,22 +67,15 @@ namespace AsteroidGame.Handlers protected override void OnRightClick(InputAction.CallbackContext context) { - if (!isBuilding) return; - DestroyGhostStructure(); - isBuilding = false; + AbortPlaceStructure(); } protected override void OnBuild(InputAction.CallbackContext context) { EnterBuildMode(); } - - public void PlaceStructure() - { - AbortPlaceStructure(); - } - public void AbortPlaceStructure() + public void PlaceStructure() { if (!isBuilding) return; if (_ghostStructure.BuildPlacementBlocked) return; @@ -73,9 +83,17 @@ namespace AsteroidGame.Handlers SpawnStructure(); isBuilding = false; } - + + public void AbortPlaceStructure() + { + if (!isBuilding) return; + DestroyGhostStructure(); + isBuilding = false; + } + public void EnterBuildMode() { + if (isBuilding) return; isBuilding = true; SpawnGhostStructure(); } @@ -84,18 +102,17 @@ namespace AsteroidGame.Handlers { _ghostStructure = Instantiate(buildings[buildingSelector], GetPlanePoint(), Quaternion.identity, transform); _ghostStructure.name = "GhostStructure"; - + var rb = _ghostStructure.gameObject.AddComponent(); rb.useGravity = false; - - // foreach (var renderer in _ghostStructure.GetComponents()) - // { - // var color = renderer.material.color; - // var tempcolor = color; - // tempcolor.a = 0.1f; - // color = tempcolor; - // } - + + _ghostStructureMeshRenderers = _ghostStructure.GetComponentsInChildren(); + + foreach (var meshRenderer in _ghostStructureMeshRenderers) + { + meshRenderer.material = ghostStructureMaterial; + } + _ghostStructure.GetComponent().enabled = false; } @@ -106,22 +123,20 @@ namespace AsteroidGame.Handlers private void SpawnStructure() { - _tempSb = Instantiate(buildings[buildingSelector], GetPlanePoint(), Quaternion.identity, transform); - activeBuildings.Add(_tempSb); + _tempStructure = Instantiate(buildings[buildingSelector], GetPlanePoint(), Quaternion.identity, transform); + activeBuildings.Add(_tempStructure); } private Vector3 GetPlanePoint() { - Ray ray = camera.ScreenPointToRay(Mouse.current.position.ReadValue()); + Ray ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue()); if (_buildPlane.Raycast(ray, out float distance)) { return ray.GetPoint(distance); } - else - { - print("BuildPlaneNotHit"); - return Vector3.zero; - } + + print("BuildPlaneNotHit"); + return Vector3.zero; } } } \ No newline at end of file diff --git a/Assets/Materials/GhostMaterial.mat b/Assets/Materials/GhostMaterial.mat new file mode 100644 index 0000000..6b6966c --- /dev/null +++ b/Assets/Materials/GhostMaterial.mat @@ -0,0 +1,269 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: GhostMaterial + m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3} + m_ValidKeywords: + - _DISABLE_SSR_TRANSPARENT + - _ENABLE_FOG_ON_TRANSPARENT + - _NORMALMAP_TANGENT_SPACE + - _SURFACE_TYPE_TRANSPARENT + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: 3000 + stringTagMap: + RenderType: Transparent + disabledShaderPasses: + - TransparentDepthPrepass + - TransparentDepthPostpass + - TransparentBackface + - RayTracingPrepass + - MOTIONVECTORS + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AnisotropyMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BaseColorMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BentNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BentNormalMapOS: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _CoatMaskMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissiveColorMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _HeightMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _IridescenceMaskMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _IridescenceThicknessMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MaskMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NormalMapOS: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecularColorMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SubsurfaceMaskMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TangentMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TangentMapOS: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ThicknessMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TransmittanceColorMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AORemapMax: 1 + - _AORemapMin: 0 + - _ATDistance: 1 + - _AddPrecomputedVelocity: 0 + - _AlbedoAffectEmissive: 0 + - _AlphaCutoff: 0.5 + - _AlphaCutoffEnable: 0 + - _AlphaCutoffPostpass: 0.5 + - _AlphaCutoffPrepass: 0.5 + - _AlphaCutoffShadow: 0.5 + - _AlphaDstBlend: 10 + - _AlphaSrcBlend: 1 + - _AlphaToMask: 0 + - _AlphaToMaskInspectorValue: 0 + - _Anisotropy: 0 + - _BlendMode: 0 + - _CoatMask: 0 + - _CullMode: 2 + - _CullModeForward: 2 + - _Cutoff: 0.5 + - _DepthOffsetEnable: 0 + - _DetailAlbedoScale: 1 + - _DetailNormalScale: 1 + - _DetailSmoothnessScale: 1 + - _DiffusionProfile: 0 + - _DiffusionProfileHash: 0 + - _DisplacementLockObjectScale: 1 + - _DisplacementLockTilingScale: 1 + - _DisplacementMode: 0 + - _DoubleSidedEnable: 0 + - _DoubleSidedGIMode: 0 + - _DoubleSidedNormalMode: 1 + - _DstBlend: 10 + - _EmissiveColorMode: 1 + - _EmissiveExposureWeight: 1 + - _EmissiveIntensity: 1 + - _EmissiveIntensityUnit: 0 + - _EnableBlendModePreserveSpecularLighting: 1 + - _EnableFogOnTransparent: 1 + - _EnableGeometricSpecularAA: 0 + - _EnergyConservingSpecularColor: 1 + - _HeightAmplitude: 0.02 + - _HeightCenter: 0.5 + - _HeightMapParametrization: 0 + - _HeightMax: 1 + - _HeightMin: -1 + - _HeightOffset: 0 + - _HeightPoMAmplitude: 2 + - _HeightTessAmplitude: 2 + - _HeightTessCenter: 0.5 + - _InvTilingScale: 1 + - _Ior: 1.5 + - _IridescenceMask: 1 + - _IridescenceThickness: 1 + - _LinkDetailsWithBase: 1 + - _MaterialID: 1 + - _Metallic: 0 + - _MetallicRemapMax: 1 + - _MetallicRemapMin: 0 + - _NormalMapSpace: 0 + - _NormalScale: 1 + - _OpaqueCullMode: 2 + - _PPDLodThreshold: 5 + - _PPDMaxSamples: 15 + - _PPDMinSamples: 5 + - _PPDPrimitiveLength: 1 + - _PPDPrimitiveWidth: 1 + - _RayTracing: 0 + - _ReceivesSSR: 1 + - _ReceivesSSRTransparent: 0 + - _RefractionModel: 0 + - _Smoothness: 0.5 + - _SmoothnessRemapMax: 1 + - _SmoothnessRemapMin: 0 + - _SpecularAAScreenSpaceVariance: 0.1 + - _SpecularAAThreshold: 0.2 + - _SpecularOcclusionMode: 1 + - _SrcBlend: 1 + - _StencilRef: 0 + - _StencilRefDepth: 0 + - _StencilRefGBuffer: 2 + - _StencilRefMV: 32 + - _StencilWriteMask: 6 + - _StencilWriteMaskDepth: 8 + - _StencilWriteMaskGBuffer: 14 + - _StencilWriteMaskMV: 40 + - _SubsurfaceMask: 1 + - _SupportDecals: 1 + - _SurfaceType: 1 + - _TexWorldScale: 1 + - _TexWorldScaleEmissive: 1 + - _Thickness: 1 + - _TransmissionEnable: 1 + - _TransparentBackfaceEnable: 0 + - _TransparentCullMode: 2 + - _TransparentDepthPostpassEnable: 0 + - _TransparentDepthPrepassEnable: 0 + - _TransparentSortPriority: 0 + - _TransparentWritingMotionVec: 0 + - _TransparentZWrite: 0 + - _UVBase: 0 + - _UVDetail: 0 + - _UVEmissive: 0 + - _UseEmissiveIntensity: 0 + - _UseShadowThreshold: 0 + - _ZTestDepthEqualForOpaque: 4 + - _ZTestGBuffer: 4 + - _ZTestTransparent: 4 + - _ZWrite: 0 + m_Colors: + - _BaseColor: {r: 0.41509432, g: 0.40530434, b: 0.40530434, a: 0.11764706} + - _BaseColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0} + - _Color: {r: 0.4150943, g: 0.4053043, b: 0.4053043, a: 0.11764706} + - _DiffusionProfileAsset: {r: 0, g: 0, b: 0, a: 0} + - _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0} + - _EmissionColor: {r: 1, g: 1, b: 1, a: 1} + - _EmissiveColor: {r: 0, g: 0, b: 0, a: 1} + - _EmissiveColorLDR: {r: 0, g: 0, b: 0, a: 1} + - _InvPrimScale: {r: 1, g: 1, b: 0, a: 0} + - _IridescenceThicknessRemap: {r: 0, g: 1, b: 0, a: 0} + - _SpecularColor: {r: 1, g: 1, b: 1, a: 1} + - _ThicknessRemap: {r: 0, g: 1, b: 0, a: 0} + - _TransmittanceColor: {r: 1, g: 1, b: 1, a: 1} + - _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0} + - _UVMappingMask: {r: 1, g: 0, b: 0, a: 0} + - _UVMappingMaskEmissive: {r: 1, g: 0, b: 0, a: 0} + m_BuildTextureStacks: [] +--- !u!114 &7722237999415144100 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: da692e001514ec24dbc4cca1949ff7e8, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 12 + hdPluginSubTargetMaterialVersions: + m_Keys: [] + m_Values: diff --git a/Assets/Materials/GhostMaterial.mat.meta b/Assets/Materials/GhostMaterial.mat.meta new file mode 100644 index 0000000..3dfd73c --- /dev/null +++ b/Assets/Materials/GhostMaterial.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dc919a35edbf85647939132e73b39642 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Playground.unity b/Assets/Scenes/Playground.unity index 0996d6b..b9e0e61 100644 --- a/Assets/Scenes/Playground.unity +++ b/Assets/Scenes/Playground.unity @@ -262,12 +262,15 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 51bf353b43f7b2448bbb3088d78ee8a6, type: 3} m_Name: m_EditorClassIdentifier: - camera: {fileID: 0} + colorGhost: {r: 1, g: 1, b: 1, a: 0.12} + colorBuildingBlocked: {r: 1, g: 0, b: 0, a: 0.12} + ghostStructureMaterial: {fileID: 2100000, guid: dc919a35edbf85647939132e73b39642, type: 2} isBuilding: 0 buildingSelector: 0 buildings: - {fileID: 8787361557661825162, guid: 534f8d15e0c83c646887bebfda2bdfd6, type: 3} - {fileID: 309657227} + colorCurrent: {r: 0, g: 0, b: 0, a: 0} activeBuildings: [] --- !u!1001 &1191794244 PrefabInstance: @@ -612,6 +615,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 3252872069634226352, guid: 534f8d15e0c83c646887bebfda2bdfd6, type: 3} + propertyPath: m_Enabled + value: 0 + objectReference: {fileID: 0} - target: {fileID: 4256226406833302537, guid: 534f8d15e0c83c646887bebfda2bdfd6, type: 3} propertyPath: m_IsTrigger value: 1 @@ -660,6 +667,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 8385032484663529878, guid: 534f8d15e0c83c646887bebfda2bdfd6, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 8704396752535238434, guid: 534f8d15e0c83c646887bebfda2bdfd6, type: 3} propertyPath: m_Name value: Turret