예제 #1
0
        void Update()
        {
            var cm  = ClientChunkManager.Instance;
            var dir = ViewDirection;
            var im  = ClientInputManager.Instance;

            if (VoxelsUtils.Cast(transform.position, dir, MAX_SIGHT_DISTANCE, HasBlockIn, out var castResult))
            {
                CurrentInPos  = castResult.HitPosition + dir * 0.03f;
                CurrentOutPos = castResult.HitPosition - dir * 0.015f;

                var chunk = cm.GetChunkInCoords(CurrentInPos);
                if (chunk != null)
                {
                    var block = cm.GetBlockIn(CurrentInPos);
                    BlockInSight = block;
                    var outBlock = cm.GetBlockIn(CurrentOutPos);
                    BlockOutSight = outBlock;
                    if (im.IsMovementEnabled)
                    {
                        if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonUp(1))
                        {
                            InteractWithBlock();
                        }
                        else if (Input.GetMouseButtonUp(1) && CanPlaceBlock(CurrentOutPos))
                        {
                            var desc = ClientUIManager.Instance.Hotbar.SelectedBlock;
                            cm.PutBlock(CurrentOutPos, new BlockData(desc.Type, desc.Subtype));
                        }
                        else if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonUp(0))
                        {
                            PaintBlockInSight(PaintColor);
                        }
                        else if (Input.GetMouseButtonUp(0))
                        {
                            cm.DestroyBlock(CurrentInPos);
                        }
                    }
                }
            }
            else
            {
                CurrentOutPos = Vector3.zero;
                CurrentInPos  = Vector3.zero;
                BlockInSight  = BlockData.Empty;
                BlockOutSight = BlockData.Empty;
            }

            if (im.IsMovementEnabled && Input.GetKeyUp(KeyCode.N))
            {
                LaunchBlock();
            }
        }
예제 #2
0
        bool CheckHorizontalPoints(Vector3 direcion, float distance, out float minDistance)
        {
            var bottomCheckPos = transform.position + new Vector3(0, -DownHeight + Radius, 0);
            var upCheckPos     = transform.position + new Vector3(0, UpHeight - Radius, 0);

            minDistance = 0f;
            var a = VoxelsUtils.Cast(bottomCheckPos, direcion, distance, IsBlockSolid, out var bottomCastResult);
            var b = VoxelsUtils.Cast(upCheckPos, direcion, distance, IsBlockSolid, out var upCastResult);

            if (a || b)
            {
                var upD = Vector3.Distance(upCheckPos, upCastResult.HitPosition);
                var dnD = Vector3.Distance(bottomCheckPos, bottomCastResult.HitPosition);
                minDistance = Mathf.Min(upD, dnD);
                return(true);
            }
            return(false);
        }