本文整理汇总了C#中MyEntity.Where方法的典型用法代码示例。如果您正苦于以下问题:C# MyEntity.Where方法的具体用法?C# MyEntity.Where怎么用?C# MyEntity.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyEntity
的用法示例。
在下文中一共展示了MyEntity.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Command_Delete
protected void Command_Delete( ChatEvent chatEvent )
{
ulong remoteUserId = chatEvent.RemoteUserId;
List<string> commandParts = CommandParser.GetCommandParts( chatEvent.Message );
int paramCount = commandParts.Count - 1;
MyEntity[] entities = new MyEntity[0];
SandboxGameAssemblyWrapper.Instance.GameAction(() => entities = MyEntities.GetEntities().ToArray());
var toRemove = new HashSet<MyEntity>();
//All entities
if ( paramCount > 1 && commandParts[ 1 ].ToLower( ).Equals( "all" ) )
{
//All cube grids that have no beacon or only a beacon with no name
if ( commandParts[ 2 ].ToLower( ).Equals( "nobeacon" ) )
{
int removeCount = 0;
Parallel.ForEach(MyCubeGridGroups.Static.Logical.Groups, group =>
{
bool found = false;
foreach (var node in group.Nodes)
{
var grid = node.NodeData;
if (grid.MarkedForClose || grid.Closed)
continue;
if (grid.CubeBlocks.OfType<MyBeacon>().Any())
{
found = true;
break;
}
}
if (!found)
return;
removeCount++;
foreach (var closeNode in group.Nodes)
{
SandboxGameAssemblyWrapper.Instance.BeginGameAction(()=>closeNode.NodeData.Close(), null, null);
}
});
SendPrivateChatMessage(remoteUserId, $"{removeCount} cube grids have been removed");
}
//All cube grids that have no power
else if ( commandParts[ 2 ].ToLower( ).Equals( "nopower" ) )
{
//List<CubeGridEntity> entities = SectorObjectManager.Instance.GetTypedInternalData<CubeGridEntity>( );
//List<CubeGridEntity> entitiesToDispose = entities.Where( entity => entity.TotalPower <= 0 ).ToList( );
//foreach ( CubeGridEntity entity in entitiesToDispose )
//{
// entity.Dispose( );
//}
//SendPrivateChatMessage( remoteUserId, string.Format( "{0} cube grids have been removed", entitiesToDispose.Count ) );
SendPrivateChatMessage( remoteUserId, "Unpowered grids removal temporarily unavailable in this version." );
}
else if ( commandParts[ 2 ].ToLower( ).Equals( "floatingobjects" ) ) //All floating objects
{
int count = 0;
foreach (var floating in entities.Where(e => e is MyFloatingObject))
{
count++;
SandboxGameAssemblyWrapper.Instance.BeginGameAction(() => floating.Close(), null, null);
}
SendPrivateChatMessage(remoteUserId, $"Removed {count} floating objects");
}
else
{
string entityName = commandParts[ 2 ];
if ( commandParts.Count > 3 )
{
for ( int i = 3; i < commandParts.Count; i++ )
{
entityName += " " + commandParts[ i ];
}
}
int matchingEntitiesCount = 0;
foreach ( var entity in entities )
{
if (entity.MarkedForClose || entity.Closed)
continue;
bool isMatch = Regex.IsMatch( entity.Name, entityName, RegexOptions.IgnoreCase );
if ( !isMatch )
continue;
SandboxGameAssemblyWrapper.Instance.BeginGameAction(() => entity.Close(), null, null);
matchingEntitiesCount++;
}
SendPrivateChatMessage( remoteUserId, $"{matchingEntitiesCount} objects have been removed");
}
}
//.........这里部分代码省略.........