// Begin writing the next text available in the cutscene
    void NextText()
    {
        // if there are no more batches in the frame, then go to the next one
        if (activeTextBatches.Count == 0 && activeTextData.Count == 0)
        {
            Debug.Log("Frame is done");
            fadeSpeed = allFrames[frameCount].fadeSpeeds[1];
            fader.BeginFade(1, fadeSpeed);          // fade out at fade out speed
            StartCoroutine(WaitFade(false, 1));     // wait for the fade out to finish
            return;                                 // escape this function for WaitFade will call what we need next (NextFrame)
        }

        // if there are no more texts in this batch, then go to the next batch
        if (activeTextData.Count == 0)
        {
            currentBatch = activeTextBatches.Dequeue();

            for (int i = 0; i < currentBatch.cutsceneTextDatas.Length; i++)
            {
                activeTextData.Enqueue(currentBatch.cutsceneTextDatas[i]);
            }

            // reset all text to "" when starting a new batch
            foreach (CutsceneTextObject cto in textHandlers)
            {
                cto.SetTextToBlank();
            }

            batchStep = 0;  // reset batchStep to 0
        }

        // create enough text handler gameobjects for the size of our text batch
        if (textHandlerObjects.Count < activeTextData.Count)
        {
            int handlerObjectCount = textHandlerObjects.Count;  // use a variable as the loop will change textHandlerObjects.Count while looping and we don't want that to mess it up

            for (int i = 0; i < activeTextData.Count - handlerObjectCount; i++)
            {
                GameObject textGO = Instantiate(cutsceneTextHandlerPrefab, transform);

                textHandlerObjects.Add(textGO);
                textHandlers.Add(textGO.GetComponent <CutsceneTextObject>());
            }
        }

        // use the text handler based on how far we are in the batch
        textHandlers[batchStep].Init(activeTextData.Dequeue(), typeDelaySpeed);

        // step to the next index in the batch
        batchStep++;
    }
    // Sets up a single frame
    void SetUpCurrentFrame()
    {
        // make sure there is no invalid frame data
        string check   = ExceptionChecker();
        bool   invalid = check.Equals("") ? false : true; // if the check returns an empty string, then there are no errors in the json

        if (invalid)
        {
            Debug.Log("Invalid data found in json file.");
            Debug.Log(check);
            return;
        }

        // empty the strings for any texts currently in the scene
        foreach (CutsceneTextObject cto in textHandlers)
        {
            cto.SetTextToBlank();
        }

        // set the sprite and its color
        background.sprite = Resources.Load <Sprite>("CutsceneImages/" + allFrames[frameCount].imageName);
        background.color  = new Color(allFrames[frameCount].imageColor[0], allFrames[frameCount].imageColor[1], allFrames[frameCount].imageColor[2], allFrames[frameCount].imageColor[3]);

        batchStep = 0;  // reset batchStep to 0

        // reset batch and text lists
        activeTextBatches = new Queue <CutsceneTextBatchData>();
        activeTextData    = new Queue <CutsceneTextData>();

        // add in all batches in the frame to the activeTextBatch queue
        foreach (CutsceneTextBatchData ctbd in allFrames[frameCount].cutsceneTextBatchDatas)
        {
            activeTextBatches.Enqueue(ctbd);
        }

        currentBatch = activeTextBatches.Dequeue(); // set the current batch we will view

        // set up the activeTextData queue that we'll read sentences off of from the current batch
        for (int i = 0; i < currentBatch.cutsceneTextDatas.Length; i++)
        {
            activeTextData.Enqueue(currentBatch.cutsceneTextDatas[i]);
        }

        fadeSpeed = allFrames[frameCount].fadeSpeeds[0]; // set fade in speed for the frame

        fader.BeginFade(-1, fadeSpeed);                  // fade in (hence the -1) at the given speed in the data
        StartCoroutine(WaitFade(true, 0));               // wait for the fade in to finish
    }
示例#3
0
    // Save a batch for the current frame
    public void SaveBatch()
    {
        // if there are no texts and no text data, then there is nothing to save
        if (allActiveTexts.Count == 0 || currentTextDataList.Count == 0)
        {
            Debug.Log("No texts available. Please add a text.");
            return;
        }

        // create a CutsceneTextBatchData and add the currentTextDataList to its cutsceneTextDatas string[]
        CutsceneTextBatchData ctbd = new CutsceneTextBatchData();

        ctbd.cutsceneTextDatas = currentTextDataList.ToArray();

        // if we're looking at a new batch, then add to the list
        if (batchStep == currentBatchList.Count)
        {
            currentBatchList.Add(ctbd); // add the new data

            // clear relevant lists
            DestroyAllText();
            currentTextDataList.Clear();
            allActiveTexts.Clear();

            batchStep++;    // increment batch as we're not looking at a new batch
            textCount = 0;  // reset text count

            Debug.Log("Batch saved at index " + batchStep + ". Now looking at new batch.");
        }
        // if our batchStep is not equal to the count (beyond the last index), then we want to update data instead of add data
        else
        {
            currentBatchList[batchStep] = ctbd;
            Debug.Log("Batch at index " + batchStep + "replaced.");
        }
    }