当前位置: 首页>>代码示例>>C#>>正文


C# MyPhysicalInventoryItem类代码示例

本文整理汇总了C#中MyPhysicalInventoryItem的典型用法代码示例。如果您正苦于以下问题:C# MyPhysicalInventoryItem类的具体用法?C# MyPhysicalInventoryItem怎么用?C# MyPhysicalInventoryItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MyPhysicalInventoryItem类属于命名空间,在下文中一共展示了MyPhysicalInventoryItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            var builder = objectBuilder as MyObjectBuilder_FloatingObject;
            if (builder.Item.Amount <= 0)
            {
                // I can only prevent creation of entity by throwing exception. This might cause crashes when thrown outside of MyEntities.CreateFromObjectBuilder().
                throw new ArgumentOutOfRangeException("MyPhysicalInventoryItem.Amount", string.Format("Creating floating object with invalid amount: {0}x '{1}'", builder.Item.Amount, builder.Item.Content.GetId()));
            }
            base.Init(objectBuilder);

            this.Item = new MyPhysicalInventoryItem(builder.Item);

            InitInternal();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
        }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:16,代码来源:MyFloatingObject.cs

示例2: Spawn

        public static MyEntity Spawn(ref MyPhysicalInventoryItem item, Vector3 position, Vector3 speed)
        {
            var builder = PrepareBuilder(ref item);
            var meteorEntity = MyEntities.CreateFromObjectBuilder(builder);

            Vector3 forward = -MySector.DirectionToSunNormalized;
            Vector3 up = MyUtils.GetRandomVector3Normalized();
            while (forward == up)
                up = MyUtils.GetRandomVector3Normalized();

            Vector3 right = Vector3.Cross(forward, up);
            up = Vector3.Cross(right, forward);

            meteorEntity.WorldMatrix = Matrix.CreateWorld(position, forward, up);
            MyEntities.Add(meteorEntity);
            meteorEntity.Physics.RigidBody.MaxLinearVelocity = 500;
            meteorEntity.Physics.LinearVelocity = speed;
            meteorEntity.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(1.5f, 3);
            return meteorEntity;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:20,代码来源:MyMeteor.cs

示例3: Init

        public void Init(MyObjectBuilder_ConveyorPacket builder, MyEntity parent)
        {
            Item = new MyPhysicalInventoryItem(builder.Item);
            LinePosition = builder.LinePosition;

            var physicalItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content);

            var ore = Item.Content as MyObjectBuilder_Ore;

            string model = physicalItem.Model;
            float scale = 1.0f;
            if (ore != null)
            {
                foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    if (mat.MinedOre == ore.SubtypeName)
                    {
                        model = MyDebris.GetRandomDebrisVoxel();
                        scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
                        break;
                    }
                }
            }

            if (scale < 0.05f)
                scale = 0.05f;
            else if (scale > 1.0f)
                scale = 1.0f;

            bool entityIdAllocationSuspended = MyEntityIdentifier.AllocationSuspended;
            MyEntityIdentifier.AllocationSuspended = false;
            Init(null, model, parent, null, null);
            MyEntityIdentifier.AllocationSuspended = entityIdAllocationSuspended;
            PositionComp.Scale = scale;

            // Packets are serialized by conveyor lines
            Save = false;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:38,代码来源:MyConveyorPacket.cs

示例4: AddItemsToNewStack

        private MyFixedPoint AddItemsToNewStack(MyFixedPoint amount, MyFixedPoint maxStack, MyObjectBuilder_PhysicalObject objectBuilder, uint? itemId, int index = -1)
        {
            Debug.Assert(m_items.Count < MaxItemCount, "Adding a new item beyond the max item count limit!");

            MyFixedPoint addedAmount = MyFixedPoint.Min(amount, maxStack);

            var newItem = new MyPhysicalInventoryItem() { Amount = addedAmount, Scale = 1f, Content = objectBuilder };
            newItem.ItemId = itemId.HasValue ? itemId.Value : GetNextItemID();

            if (index >= 0 && index < m_items.Count)
            {
                //GR: Shift items not add to last position. Slower but more consistent with game logic
                m_items.Add(m_items[m_items.Count - 1]);
                for (int i = m_items.Count - 3; i >= index; i--)
                {
                    m_items[i+1] = m_items[i];
                }
                m_items[index] = newItem;
                
            }
            else
            {
                m_items.Add(newItem);
            }

            m_usedIds.Add(newItem.ItemId);

            if (Sync.IsServer)
                NotifyHudChangedInventoryItem(addedAmount, ref newItem, true);

            return amount - addedAmount;
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:32,代码来源:MyInventory.cs

示例5: FixTransferAmount

        private static void FixTransferAmount(MyInventory src, MyInventory dst, MyPhysicalInventoryItem? srcItem, bool spawn, ref MyFixedPoint remove, ref MyFixedPoint add)
        {
            Debug.Assert(Sync.IsServer);
            if (srcItem.Value.Amount < remove)
            {
                remove = srcItem.Value.Amount;
                add = remove;
            }

            if (!MySession.Static.CreativeMode && src != dst)
            {
                MyFixedPoint space = dst.ComputeAmountThatFits(srcItem.Value.Content.GetObjectId());
                if (space < remove)
                {
                    if (spawn)
                    {
                        MyEntity e = (dst.Owner as MyEntity);
                        Matrix m = e.WorldMatrix;
                        MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(remove - space, srcItem.Value.Content), e.PositionComp.GetPosition() + m.Forward + m.Up, m.Forward, m.Up, e.Physics);
                    }
                    else
                    {
                        remove = space;
                    }
                    add = space;
                }
            }
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:28,代码来源:MyInventory.cs

示例6: SpawnConstructionStockpile

        public void SpawnConstructionStockpile()
        {
            if (m_stockpile == null) return;

            Matrix worldMat = CubeGrid.WorldMatrix;

            int dist = (Max).RectangularDistance(Min) + 3;
            Vector3 a = Min;
            Vector3 b = Max;
            a *= CubeGrid.GridSize;
            b *= CubeGrid.GridSize;
            a = Vector3.Transform(a, worldMat);
            b = Vector3.Transform(b, worldMat);
            Vector3 avgPos = (a + b) / 2;

            Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPoint(avgPos);
            if (gravity.Length() != 0.0f)
            {
                gravity.Normalize();

                Vector3I? intersected = CubeGrid.RayCastBlocks(avgPos, avgPos + gravity * dist * CubeGrid.GridSize);
                if (!intersected.HasValue)
                {
                    a = avgPos;
                }
                else
                {
                    a = intersected.Value;
                    a *= CubeGrid.GridSize;
                    a = Vector3.Transform(a, worldMat);
                    a -= gravity * CubeGrid.GridSize * 0.1f;
                }
            }

            var items = m_stockpile.GetItems();
            foreach (var item in items)
            {
                var inventoryItem = new MyPhysicalInventoryItem(item.Amount, item.Content);
                MyFloatingObjects.Spawn(inventoryItem, a, worldMat.Forward, worldMat.Up, CubeGrid.Physics);
            }
        }
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:41,代码来源:MySlimBlock.cs

示例7: RemoveOperatingItem

 protected void RemoveOperatingItem(MyPhysicalInventoryItem item, MyFixedPoint amount)
 {
     MyMultiplayer.RaiseEvent(this, x => x.RemoveOperatingItem_Request, item.GetObjectBuilder(), amount, m_lockedByEntityId);
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:4,代码来源:MyCraftingComponentBase.cs

示例8: InsertOperatingItem_Event

 private void InsertOperatingItem_Event([DynamicObjectBuilder] MyObjectBuilder_InventoryItem itemBuilder)
 {           
     var item = new MyPhysicalInventoryItem(itemBuilder);
     InsertOperatingItem_Implementation(item);
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:5,代码来源:MyCraftingComponentBase.cs

示例9: CreateInventoryBlockItem

        protected IMyInventoryItem CreateInventoryBlockItem(MyDefinitionId blockDefinition, MyFixedPoint amount)
        {
            var content = new MyObjectBuilder_BlockItem() { BlockDefId = blockDefinition };
            MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content);

            return inventoryItem;
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:7,代码来源:MyCraftingComponentBase.cs

示例10: SpawnRandomLarge

 public static MyEntity SpawnRandomLarge(Vector3 position, Vector3 direction)
 {
     MyPhysicalInventoryItem i = new MyPhysicalInventoryItem(400 * (MyFixedPoint)MyUtils.GetRandomFloat(0f, 25f), MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"));
     return Spawn(ref i, position, direction * (MIN_SPEED + MyUtils.GetRandomInt(MIN_SPEED / 2)));
 }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:5,代码来源:MyMeteor.cs

示例11: Init

            public override void Init(MyObjectBuilder_EntityBase objectBuilder)
            {
                Entity.SyncFlag = true;
                base.Init(objectBuilder);
                Entity.SyncObject.UpdatePosition();

                var builder = (MyObjectBuilder_Meteor)objectBuilder;
                Item = new MyPhysicalInventoryItem(builder.Item);
                m_particleEffectId = MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM_UNREAL ? (int)MyParticleEffectsIDEnum.MeteorTrail_FireAndSmoke : (int)MyParticleEffectsIDEnum.MeteorParticle;
                InitInternal();

                Entity.Physics.LinearVelocity = builder.LinearVelocity;
                Entity.Physics.AngularVelocity = builder.AngularVelocity;

                m_integrity = builder.Integrity;
            }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:16,代码来源:MyMeteor.cs

示例12: PrepareBuilder

 private static MyObjectBuilder_Meteor PrepareBuilder(ref MyPhysicalInventoryItem item)
 {
     var meteorBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Meteor>();
     meteorBuilder.Item = item.GetObjectBuilder();
     meteorBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene;
     return meteorBuilder;
 }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:7,代码来源:MyMeteor.cs

示例13: ThrowFloatingObjectsFunc

        private bool ThrowFloatingObjectsFunc()
        {
            var view = MySession.Static.CameraController.GetViewMatrix();
            var inv = Matrix.Invert(view);

            //MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(100, 
            var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone");
			var scrapBuilder = MyFloatingObject.ScrapBuilder;

            for (int i = 1; i <= 25; i++)
            {
                var item = new MyPhysicalInventoryItem((MyRandom.Instance.Next() % 200) + 1, oreBuilder);
                var obj = MyFloatingObjects.Spawn(item, inv.Translation + inv.Forward * i * 1.0f, inv.Forward, inv.Up);
                obj.Physics.LinearVelocity = inv.Forward * 50;
            }

            Vector3D scrapPos = inv.Translation;
            scrapPos.X += 10;
            for (int i = 1; i <= 25; i++)
            {
                var item = new MyPhysicalInventoryItem((MyRandom.Instance.Next() % 200) + 1, scrapBuilder);
                var obj = MyFloatingObjects.Spawn(item, scrapPos + inv.Forward * i * 1.0f, inv.Forward, inv.Up);
                obj.Physics.LinearVelocity = inv.Forward * 50;
            }

            return true;
        }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:27,代码来源:MyMichalDebugInputComponent.cs

示例14: SpawnOrePieces

        private void SpawnOrePieces(MyFixedPoint amountItems, MyFixedPoint maxAmountPerDrop, Vector3 hitPosition, MyObjectBuilder_PhysicalObject oreObjBuilder, MyVoxelMaterialDefinition voxelMaterial)
        {
            ProfilerShort.Begin("SpawnOrePieces");
            var forward = Vector3.Normalize(m_sensor.FrontPoint - m_sensor.Center);
            //var pos = m_sensor.CutOutSphere.Center + forward * m_floatingObjectSpawnOffset;
            var pos = hitPosition - forward * m_floatingObjectSpawnRadius;
            BoundingSphere bsphere = new BoundingSphere(pos, m_floatingObjectSpawnRadius);

            while (amountItems > 0)
            {
                MyFixedPoint dropAmount = MyFixedPoint.Min(amountItems, maxAmountPerDrop);
                amountItems -= dropAmount;
                var inventoryItem = new MyPhysicalInventoryItem(dropAmount, oreObjBuilder);
                var item = MyFloatingObjects.Spawn(inventoryItem, bsphere, null, voxelMaterial);
                item.Physics.LinearVelocity = MyUtils.GetRandomVector3HemisphereNormalized(forward) * MyUtils.GetRandomFloat(5, 8);
                item.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(4, 8);
            }
            ProfilerShort.End();
        }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:19,代码来源:MyDrillBase.cs

示例15: ItemPushRequest

        public static bool ItemPushRequest(IMyConveyorEndpointBlock start, MyInventory srcInventory, long playerId, MyPhysicalInventoryItem toSend, MyFixedPoint? amount = null)
        {
            var itemBuilder = toSend.Content;
            if (amount.HasValue)
                Debug.Assert(toSend.Content.TypeId == typeof(MyObjectBuilder_Ore) ||
                                toSend.Content.TypeId == typeof(MyObjectBuilder_Ingot) ||
                                MyFixedPoint.Floor(amount.Value) == amount.Value);

            MyFixedPoint remainingAmount = toSend.Amount;
            if (amount.HasValue)
            {
                remainingAmount = amount.Value;
            }

            SetTraversalPlayerId(playerId);

            var toSendContentId = toSend.Content.GetId();
            SetTraversalInventoryItemDefinitionId(toSendContentId);

            if (NeedsLargeTube(toSendContentId))
            {
                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorLargePredicate);
            }
            else
            {
                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate);
            }

            bool success = false;

            foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
            {
                IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner;
                if (owner == null) continue;

                for (int i = 0; i < owner.InventoryCount; ++i)
                {
                    var inventory = owner.GetInventory(i);
                    if ((inventory.GetFlags() & MyInventoryFlags.CanReceive) == 0)
                        continue;

                    if (inventory == srcInventory)
                        continue;

                    var fittingAmount = inventory.ComputeAmountThatFits(toSendContentId);
                    fittingAmount = MyFixedPoint.Min(fittingAmount, remainingAmount);
                    if (!inventory.CheckConstraint(toSendContentId))
                        continue;
                    if (fittingAmount == 0)
                        continue;

                    MyInventory.Transfer(srcInventory, inventory, toSend.ItemId, -1, fittingAmount);
                    success = true;
                }
            }
            return success;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:57,代码来源:MyGridConveyorSystem.cs


注:本文中的MyPhysicalInventoryItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。