예제 #1
0
        private void DrawBlockCursor(RaycastHit hit, bool adjacent)
        {
            if (m_LookAround)
            {
                m_PlacementCube.gameObject.SetActive(false);
                return;
            }

            if (hit.transform != null)
            {
                m_PlacementCube.gameObject.SetActive(true);
                Vector3 position = Vector3.zero;
                Vector3 scale    = Vector3.one + new Vector3(0.02f, 0.02f, 0.02f);
                if (!m_Dragging)
                {
                    position = VoxelTerrain.GetBlockPos(hit, adjacent);
                }
                else
                {
                    position = new Vector3(m_DragStart.x + m_DragEnd.x, m_DragStart.y + m_DragEnd.y, m_DragStart.z + m_DragEnd.z) / 2;
                    scale    = new Vector3(Mathf.Abs(m_DragStart.x - m_DragEnd.x) + 1, Mathf.Abs(m_DragStart.y - m_DragEnd.y) + 1, Mathf.Abs(m_DragStart.z - m_DragEnd.z) + 1) + new Vector3(0.02f, 0.02f, 0.02f);
                }
                m_PlacementCube.position   = position;
                m_PlacementCube.localScale = scale;
            }
            else
            {
                m_PlacementCube.gameObject.SetActive(false);
            }
        }
예제 #2
0
        void HandleBuilding()
        {
            if (m_CurrentEventSystem.IsPointerOverGameObject())
            {
                m_PlacementCube.gameObject.SetActive(false);
                return;
            }

            if (m_CurrentEventSystem.IsPointerOverGameObject())
            {
                return;
            }

            m_Hit = GetMouseHitPosition();
            bool adjacent = true;

            if (((Block)m_SelectedBlock).type == Block.Air.type)
            {
                adjacent = false;
            }

            DrawBlockCursor(m_Hit, adjacent);

            if (m_LookAround)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                m_Dragging = true;

                //VoxelTerrain.SetBlock(m_Hit, m_SelectedBlock, adjacent);
                m_DragStart = VoxelTerrain.GetBlockPos(GetMouseHitPosition(), adjacent);
            }

            if (Input.GetMouseButton(0) && m_Dragging)
            {
                m_DragEnd = VoxelTerrain.GetBlockPos(GetMouseHitPosition(), adjacent);
            }

            if (Input.GetMouseButtonUp(0) && m_Dragging)
            {
                m_Dragging = false;
                m_DragEnd  = VoxelTerrain.GetBlockPos(GetMouseHitPosition(), adjacent);

                VoxelTerrain.FillBlocks(m_DragStart, m_DragEnd, m_SelectedBlock);
            }
        }