本文整理汇总了C#中Vector3D.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3D.IsValid方法的具体用法?C# Vector3D.IsValid怎么用?C# Vector3D.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3D
的用法示例。
在下文中一共展示了Vector3D.IsValid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public override bool Invoke(string messageText)
{
var match = Regex.Match(messageText, @"/flyto\s{1,}(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s{1,}(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s{1,}(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s{1,}(?<V>[+-]?((\d+(\.\d*)?)|(\.\d+)))", RegexOptions.IgnoreCase);
if (match.Success)
{
var destination = new Vector3D(
double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));
var velocity = double.Parse(match.Groups["V"].Value, CultureInfo.InvariantCulture);
if (destination.IsValid())
{
var entity = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity;
if (entity is IMyCubeBlock) entity = entity.Parent;
if (entity.Physics != null)
{
var position = entity.GetPosition();
var vector = Vector3D.Normalize(destination - position) * velocity;
entity.Physics.LinearVelocity = vector;
}
return true;
}
}
return false;
}
示例2: Invoke
public override bool Invoke(string messageText)
{
var match = Regex.Match(messageText, @"/setvector\s{1,}(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s{1,}(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s{1,}(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))", RegexOptions.IgnoreCase);
if (match.Success)
{
var targetVector = new Vector3D(
double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));
if (targetVector.IsValid())
{
var entity = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity;
if (entity is IMyCubeBlock) entity = entity.Parent;
if (entity.Physics != null)
{
entity.Physics.LinearVelocity = targetVector;
}
return true;
}
}
return false;
}
示例3: Invoke
public override bool Invoke(ulong steamId, long playerId, string messageText)
{
var match = Regex.Match(messageText, @"/createroid\s+(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Size>(\d+?))\s+(?<Name>.+)", RegexOptions.IgnoreCase);
if (match.Success)
{
var position = new Vector3D(
double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));
var length = int.Parse(match.Groups["Size"].Value, CultureInfo.InvariantCulture);
if (length < 1 || length % 64 != 0)
{
MyAPIGateway.Utilities.ShowMessage("Invalid", "Size specified.");
return true;
}
var size = new Vector3I(length, length, length);
var name = match.Groups["Name"].Value;
if (position.IsValid() && ((Vector3D)size).IsValid())
{
MyAPIGateway.Utilities.ShowMessage("Size", size.ToString());
var newName = Support.CreateUniqueStorageName(name);
// MyAPIGateway.Session.VoxelMaps.CreateVoxelMap will always create a square shaped asteroid.
// This is by design within the API itself and cannot be altered.
var newVoxelMap = Support.CreateNewAsteroid(newName, size, position);
return true;
}
}
return false;
}
示例4: Invoke
public override bool Invoke(string messageText)
{
var match = Regex.Match(messageText, @"/addvoxel\s+(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Name>.+)", RegexOptions.IgnoreCase);
if (match.Success)
{
var position = new Vector3D(
double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));
var searchName = match.Groups["Name"].Value;
string voxelName = null;
int index;
if (searchName.Substring(0, 1) == "#" && Int32.TryParse(searchName.Substring(1), out index) && index > 0 && index <= CommandVoxelsList.VoxelCache.Count)
{
voxelName = CommandVoxelsList.VoxelCache[index - 1];
}
if (voxelName == null)
{
var stockVoxel = MyDefinitionManager.Static.GetVoxelMapStorageDefinitions().FirstOrDefault(d => d.Id.SubtypeName.Equals(searchName, StringComparison.InvariantCultureIgnoreCase));
if (stockVoxel != null)
{
voxelName = stockVoxel.Id.SubtypeName;
}
}
if (voxelName == null)
{
MyAPIGateway.Utilities.ShowMessage("Failed", "Cannot find the specified Voxel '{0}'", searchName);
return true;
}
if (position.IsValid())
{
var uniqueName = Support.CreateUniqueStorageName(voxelName);
MyAPIGateway.Utilities.ShowMessage("Creating", "Asteroid '{0}'", uniqueName);
var newVoxelMap = MyAPIGateway.Session.VoxelMaps.CreateVoxelMapFromStorageName(uniqueName, voxelName, position);
return true;
}
}
return false;
}
示例5: Invoke
public override bool Invoke(string messageText)
{
if (MyAPIGateway.Session.OnlineMode != MyOnlineModeEnum.OFFLINE)
{
MyAPIGateway.Utilities.ShowMessage("Warning", "This command must be carried out in an 'Offline' game, as it is too processor intensive to run in a multiplayer game.");
return true;
}
var match = Regex.Match(messageText, @"/createroidsphere\s+(?<Name>[^\s]+)\s+(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Grid>(\d+?))(?:\s+(?<Material>[^\s]+)\s+(?<Diameter>[+-]?((\d+(\.\d*)?)|(\.\d+))))+", RegexOptions.IgnoreCase);
if (match.Success)
{
StringBuilder description;
var position = new Vector3D(
double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));
var grid = int.Parse(match.Groups["Grid"].Value, CultureInfo.InvariantCulture);
if (grid <= 1)
grid = 1;
else if (grid <= 2)
grid = 2;
else if (grid <= 4)
grid = 4;
else
grid = 8;
var layers = new List<AsteroidSphereLayer>();
double maxDiameter = 0;
for (var i = 0; i < match.Groups["Material"].Captures.Count; i++)
{
byte material = 0;
var checkName = match.Groups["Material"].Captures[i].Value;
var materialName = checkName;
if (checkName.Equals("none", StringComparison.InvariantCultureIgnoreCase))
{
material = 255;
}
else
{
MyVoxelMaterialDefinition materialDef;
string suggestedMaterials = "";
if (!Support.FindMaterial(checkName, out materialDef, ref suggestedMaterials))
{
MyAPIGateway.Utilities.ShowMessage("Invalid Material1 specified.", "Cannot find the material '{0}'.\r\nTry the following: {1}", checkName, suggestedMaterials);
return true;
}
materialName = materialDef.Id.SubtypeName;
material = materialDef.Index;
}
var diameter = double.Parse(match.Groups["Diameter"].Captures[i].Value, CultureInfo.InvariantCulture);
if (diameter < 4 || diameter > 5000)
{
MyAPIGateway.Utilities.ShowMessage("Invalid", "Diamater specified. Between 4 and 5000");
return true;
}
maxDiameter = Math.Max(maxDiameter, diameter);
layers.Add(new AsteroidSphereLayer() { Diameter = diameter, Material = material, MaterialName = materialName });
}
var length = (int)(maxDiameter + 4).RoundUpToNearest(64);
var size = new Vector3I(length, length, length);
var name = match.Groups["Name"].Value;
if (position.IsValid() && ((Vector3D)size).IsValid())
{
var boundingSphere = new BoundingSphereD(position, (maxDiameter + 2) / 2);
var floatingList = MyAPIGateway.Entities.GetEntitiesInSphere(ref boundingSphere);
floatingList = floatingList.Where(e =>
(e is Sandbox.ModAPI.IMyCubeGrid && ((Sandbox.ModAPI.IMyCubeGrid)e).IsStatic == false)
|| (e is Sandbox.ModAPI.IMyCubeBlock && ((Sandbox.ModAPI.IMyCubeGrid)((Sandbox.ModAPI.IMyCubeBlock)e).Parent).IsStatic == false)
|| (e is Sandbox.ModAPI.IMyCharacter)).ToList();
if (floatingList.Count > 0)
{
description = new StringBuilder();
description.AppendFormat(@"{0} items were found floating in the specified location.
The asteroid cannot be generated until this area is cleared of ships and players.", floatingList.Count);
MyAPIGateway.Utilities.ShowMissionScreen("Cannot generate Asteroid:", null, " ", description.ToString(), null, "OK");
return true;
}
var origin = new Vector3I(size.X / 2, size.Y / 2, size.Z / 2);
_startTime = DateTime.Now;
layers = layers.OrderByDescending(e => e.Diameter).ToList();
switch (grid)
{
case 1:
ProcessAsteroid(name, size, position, Vector3D.Zero, origin, layers);
break;
case 2:
//.........这里部分代码省略.........