Example #1
0
    //T = 0.0 - 1.0 defines progress of animation.
    //Am = amount of cubes.
    //
    //TweenTime = T/animTime
    public IEnumerator PlayIntroAnimation(GameObject playerObj, CutSceneObj introCutsceneObj = null)
    {
        Messenger.Invoke(LevelIntroMessage.IntroStarted.ToString());
        if (introCutsceneObj != null && cutSceneController != null)
        {
            playingCutsceneObj = introCutsceneObj;
            cutSceneController.DisplayCutscene(playingCutsceneObj);
            print(playingCutsceneObj.lengthInSeconds);
            introAnimTime = playingCutsceneObj.lengthInSeconds;
        }
        else
        {
            introAnimTime = 4.0f;
        }

        mapRoot      = GameObject.Find("MapRoot");
        playingIntro = true;
        var movePos = mapRoot.transform.up * 20;

        while (LevelSerializer.IsDeserializing)
        {
            yield return(new WaitForEndOfFrame());
        }

        foreach (var cube in animatingCubes)
        {
            movePos = new Vector3(UnityEngine.Random.Range(0, (cube.theCube.transform.position.x * 1.5f)), movePos.y, UnityEngine.Random.Range(0, (cube.theCube.transform.position.z * 1.5f)));
            cube.MoveFromSkyToEndPos(movePos);
        }

        //Calculate the angle we need to get the camera behind the player, then animate so that we end up at that pos after animTime seconds.
        float timeCounter = introAnimTime;

        var camForward    = Camera.main.transform.forward;
        var playerForward = playerObj.transform.forward;

        camForward.y    = 0;
        playerForward.y = 0;
        var angle = Vector3.Angle(camForward, playerForward);

        //Stop just before we get behind to smooth the transition when CameraFollow gets turned on.
        angle += 350f;
        var rotAmount = angle / introAnimTime;

        while (timeCounter > 0 && playingIntro)
        {
            timeCounter -= Time.deltaTime;

            Camera.main.transform.RotateAround(playerObj.transform.position, Vector3.up, (rotAmount * Time.deltaTime));

            yield return(new WaitForEndOfFrame());
        }
        if (playingIntro)
        {
            Messenger.Invoke(LevelIntroMessage.IntroFinished.ToString());
        }
    }
Example #2
0
    IEnumerator CutSceneTimerRoutine(float length, CutSceneObj cutsceneObj)
    {
        yield return(new WaitForSeconds(length));

        StopCutScene();
        cutsceneObj.UnloadAudio();
        cutsceneObj.dialogue.UnloadDialogue();
        cutsceneObj.UnloadCameraAnim();
    }
Example #3
0
    void StartGameAfterIntro(CutSceneObj introCutsceneObj = null)
    {
        playerChar.playerMovement.canMove = false;
        playerChar.rigidbody.useGravity   = false;

        Messenger.AddListener(LevelIntroMessage.IntroFinished.ToString(), IntroFinished);
        Messenger.AddListener(LevelIntroMessage.IntroInterrupted.ToString(), IntroInterrupted);
        Camera.main.GetComponent <CameraFollow>().PutCameraBehindPlayer();
        Camera.main.GetComponent <CameraFollow>().enabled = false;

        StartCoroutine(levelIntro.PlayIntroAnimation(playerChar.gameObject, introCutsceneObj));
    }
Example #4
0
    public void InitLevel(bool playIntro, CutSceneObj introCutsceneObj = null)
    {
        hasCheckpoint = false;
        DestroyCombinedMeshes();
        var playerObj = GameObject.FindWithTag("Player");

        if (playerObj == null)
        {
            CreatePlayer();
            playerObj = GameObject.FindWithTag("Player");
        }

        if (playerObj != null)
        {
            playerChar = playerObj.GetComponent <PlayerCharacter>();
            playerChar.DisablePhysics();
        }

        //Create floor and make sure player is on it
        mapRoot = GameObject.Find("MapRoot");

        CreateFloor();
        playerObj.transform.position = new Vector3(playerObj.transform.position.x, (playerObj.transform.position.y + 0.6f), playerObj.transform.position.z);

        SetupNullCubes();

        Camera.main.GetComponent <CameraFollow>().target = playerObj.transform;

        combinedMeshes = OptimiseLevelMesh();
        foreach (var go in combinedMeshes)
        {
            go.renderer.enabled = false;
        }
        var walls = GameObject.FindGameObjectsWithTag("WallCube");

        foreach (var wall in walls)
        {
            wall.renderer.enabled = false;
        }

        Messenger.Invoke(LevelStateMessage.LevelInitialized.ToString());

        if (playIntro)
        {
            levelIntro.InitIntro();
            StartGameAfterIntro(introCutsceneObj);
        }
        else
        {
            IntroFinished();
        }
    }
Example #5
0
    public StoryLevel(string lineFromIni)
    {
        var splitLine = lineFromIni.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);

        levelNumber = (int)int.Parse(splitLine[0]);
        displayName = splitLine[1];
        levelName   = splitLine[2];
        if (splitLine.Length > 3)
        {
            if (!string.IsNullOrEmpty(splitLine[3]))
            {
                introCutSceneObjFilename = splitLine[3];
                cutSceneObj = (CutSceneObj)Resources.Load(introCutSceneObjFilename, typeof(CutSceneObj));
                Debug.Log("Loaded cutscene obj from: " + introCutSceneObjFilename);
                Debug.Log("Cutscene obj: " + cutSceneObj);
            }
        }
    }
Example #6
0
    IEnumerator QuickFinishAnimation()
    {
        playingIntro = false;

        foreach (var cube in animatingCubes)
        {
            cube.InterruptAnimation();
        }
        //Have to wait for a frame due to removing components (iTweens)
        yield return(new WaitForEndOfFrame());

        if (playingCutsceneObj)
        {
            cutSceneController.StopCutScene();
            playingCutsceneObj = null;
        }
        Messenger.Invoke(LevelIntroMessage.IntroInterrupted.ToString());
        yield return(new WaitForSeconds(0.55f));

        Messenger.Invoke(LevelIntroMessage.IntroFinished.ToString());
    }
Example #7
0
    public void DisplayCutscene(CutSceneObj cutSceneObj)
    {
        Messenger.Invoke(CutSceneMessage.CutSceneStarted.ToString());

        if (cutSceneObj.dialogue.dialogueAsset != null)
        {
            //Calculate chars per second given amount of chars in each line and the length of this cutscene

            dialogueDisplayer.StartCoroutine(dialogueDisplayer.DisplayText(cutSceneObj.dialogue.dialogueLines));
        }
        if (cutSceneObj.audioClip != null)
        {
            //play audioclip.
            audio.clip = cutSceneObj.audioClip;
            audio.Play();
        }
        if (cutSceneObj.cameraAnimation != null)
        {
            cutsceneCamera.PlayAnimation(cutSceneObj.cameraAnimation);
        }
    }
Example #8
0
 void Init()
 {
     cutsceneObj          = ScriptableObject.CreateInstance <CutSceneObj>();
     cutsceneObj.dialogue = new Dialogue();
 }
Example #9
0
    void TriggererEntered(CutSceneObj cutSceneObj)
    {
        StartCoroutine(CutSceneTimerRoutine(cutSceneObj.lengthInSeconds, cutSceneObj));

        DisplayCutscene(cutSceneObj);
    }