Ejemplo n.º 1
0
        public void StartRecording()
        {
            gameplayRecording = new GamePlayRecording(recordingFilePath + CreateFileName());
            Debug.Log("recording started!");

            recording = true;
            StartCoroutine((RecordingCoroutine()));
        }
Ejemplo n.º 2
0
        public void InitPlayback(string filePath)
        {
            gameplayRecording = ParseRecordingV2(filePath);

            //Hiding all the exisiting objects
            foreach (Transform child in transform)
            {
                if (child.GetComponent <Camera>() == null)
                {
                    child.gameObject.SetActive(false);
                }
                else // spcial things to do for the camera and its child
                {
                    FollowTarget follow = child.GetComponent <FollowTarget>();

                    if (follow != null)
                    {
                        follow.enabled = false;
                    }

                    foreach (Transform t in child)
                    {
                        t.gameObject.SetActive(false);
                    }
                }
            }
            // Destroying all the spriteRenderers previously created for playback
            if (srPlayback != null)
            {
                foreach (SpriteRenderer sr in srPlayback)
                {
                    Destroy(sr.gameObject);
                }
            }
            // We create as many sr as the frame that needs the most
            int spriteRenderersNeeded = 0;

            for (int i = 0; i < gameplayRecording.frames.Count; i++)
            {
                if (gameplayRecording.frames[i].spriteRenderers.Count > spriteRenderersNeeded)
                {
                    spriteRenderersNeeded = gameplayRecording.frames[i].spriteRenderers.Count;
                }
            }
            srPlayback = new SpriteRenderer[spriteRenderersNeeded];
            for (int i = 0; i < spriteRenderersNeeded; i++)
            {
                // Create a game object for each sprite renderer recorded
                GameObject go = new GameObject(i.ToString());
                go.transform.SetParent(transform);
                srPlayback[i] = go.AddComponent <SpriteRenderer>();
                srPlayback[i].gameObject.SetActive(false);
            }
        }
Ejemplo n.º 3
0
        public static GamePlayRecording[] FindAllRecordings()
        {
            string[]            files      = Directory.GetFiles(recordingFilePath);
            GamePlayRecording[] recordings = new GamePlayRecording[files.Length];

            //TODO here should be able to tell if it is compressed or not and then do magic accordingly
            for (int i = 0; i < files.Length; i++)
            {
                recordings[i] = ParseRecordingV2(files[i]);
            }
            return(recordings);
        }
Ejemplo n.º 4
0
 public void StartPlayback(GamePlayRecording recording, bool looping = true)
 {
     StartPlayback(recording.path, looping);
 }
Ejemplo n.º 5
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);
        }