本文整理汇总了C#中IMyCubeGrid.GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IMyCubeGrid.GetPosition方法的具体用法?C# IMyCubeGrid.GetPosition怎么用?C# IMyCubeGrid.GetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMyCubeGrid
的用法示例。
在下文中一共展示了IMyCubeGrid.GetPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDistanceBetweenGridAndPlayer
public static bool GetDistanceBetweenGridAndPlayer(IMyCubeGrid grid, IMyPlayer player, out double distance)
{
distance = 0d;
try
{
if (player.Controller == null || player.Controller.ControlledEntity == null || player.Controller.ControlledEntity.Entity == null)
return false;
Vector3D playerPosition = player.Controller.ControlledEntity.Entity.GetPosition();
distance = Vector3D.Distance(grid.GetPosition(), playerPosition);
}
catch (Exception ex)
{
Logging.WriteLineAndConsole("GetDistanceBetweenGridAndPlayer(): {0}", ex.ToString());
return false;
}
return true;
}
示例2: MoveShipToVoxel
public static bool MoveShipToVoxel(IMyCubeGrid sourceGrid, IMyVoxelBase targetVoxel, bool safely,
Action<Vector3D> updatedPosition, Action emptySourceMessage, Action emptyTargetMessage, Action noSafeLocationMessage)
{
// TODO: find a more accurate position to transport a ship to around a planet and asteroid.
var worldOffset = targetVoxel.WorldMatrix.Translation - sourceGrid.GetPosition();
return MoveShipByOffset(sourceGrid, worldOffset, safely, updatedPosition, noSafeLocationMessage);
}
示例3: GetBoundingBox
public static OrientedBoundingBoxD GetBoundingBox(IMyCubeGrid entity)
{
var min = new Vector3D(int.MaxValue, int.MaxValue, int.MaxValue);
var max = new Vector3D(int.MinValue, int.MinValue, int.MinValue);
float multiplier = 2.5f;
if (entity.GridSizeEnum == MyCubeSize.Small)
multiplier = 0.5f;
List<IMySlimBlock> blocks = new List<IMySlimBlock>();
entity.GetBlocks(blocks, null);
foreach (IMySlimBlock block in blocks)
{
//Vector3 pos = Entity.GetBlockEntityPosition(block);
min = Vector3D.Min(block.Position * multiplier, min);
max = Vector3D.Max(block.Position * multiplier, max);
}
Vector3D size = max - min;
BoundingBoxD bb = new BoundingBoxD(new Vector3D(0, 0, 0), size).Translate(entity.GetPosition() - (size / 2));
return new OrientedBoundingBoxD(bb.Center, bb.HalfExtents, Quaternion.CreateFromRotationMatrix(entity.WorldMatrix.GetOrientation()));
}
示例4: CheckRevealBlockRules
private static bool CheckRevealBlockRules(IMyCubeGrid grid, List<IMyPlayer> players, out string reason)
{
reason = "";
// This is actually faster, but doesn't include power checks
// Live dangerously
List<IMySlimBlock> blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, x => x.FatBlock != null);
//CubeGrids.GetAllConnectedBlocks(m_processedGrids, grid, blocks, x => x.FatBlock != null);
//bool found = false;
//bool powered = false;
foreach (IMySlimBlock block in blocks)
{
IMyCubeBlock cubeBlock = block.FatBlock;
if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
{
//MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.IMyBeacon)cubeBlock;
if (!beacon.Enabled)
continue;
//Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
//if (!functionalBlock.Enabled)
// continue;
//Console.WriteLine("Beacon: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
//if (!terminalBlock.IsWorking)
// continue;
foreach (IMyPlayer player in players)
{
double distance = 0d;
if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
{
if (distance < beacon.Radius)
{
//found = true;
//break;
reason = string.Format("{0} distance to beacon broadcast: {1}", player.DisplayName, distance);
return true;
}
}
}
}
if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
{
//MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
Sandbox.ModAPI.Ingame.IMyRadioAntenna antenna = (Sandbox.ModAPI.Ingame.IMyRadioAntenna)cubeBlock;
if (!antenna.Enabled)
continue;
//Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
//if (!functionalBlock.Enabled)
// continue;
foreach (IMyPlayer player in players)
{
double distance = 0d;
if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
{
if (distance < antenna.Radius)
{
//found = true;
//break;
reason = string.Format("{0} distance to antenna broadcast: {1}", player.DisplayName, distance);
return true;
}
}
}
}
if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
{
//MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock;
if (!medical.Enabled)
continue;
Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
if (!functionalBlock.IsFunctional)
continue;
//if (!functionalBlock.Enabled)
// continue;
if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
{
lock (m_online)
{
foreach (ulong connectedPlayer in m_online)
{
long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
//if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
if (functionalBlock.OwnerId == playerId)
{
reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
return true;
//.........这里部分代码省略.........
示例5: CheckConcealBlockRules
private static bool CheckConcealBlockRules(IMyCubeGrid grid, List<IMyPlayer> players)
{
List<IMySlimBlock> blocks = new List<IMySlimBlock>();
// Live dangerously
grid.GetBlocks(blocks, x => x.FatBlock != null);
//CubeGrids.GetAllConnectedBlocks(m_processedGrids, grid, blocks, x => x.FatBlock != null);
int beaconCount = 0;
//bool found = false;
//bool powered = false;
foreach (IMySlimBlock block in blocks)
{
IMyCubeBlock cubeBlock = block.FatBlock;
if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
{
Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.IMyBeacon)cubeBlock;
//MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
beaconCount++;
// Keep this return here, as 4 beacons always means true
if(beaconCount >= 4)
{
return true;
}
if (!beacon.Enabled)
continue;
Sandbox.ModAPI.Ingame.IMyTerminalBlock terminalBlock = (Sandbox.ModAPI.Ingame.IMyTerminalBlock)cubeBlock;
// Console.WriteLine("Found: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
//if (!terminalBlock.IsWorking)
//{
// continue;
//}
foreach(IMyPlayer player in players)
{
double distance = 0d;
if(Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
{
if (distance < beacon.Radius)
{
// Console.WriteLine("Not concealed due to broadcast radius");
//found = true;
//break;
return true;
}
}
}
}
if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
{
//MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
Sandbox.ModAPI.Ingame.IMyRadioAntenna antenna = (Sandbox.ModAPI.Ingame.IMyRadioAntenna)cubeBlock;
if (!antenna.Enabled)
continue;
Sandbox.ModAPI.Ingame.IMyTerminalBlock terminalBlock = (Sandbox.ModAPI.Ingame.IMyTerminalBlock)cubeBlock;
//if (!terminalBlock.IsWorking)
// continue;
foreach (IMyPlayer player in players)
{
double distance = 0d;
if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
{
if (distance < antenna.Radius)
{
// Console.WriteLine("Not concealed due to antenna broadcast radius");
//found = true;
//break;
return true;
}
}
}
}
if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
{
//MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
Sandbox.ModAPI.Ingame.IMyMedicalRoom medical = (Sandbox.ModAPI.Ingame.IMyMedicalRoom)cubeBlock;
if (!medical.Enabled)
continue;
Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
//if (!terminalBlock.IsWorking)
// continue;
if(PluginSettings.Instance.DynamicConcealIncludeMedBays)
{
lock (m_online)
{
foreach (ulong connectedPlayer in m_online)
{
//if (PlayerMap.Instance.GetPlayerIdsFromSteamId(connectedPlayer).Count < 1)
//continue;
//.........这里部分代码省略.........
示例6: getPlayersNearGrid
/// <summary>
/// Returns a list of players near a grid. Used to send messages
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private List<long> getPlayersNearGrid(IMyCubeGrid grid)
{
log("Getting players near grid " + grid.DisplayName);
Vector3 gridPos = grid.GetPosition();
VRageMath.Vector3 gridSize = grid.LocalAABB.Size;
float gridMaxLength =
Math.Max(gridSize.X, Math.Max(gridSize.Y, gridSize.Z));
int maxDistFromGrid = (int)gridMaxLength + INGAME_PLACEMENT_MAX_DISTANCE;
List<IMyPlayer> allPlayers = new List<IMyPlayer>();
MyAPIGateway.Players.GetPlayers(allPlayers);
float pDistFromGrid = 0.0f;
List<long> nearbyPlayerIds = new List<long>();
foreach (IMyPlayer p in allPlayers)
{
pDistFromGrid = VRageMath.Vector3.Distance(p.GetPosition(), gridPos);
if (pDistFromGrid < maxDistFromGrid) {
nearbyPlayerIds.Add((long)p.PlayerID);
}
}
log(nearbyPlayerIds.Count + " Nearby players: " + String.Join(" ,", nearbyPlayerIds));
return nearbyPlayerIds;
}
示例7: DoesGridHaveTarget
private static bool DoesGridHaveTarget(IMyCubeGrid grid, IMySlimBlock block, bool disabling = false)
{
if (_scanCache.Count < 1)
{
BoundingSphereD sphere = new BoundingSphereD(grid.GetPosition(), PluginSettings.Instance.DynamicTurretTargetDistance);
_scanCache = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
}
/*
HashSet<IMyEntity> testEntities = new HashSet<IMyEntity>();
try
{
MyAPIGateway.Entities.GetEntities(testEntities);
}
catch
{
return false;
}
*/
//bool found = false;
foreach (IMyEntity testEntity in _scanCache)
{
if (grid == testEntity)
continue;
if (!testEntity.InScene)
continue;
if (testEntity is IMyCubeBlock)
{
continue;
/*
IMyCubeBlock cubeBlock = (IMyCubeBlock)testEntity;
if (cubeBlock.OwnerId == 0)
continue;
if (PluginSettings.Instance.DynamicTurretManagementMode == DynamicTurretManagementMode.AllButOwner)
{
if (block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) != Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Owner)
{
Console.WriteLine("Block: Not owner");
return true;
}
}
if (PluginSettings.Instance.DynamicTurretManagementMode == DynamicTurretManagementMode.NeutralAndEnemy)
{
if (block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Enemies ||
block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Neutral)
{
Console.WriteLine("Block: Enemy or Neutral: {0} {1} {2}", cubeBlock.OwnerId, cubeBlock.Parent.DisplayName, cubeBlock.BlockDefinition);
return true;
}
}
if (PluginSettings.Instance.DynamicTurretManagementMode == DynamicTurretManagementMode.Enemy)
{
if (block.FatBlock.GetUserRelationToOwner(cubeBlock.OwnerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Enemies)
{
// Console.WriteLine("Block: Enemy: {0} {1} {2}", cubeBlock.OwnerId, cubeBlock.Parent.DisplayName, cubeBlock.BlockDefinition);
return true;
}
}
*/
}
if (testEntity is IMyCubeGrid)
{
if (PluginSettings.Instance.DynamicTurretManagementMode == DynamicTurretManagementMode.All)
return true;
IMyCubeGrid testGrid = (IMyCubeGrid)testEntity;
// Always enable if grid has no owner. Seems suspect. Might be a user trying to abuse a no ownership ship.
/*
if (testGrid.BigOwners.Count < 1 && testGrid.SmallOwners.Count < 1)
{
//if(!(testEntity is IMyControllableEntity))
//Console.WriteLine("Grid: No owner");
return true;
}
*/
foreach (long owner in testGrid.BigOwners)
{
if (PluginSettings.Instance.DynamicTurretManagementMode == DynamicTurretManagementMode.AllButOwner)
{
if (block.FatBlock.GetUserRelationToOwner(owner) != MyRelationsBetweenPlayerAndBlock.Owner)
{
//Console.WriteLine("Grid: Not owner");
return true;
}
}
if (PluginSettings.Instance.DynamicTurretManagementMode == DynamicTurretManagementMode.NeutralAndEnemy)
{
if (block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Enemies ||
block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Neutral)
{
//Console.WriteLine("Grid: Enemy or Neutral: {0} {1}", owner, grid.DisplayName);
return true;
}
//.........这里部分代码省略.........