Example #1
0
 public PhysicalObject(GameObject gameObj, PhysicalObject po) : base(gameObj)
 {
     this.Mass                = po.Mass;
     this.DragFactor          = po.DragFactor;
     this.IsUsingGravity      = po.IsUsingGravity;
     this.Sleeping            = po.Sleeping;
     this.RotationConstraints = po.RotationConstraints;
     this.PositionConstraints = po.PositionConstraints;
     this.Velocity            = po.Velocity;
 }
        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.MoveToContent();
            //reader.ReadStartElement();

            UniqueID = (uint)reader.ReadElementContentAsInt("UniqueID", "");
            Name     = reader.ReadElementString("Name", "");
            DrawLast = reader.ReadElementContentAsBoolean("DrawLast", "");

            if (reader.Name == "Tags")
            {
                reader.ReadStartElement();
                Tags = new List <string>();
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    string s = reader.ReadElementString("Tag", "");
                    if (s != "null")
                    {
                        Tags.Add(s);
                    }
                }
                reader.ReadEndElement();
            }
            Dynamic = reader.ReadElementContentAsBoolean("Dynamic", "");

            if (reader.Name == "MyTransform")
            {
                MyTransform = new Transform(this);
                (MyTransform as IXmlSerializable).ReadXml(reader);
            }

            if (reader.Name == "MyPhysicalObject")
            {
                MyPhysicalObject = new PhysicalObject(this);
                (MyPhysicalObject as IXmlSerializable).ReadXml(reader);
            }

            //if (reader.Name == "MyCollider")
            //{
            //    reader.ReadStartElement();
            //    String s = reader.ReadElementString("Type", "");
            //    switch(s)
            //    {
            //        case "TrashSoup.Engine.BoxCollider":
            //            MyCollider = new BoxCollider(this);
            //            break;
            //        case "TrashSoup.Engine.SphereCollider":
            //            MyCollider = new SphereCollider(this);
            //            break;
            //        default:
            //            MyCollider = new Collider(this);
            //            break;
            //    }
            //    (MyCollider as IXmlSerializable).ReadXml(reader);
            //    reader.ReadEndElement();
            //}

            if (reader.Name == "MyAnimator")
            {
                reader.ReadStartElement();
                Model  baseAnim     = null;
                string baseAnimPath = reader.ReadElementString("BaseAnim", "");
                if (!ResourceManager.Instance.Models.TryGetValue(baseAnimPath, out baseAnim))
                {
                    baseAnim = ResourceManager.Instance.LoadModel(baseAnimPath);
                }
                MyAnimator = new Animator(this, ResourceManager.Instance.Models[baseAnimPath]);
                (MyAnimator as IXmlSerializable).ReadXml(reader);
                //MyAnimator.MyObject = ResourceManager.Instance.CurrentScene.GetObject(MyAnimator.tmp);
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    String s = reader.ReadElementString("AnimatorClip", "");
                    MyAnimator.AddAnimationClip(ResourceManager.Instance.LoadAnimationFromModel(
                                                    ResourceManager.Instance.Models[baseAnimPath],
                                                    ResourceManager.Instance.LoadAnimation(s),
                                                    s
                                                    ));
                    //MyAnimator.animationPlayers.Add(s, new SkinningModelLibrary.AnimationPlayer(MyAnimator.SkinningData, s));
                }
                reader.ReadEndElement();
            }

            if (reader.Name == "Components")
            {
                List <object> parameters = new List <object>();
                parameters.Add(this);
                reader.MoveToContent();
                reader.ReadStartElement();
                while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                {
                    Object obj = Activator.CreateInstance(Type.GetType(reader.Name), parameters.ToArray());
                    (obj as IXmlSerializable).ReadXml(reader);
                    Components.Add((ObjectComponent)obj);
                }
            }
            if (reader.NodeType == System.Xml.XmlNodeType.EndElement)
            {
                reader.ReadEndElement();
            }

            if (reader.Name == "MyCollider")
            {
                reader.ReadStartElement();
                String s = reader.ReadElementString("Type", "");
                switch (s)
                {
                //commented because Collider system will be changed
                case "TrashSoup.Engine.BoxCollider":
                    MyCollider = new BoxCollider(this);
                    break;

                case "TrashSoup.Engine.SphereCollider":
                    MyCollider = new SphereCollider(this);
                    break;

                default:
                    //MyCollider = new Collider(this);
                    break;
                }
                (MyCollider as IXmlSerializable).ReadXml(reader);
                reader.ReadEndElement();
            }

            //this.Initialize();

            //reader.ReadEndElement();
        }