本文整理汇总了C#中Sandbox.Game.Entities.MyCubeGrid.GetBlocks方法的典型用法代码示例。如果您正苦于以下问题:C# MyCubeGrid.GetBlocks方法的具体用法?C# MyCubeGrid.GetBlocks怎么用?C# MyCubeGrid.GetBlocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sandbox.Game.Entities.MyCubeGrid
的用法示例。
在下文中一共展示了MyCubeGrid.GetBlocks方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyStructuralIntegrity
public MyStructuralIntegrity(MyCubeGrid cubeGrid)
{
m_cubeGrid = cubeGrid;
m_cubeGrid.OnBlockAdded += cubeGrid_OnBlockAdded;
switch (1)
{
case 0: m_simulator = new MyJacobianConstraintSimulator(m_cubeGrid.GetBlocks().Count); break;
case 1: m_simulator = new MyAdvancedStaticSimulator(m_cubeGrid); break;
case 2: m_simulator = new MyOndraSimulator(m_cubeGrid); break;
case 3: m_simulator = new MyOndraSimulator2(m_cubeGrid); break;
case 4: m_simulator = new MyOndraSimulator3(m_cubeGrid); break;
}
foreach (var block in m_cubeGrid.GetBlocks())
{
cubeGrid_OnBlockAdded(block);
}
}
示例2: GetBattlePoints
public static ulong GetBattlePoints(MyCubeGrid grid)
{
ulong points = 0;
foreach (var block in grid.GetBlocks())
{
MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
if (compoundBlock != null)
{
foreach (var blockInCompound in compoundBlock.GetBlocks())
points += GetBattlePoints(blockInCompound);
}
else
{
points += GetBattlePoints(block);
}
}
return points;
}
示例3: CheckMergeConnectivity
public static bool CheckMergeConnectivity(MyCubeGrid hitGrid, MyCubeGrid gridToMerge, Vector3I gridOffset)
{
// CH: Beware, this funtion seems horribly inefficient! Think twice before using it (e.g. don't use it in a 10000x loop) or optimize it :-)
MatrixI mergeTransform = hitGrid.CalculateMergeTransform(gridToMerge, gridOffset);
Quaternion mergeOri;
mergeTransform.GetBlockOrientation().GetQuaternion(out mergeOri);
foreach (var block in gridToMerge.GetBlocks())
{
Quaternion ori;
Vector3I pos = Vector3I.Transform(block.Position, mergeTransform);
block.Orientation.GetQuaternion(out ori);
//Matrix mergeGridMatrix = Matrix.CreateFromQuaternion(mergeOri);
//Matrix oriMatrix = Matrix.CreateFromQuaternion(ori);
//Matrix result = oriMatrix * mergeGridMatrix;
//Quaternion quatFromMatrix = Quaternion.CreateFromRotationMatrix(result);
// Seems that quaternion multiplication is reversed to matrix multiplication!
ori = mergeOri * ori;
var mountPoints = block.BlockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio);
if (MyCubeGrid.CheckConnectivity(hitGrid, block.BlockDefinition, mountPoints, ref ori, ref pos))
return true;
}
return false;
}
示例4: ShouldBeStatic
public static bool ShouldBeStatic(MyCubeGrid grid)
{
if (grid.GridSizeEnum == MyCubeSize.Small && MyCubeGridSmallToLargeConnection.Static != null &&
MyCubeGridSmallToLargeConnection.Static.TestGridSmallToLargeConnection(grid))
return true;
foreach (var block in grid.GetBlocks())
{
if (IsInVoxels(block))
return true;
}
return false;
}
示例5: AddGrid
public bool AddGrid(MyCubeGrid grid)
{
//TODO: create static list
List<Vector3I> lst = new List<Vector3I>();
foreach (var block in grid.GetBlocks())
{
if (block.FatBlock is MyCompoundCubeBlock)
{
bool added = false;
foreach (var subb in (block.FatBlock as MyCompoundCubeBlock).GetBlocks())
{
if (AddBlock(subb))
{
if (!added)
lst.Add(block.Position);
added = true;
}
}
}
else
{
if (AddBlock(block))
{
lst.Add(block.Position);
}
}
}
if (lst.Count > 0)
{
grid.RazeBlocks(lst);
return true;
}
return false;
}
示例6: GetTrashState
static MyTrashRemovalFlags GetTrashState(MyCubeGrid grid, MyTrashRemovalSettings settings, out float metric,bool checkGroup = false)
{
metric = -1;
HashSet<MySlimBlock> blocks = grid.GetBlocks();
if (blocks != null && blocks.Count > settings.BlockCountThreshold)
{
metric = settings.BlockCountThreshold;
return MyTrashRemovalFlags.WithBlockCount;
}
if (!settings.HasFlag(MyTrashRemovalFlags.Fixed) && grid.IsStatic)
return MyTrashRemovalFlags.Fixed;
bool isAccelerating = false;
bool isLinearMoving = false;
bool isStationary = true;
if (grid.Physics != null)
{
isAccelerating = grid.Physics.AngularAcceleration.AbsMax() > 0.05f || grid.Physics.LinearAcceleration.AbsMax() > 0.05f;
isStationary = grid.Physics.AngularVelocity.AbsMax() < 0.05f && grid.Physics.LinearVelocity.AbsMax() < 0.05f;
isLinearMoving = !isAccelerating && !isStationary;
}
if (!settings.HasFlag(MyTrashRemovalFlags.Stationary) && isStationary)
return MyTrashRemovalFlags.Stationary;
if (!settings.HasFlag(MyTrashRemovalFlags.Linear) && isLinearMoving)
return MyTrashRemovalFlags.Linear;
if (!settings.HasFlag(MyTrashRemovalFlags.Accelerating) && isAccelerating)
return MyTrashRemovalFlags.Accelerating;
if (grid.GridSystems != null)
{
bool isPowered = grid.GridSystems.ResourceDistributor.ResourceStateByType(MyResourceDistributorComponent.ElectricityId) != MyResourceStateEnum.NoPower;
if (!settings.HasFlag(MyTrashRemovalFlags.Powered) && isPowered)
return MyTrashRemovalFlags.Powered;
if (!settings.HasFlag(MyTrashRemovalFlags.Controlled) && grid.GridSystems.ControlSystem.IsControlled)
return MyTrashRemovalFlags.Controlled;
if (!settings.HasFlag(MyTrashRemovalFlags.WithProduction) && grid.GridSystems.ControlSystem.IsControlled)
return MyTrashRemovalFlags.WithProduction;
}
if (!settings.HasFlag(MyTrashRemovalFlags.WithMedBay) && grid.BlocksCounters.GetValueOrDefault(typeof(MyObjectBuilder_MedicalRoom)) > 0)
return MyTrashRemovalFlags.WithMedBay;
if (IsCloseToPlayerOrCamera(grid, settings.PlayerDistanceThreshold))
{
metric = settings.PlayerDistanceThreshold;
return MyTrashRemovalFlags.DistanceFromPlayer;
}
if (checkGroup && MyCubeGridGroups.Static.Physical != null)
{
var physicalGroup = MyCubeGridGroups.Static.Physical.GetGroup(grid);
if (physicalGroup != null)
{
foreach (var cubeGrid in physicalGroup.Nodes)
{
if (cubeGrid.NodeData == null || cubeGrid.NodeData.Physics == null || cubeGrid.NodeData.Physics.Shape == null || cubeGrid.NodeData == grid)
continue;
var subGridReason = GetTrashState(cubeGrid.NodeData, settings, out metric, false);
if (subGridReason != MyTrashRemovalFlags.None)
{
return subGridReason;
}
}
}
}
return MyTrashRemovalFlags.None;
}
示例7: MyOndraSimulator3
public MyOndraSimulator3(MyCubeGrid grid)
{
m_grid = grid;
m_selectedGrid = m_grid;
SelectedCube = m_grid.GetBlocks().First().Position;
}
示例8: MyAdvancedStaticSimulator
public MyAdvancedStaticSimulator(MyCubeGrid grid)
{
m_grid = grid;
m_selectedGrid = m_grid;
if (m_grid.BlocksCount > 0)
SelectedCube = m_grid.GetBlocks().First().Position;
}
示例9: AddGrid
public bool AddGrid(MyCubeGrid grid)
{
HashSet<Sandbox.Game.Entities.Cube.MySlimBlock> lst = new HashSet<Sandbox.Game.Entities.Cube.MySlimBlock>();
foreach(var b in grid.GetBlocks())
{
if(b.FatBlock is MyCompoundCubeBlock)
{
foreach(var subb in (b.FatBlock as MyCompoundCubeBlock).GetBlocks())
{
if (AddBlock(subb))
lst.Add(b);
}
}
else
{
if (AddBlock(b))
lst.Add(b);
}
}
foreach(var b in lst)
{
grid.RemoveBlock(b);
}
return lst.Count > 0;
//grid.Close();
}
示例10: AddGrid
public bool AddGrid(MyCubeGrid grid)
{
HashSet<Sandbox.Game.Entities.Cube.MySlimBlock> lst = new HashSet<Sandbox.Game.Entities.Cube.MySlimBlock>();
foreach (var block in grid.GetBlocks())
{
if (block.FatBlock is MyCompoundCubeBlock)
{
bool added = false;
foreach (var subb in (block.FatBlock as MyCompoundCubeBlock).GetBlocks())
{
if (AddBlock(subb))
{
added = true;
}
}
if (added)
{
lst.Add(block);
}
}
else
{
if (AddBlock(block))
{
lst.Add(block);
}
}
}
foreach (var b in lst)
{
Vector3I pos = b.Position;
Vector3UByte size = new Vector3UByte(1, 1, 1);
grid.RazeBlocks(ref pos, ref size);
// grid.RemoveBlock(b, true); not synced
}
return lst.Count > 0;
}
示例11: ShouldBeStatic
static bool ShouldBeStatic(MyCubeGrid grid, MyCubeGrid.MyTestDynamicReason testReason)
{
if (grid.GridSizeEnum == MyCubeSize.Small && MyCubeGridSmallToLargeConnection.Static != null &&
MyCubeGridSmallToLargeConnection.Static.TestGridSmallToLargeConnection(grid))
return true;
if (testReason == MyTestDynamicReason.GridSplit)
{
foreach (var block in grid.GetBlocks())
{
if (IsInVoxels(block))
return true;
}
return false;
}
return grid.IsStatic;
}
示例12: CheckValidBlocksRotation
public static bool CheckValidBlocksRotation(Matrix gridLocalMatrix, MyCubeGrid grid)
{
Matrix blockLocalMatrix;
bool retval = true;
foreach (var block in grid.GetBlocks())
{
MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
if (compoundBlock != null)
{
foreach (var blockInCompound in compoundBlock.GetBlocks())
{
blockInCompound.Orientation.GetMatrix(out blockLocalMatrix);
blockLocalMatrix = blockLocalMatrix * gridLocalMatrix;
retval = retval && CheckValidBlockRotation(blockLocalMatrix, blockInCompound.BlockDefinition.Direction, blockInCompound.BlockDefinition.Rotation);
if (!retval)
break;
}
}
else
{
block.Orientation.GetMatrix(out blockLocalMatrix);
blockLocalMatrix = blockLocalMatrix * gridLocalMatrix;
retval = retval && CheckValidBlockRotation(blockLocalMatrix, block.BlockDefinition.Direction, block.BlockDefinition.Rotation);
}
if (!retval)
break;
}
return retval;
}