Esempio n. 1
0
    void Update()
    {
        //if(testDebug != null)
        //{
        //    int currNode = 0;
        //    while(currNode < testDebug.Count-1)
        //    {
        //        Vector3 start = mapConfig.tileMap.TileCoordToWorldCoord(testDebug[currNode].x, testDebug[currNode].y) +
        //            new Vector3(0, 1, 0);
        //        Vector3 end = mapConfig.tileMap.TileCoordToWorldCoord(testDebug[currNode+1].x, testDebug[currNode+1].y) +
        //           new Vector3(0, 1, 0);

        //        Debug.DrawLine(start, end, Color.red);
        //        currNode++;
        //    }

        //}
        if (!isSelected && isFriendly)
        {
            currentPath        = null;
            line.positionCount = 0;
        }
        if (CheckUnitState(UnitState.Shooting))
        {
        }
        //Turn in the direction they're moving.
        else if (CheckUnitState(UnitState.Walking) || CheckUnitState(UnitState.Sprinting))
        {
            mapConfig.turnSystem.cameraControl.MoveToTarget(transform.position, cameraStartPosition, true);
            if (currentPath != null && pathIndex < (currentPath.Count - 1))
            {
                Vector3 previousPosition = mapConfig.tileMap.TileCoordToWorldCoord(currentPath[pathIndex].x, currentPath[pathIndex].y);
                Vector3 nextPosition     = mapConfig.tileMap.TileCoordToWorldCoord(currentPath[pathIndex + 1].x, currentPath[pathIndex + 1].y);

                pathProgress      += Time.deltaTime * animaitionSpeed;
                transform.position = Vector3.Lerp(previousPosition, nextPosition, pathProgress);
                //if unit have reached the end of path reset pathprogress and increase pathindex
                if (pathProgress >= 1.0)
                {
                    pathProgress = 0.0f;
                    pathIndex++;
                }
                //set unit tile postition
                tileX = currentPath[pathIndex].x;
                tileY = currentPath[pathIndex].y;

                if (mapConfig.turnSystem.playerTurn && isFriendly)
                {
                    line.positionCount = 0;
                }
            }

            else//when unit reach location reset special stats
            {
                mapConfig.tileMap.UnitMapData(tileX, tileY);
                if (!CheckUnitState(UnitState.Shooting))
                {
                    SetUnitState(UnitState.Idle);
                }
                currentPath = null;
                pathIndex   = 0;
                mapConfig.turnSystem.MoveMarker(mapConfig.turnSystem.unitMarker, transform.position);
                if (mapConfig.turnSystem.playerTurn)
                {
                    mapConfig.turnSystem.cameraControl.MoveToTarget(TurnSystem.selectedUnit.transform.position);
                }

                if (actionPoints.ReturnAvailableActions() <= 0)
                {
                    mapConfig.turnSystem.KeyboardSelect(true, mapConfig.turnSystem.playerUnits, TurnSystem.selectedUnit);
                }
                else if (actionPoints.CheckAvailableActions(1) && isFriendly && mapConfig.turnSystem.playerTurn)
                {
                    mapConfig.tileMap.ChangeGridColor(movePoints, actionPoints.ReturnAvailableActions(), this);
                }
            }
        }
        //draw line
        if (currentPath != null && isFriendly && CheckUnitState(UnitState.Idle) && isSelected)//1 long path
        {
            mapConfig.turnSystem.ToggleMarkers(true);
            if (currentPath.Count < movePoints + 2 && actionPoints.CheckAvailableActions(2))//Walk
            {
                currentColor = mapConfig.turnSystem.lineColors[0];
            }
            else//dash
            {
                currentColor = mapConfig.turnSystem.lineColors[1];
            }

            for (int i = 0; i < mapConfig.turnSystem.markerImage.Length; i++)
            {
                mapConfig.turnSystem.markerImage[i].color = currentColor;
            }
            line.startColor = currentColor;
            line.endColor   = currentColor;

            int currNode = 0;
            line.positionCount = 0;
            int currNodeOffset = 1;
            while (currNode <= currentPath.Count - 1 && currNode <= movePoints * actionPoints.ReturnAvailableActions())
            {
                if (currNode < currentPath.Count - 1)
                {
                    currNodeOffset = 1;
                }
                else
                {
                    currNodeOffset = 0;
                }

                Vector3 start = mapConfig.tileMap.TileCoordToWorldCoord(currentPath[currNode].x, currentPath[currNode].y);
                Vector3 end   = mapConfig.tileMap.TileCoordToWorldCoord(currentPath[currNode + currNodeOffset].x, currentPath[currNode + currNodeOffset].y);

                if (currNode == 0)
                {
                    line.positionCount = currNode + 1;
                    line.SetPosition(currNode, new Vector3(start.x, mapConfig.turnSystem.lineYOffset, start.z));
                }
                line.positionCount = currNode + 2;
                line.SetPosition(currNode + 1, new Vector3(end.x, mapConfig.turnSystem.lineYOffset, end.z));

                currNode++;

                if (line.positionCount > 0 && mapConfig.turnSystem.cursorMarker.position != end)
                {
                    mapConfig.turnSystem.MoveMarker(mapConfig.turnSystem.cursorMarker, end);
                }
            }
            line.positionCount = line.positionCount - 1;
        }
        else if (isFriendly && isSelected)
        {
            line.positionCount = 0;
            mapConfig.turnSystem.ToggleMarkers(false);
        }
    }