コード例 #1
0
 private void ResetGrabbedObject()
 {
     state                 = Mode.EMPTY;
     currentCell           = null;
     currentTower          = null;
     currentTowerRenderer  = null;
     currentTowerArchetype = null;
 }
コード例 #2
0
 // Update is called once per frame
 void SetupView()
 {
     starNumberText.text = PersistentDataManager.Instance.totalStar.ToString();
     foreach (StageInfo stageInfo in LevelManager.Instance.stageInfoList)
     {
         GameObject stageObject = Instantiate(stagePrefab, stageTable);
         StageCell  stageCell   = stageObject.GetComponent <StageCell>();
         stageCell.InitWithStageInfo(stageInfo);
     }
 }
コード例 #3
0
    private void Update()
    {
        if (state == Mode.HOLDING)
        {
            var currentPos = MousePositionToGameWorldPosition();
            currentTower.transform.position = currentPos;

            foreach (var cell in stage.Layout)
            {
                if (currentPos.x >= cell.BottomLeft.x && currentPos.x <= cell.TopRight.x && currentPos.y >= cell.BottomLeft.y && currentPos.y <= cell.TopRight.y)
                {
                    if (currentCell != null)
                    {
                        currentCell.UnHighlight();
                    }

                    currentTowerRenderer.color = originalColor * legalPlacementTint;
                    currentCell       = cell;
                    hoveringValidCell = true;
                    break;
                }

                hoveringValidCell = false;
            }

            if (hoveringValidCell)
            {
                currentCell.Highlight(Color.yellow);

                if (Input.GetMouseButtonDown(0) && TowerCurrency.Instance.Currency >= currentTowerArchetype.cost)
                {
                    currentTower.transform.position = currentCell.Center;
                    currentTowerRenderer.color      = originalColor;
                    currentCell.UnHighlight();

                    TowerCurrency.Instance.ConsumeCurrency(currentTowerArchetype.cost);

                    OnTowerPlaced?.Invoke(currentTowerArchetype.type, currentTower);

                    ResetGrabbedObject();
                }
                else
                {
                    currentTowerRenderer.color = originalColor * legalPlacementTint;
                }
            }
            else
            {
                currentTowerRenderer.color = originalColor * illegalPlacementTint;
            }
        }
    }
コード例 #4
0
ファイル: StageLevelManager.cs プロジェクト: minha-lim/Unity
    public void CreateNewStage()
    {
        for (int x = 0; x < stageSize; x++)
        {
            for (int y = 0; y < stageSize; y++)
            {
                StageCell cell = new StageCell(x, y, StageCellType.None);

                GameObject editTile = instantiate(editTilePrefab, transform);
                editTile.name = "tile(" + x + "," + y + ")";
                SetTilePosition(editTile, x, y);

                stageTiles.Add(editTile.GetComponent <StageEditTile>());
            }
        }
    }
コード例 #5
0
    void CreateTile(int x, int y, StageCellType type)
    {
        StageCell cell = new StageCell(x, y, type);

        GameObject editTile = Instantiate(editTilePrefab, transform);

        editTile.name = "tile(" + x + "," + y + ")";
        SetTilePosition(editTile, x, y);

        StageEditTile tile = editTile.GetComponent <StageEditTile>();

        tile.SetCell(cell);
        stageTiles.Add(tile);

        GameObject child = GetTileTypePrefab(type);

        if (child != null)
        {
            tile.EditType(type, child);
        }
    }
コード例 #6
0
ファイル: StageManager.cs プロジェクト: yum-kvn/simarisu
    public void AddRoute(StageCell cell)
    {
        if (IsUsedForRoute(cell))
        {
            RemoveLastRouteIfCan(cell);
        }
        else
        {
            StageCell lastCell = route.Last();
            Vector2 diffPosition = cell.Position() - lastCell.Position();
            if (Mathf.Abs(diffPosition.x) <= 1 && Mathf.Abs(diffPosition.y) <= 1)
            {
                route.Add(cell);
                cell.SetSelectColor();

                if (routeCount != 1)
                {
                    lastCell.SetArrow(diffPosition);
                }
            }
        }
    }
コード例 #7
0
    public bool playStage(Stage stage)
    {
        cleanBoard();

        int length = stage.boardLength;

        float         boardSize  = length;
        float         size       = 1;
        CameraHandler mainCamera = Camera.main.GetComponent <CameraHandler>();

        mainCamera.setCameraDistance(boardSize);

        for (int cellId = 0; cellId < stage.board.Length; cellId++)
        {
            StageCell cell = stage.board[cellId];
            InstantiateEntity(cell.type, cell.position, size);
        }
        player     = InstantiateEntity(stage.playerType, stage.playerPosition, size);
        player.tag = "Player";

        buildBoundries(stage);

        return(true);
    }
コード例 #8
0
ファイル: StageManager.cs プロジェクト: yum-kvn/simarisu
 public void CreateRoute(StageCell startCell)
 {
     route = new List<StageCell>();
     route.Add(startCell);
 }
コード例 #9
0
ファイル: StageManager.cs プロジェクト: yum-kvn/simarisu
 private bool IsUsedForRoute(StageCell cell)
 {
     return route.Contains(cell);
 }
コード例 #10
0
ファイル: StageManager.cs プロジェクト: yum-kvn/simarisu
    public void RemoveLastRouteIfCan(StageCell cell)
    {
        StageCell lastCell = route.Last();
        if (lastCell != cell) {return;}

        route.Remove(cell);
        cell.UnsetSelectColor();
    }
コード例 #11
0
ファイル: BaseCharacter.cs プロジェクト: yum-kvn/simarisu
    public void MoveTo(StageCell stageCell, System.Func<Vector3, Vector2> convertToCanvasPosition, bool movePosition = true)
    {
        this.cell = stageCell;

        hpLabel.MoveTo(convertToCanvasPosition(cell.PositionInWorld()));

        if (movePosition)
        {
            transform.position = cell.PositionInWorld();
        }
    }
コード例 #12
0
ファイル: Stage.cs プロジェクト: gemesisiiv/56019828
    bool CheckCellConnection(StageCell fromCell, StageCell toCell)
    {
        Vector3 origin = fromCell.Position;
        Vector3 destination = toCell.Position;

        Vector3 diff = destination - origin;
        Vector3 direction = diff.normalized;
        float distance = diff.magnitude;

        RaycastHit hit;
        if (Physics.Raycast(origin, direction, out hit, distance)) {
            return false;
        }
        else {
            return true;
        }
    }
コード例 #13
0
ファイル: Stage.cs プロジェクト: gemesisiiv/56019828
    void Awake()
    {
        int bottomLeftCell_x = Mathf.FloorToInt(BottomLeftCellPosition.x);
        int bottomLeftCell_z = Mathf.FloorToInt(BottomLeftCellPosition.z);

        int topRightCell_x = Mathf.FloorToInt(TopRightCellPosition.x);
        int topRightCell_z = Mathf.FloorToInt(TopRightCellPosition.z);

        mNumberOfColumns = ((topRightCell_x - bottomLeftCell_x) / CellSize) + 1;
        mNumberOfRows = ((topRightCell_z - bottomLeftCell_z) / CellSize) + 1;

        // Create all cells
        mCells = new StageCell[mNumberOfColumns, mNumberOfRows];
        for (int c=0; c<mNumberOfColumns; c++) {
            for (int r=0;r<mNumberOfRows; r++) {
                StageCell cell = new StageCell();
                cell.Position = new Vector3(bottomLeftCell_x + (c * CellSize), 0, bottomLeftCell_z + (r * CellSize));
                cell.North = null;
                cell.South = null;
                cell.West = null;
                cell.East = null;

                mCells[c, r] = cell;
            }
        }
        // Link cells
        for (int c=0; c<mNumberOfColumns; c++) {
            for (int r=0; r<mNumberOfRows; r++) {
                StageCell cell = mCells[c, r];

                // link north cell
                if (r + 1 < mNumberOfRows) {
                    StageCell northCell = mCells[c, r + 1];
                    bool canConnect = CheckCellConnection(cell, northCell);
                    if (canConnect) {
                        cell.North = northCell;
                    }
                }

                // link south cell
                if (r - 1 >= 0) {
                    StageCell southCell = mCells[c, r - 1];
                    bool canConnect =CheckCellConnection(cell, southCell);
                    if (canConnect) {
                        cell.South = southCell;
                    }
                }

                // link west cell
                if (c - 1 >= 0) {
                    StageCell westCell = mCells[c - 1, r];
                    bool canConnect = CheckCellConnection(cell, westCell);
                    if (canConnect) {
                        cell.West = westCell;
                    }
                }

                // link east cell
                if (c + 1 < mNumberOfColumns) {
                    StageCell eastCell = mCells[c + 1, r];
                    bool canConnect = CheckCellConnection(cell, eastCell);
                    if (canConnect) {
                        cell.East = eastCell;
                    }
                }
            }
        }
    }
コード例 #14
0
ファイル: GameManager.cs プロジェクト: yum-kvn/simarisu
    private void OnCellPointerEnter(StageCell cell)
    {
        if (!isStandby) {return;}
        if (!characterManager.IsCellAvilable(cell)) {return;}

        if (stageManager.routeCount >= characterManager.GetUserCharacterMove())
        {
            stageManager.RemoveLastRouteIfCan(cell);
        }
        else
        {
            stageManager.AddRoute(cell);
        }
    }