Beispiel #1
0
 public MoCapTimeRecorder(MoCapManager.Group group, string customPrefix)
 {
     this.recordingState          = MoCapManager.State.Ongoing;
     this.group                   = group;
     this.customPrefix            = customPrefix;
     MoCapManager.recordingEvent += OnRecordingEvent;
 }
Beispiel #2
0
        /// <summary>
        /// Serializes an object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serializableObject"></param>
        /// <param name="fileName"></param>
        public static void SerializeObject <T>(T serializableObject, MoCapManager.Group group, string prefix, string fileName)
        {
            if (serializableObject == null)
            {
                return;
            }

            try
            {
                XmlDocument   xmlDocument = new XmlDocument();
                XmlSerializer serializer  = new XmlSerializer(serializableObject.GetType());

                string folderPath = FolderPath() + "/" + group;
                folderPath = String.IsNullOrEmpty(prefix) ? folderPath : folderPath + "/" + prefix;
                if (!Directory.Exists(folderPath))
                {
                    Debug.Log("Creating folderPath: " + folderPath);
                    Directory.CreateDirectory(folderPath);
                }

                using (FileStream stream = new FileStream(folderPath + "/" + fileName, FileMode.Create))
                {
                    serializer.Serialize(stream, serializableObject);
                    stream.Position = 0;
                    xmlDocument.Load(stream);
                    xmlDocument.Save(fileName);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("cannot save object" + ex);
            }
        }
Beispiel #3
0
 public MoCapTimePlayback(MoCapManager.Group group, string customPrefix)
 {
     this.group                  = group;
     this.customPrefix           = customPrefix;
     this.playbackState          = MoCapManager.State.Ongoing;
     MoCapManager.playbackEvent += OnPlaybackEvent;
     durationLeft                = FileManager.DeSerializeObject <float>(group, customPrefix, "time");
 }
Beispiel #4
0
        void OnPlaybackEvent(MoCapManager.Group group, MoCapManager.State state,
                             string customPrefix)
        {
            if (this.group != group)
            {
                Debug.Log(
                    "Found recording group " + this.group +
                    ", not responding to " + group + " call");
                return;
            }

            this.customPrefix = customPrefix;

            switch (state)
            {
            case MoCapManager.State.Preload:
            {
                LoadFromDisk();
            }
            break;

            case MoCapManager.State.Ongoing:
                if (playbackState == MoCapManager.State.Stopped || playbackState == MoCapManager.State.Preload)
                {
                    Debug.Log("Starting to playback");
                    time = 0;
                    LoadFromDisk();
                }
                break;

            case MoCapManager.State.Paused:
                // Only valid when recording is ongoing.
                if (playbackState != MoCapManager.State.Ongoing)
                {
                    Debug.LogWarning("Playback state is " + playbackState);
                    return;
                }
                break;

            case MoCapManager.State.Stopped:
                // Only invalid when no recording is going on.
                if (playbackState == MoCapManager.State.Stopped)
                {
                    Debug.LogError("No ongoing playback");
                    return;
                }
                Debug.Log("playback has stopped");
                break;
            }
            playbackState = state;
        }
Beispiel #5
0
        private void OnRecordingEvent(MoCapManager.Group group, MoCapManager.State state, string customPrefix)
        {
            // Make sure this is the correct group and prefix.
            if (this.group != group || !string.Equals(this.customPrefix, customPrefix))
            {
                return;
            }

            if (state == MoCapManager.State.Stopped && recordingState != MoCapManager.State.Stopped)
            {
                RecordTime();
            }

            recordingState = state;
        }
Beispiel #6
0
        private void OnPlaybackEvent(MoCapManager.Group group, MoCapManager.State state, string customPrefix)
        {
            // Make sure this is the correct group and prefix.
            if (this.group != group || !string.Equals(this.customPrefix, customPrefix))
            {
                return;
            }

            if (state == MoCapManager.State.Stopped && playbackState != MoCapManager.State.Stopped)
            {
                onPlaybackFinishedEvent?.Invoke(group, customPrefix);
            }

            playbackState = state;
        }
Beispiel #7
0
        void OnRecordingEvent(MoCapManager.Group group, MoCapManager.State state, string customPrefix)
        {
            if (this.group != group)
            {
                Debug.Log("Found recording group " + this.group + ", not responding to " + group + " call");
                return;
            }

            this.customPrefix = customPrefix;
            Debug.Log("Found recording group " + this.group + state);

            switch (state)
            {
            case MoCapManager.State.Ongoing:
                // If stopped, start.
                if (recordingState == MoCapManager.State.Stopped)
                {
                    Debug.Log("Starting recording");
                    // This is needed here as we start recording coroutine right here. Waiting until it leaves the switch will be too late.
                    recordingState        = state;
                    maxTime               = MoCapManager.instance.maxTime;
                    this.keyframeInterval = MoCapManager.instance.keyframeInterval;
                    StartCoroutine("WriteCurves");
                }
                // If paused, resume.
                break;

            case MoCapManager.State.Paused:
                // Only valid when recording is ongoing.
                if (recordingState != MoCapManager.State.Ongoing)
                {
                    Debug.LogWarning("Recording state is " + recordingState);
                    return;
                }
                break;

            case MoCapManager.State.Stopped:
                // Only invalid when no recording is going on.
                if (recordingState == MoCapManager.State.Stopped)
                {
                    Debug.LogError("No ongoing record");
                    return;
                }
                break;
            }
            recordingState = state;
        }
Beispiel #8
0
        /// <summary>
        /// Deserializes an xml file into an object list
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static T DeSerializeObject <T>(MoCapManager.Group group, string prefix, string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(default(T));
            }

            T objectOut = default(T);

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                string      folderPath  = FolderPath() + "/" + group;
                folderPath = String.IsNullOrEmpty(prefix) ? folderPath : folderPath + "/" + prefix;

                Debug.Log("Openning " + folderPath + "/" + fileName);
                using (FileStream stream = new FileStream(folderPath + "/" + fileName, FileMode.Open))
                {
                    stream.Position = 0;
                    xmlDocument.Load(stream);
                    xmlDocument.Load(fileName);
                }
                string xmlString = xmlDocument.OuterXml;

                using (StringReader read = new StringReader(xmlString))
                {
                    Type outType = typeof(T);

                    XmlSerializer serializer = new XmlSerializer(outType);
                    using (XmlReader reader = new XmlTextReader(read))
                    {
                        objectOut = (T)serializer.Deserialize(reader);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("cannot load object" + ex);
            }

            return(objectOut);
        }