本文整理汇总了C#中VRage.MyFixedPoint类的典型用法代码示例。如果您正苦于以下问题:C# MyFixedPoint类的具体用法?C# MyFixedPoint怎么用?C# MyFixedPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MyFixedPoint类属于VRage命名空间,在下文中一共展示了MyFixedPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyInventoryItem
public MyInventoryItem(MyFixedPoint amount, MyObjectBuilder_PhysicalObject content)
{
Debug.Assert(amount > 0, "Creating inventory item with zero amount!");
ItemId = 0;
Amount = amount;
Content = content;
}
示例2: Spawn
public static MyEntity Spawn(this MyPhysicalInventoryItem thisItem, MyFixedPoint amount, BoundingBoxD box, MyEntity owner = null)
{
if(amount < 0)
{
return null;
}
MatrixD spawnMatrix = MatrixD.Identity;
spawnMatrix.Translation = box.Center;
var entity = Spawn(thisItem, amount, spawnMatrix, owner);
if (entity == null)
return null;
var size = entity.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);
Vector3 forward = MyUtils.GetRandomVector3Normalized();
Vector3 up = MyUtils.GetRandomVector3Normalized();
while (forward == up)
up = MyUtils.GetRandomVector3Normalized();
Vector3 right = Vector3.Cross(forward, up);
up = Vector3.Cross(right, forward);
entity.WorldMatrix = MatrixD.CreateWorld(pos, forward, up);
return entity;
}
示例3: MyRepairBlueprintToProduce
public MyRepairBlueprintToProduce(MyFixedPoint amount, MyBlueprintDefinitionBase blueprint, uint inventoryItemId, MyObjectBuilderType inventoryItemType, MyStringHash inventoryItemSubtypeId) : base(amount, blueprint)
{
System.Diagnostics.Debug.Assert(Blueprint is MyRepairBlueprintDefinition, "MyRepairBlueprintToProduce class should be used together with blueprints type of MyRepairBlueprintDefinition only!");
InventoryItemId = inventoryItemId;
InventoryItemType = inventoryItemType;
InventoryItemSubtypeId = inventoryItemSubtypeId;
}
示例4: Spawn
public MyEntity Spawn(MyFixedPoint amount, MatrixD worldMatrix, MyEntity owner = null)
{
if (Content is MyObjectBuilder_BlockItem)
{
Debug.Assert(MyFixedPoint.IsIntegral(amount), "Spawning fractional number of grids!");
var blockItem = Content as MyObjectBuilder_BlockItem;
var builder = MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeGrid)) as MyObjectBuilder_CubeGrid;
builder.GridSizeEnum = MyCubeSize.Small;
builder.IsStatic = false;
builder.PersistentFlags |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled;
builder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
var block = MyObjectBuilderSerializer.CreateNewObject(blockItem.BlockDefId) as MyObjectBuilder_CubeBlock;
builder.CubeBlocks.Add(block);
MyCubeGrid firstGrid = null;
for (int i = 0; i < amount; ++i)
{
builder.EntityId = MyEntityIdentifier.AllocateId();
block.EntityId = MyEntityIdentifier.AllocateId();
MyCubeGrid newGrid = MyEntities.CreateFromObjectBuilder(builder) as MyCubeGrid;
firstGrid = firstGrid ?? newGrid;
MyEntities.Add(newGrid);
Sandbox.Game.Multiplayer.MySyncCreate.SendEntityCreated(builder);
}
return firstGrid;
}
else
return MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(amount, Content),worldMatrix, owner != null ? owner.Physics : null);
}
示例5: Reload
private static void Reload(IMyInventoryOwner gun, SerializableDefinitionId ammo, bool reactor = false)
{
var cGun = gun;
Sandbox.ModAPI.IMyInventory inv = (Sandbox.ModAPI.IMyInventory)cGun.GetInventory(0);
VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt");
if (point.RawValue > 1000000)
return;
//inv.Clear();
VRage.MyFixedPoint amount = new VRage.MyFixedPoint();
amount.RawValue = 2000000;
MyObjectBuilder_InventoryItem ii;
if (reactor)
{
ii = new MyObjectBuilder_InventoryItem()
{
Amount = 10,
Content = new MyObjectBuilder_Ingot() { SubtypeName = ammo.SubtypeName }
};
}
else
{
ii = new MyObjectBuilder_InventoryItem()
{
Amount = 4,
Content = new MyObjectBuilder_AmmoMagazine() { SubtypeName = ammo.SubtypeName }
};
}
inv.AddItems(amount, ii.PhysicalContent);
point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt");
}
示例6: MyInventory
public MyInventory(MyFixedPoint maxVolume, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
{
m_maxVolume = MyPerGameSettings.ConstrainInventory() ? maxVolume * MySession.Static.InventoryMultiplier : MyFixedPoint.MaxValue;
m_size = size;
m_flags = flags;
m_owner = owner;
Clear();
SyncObject = new MySyncInventory();
}
示例7: MyInventory
public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
{
m_maxVolume = maxVolume;
m_maxMass = maxMass;
m_size = size;
m_flags = flags;
m_owner = owner;
Clear();
SyncObject = new MySyncInventory();
//ContentsChanged += OnContentsChanged;
}
示例8: TransferItems
/// <summary>
/// Transfers safely given item from one to another inventory, uses ItemsCanBeAdded and ItemsCanBeRemoved checks
/// </summary>
/// <returns>true if items were succesfully transfered, otherwise, false</returns>
public static bool TransferItems(MyInventoryBase sourceInventory, MyInventoryBase destinationInventory, IMyInventoryItem item, MyFixedPoint amount)
{
if (sourceInventory == null)
{
System.Diagnostics.Debug.Fail("Source inventory is null!");
return false;
}
if (destinationInventory == null)
{
System.Diagnostics.Debug.Fail("Destionation inventory is null!");
return false;
}
if (item == null)
{
System.Diagnostics.Debug.Fail("Item is null!");
return false;
}
if (amount == 0)
{
return true;
}
if (destinationInventory.ItemsCanBeAdded(amount, item) && sourceInventory.ItemsCanBeRemoved(amount, item))
{
if (Sync.IsServer)
{
if (destinationInventory.Add(item, amount))
{
if (sourceInventory.Remove(item, amount))
{
// successfull transaction
return true;
}
else
{
System.Diagnostics.Debug.Fail("Error! Items were added to inventory, but can't be removed!");
}
}
}
else
{
MySyncInventory.SendTransferItemsMessage(sourceInventory, destinationInventory, item, amount);
}
}
return false;
}
示例9: PostprocessAddSubblueprint
private void PostprocessAddSubblueprint(MyBlueprintDefinitionBase blueprint, MyFixedPoint blueprintAmount)
{
for (int i = 0; i < blueprint.Prerequisites.Length; ++i)
{
Item prerequisite = blueprint.Prerequisites[i];
prerequisite.Amount *= blueprintAmount;
AddToItemList(m_tmpPrerequisiteList, prerequisite);
}
for (int i = 0; i < blueprint.Results.Length; ++i)
{
Item result = blueprint.Results[i];
result.Amount *= blueprintAmount;
AddToItemList(m_tmpResultList, result);
}
}
示例10: Spawn
public MyEntity Spawn(MyFixedPoint amount, BoundingBoxD box, MyEntity owner = null)
{
var entity = Spawn(amount, MatrixD.Identity, owner);
var size = entity.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);
Vector3 forward = MyUtils.GetRandomVector3Normalized();
Vector3 up = MyUtils.GetRandomVector3Normalized();
while (forward == up)
up = MyUtils.GetRandomVector3Normalized();
Vector3 right = Vector3.Cross(forward, up);
up = Vector3.Cross(right, forward);
entity.WorldMatrix = MatrixD.CreateWorld(pos, forward, up);
return entity;
}
示例11: RemoveItems
public MyEntity RemoveItems(uint itemId, MyFixedPoint? amount = null, bool sendEvent = true, bool spawn = false, MatrixD? spawnPos = null)
{
var item = GetItemByID(itemId);
var am = amount.HasValue ? amount.Value : (item.HasValue ? item.Value.Amount : 1);
MyEntity spawned = null;
if (Sync.IsServer)
{
if (item.HasValue && RemoveItemsInternal(itemId, am, sendEvent))
{
if (spawn)
{
MyEntity owner;
if (Owner is MyEntity)
{
owner = Owner as MyEntity;
}
else
{
owner = Container.Entity as MyEntity;
}
if (!spawnPos.HasValue)
spawnPos = MatrixD.CreateWorld(owner.PositionComp.GetPosition() + owner.PositionComp.WorldMatrix.Forward + owner.PositionComp.WorldMatrix.Up, owner.PositionComp.WorldMatrix.Forward, owner.PositionComp.WorldMatrix.Up);
spawned = item.Value.Spawn(am, spawnPos.Value, owner);
if (spawned != null && spawnPos.HasValue)
{
if (owner == MySession.Static.LocalCharacter)
{
MyGuiAudio.PlaySound(MyGuiSounds.PlayDropItem);
}
else
{
MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter();
if (emitter != null)
{
emitter.SetPosition(spawnPos.Value.Translation);
emitter.PlaySound(dropSound);
}
}
}
}
}
}
return spawned;
}
示例12: Update
public override ChangeInfo Update(MyEntity owner, long playerID = 0)
{
ChangeInfo changed = ChangeInfo.None;
bool enable = true;
if (MyCubeBuilder.Static == null)
return changed;
var blockDefinition = MyCubeBuilder.Static.IsActivated ? MyCubeBuilder.Static.ToolbarBlockDefinition : null;
var blockDef = (this.Definition as Sandbox.Definitions.MyCubeBlockDefinition);
if ((MyCubeBuilder.Static.BlockCreationIsActivated || MyCubeBuilder.Static.MultiBlockCreationIsActivated) && blockDefinition != null && (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle))
{
if (blockDefinition.BlockPairName == blockDef.BlockPairName)
{
WantsToBeSelected = true;
}
else if (blockDef.BlockStages != null && blockDef.BlockStages.Contains(blockDefinition.Id))
{
WantsToBeSelected = true;
}
else
{
WantsToBeSelected = false;
}
}
else
{
WantsToBeSelected = false;
}
var character = MySession.Static.LocalCharacter;
if (MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID)
{
if (blockDef.CubeSize == MyCubeSize.Small && character != null)
{
var inventory = character.GetInventory();
MyFixedPoint amount = inventory != null ? inventory.GetItemAmount(Definition.Id) : 0;
if (m_lastAmount != amount)
{
m_lastAmount = amount;
changed |= ChangeInfo.IconText;
}
if (MySession.Static.SurvivalMode)
{
enable &= m_lastAmount > 0;
}
else
{
// so that we correctly set icontext when changing from enabled to disabled even when the amount is the same
changed |= ChangeInfo.IconText;
}
}
}
if (MyPerGameSettings.EnableResearch && MySessionComponentResearch.Static != null && (blockDef.CubeSize == MyCubeSize.Large))
enable &= MySessionComponentResearch.Static.CanUse(character, Definition.Id);
changed |= SetEnabled(enable);
return changed;
}
示例13: Consume
public void Consume(MyFixedPoint amount, MyConsumableItemDefinition definition)
{
if (definition == null)
return;
MyEntityStat stat;
var regenEffect = new MyObjectBuilder_EntityStatRegenEffect();
regenEffect.Interval = 1.0f;
regenEffect.MaxRegenRatio = 1.0f;
regenEffect.MinRegenRatio = 0.0f;
foreach (var statValue in definition.Stats)
{
if (Stats.TryGetValue(MyStringHash.GetOrCompute(statValue.Name), out stat))
{
regenEffect.TickAmount = statValue.Value*(float)amount;
regenEffect.Duration = statValue.Time;
stat.AddEffect(regenEffect);
}
}
}
示例14: Round
public static MyFixedPoint Round(MyFixedPoint a)
{
a.RawValue = (a.RawValue + Divider / 2) / Divider;
return a;
}
示例15: Max
public static MyFixedPoint Max(MyFixedPoint a, MyFixedPoint b)
{
return a > b ? a : b;
}