// Save a frame for the current cutscene public void SaveFrame() { frameImage = GetComponent <Image>(); // set frameImage to the Image component // check if the sprite is null - if it is, then we cannot save the data if (frameImage.sprite == null) { Debug.LogError("Image sprite has not been set."); return; } // save the frame data - imageName, imageColor, fadeSpeeds, and cutsceneTextBatchDatas CutsceneFrameData cfd = new CutsceneFrameData(); cfd.imageName = frameImage.sprite.name; cfd.imageColor = new float[] { frameImage.color.r, frameImage.color.g, frameImage.color.b, frameImage.color.a }; cfd.fadeSpeeds = new float[] { fadeInSpeed, fadeOutSpeed }; CutsceneTextBatchData[] temp = currentBatchList.ToArray(); cfd.cutsceneTextBatchDatas = temp; // if we're looking beyond the last frame (making a new frame), then add to the list if (frameStep == allFrames.Count) { allFrames.Add(cfd); Debug.Log("Frame saved at index " + frameStep + ". Now looking at new frame."); NewFrame(); // after we add, start a new frame } // otherwise we want to replace frame data else { allFrames[frameStep] = cfd; Debug.Log("Frame at index " + frameStep + "replaced."); } }
// Go to the target frame public void GoToFrame(int index) { frameStep = index; // update the frameStep to match the index // get the frame data at that index and set up the parameters to match it CutsceneFrameData cfd = allFrames[index]; frameImage = GetComponent <Image>(); frameImage.color = new Color(cfd.imageColor[0], cfd.imageColor[1], cfd.imageColor[2], cfd.imageColor[3]); frameImage.sprite = Resources.Load <Sprite>("CutsceneImages/" + cfd.imageName); fadeInSpeed = cfd.fadeSpeeds[0]; fadeOutSpeed = cfd.fadeSpeeds[1]; // update relevant lists DestroyAllText(); currentBatchList.Clear(); currentTextDataList.Clear(); allActiveTexts.Clear(); // set up the batches of the frame CutsceneTextBatchData[] temp = cfd.cutsceneTextBatchDatas; for (int i = 0; i < temp.Length; i++) { currentBatchList.Add(temp[i]); } // check if there are no batches in this frame if (currentBatchList.Count == 0) { Debug.Log("There are no text batches in this frame"); } // but if there are else { // set the batch to the last one in the frame and go to that batch batchStep = currentBatchList.Count - 1; GoToBatch(batchStep); } }