Example #1
0
        IEnumerator PlaybackCoroutine(bool looping)
        {
START:
            float prevTime = 0;

            for (int i = 0; i < gameplayRecording.frames.Count; i++)
            {
                Frame currentFrame = gameplayRecording.frames[i];

                for (int j = 0; j < srPlayback.Length; j++)
                {
                    srPlayback[j].gameObject.SetActive(false);
                }

                for (int j = 0; j < currentFrame.spriteRenderers.Count; j++)
                {
                    SpriteRendererFrame srf = currentFrame.spriteRenderers[j];

                    srPlayback[j].gameObject.SetActive(true);

                    srPlayback[j].sprite                = SpriteDatabase.FindSpriteByName(srf.spriteName);
                    srPlayback[j].transform.position    = srf.pos;
                    srPlayback[j].transform.eulerAngles = new Vector3(0, srf.angleYZ.x, srf.angleYZ.y);
                    srPlayback[j].sortingOrder          = srf.layer;

                    Camera.main.transform.position = currentFrame.cameraPosition;
                }

                float timeToWait = prevTime == 0 ? 0.1f : currentFrame.time - prevTime;
                yield return(new WaitForSeconds(timeToWait));

                prevTime = currentFrame.time;
            }

            if (looping)
            {
                goto START; // ZOMGBBQ goto
            }
        }
Example #2
0
        void CaptureFrame()
        {
            Frame frame = new Frame();

            gameplayRecording.frames.Add(frame);

            frame.cameraPosition = Camera.main.transform.position;
            frame.time           = Time.time;

            SpriteRenderer[] sr = GetComponentsInChildren <SpriteRenderer>();
            for (int i = 0; i < sr.Length; i++)
            {
                if (sr[i].sprite == null || !sr[i].isVisible)
                {
                    continue;
                }

                SpriteRendererFrame srFrame = new SpriteRendererFrame();

                frame.spriteRenderers.Add(srFrame);

                srFrame.spriteName = sr[i].sprite.name;

                srFrame.pos = sr[i].transform.position;

                srFrame.angleYZ.x = sr[i].transform.eulerAngles.y;
                srFrame.angleYZ.y = sr[i].transform.eulerAngles.z;

                srFrame.layer = sr[i].sortingOrder;

                //populating database
                if (SpriteDatabase.FindSpriteByName(srFrame.spriteName) == null)
                {
                    SpriteDatabase.AddSprite(sr[i].sprite, sr[i].sprite.name);
                }
            }
        }
Example #3
0
        private static GamePlayRecording ParseRecordingV2(string fileNameWithPath)
        {
            GamePlayRecording recording = new GamePlayRecording(fileNameWithPath);

            recording.path = fileNameWithPath;


            string[] lines = null;
            try
            {
                // StreamReader stream = new StreamReader(fileNameWithPath);
                lines = File.ReadAllLines("a.txt");
            }
            catch (FileNotFoundException e)
            {
                print("looking for " + fileNameWithPath);
                TextAsset t = Resources.Load(fileNameWithPath, typeof(TextAsset)) as TextAsset;

                if (t == null)
                {
                    print("NOT FOUND");
                }

                lines = Regex.Split(t.text, "\n|\r|\r\n");
            }

            string line;

            //while((line = stream.ReadLine()) != null)
            for (int lineNumber = 0; lineNumber < lines.Length; lineNumber++)
            {
                line = lines[lineNumber];

                string[] values = line.Split(',');

                Frame frame = new Frame();

                try
                {
                    frame.cameraPosition.x = float.Parse(values[0]);
                    frame.cameraPosition.y = float.Parse(values[1]);
                    frame.time             = float.Parse(values[2]);

                    for (int i = 3; i < values.Length; i = i + 6)
                    {
                        SpriteRendererFrame srFrame = new SpriteRendererFrame();

                        srFrame.spriteName = values[i];
                        srFrame.pos.x      = float.Parse(values[i + 1]);
                        srFrame.pos.y      = float.Parse(values[i + 2]);
                        srFrame.angleYZ.x  = float.Parse(values[i + 3]);
                        srFrame.angleYZ.y  = float.Parse(values[i + 4]);
                        srFrame.layer      = int.Parse(values[i + 5]);

                        frame.spriteRenderers.Add(srFrame);
                    }
                    recording.frames.Add(frame);
                }
                catch (Exception e)
                {
                    print(e);
                }
            }
            return(recording);
        }