Exemple #1
0
 public void ChangeFocusToNewGrid(CameraInfoClass newGrid, float duration, bool moveCameraInternally)
 {
     if (GridManagerScript.Instance.currentGridStructureObject == null)
     {
         GetComponent <Camera>().orthographicSize = newGrid.OrthographicSize;
         transform.position  = newGrid.CameraPosition;
         CurrentCameraOffset = newGrid.CameraPosition;
         return;
     }
     if (moveCameraInternally)
     {
         StartCoroutine(CameraFocusSequence(newGrid.CameraPosition - CurrentCameraOffset, duration, newGrid.OrthographicSize, newGrid));
     }
 }
Exemple #2
0
    IEnumerator CameraFocusSequence(Vector3 translation, float duration, float endOrtho, CameraInfoClass newGrid)
    {
        bool    hasStarted             = false;
        float   startingOrtho          = GetComponent <Camera>().orthographicSize;
        Vector3 cameraStartingPosition = transform.position;

        float durationLeft = duration;
        float progress     = 0f;

        while (durationLeft != 0 || !hasStarted)
        {
            hasStarted = true;

            durationLeft = Mathf.Clamp(durationLeft - Time.deltaTime, 0f, 999f);
            progress     = 1f - (durationLeft / (duration != 0f ? duration : 1f));
            GetComponent <Camera>().orthographicSize = Mathf.Lerp(startingOrtho, endOrtho, progress);
            transform.position = Vector3.Lerp(cameraStartingPosition, cameraStartingPosition + translation, progress);
            yield return(null);
        }

        CurrentCameraOffset = newGrid.CameraPosition;
    }
Exemple #3
0
    IEnumerator GridLeapSequence(float duration, Vector3 translation, bool moveChars = true)
    {
        //Ensure new grid is set and moved to correct position before everything
        jumpingchars.Clear();
        float jumpHeight = 2f;
        CharacterAnimationStateType jumpAnim = CharacterAnimationStateType.DashUp;

        Vector3         cameraStartPos = MainCamera.transform.position;
        CameraInfoClass cic            = CameraStage.CameraInfo.Where(r => r.StageIndex == currentGridIndex && !r.used).First();

        Vector3 cameraOffsetChange = cic.CameraPosition - CameraManagerScript.Instance.CurrentCameraOffset;
        float   cameraStartOrtho   = MainCamera.orthographicSize;
        float   cameraEndOrtho     = cic.OrthographicSize;

        cic.used = true;
        //DONT FORGET TO ADD CAMERA OFFSET ADJUSTMENT
        if (moveChars)
        {
            chars = System.Array.ConvertAll(BattleManagerScript.Instance.AllCharactersOnField.Where(r => r.IsOnField).ToArray(), item => (CharacterType_Script)item);
        }
        else
        {
            chars = new CharacterType_Script[0];
        }
        Vector3[] charStartPositions = new Vector3[chars != null ? chars.Length : 0];
        Vector3[] charGridPosOffsets = new Vector3[chars != null ? chars.Length : 0];
        for (int i = 0; i < (chars != null ? chars.Length : 0); i++)
        {
            charStartPositions[i] = chars[i].transform.position;
            BattleTileScript bts = GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).FirstOrDefault();
            if (bts.BattleTileState != BattleTileStateType.Empty ||
                chars[i].UMS.WalkingSide != bts.WalkingSide)
            {
                BattleTileScript newGridTile = GridManagerScript.Instance.GetRandomFreeAdjacentTile(chars[i].UMS.CurrentTilePos, 5, false, chars[i].UMS.WalkingSide);
                Debug.Log(newGridTile.Pos);
                charGridPosOffsets[i] = GridManagerScript.GetTranslationBetweenTiles(GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).First(), newGridTile);
                GridManagerScript.Instance.SetBattleTileState(newGridTile.Pos, BattleTileStateType.Occupied);
                chars[i].CurrentBattleTiles = new List <BattleTileScript>()
                {
                    newGridTile
                };
                chars[i].UMS.CurrentTilePos = newGridTile.Pos;
                chars[i].UMS.Pos            = new List <Vector2Int>()
                {
                    newGridTile.Pos
                };
            }
            else
            {
                GridManagerScript.Instance.SetBattleTileState(bts.Pos, BattleTileStateType.Occupied);
                charGridPosOffsets[i] = Vector3.zero;
            }
            chars[i].SetAttackReady(false);

            if (translation == Vector3.zero && charGridPosOffsets[i] == Vector3.zero)
            {
                continue;
            }
            jumpingchars.Add(chars[i]);
            chars[i].SetAnimation(jumpAnim);
        }

        float timeRemaining = duration;
        float progress      = 0;
        float xPos          = 0f;
        float yPos          = 0f;
        bool  hasStarted    = false;

        while (timeRemaining != 0 || !hasStarted)
        {
            hasStarted    = true;
            timeRemaining = Mathf.Clamp(timeRemaining - Time.deltaTime, 0f, 9999f);
            progress      = 1f - (timeRemaining / (duration != 0f ? duration : 1f));

            MainCamera.transform.position = Vector3.Lerp(cameraStartPos, cameraStartPos + translation + cameraOffsetChange, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress));
            MainCamera.orthographicSize   = Mathf.Lerp(cameraStartOrtho, cameraEndOrtho, progress);


            for (int i = 0; i < (jumpingchars != null ? jumpingchars.Count : 0); i++)
            {
                xPos  = Mathf.Lerp(charStartPositions[i].x, charStartPositions[i].x + translation.x + charGridPosOffsets[i].x, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress));
                yPos  = Mathf.Lerp(charStartPositions[i].y, charStartPositions[i].y + translation.y + charGridPosOffsets[i].y, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress));
                yPos += jumpHeight * UniversalGameBalancer.Instance.characterJumpCurve.Evaluate(progress);
                jumpingchars[i].transform.position = new Vector3(xPos, yPos, jumpingchars[i].transform.position.z);
                jumpingchars[i].SpineAnim.SetAnimationSpeed(UniversalGameBalancer.Instance.jumpAnimationCurve.Evaluate(progress));
            }
            yield return(null);
        }
        CameraManagerScript.Instance.CurrentCameraOffset = cic.CameraPosition;

        if (chars.Length != 0)
        {
            foreach (CharacterType_Script character in BattleManagerScript.Instance.PlayerControlledCharacters)
            {
                character.SetAttackReady(true);
            }
        }
    }