private void DigBlock(Ray ray, IWorld world) { if (Physics.RaycastBlock(ray, RaycastMaxDistance, world, m_DestroyRaycastSelector, out BlockRaycastHit hit)) { ShaderUtility.TargetedBlockPosition = hit.Position; if (Input.GetMouseButton(0)) { if (m_IsDigging) { if (hit.Position == m_FirstDigPos) { m_DiggingDamage += Time.deltaTime * 5; SetDigProgress(m_DiggingDamage / hit.Block.Hardness); if (m_DiggingDamage >= hit.Block.Hardness) { SetDigProgress(0); m_IsDigging = false; world.RWAccessor.SetBlock(hit.Position.x, hit.Position.y, hit.Position.z, world.BlockDataTable.GetBlock(0), Quaternion.identity, ModificationSource.PlayerAction); //block.PlayDigAudio(m_AudioSource); // if (Setting.SettingManager.Active.RenderingSetting.EnableDestroyEffect) // { // ParticleSystem effect = Instantiate(m_DestroyEffectPrefab, firstHitPos + new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity).GetComponent<ParticleSystem>(); // ParticleSystem.MainModule main = effect.main; // main.startColor = block.DestoryEffectColor; // } } } else { SetDigProgress(0); m_IsDigging = false; } } else { BlockData block = world.RWAccessor.GetBlock(hit.Position.x, hit.Position.y, hit.Position.z); m_IsDigging = true; m_DiggingDamage = 0; m_FirstDigPos = hit.Position; } } if (Input.GetMouseButtonDown(0)) { m_ClickedPos = hit.Position; m_ClickTime = Time.time; } if (Input.GetMouseButtonUp(0)) { SetDigProgress(0); m_IsDigging = false; BlockData block = world.RWAccessor.GetBlock(hit.Position.x, hit.Position.y, hit.Position.z); if ((hit.Position == m_ClickedPos) && (Time.time - m_ClickTime <= MaxClickSpacing)) { block.Click(world, hit.Position.x, hit.Position.y, hit.Position.z); } m_ClickedPos = Vector3Int.down; m_ClickTime = 0; } } else { // 无选定方块 ShaderUtility.TargetedBlockPosition = Vector3.down; } }