Esempio n. 1
0
    // Determine whether user clicked on right or left side of the screen
    public void sideTouched()
    {
        if (Input.GetTouch(0).phase == TouchPhase.Began && !BlockRaycast.IsPointerOverUIObject())
        {
            // Left = true right = false
            touch_position = Input.GetTouch(0).position;
            side_touched   = touch_position.x <= screen_width / 2;
            tap_valid      = Time.time > time_of_last_tap + minimum_tap_time || side_touched != pre_side_touched;
            avatar_controller_script.setTapValid(tap_valid);

            // Check if the player tapped too fast
            //tap_valid = Time.time > time_of_last_tap + minimum_tap_time;
            //avatar_controller_script.setTapValid(tap_valid);
            //touch_position = Input.GetTouch(0).position;

            // Left = turn ccw, Right = turn cw
            //if (touch_position.x <= screen_width / 2)
            if (side_touched)
            {
                avatar_controller_script.rotate_avatar(Mathf.PI / 2);
            }

            else
            {
                avatar_controller_script.rotate_avatar(-Mathf.PI / 2);
            }

            time_of_last_tap = Time.time;
            pre_side_touched = side_touched;
        }
    }
Esempio n. 2
0
    //For testing in the editor
    public void editorSideTouched()
    {
        if (Input.GetMouseButtonDown(0) && !BlockRaycast.IsPointerOverUIObject())
        {
            mouse_position = Input.mousePosition;
            side_touched   = mouse_position.x <= screen_width / 2;
            tap_valid      = Time.time > time_of_last_tap + minimum_tap_time || side_touched != pre_side_touched;
            avatar_controller_script.setTapValid(tap_valid);

            //// Check if the player tapped too fast
            //tap_valid = Time.time > time_of_last_tap + minimum_tap_time;
            //avatar_controller_script.setTapValid(tap_valid);
            //mouse_position = Input.mousePosition;

            //if (mouse_position.x <= screen_width / 2)
            if (side_touched)
            {
                avatar_controller_script.rotate_avatar(Mathf.PI / 2);
            }

            else
            {
                avatar_controller_script.rotate_avatar(-Mathf.PI / 2);
            }

            time_of_last_tap = Time.time;
            pre_side_touched = side_touched;
        }
    }
Esempio n. 3
0
 public override void SetBlockRaycast(BlockRaycast active)
 {
     if (!NoResolvePopUps)
     {
         return;
     }
     base.SetBlockRaycast(active);
 }
Esempio n. 4
0
    void RemoveBlock()
    {
        Vector3Int?pos = BlockRaycast.RaycastBlockPosition(Game.cameratr.position, Game.cameratr.forward, .1f, 1000);

        if (move.enabled && pos.HasValue)
        {
            World.RemoveBlock(pos.Value);
        }
    }
Esempio n. 5
0
    void PlaceBlock()
    {
        Vector3Int?pos = BlockRaycast.RaycastBlockForPlace(Game.cameratr.position, Game.cameratr.forward, .05f, 2000);

        if (pos.HasValue && !Game.Paused && building.Chunks.Contains(World.GetChunkByBlock(pos.Value.x, pos.Value.z)))
        {
            World.SetBlock(pos.Value, Block.Blocks[selectedBlock].Instance(), true);
        }
    }
Esempio n. 6
0
 public virtual void SetBlockRaycast(BlockRaycast active)
 {
     if (CanAllowKeys)
     {
         _myCanvasGroup.blocksRaycasts = false;
     }
     else
     {
         _myCanvasGroup.blocksRaycasts = active == BlockRaycast.Yes;
     }
 }
Esempio n. 7
0
 public override void SetBlockRaycast(BlockRaycast active)
 {
     if (!GameIsPaused && NoResolvePopUps)
     {
         base.SetBlockRaycast(IsControlBar ? BlockRaycast.Yes: active);
     }
     else
     {
         base.SetBlockRaycast(active);
     }
 }
Esempio n. 8
0
    public override void SetBlockRaycast(BlockRaycast active)
    {
        if (_myCanvasGroup == null)
        {
            return;
        }

        if (OnHomeScreen)
        {
            _myCanvasGroup.blocksRaycasts = active == BlockRaycast.Yes;
        }
    }
Esempio n. 9
0
    public override void SetBlockRaycast(BlockRaycast active)
    {
        if (!CanStart)
        {
            return;
        }

        if (CanAllowKeys)
        {
            _myCanvasGroup.blocksRaycasts = false;
        }
        else
        {
            _myCanvasGroup.blocksRaycasts = active == BlockRaycast.Yes;
        }
    }
Esempio n. 10
0
    static void SelectChunk()
    {
        if (!Circle.isActive && !EventSystem.current.IsPointerOverGameObject())
        {
            Vector3Int?pos = BlockRaycast.RaycastBlockPosition(camera.position, Game.camera.ScreenPointToRay(Input.mousePosition).direction, .1f, 1000);
            if (!pos.HasValue)
            {
                while (SelectedChunks.Count > 0)
                {
                    UnselectChunk(SelectedChunks[0]);
                }
                return;
            }

            tempchunk = GetChunkByBlock(pos.Value.x, pos.Value.z);

            if (Input.GetKey(KeyCode.LeftControl))
            {
                if (SelectedChunks.Contains(tempchunk))
                {
                    UnselectChunk(tempchunk);
                }
                else
                {
                    SelectChunk(tempchunk);
                }
            }
            else
            {
                while (SelectedChunks.Count > 0)
                {
                    UnselectChunk(SelectedChunks[0]);
                }
                SelectChunk(tempchunk);
            }
        }
    }
Esempio n. 11
0
    public void Update()
    {
        Chunks.Update();

        if (!Chunks.ChunksReady)
        {
            return;
        }

        (bool hit, Vector3Int blockPos, Vector3Int face) = BlockRaycast.Raycast(Camera.main.transform.position, ForwardVector(Camera.main.transform.eulerAngles), 8, Chunks);

        if (hit && face != Vector3Int.zero && Chunks.Chunks.TryGetValue(Chunk.WorldToChunk(blockPos), out Chunk chunk))
        {
            Initialization.Inst.Outline.localPosition = blockPos;
            if (face.sqrMagnitude > 0.01f)
            {
                Initialization.Inst.OutlineSelected.forward = face;
            }

            int   blockIndex = Chunk.WorldToIndex(blockPos);
            Block block      = chunk.GetBlock(blockIndex);
            Initialization.Inst.OutlineVisual.localPosition = block.Bounds.center;
            Initialization.Inst.OutlineVisual.localScale    = block.Bounds.size + Vector3.one / 100;

            Initialization.Inst.Outline.gameObject.SetActive(true);

            if (Input.GetMouseButtonDown(0))
            {
                Chunks.BreakBlock(blockPos, chunk);
            }
            else if (Input.GetMouseButtonDown(1))
            {
                Block b       = BlockManager.Inst.GetBlockOrDefault("Base/Block/Stone");
                Block placeOn = chunk.GetBlock(Chunk.WorldToIndex(blockPos));

                Vector3Int newBlockPos   = blockPos + (placeOn.CanPlaceOver ? Vector3Int.zero : face);
                Vector3Int newBlockChunk = Chunk.WorldToChunk(newBlockPos);

                Chunk placeChunk = chunk;

                if (newBlockChunk != chunk.Position)
                {
                    Chunks.Chunks.TryGetValue(newBlockChunk, out placeChunk);
                }

                Block existing = placeChunk.GetBlock(Chunk.WorldToIndex(newBlockPos));
                if (placeChunk != null && existing.CanPlaceOver)
                {
                    if (b.CanCollide)
                    {
                        if (!PhysicsEngine.CheckIfEntityWithinBounds(new Bounds(newBlockPos + b.Bounds.center, b.Bounds.size)))
                        {
                            Chunks.PlaceBlock(newBlockPos, b, placeChunk);
                        }
                    }
                    else
                    {
                        Chunks.PlaceBlock(newBlockPos, b, placeChunk);
                    }
                }
            }
        }
        else
        {
            Initialization.Inst.Outline.gameObject.SetActive(false);
        }


        PhysicsEngine.Update();
    }
Esempio n. 12
0
 //Main
 public void StoreClearScreenData(IBranch[] allBranches, IBranch thisBranch, BlockRaycast blockRaycast)
 {
     WasOnHomeScreen = _myDataHub.OnHomeScreen;
     StoreActiveBranches(allBranches, thisBranch, blockRaycast == BlockRaycast.Yes);
 }
Esempio n. 13
0
 public void SetBlockRaycast(BlockRaycast blockRaycast) => _branchTypeBaseClass.SetBlockRaycast(blockRaycast);
Esempio n. 14
0
    void SetOutline()
    {
        Vector3Int?pos = BlockRaycast.RaycastBlockPosition(Game.cameratr.position, Game.cameratr.forward, .1f, 1000);

        if (pos.HasValue && building.Chunks.Contains(World.GetChunkByBlock(pos.Value.x, pos.Value.z)))
        {
            const float size     = 1.05f;
            Vector3     blockPos = pos.Value - Vector3.one * (size - 1f) / 2f;

            GL.PushMatrix();
            GL.Begin(GL.LINES);
            GL.Color(new Color(.1f, .1f, .1f));

            Vector3 temp = new Vector3();
            GL.Vertex(blockPos + temp);
            temp.y = size;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.x = size;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.y = 0f;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.x = 0f;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.z = size;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.y = size;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.z = 0f;
            GL.Vertex(blockPos + temp);

            temp.Set(size, 0f, 0f);
            GL.Vertex(blockPos + temp);
            temp.z = size;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.y = size;
            GL.Vertex(blockPos + temp);
            GL.Vertex(blockPos + temp);
            temp.z = 0f;
            GL.Vertex(blockPos + temp);

            temp.Set(0f, 0f, size);
            GL.Vertex(blockPos + temp);
            temp.x = size;
            GL.Vertex(blockPos + temp);

            temp.Set(0f, size, size);
            GL.Vertex(blockPos + temp);
            temp.x = size;
            GL.Vertex(blockPos + temp);

            GL.End();
            GL.PopMatrix();
        }
    }