Ejemplo n.º 1
0
        public override MyObjectBuilder_ComponentBase Serialize(bool copy = false)
        {
            var builder = MyComponentFactory.CreateObjectBuilder(this) as MyObjectBuilder_PhysicsComponentBase;

            builder.LinearVelocity  = LinearVelocity;
            builder.AngularVelocity = AngularVelocity;
            return(builder);
        }
        public void Deserialize(MyObjectBuilder_ComponentContainer builder)
        {
            if (builder == null || builder.Components == null)
            {
                return;
            }

            foreach (var data in builder.Components)
            {
                MyComponentBase instance            = null;
                var             createdInstanceType = MyComponentFactory.GetCreatedInstanceType(data.Component.TypeId);

                // Old component deserialized type.
                var dictType = MyComponentTypeFactory.GetType(data.TypeId);
                // Component type can be set as attribute now
                var dictTypeFromAttr = MyComponentTypeFactory.GetComponentType(createdInstanceType);
                if (dictTypeFromAttr != null)
                {
                    dictType = dictTypeFromAttr;
                }

                bool hasComponent = TryGet(dictType, out instance);
                if (hasComponent)
                {
                    // If component is found then check also type because some components have default instances (MyNullGameLogicComponent)
                    if (createdInstanceType != instance.GetType())
                    {
                        hasComponent = false;
                    }
                }

                if (!hasComponent)
                {
                    instance = MyComponentFactory.CreateInstanceByTypeId(data.Component.TypeId);
                }

                instance.Deserialize(data.Component);

                if (!hasComponent)
                {
                    Add(dictType, instance);
                }
            }
        }
Ejemplo n.º 3
0
 public virtual MyObjectBuilder_ComponentBase Serialize()
 {
     return(MyComponentFactory.CreateObjectBuilder(this));
 }