本文整理汇总了C#中Sandbox.Game.Entities.MyCubeGrid.GetCubeBlock方法的典型用法代码示例。如果您正苦于以下问题:C# MyCubeGrid.GetCubeBlock方法的具体用法?C# MyCubeGrid.GetCubeBlock怎么用?C# MyCubeGrid.GetCubeBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sandbox.Game.Entities.MyCubeGrid
的用法示例。
在下文中一共展示了MyCubeGrid.GetCubeBlock方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DamageGrid
private void DamageGrid(FlameInfo flameInfo, LineD l, MyCubeGrid grid)
{
HkSphereShape sph = new HkSphereShape(flameInfo.Radius * BlockDefinition.FlameDamageLengthScale);
var transform = MatrixD.CreateWorld(l.From, Vector3.Forward, Vector3.Up);
var hit = MyPhysics.CastShapeReturnPoint(l.To, sph, ref transform, (int)MyPhysics.DefaultCollisionLayer, 0.05f);
sph.Base.RemoveReference();
if (hit.HasValue)
{
//MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
MyPhysics.CastRay(hit.Value - l.Direction * 0.1f, hit.Value + l.Direction * 0.1f, m_gridRayCastLst, MyPhysics.ObjectDetectionCollisionLayer);
if ((m_gridRayCastLst.Count == 0 || m_gridRayCastLst[0].HkHitInfo.GetHitEntity() != grid) && grid == CubeGrid)
{
m_gridRayCastLst.Clear();
return;
}
m_gridRayCastLst.Clear();
var block = grid.GetCubeBlock(grid.WorldToGridInteger(hit.Value));
//if (block != this.SlimBlock)
{
//MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
var invWorld = grid.PositionComp.GetWorldMatrixNormalizedInv();
var gridPos = Vector3D.Transform(hit.Value, invWorld);
var gridDir = Vector3D.TransformNormal(l.Direction, invWorld);
if (block != null)
if (block.FatBlock != this && (CubeGrid.GridSizeEnum == MyCubeSize.Large || block.BlockDefinition.DeformationRatio > 0.25))
{
block.DoDamage(30 * BlockDefinition.FlameDamage, MyDamageType.Environment, attackerId: EntityId);
}
var areaPlanar = 0.5f * flameInfo.Radius * CubeGrid.GridSize;
var areaVertical = 0.5f * CubeGrid.GridSize;
grid.Physics.ApplyDeformation(BlockDefinition.FlameDamage, areaPlanar, areaVertical, gridPos, gridDir, MyDamageType.Environment, CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.1f : 0, attackerId: EntityId);
}
}
}
示例2: AfterStaticGridSpawn
public static void AfterStaticGridSpawn(MyCubeGrid grid)
{
Debug.Assert(grid.IsStatic);
MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
if (block != null)
{
MyCubeGrid mainGrid = grid.DetectMerge(block);
if (mainGrid == null)
mainGrid = grid;
mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(block));
if (MyFakes.ENABLE_SMALL_BLOCK_TO_LARGE_STATIC_CONNECTIONS)
{
MyCubeGridSmallToLargeConnection.Static.CheckBlockSmallToLargeConnect(block);
}
}
else
Debug.Fail("Block not created");
}
示例3: GetDefinitionOffsetWithNeighbours
public Vector3 GetDefinitionOffsetWithNeighbours(Vector3I cubePos, Vector3I bonePos, MyCubeGrid grid)
{
Vector3I boneOffset = GetCubeBoneOffset(cubePos, bonePos);
if (m_tempAffectedCubes == null)
{
m_tempAffectedCubes = new List<Vector3I>();
}
m_tempAffectedCubes.Clear();
GetAffectedCubes(cubePos, boneOffset, m_tempAffectedCubes, grid);
Vector3 offset = Vector3.Zero;
int affectedCount = 0;
foreach (var cube in m_tempAffectedCubes)
{
var cubeBlock = grid.GetCubeBlock(cube);
if (cubeBlock != null && cubeBlock.BlockDefinition.Skeleton != null)
{
Vector3I currentBoneOffset = GetCubeBoneOffset(cube, bonePos);
var defOffset = GetDefinitionOffset(cubeBlock, currentBoneOffset);
if (defOffset != null)
{
offset += defOffset.Value;
affectedCount++;
}
}
}
if (affectedCount == 0)
{
return offset;
}
return offset / affectedCount;
}
示例4: AfterGridBuild
public static void AfterGridBuild(MyEntity builder, MyCubeGrid grid)
{
if (grid != null)
{
MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
if (block != null)
{
if (grid.IsStatic)
{
MyCubeGrid mainGrid = grid.DetectMerge(block);
if (mainGrid == null)
mainGrid = grid;
mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(block));
if (MyFakes.ENABLE_SMALL_BLOCK_TO_LARGE_STATIC_CONNECTIONS)
{
MyCubeGridSmallToLargeConnection.Static.AddBlockSmallToLargeConnection(block);
}
}
if (Sync.IsServer)
{
MyCubeBuilder.BuildComponent.AfterGridCreated(grid, builder);
}
}
else
Debug.Fail("Block not created");
}
}
示例5: OnWorldPosChanged
public void OnWorldPosChanged(ref MatrixD newTransform)
{
MatrixD worldPos = newTransform;
m_caster.OnWorldPositionChanged(ref worldPos);
var entitiesInRange = this.m_caster.EntitiesInRange;
float closestDistance = float.MaxValue;
MyEntity closestEntity = null;
if (!m_isPointOfRefSet)
m_pointOfReference = worldPos.Translation;
if (entitiesInRange != null && entitiesInRange.Count > 0)
{
// int i = 0;
foreach (var entity in entitiesInRange.Values)
{
float distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_pointOfReference);
if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
{
if (distanceSq < closestDistance)
{
closestEntity = entity.Entity;
this.m_distanceToHitSq = distanceSq;
this.m_hitPosition = entity.DetectionPoint;
closestDistance = distanceSq;
}
}
// ++i;
}
}
this.m_hitCubeGrid = closestEntity as MyCubeGrid;
this.m_hitBlock = null;
this.m_hitDestroaybleObj = closestEntity as IMyDestroyableObject;
this.m_hitFloatingObject = closestEntity as MyFloatingObject;
this.m_hitCharacter = closestEntity as MyCharacter;
if (m_hitCubeGrid != null)
{
var invWorld = m_hitCubeGrid.PositionComp.WorldMatrixNormalizedInv;
var gridLocalPos = Vector3D.Transform(this.m_hitPosition, invWorld);
Vector3I blockPos;
m_hitCubeGrid.FixTargetCube(out blockPos, gridLocalPos / m_hitCubeGrid.GridSize);
m_hitBlock = m_hitCubeGrid.GetCubeBlock(blockPos);
}
}
示例6: TryDrillBlocks
protected virtual bool TryDrillBlocks(MyCubeGrid grid, Vector3 worldPoint, bool onlyCheck)
{
var invWorld = grid.PositionComp.GetWorldMatrixNormalizedInv();
var gridLocalPosCenter = Vector3.Transform(m_sensor.Center, invWorld);
var gridLocalPos = Vector3.Transform(m_sensor.FrontPoint, invWorld);
var gridLocalTarget = Vector3.Transform(worldPoint, invWorld);
var gridSpacePos = Vector3I.Round(gridLocalPos / grid.GridSize);
var block = grid.GetCubeBlock(gridSpacePos);
bool createDebris = false;
if (!onlyCheck)
{
if (block != null && block is IMyDestroyableObject && block.CubeGrid.BlocksDestructionEnabled)
{
var destroyable = (block as IMyDestroyableObject);
destroyable.DoDamage(60, MyDamageType.Drill, Sync.IsServer);
createDebris = grid.Physics.ApplyDeformation(0.25f, 1.5f, 2f, gridLocalTarget, Vector3.Normalize(gridLocalPos - gridLocalPosCenter), MyDamageType.Drill);
}
}
m_target = createDebris ? null : block;
bool success = false;
if (block != null)
{
if (createDebris)
{
BoundingSphereD bsphere = m_cutOut.Sphere;
BoundingBoxD aabb = BoundingBoxD.CreateFromSphere(bsphere);
MyDebris.Static.CreateExplosionDebris(ref bsphere, block.CubeGrid, ref aabb, 0.3f);
}
success = true;
}
return success;
}
示例7: GetBlocksInMultiBlock
/// <summary>
/// Writes multiblocks (compound block and block ID) to outMultiBlocks collection with the same multiblockId.
/// </summary>
public static void GetBlocksInMultiBlock(MyCubeGrid grid, Vector3I minPosition, Vector3I maxPosition, MyMultiBlockDefinition multiBlockDefinition, int multiBlockId,
HashSet<Tuple<MySlimBlock, ushort?>> outMultiBlocks)
{
Debug.Assert(multiBlockId != 0);
if (multiBlockId == 0)
return;
Vector3I cube = minPosition;
for (Vector3I.RangeIterator it = new Vector3I.RangeIterator(ref minPosition, ref maxPosition); it.IsValid(); it.GetNext(out cube))
{
MySlimBlock slimBlock = grid.GetCubeBlock(cube);
if (slimBlock == null)
continue;
MyCompoundCubeBlock compound = slimBlock.FatBlock as MyCompoundCubeBlock;
if (compound != null)
{
m_tmpSlimBlocks.Clear();
foreach (var blockInCompound in compound.GetBlocks(m_tmpSlimBlocks))
{
if (blockInCompound.MultiBlockDefinition == multiBlockDefinition && blockInCompound.MultiBlockId == multiBlockId)
{
ushort? blockInCompoundId = compound.GetBlockId(blockInCompound);
outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, blockInCompoundId));
}
}
m_tmpSlimBlocks.Clear();
}
else
{
MyFracturedBlock fracturedBlock = slimBlock.FatBlock as MyFracturedBlock;
if (fracturedBlock != null)
{
if (fracturedBlock.IsMultiBlockPart(multiBlockDefinition.Id, multiBlockId))
outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, null));
}
else
{
if (slimBlock.MultiBlockDefinition == multiBlockDefinition && slimBlock.MultiBlockId == multiBlockId)
outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, null));
}
}
}
}
示例8: TryDrillBlocks
protected virtual bool TryDrillBlocks(MyCubeGrid grid, Vector3 worldPoint, bool onlyCheck, out MyStringHash blockMaterial)
{
var invWorld = grid.PositionComp.WorldMatrixNormalizedInv;
var gridLocalPosCenter = Vector3.Transform(m_sensor.Center, invWorld);
var gridLocalPos = Vector3.Transform(m_sensor.FrontPoint, invWorld);
var gridLocalTarget = Vector3.Transform(worldPoint, invWorld);
var gridSpacePos = Vector3I.Round(gridLocalPos / grid.GridSize);
var block = grid.GetCubeBlock(gridSpacePos);
if (block != null)
{
if (block.BlockDefinition.PhysicalMaterial.Id.SubtypeId == MyStringHash.NullOrEmpty)
blockMaterial = m_metalMaterial;
else
blockMaterial = block.BlockDefinition.PhysicalMaterial.Id.SubtypeId;
}
else
blockMaterial = MyStringHash.NullOrEmpty;
int createDebris = 0;
if (!onlyCheck)
{
if (block != null && block is IMyDestroyableObject && block.CubeGrid.BlocksDestructionEnabled)
{
var destroyable = (block as IMyDestroyableObject);
destroyable.DoDamage(60, MyDamageType.Drill, Sync.IsServer, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
createDebris = grid.Physics.ApplyDeformation(0.25f, 1.5f, 2f, gridLocalTarget, Vector3.Normalize(gridLocalPos - gridLocalPosCenter), MyDamageType.Drill, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
}
}
m_target = createDebris != 0 ? null : block;
bool success = false;
if (block != null)
{
if (createDebris != 0)
{
BoundingSphereD bsphere = m_cutOut.Sphere;
BoundingBoxD aabb = BoundingBoxD.CreateFromSphere(bsphere);
MyDebris.Static.CreateExplosionDebris(ref bsphere, block.CubeGrid, ref aabb, 0.3f);
}
success = true;
}
return success;
}
示例9: AfterGridBuild
protected static void AfterGridBuild(MyEntity builder, MyCubeGrid grid, bool instantBuild)
{
if (grid != null)
{
MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
if (block != null)
{
if (grid.IsStatic)
{
MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
MySlimBlock blockInCompound = compoundBlock != null && compoundBlock.GetBlocksCount() > 0 ? compoundBlock.GetBlocks()[0] : null;
MyCubeGrid mainGrid = grid.DetectMerge(block);
if (mainGrid == null)
mainGrid = grid;
MySlimBlock mainBlock = block;
if (blockInCompound != null)
{
Debug.Assert(blockInCompound.CubeGrid == mainGrid);
mainBlock = mainGrid.GetCubeBlock(blockInCompound.Position);
}
mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(mainBlock));
if (MyCubeGridSmallToLargeConnection.Static != null)
{
if (Sync.IsServer && !MyCubeGridSmallToLargeConnection.Static.AddBlockSmallToLargeConnection(block) && grid.GridSizeEnum == MyCubeSize.Small)
block.CubeGrid.TestDynamic = true;
}
}
if (Sync.IsServer)
{
MyCubeBuilder.BuildComponent.AfterSuccessfulBuild(builder, instantBuild);
}
if (block.FatBlock != null)
block.FatBlock.OnBuildSuccess(builder.EntityId);
}
else
Debug.Fail("Block not created");
}
}
示例10: AfterGridBuild
public static void AfterGridBuild(MyEntity builder, MyCubeGrid grid)
{
if (grid != null)
{
MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
if (block != null)
{
if (grid.IsStatic)
{
MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
MySlimBlock blockInCompound = compoundBlock != null && compoundBlock.GetBlocksCount() > 0 ? compoundBlock.GetBlocks()[0] : null;
MyCubeGrid mainGrid = grid.DetectMerge(block);
if (mainGrid == null)
mainGrid = grid;
MySlimBlock mainBlock = block;
if (blockInCompound != null)
{
Debug.Assert(blockInCompound.CubeGrid == mainGrid);
mainBlock = mainGrid.GetCubeBlock(blockInCompound.Position);
}
mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(mainBlock));
if (MyFakes.ENABLE_SMALL_BLOCK_TO_LARGE_STATIC_CONNECTIONS)
{
if (!MyCubeGridSmallToLargeConnection.Static.AddBlockSmallToLargeConnection(block) && grid.GridSizeEnum == MyCubeSize.Small)
block.CubeGrid.TestDynamic = true;
}
}
if (Sync.IsServer)
{
MyCubeBuilder.BuildComponent.AfterGridCreated(grid, builder);
}
}
else
Debug.Fail("Block not created");
}
}