diff --git a/Assets/Materials/SelectedSandBlockMaterial.mat b/Assets/Materials/SelectedSandBlockMaterial.mat new file mode 100644 index 0000000..3acd74a --- /dev/null +++ b/Assets/Materials/SelectedSandBlockMaterial.mat @@ -0,0 +1,138 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-3374394694674626268 +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: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion + version: 10 +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: SelectedSandBlockMaterial + m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: + - _EMISSION + m_InvalidKeywords: [] + m_LightmapFlags: 2 + m_EnableInstancingVariants: 1 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: + RenderType: Opaque + disabledShaderPasses: + - MOTIONVECTORS + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 2800000, guid: 0fb2d121a762f6949b96e09a338a9462, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: 0fb2d121a762f6949b96e09a338a9462, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + 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: + - _AddPrecomputedVelocity: 0 + - _AlphaClip: 0 + - _AlphaToMask: 0 + - _Blend: 0 + - _BlendModePreserveSpecular: 1 + - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _DstBlendAlpha: 0 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _Smoothness: 0 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SrcBlendAlpha: 1 + - _Surface: 0 + - _WorkflowMode: 1 + - _XRMotionVectorsPass: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0.044194173, g: 0.044194173, b: 0.044194173, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] + m_AllowLocking: 1 diff --git a/Assets/Materials/SelectedSandBlockMaterial.mat.meta b/Assets/Materials/SelectedSandBlockMaterial.mat.meta new file mode 100644 index 0000000..71480e4 --- /dev/null +++ b/Assets/Materials/SelectedSandBlockMaterial.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 70740e8fb777f5a46a011d9e96773fde +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Island.unity b/Assets/Scenes/Island.unity index 53de993..04051c6 100644 --- a/Assets/Scenes/Island.unity +++ b/Assets/Scenes/Island.unity @@ -10377,8 +10377,13 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Assembly-CSharp::BlockSelector _blockDetector: {fileID: 709556715} - _selectedMaterial: {fileID: 2100000, guid: 9e24435bdb83bfb43a73913d81fd3a3e, type: 2} - _isGrassOnly: 1 + _selectedMaterials: + - Material: {fileID: 2100000, guid: 9e24435bdb83bfb43a73913d81fd3a3e, type: 2} + Type: 1 + - Material: {fileID: 2100000, guid: 9e24435bdb83bfb43a73913d81fd3a3e, type: 2} + Type: 3 + - Material: {fileID: 2100000, guid: 70740e8fb777f5a46a011d9e96773fde, type: 2} + Type: 2 --- !u!1001 &1295925200 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/BlockSelector.cs b/Assets/Scripts/BlockSelector.cs index 4928398..b749ba3 100644 --- a/Assets/Scripts/BlockSelector.cs +++ b/Assets/Scripts/BlockSelector.cs @@ -1,10 +1,10 @@ +using System; using UnityEngine; public class BlockSelector : MonoBehaviour { [SerializeField] private BlockDetector _blockDetector; - [SerializeField] private Material _selectedMaterial; - [SerializeField] private bool _isGrassOnly = true; + [SerializeField] private BlockMaterial[] _selectedMaterials; private Renderer _selectedBlockRenderer; private Material _oldMaterial; @@ -25,16 +25,35 @@ public class BlockSelector : MonoBehaviour } } + private Material GetMaterialByBlockType(BlockScript.BlockType type) + { + foreach (var blockMaterial in _selectedMaterials) + { + if (blockMaterial.Type == type) + return blockMaterial.Material; + } + + return null; + } + private void OnBlockDetected(BlockScript block) { - if (_isGrassOnly && !block.CompareTag("GrassBlock")) + var selectedMaterial = GetMaterialByBlockType(block.Type); + if (selectedMaterial == null) return; - if (_selectedBlockRenderer != null) + if (_selectedBlockRenderer != null) _selectedBlockRenderer.material = _oldMaterial; _selectedBlockRenderer = block.GetComponentInChildren(); _oldMaterial = _selectedBlockRenderer.material; - _selectedBlockRenderer.material = _selectedMaterial; + _selectedBlockRenderer.material = selectedMaterial; + } + + [Serializable] + private struct BlockMaterial + { + public Material Material; + public BlockScript.BlockType Type; } }