Exemple #1
0
        public static MyEntity Spawn(MyPhysicalInventoryItem item, BoundingSphereD sphere, MyPhysicsComponentBase motionInheritedFrom = null, MyVoxelMaterialDefinition voxelMaterial = null)
        {
            ProfilerShort.Begin("MyFloatingObjects.Spawn");
            var floatingBuilder = PrepareBuilder(ref item);

            ProfilerShort.Begin("Create");
            var thrownEntity = MyEntities.CreateFromObjectBuilder(floatingBuilder);

            ProfilerShort.End();
            ((MyFloatingObject)thrownEntity).VoxelMaterial = voxelMaterial;

            var size       = thrownEntity.PositionComp.LocalVolume.Radius;
            var sphereSize = sphere.Radius - size;

            sphereSize = Math.Max(sphereSize, 0);

            sphere = new BoundingSphereD(sphere.Center, sphereSize);

            var pos = MyUtils.GetRandomBorderPosition(ref sphere);

            AddToPos(thrownEntity, pos, motionInheritedFrom);
            ProfilerShort.End();

            //Visual scripting action
            if (thrownEntity != null && MyVisualScriptLogicProvider.ItemSpawned != null)
            {
                MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, thrownEntity.EntityId, item.Amount.ToIntSafe(), pos);
            }
            return(thrownEntity);
        }
Exemple #2
0
        internal static MyEntity Spawn(MyPhysicalInventoryItem item, BoundingBoxD box, MyPhysicsComponentBase motionInheritedFrom = null)
        {
            var floatingBuilder = PrepareBuilder(ref item);
            var thrownEntity    = MyEntities.CreateFromObjectBuilder(floatingBuilder);

            System.Diagnostics.Debug.Assert(thrownEntity != null);
            if (thrownEntity != null)
            {
                var size     = thrownEntity.PositionComp.LocalVolume.Radius;
                var halfSize = box.Size / 2 - new Vector3(size);
                halfSize = Vector3.Max(halfSize, Vector3.Zero);

                box = new BoundingBoxD(box.Center - halfSize, box.Center + halfSize);
                var pos = MyUtils.GetRandomPosition(ref box);

                AddToPos(thrownEntity, pos, motionInheritedFrom);

                thrownEntity.Physics.ForceActivate();

                //Visual scripting action
                if (MyVisualScriptLogicProvider.ItemSpawned != null)
                {
                    MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, thrownEntity.EntityId, item.Amount.ToIntSafe(), pos);
                }
            }
            return(thrownEntity);
        }
Exemple #3
0
        internal static MyEntity Spawn(MyPhysicalInventoryItem item, BoundingBoxD box, MyPhysicsComponentBase motionInheritedFrom = null)
        {
            MyEntity thrownEntity = MyEntities.CreateFromObjectBuilder(PrepareBuilder(ref item), false);

            if (thrownEntity != null)
            {
                float    radius  = thrownEntity.PositionComp.LocalVolume.Radius;
                Vector3D vectord = Vector3.Max(((Vector3)(box.Size / 2.0)) - new Vector3(radius), Vector3.Zero);
                box = new BoundingBoxD(box.Center - vectord, box.Center + vectord);
                Vector3D randomPosition = MyUtils.GetRandomPosition(ref box);
                AddToPos(thrownEntity, randomPosition, motionInheritedFrom);
                thrownEntity.Physics.ForceActivate();
                if (MyVisualScriptLogicProvider.ItemSpawned != null)
                {
                    MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, thrownEntity.EntityId, item.Amount.ToIntSafe(), randomPosition);
                }
            }
            return(thrownEntity);
        }
Exemple #4
0
        public static MyEntity Spawn(MyPhysicalInventoryItem item, MatrixD worldMatrix, MyPhysicsComponentBase motionInheritedFrom = null)
        {
            var floatingBuilder = PrepareBuilder(ref item);

            floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
            var thrownEntity = MyEntities.CreateFromObjectBuilderAndAdd(floatingBuilder);

            if (thrownEntity != null)
            {
                thrownEntity.Physics.ForceActivate();
                ApplyPhysics(thrownEntity, motionInheritedFrom);
                Debug.Assert(thrownEntity.Save == true, "Thrown item will not be saved. Feel free to ignore this.");

                //Visual scripting action
                if (MyVisualScriptLogicProvider.ItemSpawned != null)
                {
                    MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, thrownEntity.EntityId, item.Amount.ToIntSafe(), worldMatrix.Translation);
                }
            }
            return(thrownEntity);
        }
Exemple #5
0
        public static void Spawn(MyPhysicalInventoryItem item, BoundingSphereD sphere, MyPhysicsComponentBase motionInheritedFrom, MyVoxelMaterialDefinition voxelMaterial, Action <MyEntity> OnDone)
        {
            Vector3D?relativeOffset = null;

            MyEntities.CreateFromObjectBuilderParallel(PrepareBuilder(ref item), false, delegate(MyEntity entity) {
                if (voxelMaterial.DamagedMaterial != MyStringHash.NullOrEmpty)
                {
                    voxelMaterial = MyDefinitionManager.Static.GetVoxelMaterialDefinition(voxelMaterial.DamagedMaterial.ToString());
                }
                ((MyFloatingObject)entity).VoxelMaterial = voxelMaterial;
                float radius = entity.PositionComp.LocalVolume.Radius;
                double num2  = Math.Max((double)(sphere.Radius - radius), (double)0.0);
                sphere       = new BoundingSphereD(sphere.Center, num2);
                Vector3D randomBorderPosition = MyUtils.GetRandomBorderPosition(ref sphere);
                AddToPos(entity, randomBorderPosition, motionInheritedFrom);
                if (MyVisualScriptLogicProvider.ItemSpawned != null)
                {
                    MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, entity.EntityId, item.Amount.ToIntSafe(), randomBorderPosition);
                }
                OnDone(entity);
            }, null, null, relativeOffset, false, false);
        }
Exemple #6
0
 public static void Spawn(MyPhysicalInventoryItem item, MatrixD worldMatrix, MyPhysicsComponentBase motionInheritedFrom, Action <MyEntity> completionCallback)
 {
     if (MyEntities.IsInsideWorld(worldMatrix.Translation))
     {
         MyObjectBuilder_FloatingObject objectBuilder = PrepareBuilder(ref item);
         objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
         Vector3D?relativeOffset = null;
         MyEntities.CreateFromObjectBuilderParallel(objectBuilder, true, delegate(MyEntity entity) {
             if ((entity != null) && (entity.Physics != null))
             {
                 entity.Physics.ForceActivate();
                 ApplyPhysics(entity, motionInheritedFrom);
                 if (MyVisualScriptLogicProvider.ItemSpawned != null)
                 {
                     MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, entity.EntityId, item.Amount.ToIntSafe(), worldMatrix.Translation);
                 }
                 if (completionCallback != null)
                 {
                     completionCallback(entity);
                 }
             }
         }, null, null, relativeOffset, false, false);
     }
 }