コード例 #1
0
 private void LateUpdate()
 {
     if (!playerIsDead)
     {
         if (specialWasPressed != specialButton)
         {
             specialButton = specialWasPressed;
             if (!specialButton)
             {
                 closestTile = null;
             }
         }
         if (gatherWasPressed != gatherButton)
         {
             gatherButton = gatherWasPressed;
             if (!gatherButton)
             {
                 if (gatherCoroutine != null)
                 {
                     CancelGathering();
                 }
                 closestTile = null;
             }
         }
         gatherWasPressed  = false;
         specialWasPressed = false;
     }
 }
コード例 #2
0
    IEnumerator HarvestTile(TileHit tileHit)
    {
        if (tileHit.tile.GetTileAbst is GatherableTileSO gatherable)
        {
            ((GatherableState)tileHit.tile.tileState).SetIsBeingGatheredState(true, tileHit.gridPosition);
            UIManager._instance.CancelProgressBar();
            tileBeingGathered = tileHit;
            float   gatheringTime = gatherable.GetGatheringTime / (gatheringSpeed.GetSetValue * equipManager.GetGatheringSpeedFromTool(gatherable.GetToolType));
            Vector2 tileWorldPos  = gridManager.GridToWorldPosition(tileHit.gridPosition, TileMapLayer.Buildings, true);
            Camera  currentCamera = CameraController._instance.GetCurrentActiveCamera;
            Vector2 tileScreenPos = currentCamera.WorldToScreenPoint(tileWorldPos);
            UIManager._instance.StartProgressBar(tileScreenPos, gatheringTime);
            SoundManager._instance.PlaySoundLooped(gatherable.getGatheringSound);


            yield return(new WaitForSeconds(gatheringTime));

            tileHit.tile.GatherInteraction(tileHit.gridPosition, TileMapLayer.Buildings);

            if ((equipManager.GetToolDurability(gatherable.GetToolType)) != null)
            {
                equipManager.LowerAmountOfToolDurability(gatherable.GetToolType, gatherable.GetGatherDurabilityCost);
            }
            SoundManager._instance.DisableLooping(gatherable.getGatheringSound);
            Debug.Log("TileHarvested");
            tileBeingGathered = null;
        }
        gatherCoroutine = null;
        closestTile     = null;
    }
コード例 #3
0
 public override void OnSwitchState()
 {
     for (int i = 0; i < Position.Length; i++)
     {
         gridManager.SetTileColor(Position[i], TileMapLayer.Buildings, Color.white);
     }
     currentTileHit = null;
 }
コード例 #4
0
 private void CancelGathering()
 {
     StopCoroutine(gatherCoroutine);
     gatherCoroutine = null;
     SoundManager._instance.DisableLooping(((GatherableTileSO)tileBeingGathered.tile.GetTileAbst).getGatheringSound);
     UIManager._instance.CancelProgressBar();
     ((GatherableState)tileBeingGathered.tile.tileState).SetIsBeingGatheredState(false, tileBeingGathered.gridPosition);
     tileBeingGathered = null;
 }
コード例 #5
0
    // Update is called once per frame
    private void Update()
    {
        viewChanged = false;
        movement    = new Vector2(
            Input.GetKey(KeyCode.D) ? 1 : 0 - (Input.GetKey(KeyCode.A) ? 1 : 0),
            Input.GetKey(KeyCode.W) ? 1 : 0 - (Input.GetKey(KeyCode.S) ? 1 : 0)
            );
        movement *= moveSpeed * Time.deltaTime;
        if (movement != Vector2.zero)
        {
            transform.position += (Vector3)movement;
            viewChanged         = true;
        }

        scrollMovement = Time.deltaTime * scrollSpeed * -Input.GetAxis("Mouse ScrollWheel");
        if (scrollMovement != 0)
        {
            viewChanged = true;
        }

        if (Input.GetKey(KeyCode.Mouse0))
        {
            TileMapLayer layer        = (Input.GetKey(KeyCode.LeftShift)) ? TileMapLayer.Buildings : TileMapLayer.Floor;
            Vector2Int   gridPosition = MouseGridPosition(TileMapLayer.Floor);
            gridManager.SetTile(new TileSlot(clickTile), gridPosition, layer);
        }
        else if (Input.GetKey(KeyCode.Mouse1))
        {
            TileMapLayer layer        = (Input.GetKey(KeyCode.LeftShift)) ? TileMapLayer.Buildings : TileMapLayer.Floor;
            Vector2Int   gridPosition = MouseGridPosition(layer);
            gridManager.SetTile(null, gridPosition, layer);
        }
        else if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            TileMapLayer layer = (Input.GetKey(KeyCode.LeftShift)) ? TileMapLayer.Buildings : TileMapLayer.Floor;
            Debug.Log(gridManager.GetTileFromGrid(MouseGridPosition(layer), layer));
        }
        else if (Input.GetKeyDown(KeyCode.Mouse2))
        {
            Vector3 mousePos = GetcameraComp().ScreenToWorldPoint(Input.mousePosition);
            mousePos.z = 0;
            TileMapLayer layer = (Input.GetKey(KeyCode.LeftShift)) ? TileMapLayer.Buildings : TileMapLayer.Floor;
            TileHit      hit   = gridManager.GetHitFromWorldPosition(mousePos, layer);

            if (hit.tile != null &&
                hit.tile.IsGatherable)
            {
                Debug.Log("Color change");
                hit.tile.GatherInteraction(hit.gridPosition, layer);
            }
        }

        if (viewChanged)
        {
            cameraController.UpdateView();
        }
    }
コード例 #6
0
 public void ImplementInteraction(bool SpecialInteract)
 {
     gatherWasPressed  = !SpecialInteract;
     specialWasPressed = SpecialInteract;
     if (closestTile == null)
     {
         if (SpecialInteract)
         {
             closestTile = Scan(new SpecialInterractionScanChecker());
         }
         else
         {
             closestTile = Scan(new GatheringScanChecker());
         }
     }
     else
     {
         Vector3 destination = gridManager.GridToWorldPosition(closestTile.gridPosition, TileMapLayer.Buildings, true);
         destination.z = base.transform.position.z;
         float distance = Vector2.Distance(base.transform.position, destination);
         if (distance > InterractionDistance)
         {
             Vector3 moveVector = Vector3.ClampMagnitude((destination - transform.position).normalized * Time.deltaTime * baseSpeed * moveSpeed.GetSetValue, distance);
             _playerGFX.Walk(true, moveVector);
             Move(moveVector);
         }
         else
         {
             if (SpecialInteract)
             {
                 if (!SpecialInterracted)
                 {
                     closestTile.tile.SpecialInteraction(closestTile.gridPosition, TileMapLayer.Buildings);
                     SpecialInterracted = true;
                 }
             }
             else
             {
                 if (gatherCoroutine == null)
                 {
                     gatherCoroutine = StartCoroutine(HarvestTile(closestTile));
                 }
             }
         }
     }
 }
コード例 #7
0
ファイル: TileControl.cs プロジェクト: gkagm2/unityGame
    public int firstStartTileIndex; // 초기에 시작되는 타일의 인덱스 번호
    void Awake()
    {
        tileStack = new Stack <Tile>();
        mapInfo   = GetComponent <MapInfo>();

        //Debug.Log("TileControl.cs " + "~~~mylevel : " + mapInfo.myLevel + "~~~myStage: " + mapInfo.myStage);

        maxTileNumber = transform.childCount;    //타일의 개수를 가져옴
        tile          = new Tile[maxTileNumber]; // 초기 타일들의 인스턴스 생성
        initTile      = new bool[maxTileNumber]; // 초기화하기위해 필요한 정보
        for (int i = 0; i < maxTileNumber; i++)  //각 타일들의 Tile 컴포넌트를 가져옴.
        {
            tile[i]     = transform.GetChild(i).GetComponent <Tile>();
            initTile[i] = tile[i].check;              // 초기화하기 위해 담는다
        }
        InitTiles();                                  // 타일 초기화.
        tileHit = cameraObj.GetComponent <TileHit>(); //TileHit 컴포넌트를 가져온다.
    }
コード例 #8
0
    public override void MousePos()
    {
        touchPosition = CameraController._instance.GetCurrentActiveCamera.ScreenToWorldPoint(Input.mousePosition);

        currentTileHit = gridManager.GetHitFromWorldPosition(touchPosition, TileMapLayer.Buildings);

        if (currentTileHit == null || currentTileHit.tile == null || gridManager.GetTileFromGrid(currentTileHit.gridPosition, TileMapLayer.Buildings) == null)
        {
            return;
        }

        tileSlotCache = currentTileHit.tile;

        if (Input.GetMouseButtonDown(0))
        {
            ConfirmRemoval();
        }
    }
コード例 #9
0
 private void CheckForTrees()
 {
     if (Time.time >= lastTreeCheckTime + treeCheckInterval)
     {
         lastTreeCheckTime = Time.time;
         if (currentPosOnGrid != lastCheckPosition)
         {
             lastCheckPosition = currentPosOnGrid;
             TileHit hit = scanner.Scan(currentPosOnGrid, gridMovementDirection, airLookRange, TileMapLayer.Buildings, new AirSourcesScanChecker());
             if (hit != null)
             {
                 airRegenCont.Begin(airRegenData);
             }
             else
             {
                 airRegenCont.Stop();
             }
         }
     }
 }
コード例 #10
0
    private void CheckPosition(Vector2 worldPos)
    {
        if (Position[0] == gridManager.GetHitFromWorldPosition(worldPos, TileMapLayer.Floor).gridPosition)
        {
            return;
        }

        currentTileHit = gridManager.GetHitFromWorldPosition(worldPos, TileMapLayer.Floor);

        Position[0] = new Vector2Int(currentTileHit.gridPosition.x, currentTileHit.gridPosition.y);

        // there is a block on the floor
        // check if there is no a block above it
        if (currentTileHit.tile != null && gridManager.GetHitFromWorldPosition(worldPos, TileMapLayer.Buildings).tile != null)
        {
            ReturnPreviousTile();
            PlaceDummyBlock();
        }

        return;
    }
コード例 #11
0
    private void CheckPosition(Vector2 worldPos)
    {
        if (Position[0] == gridManager.GetHitFromWorldPosition(worldPos, TileMapLayer.Floor).gridPosition)
        {
            return;
        }



        currentTileHit = gridManager.GetHitFromWorldPosition(touchPosition, TileMapLayer.Floor);

        if (currentTileHit == null)
        {
            return;
        }


        // there is a block on the floor
        // check if there is no a block above it
        if (currentTileHit.tile != null && gridManager.GetTileFromGrid(currentTileHit.gridPosition, TileMapLayer.Buildings) == null)
        {
            Position[0] = new Vector2Int(currentTileHit.gridPosition.x, currentTileHit.gridPosition.y);


            PlaceDummyBlock(false);
        }
        else if (currentlyPlacedOnFloor)
        {
            if (currentTileHit.tile == null && gridManager.GetTileFromGrid(currentTileHit.gridPosition, TileMapLayer.Buildings) == null)
            {
                Position[0] = new Vector2Int(currentTileHit.gridPosition.x, currentTileHit.gridPosition.y);

                PlaceDummyBlock(true);
            }
        }



        return;
    }
コード例 #12
0
    /// <summary>
    /// Gets the tile on a certain position.
    /// Input grid position for an exact position on the grid
    /// and world position if you want to also check for tiles sides.
    /// </summary>
    /// <returns></returns>
    public TileHit GetHitFromWorldPosition(Vector2 worldPosition, TileMapLayer buildingLayer)
    {
        Vector2Int gridPosition = WorldToGridPosition(worldPosition, buildingLayer);
        TileHit    hit;

        if (TryGetChunk(GridToChunkCoordinates(gridPosition), out Chunk chunk))
        {
            hit = new TileHit(chunk.GetTile(gridPosition, buildingLayer), gridPosition);
            if (hit.tile != null)
            {
                return(hit);
            }
            else
            {
                Vector2 tileWorldPosition = GridToWorldPosition(gridPosition, buildingLayer, false);
                Vector2 localPosition     = worldPosition - tileWorldPosition;
                if (localPosition.y < 0.2f && Mathf.Abs(localPosition.x) < 0.1f)
                {
                    return(hit);
                }
                Vector2Int checkPosition = gridPosition + (localPosition.x < 0 ? Vector2Int.up : Vector2Int.right);
                hit = new TileHit(GetTileFromGrid(checkPosition, buildingLayer), checkPosition);
                if (hit.tile != null)
                {
                    return(hit);
                }
                else if (Vector2.Distance(localPosition, new Vector2(0, 0.45f)) <= 0.24f)
                {
                    checkPosition = gridPosition + Vector2Int.one;
                    hit           = new TileHit(GetTileFromGrid(checkPosition, buildingLayer), checkPosition);
                    if (hit.tile != null)
                    {
                        return(hit);
                    }
                }
            }
        }
        return(new TileHit(null, gridPosition));
    }
コード例 #13
0
        public TileHit GetClosestTileInSquare(int distanceFromCenter)
        {
            TileHit[] tiles = GetAllTilesInSquare(distanceFromCenter);

            if (tiles == null || tiles.Length == 0)
            {
                return(null);
            }

            TileHit closestTile      = null;
            float   shortestDistance = float.MaxValue;

            foreach (TileHit tile in tiles)
            {
                float distance;
                if ((distance = Vector2Int.Distance(tile.gridPosition, startPosition)) < shortestDistance)
                {
                    closestTile      = tile;
                    shortestDistance = distance;
                }
            }

            return(closestTile != null ? closestTile : null);
        }
コード例 #14
0
    public void SetBuildingTile(TileAbstSO Item)
    {
        tileSlotCache = null;
        if (Item == null)
        {
            return;
        }
        tileSlotCache = new TileSlot(Item);
        if (amountOfCurrentItem <= 0)
        {
            amountOfCurrentItem = Inventory.GetInstance.GetAmountOfItem(0, new ItemSlot(Item, 1));
        }



        currentlyPlacedOnFloor = tileSlotCache.GetTileType == TileType.Block;
        if (amountOfCurrentItem == 0)
        {
            amountOfCurrentItem = Inventory.GetInstance.GetAmountOfItem(0, new ItemSlot(Item, 1));
        }

        isBuildingAttached = true;
        currentTileHit     = null;
    }
コード例 #15
0
        public TileHit Scan(Vector2Int gridStartPosition, DirectionEnum _direction, int _radius, TileMapLayer _buildingLayer, IChecker _checker)
        {
            startPosition = gridStartPosition;
            radius        = _radius;
            buildingLayer = _buildingLayer;
            checker       = _checker;
            direction     = _direction;
            TileSlot currentTile = gridManager.GetTileFromGrid(startPosition, buildingLayer);

            if (currentTile != null && checker.CheckTile(currentTile))
            {
                return(new TileHit(currentTile, startPosition));
            }
            for (int i = 1; i <= radius; i++)
            {
                TileHit tileHit = GetClosestTileInSquare(i);
                if (tileHit != null)
                {
                    return(tileHit);
                }
            }

            return(null);
        }
コード例 #16
0
 internal void MenuClosed()
 {
     SpecialInterracted = false;
     closestTile        = null;
 }
コード例 #17
0
 void ResetParam()
 {
     currentTileHit      = null;
     amountOfCurrentItem = 0;
     tileSlotCache       = null;
 }