本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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);
}
}
示例7: RemoveOperatingItem
protected void RemoveOperatingItem(MyPhysicalInventoryItem item, MyFixedPoint amount)
{
MyMultiplayer.RaiseEvent(this, x => x.RemoveOperatingItem_Request, item.GetObjectBuilder(), amount, m_lockedByEntityId);
}
示例8: InsertOperatingItem_Event
private void InsertOperatingItem_Event([DynamicObjectBuilder] MyObjectBuilder_InventoryItem itemBuilder)
{
var item = new MyPhysicalInventoryItem(itemBuilder);
InsertOperatingItem_Implementation(item);
}
示例9: CreateInventoryBlockItem
protected IMyInventoryItem CreateInventoryBlockItem(MyDefinitionId blockDefinition, MyFixedPoint amount)
{
var content = new MyObjectBuilder_BlockItem() { BlockDefId = blockDefinition };
MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content);
return inventoryItem;
}
示例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)));
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}