From 54bc27f11d47f8f848e81c9dba76ddb14af4a917 Mon Sep 17 00:00:00 2001 From: Nam Tae Gun Date: Fri, 14 Jun 2024 18:34:58 +0900 Subject: [PATCH] =?UTF-8?q?#17=20=EB=82=99=EC=84=9D=EC=97=90=20Indicator?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/02.Scripts/Prop/Rockfall.cs | 58 +++++++++++++++- .../BaseDamageableProps.prefab | 2 +- .../Props/DamageableProps/Rockfall.prefab | 68 ++++++++++++++++++- 3 files changed, 125 insertions(+), 3 deletions(-) diff --git a/Assets/02.Scripts/Prop/Rockfall.cs b/Assets/02.Scripts/Prop/Rockfall.cs index 89f2c68be..335c3a46a 100644 --- a/Assets/02.Scripts/Prop/Rockfall.cs +++ b/Assets/02.Scripts/Prop/Rockfall.cs @@ -4,6 +4,8 @@ using BlueWater.Interfaces; using BlueWater.Maps; using Sirenix.OdinInspector; using UnityEngine; +using UnityEngine.Rendering.Universal; +using UnityEngine.Serialization; namespace BlueWater { @@ -16,6 +18,13 @@ namespace BlueWater [SerializeField, Required] private SphereCollider _sphereCollider; + [SerializeField] + private DecalProjector _indicator; + + [Title("표시기 설정")] + [SerializeField] + private bool _isUsingIndicator = true; + [Title("충돌 설정")] [SerializeField] private LayerMask _targetLayer; @@ -39,16 +48,38 @@ namespace BlueWater private Collider[] _hitColliders = new Collider[4]; private bool _isGrounded; private bool _isAttacked; + + // Hashes + private static readonly int _fillHash = Shader.PropertyToID("_Fill"); private IEnumerator Start() { _sphereCollider.enabled = false; SpawnLocation = MapManager.Instance.SandMoleMapController.ParticleInstantiateLocation; + BasicSetting(); + ShowIndicator(); + + var startDistance = float.PositiveInfinity; while (!_isGrounded) { - _isGrounded = Physics.Raycast(transform.position, Vector3.down, _checkDistance, _groundLayer); + if (!Physics.Raycast(transform.position, Vector3.down, out var hit, 10f, _groundLayer)) continue; + + if (float.IsPositiveInfinity(startDistance)) + { + startDistance = hit.distance; + } + + if (_isUsingIndicator && _indicator) + { + var fillValue = Mathf.Lerp(1f, 0f, hit.distance / startDistance); + _indicator.material.SetFloat(_fillHash, fillValue); + } + _isGrounded = hit.distance <= _checkDistance; yield return null; } + + _indicator.material.SetFloat(_fillHash, 1f); + HideIndicator(); if (_rigidbody) { @@ -77,5 +108,30 @@ namespace BlueWater iDamageable.TakeDamage(_attackDamage); } } + + private void BasicSetting() + { + if (!_isUsingIndicator || !_indicator) return; + + _indicator.scaleMode = DecalScaleMode.InheritFromHierarchy; + _indicator.material = new Material(_indicator.material); + _indicator.material.SetFloat(_fillHash, 0f); + } + + private void HideIndicator() + { + if (!_isUsingIndicator || !_indicator) return; + + _indicator.enabled = false; + _indicator.material.SetFloat(_fillHash, 0); + } + + private void ShowIndicator() + { + if (!_isUsingIndicator || !_indicator) return; + + _indicator.material.SetFloat(_fillHash, 0); + _indicator.enabled = true; + } } } \ No newline at end of file diff --git a/Assets/05.Prefabs/Props/DamageableProps/BaseDamageableProps.prefab b/Assets/05.Prefabs/Props/DamageableProps/BaseDamageableProps.prefab index cf4544db2..205c001bd 100644 --- a/Assets/05.Prefabs/Props/DamageableProps/BaseDamageableProps.prefab +++ b/Assets/05.Prefabs/Props/DamageableProps/BaseDamageableProps.prefab @@ -137,7 +137,7 @@ SpriteRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 2100000, guid: d3c87e7ec1e83654cb2bff3178900c99, type: 2} + - {fileID: 2100000, guid: cc9b0fce917bc9548bd1bf66aa23a269, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 diff --git a/Assets/05.Prefabs/Props/DamageableProps/Rockfall.prefab b/Assets/05.Prefabs/Props/DamageableProps/Rockfall.prefab index 79234e964..f4c54bcf3 100644 --- a/Assets/05.Prefabs/Props/DamageableProps/Rockfall.prefab +++ b/Assets/05.Prefabs/Props/DamageableProps/Rockfall.prefab @@ -1,5 +1,61 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &8995215974275723360 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1426941151981288099} + - component: {fileID: 6370181286260610806} + m_Layer: 8 + m_Name: Indicator + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1426941151981288099 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8995215974275723360} + serializedVersion: 2 + m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} + m_LocalPosition: {x: 0, y: 5, z: 0} + m_LocalScale: {x: 1, y: 1, z: 10} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6877682250950493550} + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} +--- !u!114 &6370181286260610806 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8995215974275723360} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0777d029ed3dffa4692f417d4aba19ca, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 2100000, guid: 0b52d77e4d2f39e4096329a5a410c6a3, type: 2} + m_DrawDistance: 1000 + m_FadeScale: 0.9 + m_StartAngleFade: 180 + m_EndAngleFade: 180 + m_UVScale: {x: 1, y: 1} + m_UVBias: {x: 0, y: 0} + m_DecalLayerMask: 1 + m_ScaleMode: 1 + m_Offset: {x: 0, y: 0, z: 0.5} + m_Size: {x: 1, y: 1, z: 1} + m_FadeFactor: 1 --- !u!1001 &3577643095578124186 PrefabInstance: m_ObjectHideFlags: 0 @@ -78,7 +134,10 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] - m_AddedGameObjects: [] + m_AddedGameObjects: + - targetCorrespondingSourceObject: {fileID: 7986070582027999988, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3} + insertIndex: -1 + addedObject: {fileID: 1426941151981288099} m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 3764902268943045601, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3} insertIndex: -1 @@ -107,6 +166,8 @@ MonoBehaviour: _dieParticle: {fileID: 19826678, guid: 660dfd0ccf26cbf489a7556236949683, type: 3} _rigidbody: {fileID: 1838738275417183443} _sphereCollider: {fileID: 2971964863692897937} + _indicator: {fileID: 6370181286260610806} + _isUsingIndicator: 1 _targetLayer: serializedVersion: 2 m_Bits: 2048 @@ -127,3 +188,8 @@ SphereCollider: m_CorrespondingSourceObject: {fileID: 1772409705626034443, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3} m_PrefabInstance: {fileID: 3577643095578124186} m_PrefabAsset: {fileID: 0} +--- !u!4 &6877682250950493550 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 7986070582027999988, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3} + m_PrefabInstance: {fileID: 3577643095578124186} + m_PrefabAsset: {fileID: 0}