public override void Deserialize(MyObjectBuilder_ComponentBase builder)
        {
            base.Deserialize(builder);
            var ob = builder as MyObjectBuilder_HierarchyComponentBase;

            if (ob != null)
            {
                m_deserializedEntities.Clear();
                foreach (var child in ob.Children)
                {
                    //IMPORTANT - entities that are supposed to be saved in hierarchy should be saved ONLY in hierarchy
                    if (!MyEntityIdentifier.ExistsById(child.EntityId))
                    {
                        var childEntity = MyEntity.MyEntitiesCreateFromObjectBuilderExtCallback(child, true);
                        m_deserializedEntities.Add(childEntity);
                    }
                }

                foreach (var deserializedEntity in m_deserializedEntities)
                {
                    AddChild(deserializedEntity, true, false);
                }
            }
        }
        void OnShoot(ref MyEventShoot msg)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Shoot");
            MyEntity parent;

            if (MyEntities.TryGetEntityById(new MyEntityIdentifier(msg.ShooterEntityId), out parent))
            {
                if (parent is MySmallShip)
                {
                    var ship = (MySmallShip)parent;
                    ship.InitGroupMaskIfNeeded();
                    ship.WorldMatrix = msg.Position.GetMatrix();
                    if (msg.TargetEntityId.HasValue)
                    {
                        ship.TargetEntity = MyEntityIdentifier.GetEntityByIdOrNull(new MyEntityIdentifier(msg.TargetEntityId.Value));
                    }
                    var msgWeapon = msg.Weapon;
                    var weapon    = GetWeapon(ship, msgWeapon);
                    if (weapon == null)
                    {
                        weapon = ship.Weapons.AddWeapon(new MyMwcObjectBuilder_SmallShip_Weapon(msg.Weapon));
                    }
                    Debug.Assert(weapon.Parent != null, "Weapon parent is null, something is wrong");
                    weapon.IsDummy = true;
                    weapon.Shot(new MyMwcObjectBuilder_SmallShip_Ammo(msg.Ammo));
                    MyEntity projectile;
                    if (msg.ProjectileEntityId.HasValue && weapon.LastShotId.HasValue && MyEntities.TryGetEntityById(weapon.LastShotId.Value, out projectile))
                    {
                        MyEntityIdentifier.RemoveEntity(weapon.LastShotId.Value);
                        projectile.EntityId = new MyEntityIdentifier(msg.ProjectileEntityId.Value);
                        if (!MyEntityIdentifier.ExistsById(projectile.EntityId.Value))
                        {
                            MyEntityIdentifier.AddEntityWithId(projectile);
                        }
                    }
                }
                else if (parent is MyPrefabLargeWeapon)
                {
                    var gun = ((MyPrefabLargeWeapon)parent).GetGun();
                    if (msg.TargetEntityId.HasValue)
                    {
                        var target = MyEntityIdentifier.GetEntityByIdOrNull(new MyEntityIdentifier(msg.TargetEntityId.Value));
                        gun.SetTarget(target);
                    }

                    gun.GetBarell().IsDummy = true;
                    gun.RotateImmediately(gun.GetPosition() + msg.Position.GetMatrix().Forward * 5000);
                    gun.IsDummy = true;
                    gun.Shot(new MyMwcObjectBuilder_SmallShip_Ammo(msg.Ammo));
                    MyEntity projectile;
                    if (msg.ProjectileEntityId.HasValue && gun.LastShotId.HasValue && MyEntities.TryGetEntityById(gun.LastShotId.Value, out projectile))
                    {
                        MyEntityIdentifier.RemoveEntity(gun.LastShotId.Value);
                        projectile.EntityId = new MyEntityIdentifier(msg.ProjectileEntityId.Value);
                        if (!MyEntityIdentifier.ExistsById(projectile.EntityId.Value))
                        {
                            MyEntityIdentifier.AddEntityWithId(projectile);
                        }
                    }
                }
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Exemple #3
0
        public virtual void OnOkClick(MyGuiControlButton sender)
        {
            if (HasEntity())
            {
                if (m_idTextbox != null)
                {
                    if (m_entity.EntityId != null)
                    {
                        var newId = new MyEntityIdentifier(Convert.ToUInt32(m_idTextbox.Text));

                        if (newId.NumericValue != m_entity.EntityId.Value.NumericValue && !MyEntityIdentifier.ExistsById(newId))
                        {
                            MyEntityIdentifier.RemoveEntity(m_entity.EntityId.Value);
                            m_entity.EntityId = newId;
                            MyEntityIdentifier.AddEntityWithId(m_entity);
                        }
                    }
                }

                if (IsPositionInput())
                {
                    Vector3 position = GetNewPosition();
                    if (IsValidPositionInput(position))
                    {
                        MyEditorGizmo.MoveAndRotateObject(position, m_entity.GetWorldRotation(), m_entity);
                    }
                }
            }
        }