Exemplo n.º 1
0
        //!
        //! Saves Animation Data to a XML structure into a file
        //!
        public void OnApplicationQuit()
        {
            if (Save_Data_to_XML == false || AnimationData.Data.getAnimationClips(gameObject) == null)
            {
                return;
            }

            List <AnimationClip> clips = AnimationData.Data.getAnimationClips(gameObject);

            XML_AnimationData runtimeXMLData = new XML_AnimationData();

            List <XML_AnimationClip> XMLclipList = new List <XML_AnimationClip>();

            foreach (AnimationClip clip in clips)
            {
                XML_AnimationClip XMLclip = new XML_AnimationClip(gameObject.name + "_Amimation");
                foreach (string property in observedProperties)
                {
                    List <XML_KeyFrame> XMLkeys = new List <XML_KeyFrame>();
                    foreach (Keyframe key in AnimationData.Data.getAnimationCurve(clip, property).keys)
                    {
                        XMLkeys.Add(new XML_KeyFrame(key.inTangent, key.outTangent, key.time, key.value, key.tangentMode));
                    }
                    XML_AnimationCurve XMLcurve = new XML_AnimationCurve(XMLkeys, AnimationData.WrapModeToString(AnimationData.Data.getAnimationCurve(clip, property).postWrapMode), AnimationData.WrapModeToString(AnimationData.Data.getAnimationCurve(clip, property).preWrapMode), "UnityEngine.Transform", property);
                    XMLclip.XML_AnimationCurves.Add(XMLcurve);
                }
                XMLclipList.Add(XMLclip);
            }
            runtimeXMLData.XML_AnimationClips = XMLclipList;
            AnimationData.Save(gameObject.name, runtimeXMLData);
        }
Exemplo n.º 2
0
        //!
        //! Loads Animation Data from File if they have been saved before
        //!
        public void loadData()
        {
            if (Load_Data_from_XML)
            {
                XML_Data = AnimationData.Load(name);

                if (XML_Data == null)
                {
                    return;
                }

                foreach (XML_AnimationClip XMLclip in XML_Data.XML_AnimationClips)
                {
                    XMLclip.data = new AnimationClip();
                    AnimationData.Data.addAnimationClip(gameObject, XMLclip.data);
                    foreach (XML_AnimationCurve XMLcurve in XMLclip.XML_AnimationCurves)
                    {
                        // print( "XMLcurve " + XMLcurve.property );

                        XMLcurve.data = new AnimationCurve();
                        foreach (XML_KeyFrame XMLkey in XMLcurve.XML_KeyFrames)
                        {
                            XMLkey.data = new Keyframe(XMLkey.t, XMLkey.v, XMLkey.inT, XMLkey.outT);
                            XMLcurve.data.AddKey(XMLkey.data);


                            timeStart = Mathf.Min(timeStart, XMLkey.t);
                            timeEnd   = Mathf.Max(XMLkey.t, timeEnd);
                        }
                        XMLcurve.data.postWrapMode = AnimationData.StringToWrapMode(XMLcurve.postWM);
                        XMLcurve.data.preWrapMode  = AnimationData.StringToWrapMode(XMLcurve.preWM);
                        System.Type type = AnimationData.GetTheType(XMLcurve.type);
                        AnimationData.Data.addAnimationCurve(XMLclip.data, type, XMLcurve.property, XMLcurve.data);
                    }
                }

                //register the object in the animation Controller
                GameObject.Find("AnimationController").GetComponent <AnimationController>().registerAnimatedObject(gameObject.GetComponent <SceneObject>());

                gameObject.GetComponent <SceneObject>().setKinematic(true, false);
            }
        }
Exemplo n.º 3
0
        //!
        //! STATIC METHODS
        //!

        //!
        //! Save a XML File from disk into the given XML Data Structure
        //!
        public static void Save(string name, XML_AnimationData data)
        {
            // name might contain maya namespaces
            string _name = name;

            _name = _name.Replace(":", "_");

            string path = filePath();

            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }

            Debug.Log("Write: " + path + "/" + _name + ".xml");

            XmlSerializer serializer = new XmlSerializer(typeof(XML_AnimationData));

            using (FileStream stream = new FileStream((path + "/" + _name + ".xml"), FileMode.Create))
            {
                serializer.Serialize(stream, data);
            }
        }
        //!
        //! Loads Animation Data from File if they have been saved before
        //!
        public bool loadData()
        {
            if (Load_Data_from_XML)
            {
                XML_Data = AnimationData.Load(name);

                if (XML_Data == null)
                {
                    return(false);
                }

                foreach (XML_AnimationClip XMLclip in XML_Data.XML_AnimationClips)
                {
                    XMLclip.data = new AnimationClip();
                    AnimationData.Data.addAnimationClip(gameObject, XMLclip.data);
                    foreach (XML_AnimationCurve XMLcurve in XMLclip.XML_AnimationCurves)
                    {
                        // print( "XMLcurve " + XMLcurve.property );

                        XMLcurve.data = new AnimationCurve();
                        foreach (XML_KeyFrame XMLkey in XMLcurve.XML_KeyFrames)
                        {
                            XMLkey.data = new Keyframe(XMLkey.t, XMLkey.v, XMLkey.inT, XMLkey.outT);
                            XMLcurve.data.AddKey(XMLkey.data);
                        }
                        XMLcurve.data.postWrapMode = AnimationData.StringToWrapMode(XMLcurve.postWM);
                        XMLcurve.data.preWrapMode  = AnimationData.StringToWrapMode(XMLcurve.preWM);
                        System.Type type = AnimationData.GetTheType(XMLcurve.type);
                        AnimationData.Data.addAnimationCurve(XMLclip.data, type, XMLcurve.property, XMLcurve.data);
                    }
                }

                return(true);
            }
            return(false);
        }