本文整理汇总了C#中Main.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Main.Add方法的具体用法?C# Main.Add怎么用?C# Main.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Main
的用法示例。
在下文中一共展示了Main.Add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reload
public static void Reload(Main main, bool deleteEditor = true)
{
main.LoadingMap.Execute(main.MapFile);
using (Stream stream = new MemoryStream())
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Entity>));
serializer.Serialize(stream, main.Entities.Where(x => x.Serialize).ToList());
main.ClearEntities(deleteEditor);
stream.Seek(0, SeekOrigin.Begin);
List<Entity> entities = (List<Entity>)serializer.Deserialize(stream);
foreach (Entity entity in entities)
{
Factory factory = Factory.Get(entity.Type);
factory.Bind(entity, main);
main.Add(entity);
}
}
main.MapLoaded.Execute();
}
示例2: Load
private static void Load(Main main, Stream stream, bool deleteEditor = true)
{
main.Camera.Position.Value = new Vector3(0, -10000, 0);
main.IsLoadingMap = true;
main.ClearEntities(deleteEditor);
List<Entity> entities = null;
try
{
entities = (List<Entity>)MapLoader.Serializer.Deserialize(stream);
}
catch (InvalidOperationException e)
{
throw new Exception("Failed to deserialize file stream.", e);
}
foreach (Entity entity in entities)
{
Factory<Main> factory = Factory<Main>.Get(entity.Type);
factory.Bind(entity, main);
main.Add(entity);
}
main.IsLoadingMap = false;
main.MapLoaded.Execute();
}
示例3: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
Transform transform = result.Get<Transform>();
EnemyBase enemy = result.GetOrCreate<EnemyBase>("Base");
PlayerCylinderTrigger trigger = result.Get<PlayerCylinderTrigger>();
PointLight light = result.GetOrCreate<PointLight>();
light.Color.Value = new Vector3(1.3f, 0.5f, 0.5f);
light.Attenuation.Value = 15.0f;
light.Shadowed.Value = false;
light.Serialize = false;
ListProperty<Entity.Handle> dynamicMaps = result.GetListProperty<Entity.Handle>("DynamicMaps");
Property<float> timeUntilRebuild = result.GetProperty<float>("TimeUntilRebuild");
Property<float> timeUntilRebuildComplete = result.GetProperty<float>("TimeUntilRebuildComplete");
Property<float> rebuildDelay = result.GetProperty<float>("RebuildDelay");
Property<float> rebuildTime = result.GetProperty<float>("RebuildTime");
const float rebuildTimeMultiplier = 0.03f;
enemy.Add(new CommandBinding(enemy.Delete, result.Delete));
enemy.Add(new Binding<Matrix>(enemy.Transform, transform.Matrix));
light.Add(new Binding<Vector3>(light.Position, enemy.Position));
trigger.Add(new Binding<Matrix>(trigger.Transform, () => Matrix.CreateTranslation(0.0f, 0.0f, enemy.Offset) * transform.Matrix, transform.Matrix, enemy.Offset));
Action<Entity> fall = delegate(Entity player)
{
if (timeUntilRebuild.Value > 0 || timeUntilRebuildComplete.Value > 0)
return;
if (!enemy.IsValid)
{
result.Delete.Execute();
return;
}
// Disable the cell-emptied notification.
// This way, we won't think that the base has been destroyed by the player.
// We are not in fact dying, we're just destroying the base so we can fall over.
enemy.EnableCellEmptyBinding = false;
Map m = enemy.Map.Value.Target.Get<Map>();
m.Empty(enemy.BaseBoxes.SelectMany(x => x.GetCoords()));
m.Regenerate(delegate(List<DynamicMap> spawnedMaps)
{
Vector3 playerPos = player.Get<Transform>().Position;
playerPos += player.Get<Player>().LinearVelocity.Value * 0.65f;
foreach (DynamicMap newMap in spawnedMaps)
{
Vector3 toPlayer = playerPos - newMap.PhysicsEntity.Position;
toPlayer.Normalize();
if (Math.Abs(toPlayer.Y) < 0.9f)
{
toPlayer *= 25.0f * newMap.PhysicsEntity.Mass;
Vector3 positionAtPlayerHeight = newMap.PhysicsEntity.Position;
Vector3 impulseAtBase = toPlayer * -0.75f;
impulseAtBase.Y = 0.0f;
positionAtPlayerHeight.Y = playerPos.Y;
newMap.PhysicsEntity.ApplyImpulse(ref positionAtPlayerHeight, ref impulseAtBase);
newMap.PhysicsEntity.ApplyLinearImpulse(ref toPlayer);
}
newMap.PhysicsEntity.Material.KineticFriction = 1.0f;
newMap.PhysicsEntity.Material.StaticFriction = 1.0f;
dynamicMaps.Add(newMap.Entity);
}
});
timeUntilRebuild.Value = rebuildDelay;
};
result.Add(new PostInitialization
{
delegate()
{
foreach (Entity.Handle map in dynamicMaps)
{
if (map.Target != null)
{
BEPUphysics.Entities.MorphableEntity e = map.Target.Get<DynamicMap>().PhysicsEntity;
e.Material.KineticFriction = 1.0f;
e.Material.StaticFriction = 1.0f;
}
}
}
});
result.Add(new CommandBinding<Entity>(trigger.PlayerEntered, fall));
result.Add(new Updater
{
delegate(float dt)
{
if (timeUntilRebuild > 0)
{
if (enemy.Map.Value.Target == null || !enemy.Map.Value.Target.Active)
//.........这里部分代码省略.........
示例4: Transition
public static void Transition(Main main, string nextMap, string spawn = null)
{
Container loadingNotification = new Container();
loadingNotification.Tint.Value = Microsoft.Xna.Framework.Color.Black;
loadingNotification.Opacity.Value = UIFactory.Opacity;
TextElement loadingNotificationText = new TextElement();
loadingNotificationText.Name.Value = "Text";
loadingNotificationText.FontFile.Value = main.Font;
loadingNotificationText.Text.Value = "\\loading";
loadingNotification.Children.Add(loadingNotificationText);
Animation anim = new Animation
(
new Animation.Set<bool>(main.Menu.CanPause, false),
main.Spawner.FlashAnimation(),
new Animation.Execute(delegate()
{
main.UI.Root.GetChildByName("Notifications").Children.Add(loadingNotification);
}),
new Animation.Delay(0.01f),
new Animation.Execute(delegate()
{
#if DEMO
if (nextMap == "forest")
{
main.Spawner.StartSpawnPoint.Value = "demo";
MapLoader.Load(main, Main.MenuMap);
}
else
#endif
{
// We are exiting the map; just save the state of the map without the player.
ListProperty<RespawnLocation> respawnLocations = PlayerDataFactory.Instance.Get<PlayerData>().RespawnLocations;
respawnLocations.Clear();
List<Entity> persistentEntities = main.Entities.Where((Func<Entity, bool>)MapLoader.entityIsPersistent).ToList();
Stream stream = new MemoryStream();
IO.MapLoader.Serializer.Serialize(stream, persistentEntities);
foreach (Entity e in persistentEntities)
e.Delete.Execute();
main.Spawner.StartSpawnPoint.Value = spawn;
if (PlayerFactory.Instance != null)
PlayerFactory.Instance.Delete.Execute();
main.SaveCurrentMap(null, default(Point));
MapLoader.Load(main, nextMap);
stream.Seek(0, SeekOrigin.Begin);
List<Entity> entities = (List<Entity>)IO.MapLoader.Serializer.Deserialize(stream);
foreach (Entity e in entities)
{
Factory<Main> factory = Factory<Main>.Get(e.Type);
e.GUID = 0;
factory.Bind(e, main);
main.Add(e);
}
stream.Dispose();
}
}),
new Animation.Delay(0.01f),
new Animation.Execute(loadingNotification.Delete),
new Animation.Set<bool>(main.Menu.CanPause, true),
new Animation.Execute(main.ScheduleSave)
);
anim.EnabledWhenPaused = false;
main.AddComponent(anim);
}
示例5: LoadWithEntities
public static void LoadWithEntities(Main main, string nextMap, List<Entity> persistentEntities)
{
Stream stream = new MemoryStream();
IO.MapLoader.Serializer.Serialize(stream, persistentEntities);
MapLoader.Load(main, nextMap);
stream.Seek(0, SeekOrigin.Begin);
List<Entity> entities = (List<Entity>)IO.MapLoader.Serializer.Deserialize(stream);
foreach (Entity e in entities)
{
Factory<Main> factory = Factory<Main>.Get(e.Type);
e.GUID = 0;
factory.Bind(e, main);
main.Add(e);
}
stream.Dispose();
}
示例6: load
private static void load(Main main, Stream stream, bool deleteEditor, Entity playerData)
{
main.Camera.Position.Value = new Vector3(0, -1000, 0);
main.IsLoadingMap = true;
main.ClearEntities(deleteEditor);
if (stream == null)
main.DefaultLighting(); // There's no World entity to set the correct lighting, so set the defaults
else
{
List<Entity> entities = null;
try
{
entities = (List<Entity>)MapLoader.Serializer.Deserialize(stream);
}
catch (InvalidOperationException e)
{
throw new Exception("Failed to deserialize file stream.", e);
}
if (playerData != null)
entities.Add(playerData);
foreach (Entity entity in entities)
{
Factory<Main> factory = Factory<Main>.Get(entity.Type);
if (factory != null)
{
factory.Bind(entity, main);
main.Add(entity);
}
}
}
main.IsLoadingMap = false;
main.MapLoaded.Execute();
}
示例7: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
this.SetMain(result, main);
Transform transform = result.Get<Transform>();
PlayerTrigger trigger = result.Get<PlayerTrigger>();
Property<string> nextMap = result.GetProperty<string>("NextMap");
Property<string> startSpawnPoint = result.GetProperty<string>("SpawnPoint");
trigger.Add(new TwoWayBinding<Vector3>(transform.Position, trigger.Position));
trigger.Add(new CommandBinding<Entity>(trigger.PlayerEntered, delegate(Entity player)
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Entity>));
Container notification = new Container();
notification.Tint.Value = Microsoft.Xna.Framework.Color.Black;
notification.Opacity.Value = 0.5f;
TextElement notificationText = new TextElement();
notificationText.Name.Value = "Text";
notificationText.FontFile.Value = "Font";
notificationText.Text.Value = "Loading...";
notification.Children.Add(notificationText);
((GameMain)main).UI.Root.GetChildByName("Notifications").Children.Add(notification);
Stream stream = new MemoryStream();
main.AddComponent(new Animation
(
new Animation.Delay(0.01f),
new Animation.Execute(delegate()
{
// We are exiting the map; just save the state of the map without the player.
ListProperty<PlayerFactory.RespawnLocation> respawnLocations = Factory.Get<PlayerDataFactory>().Instance(main).GetOrMakeListProperty<PlayerFactory.RespawnLocation>("RespawnLocations");
respawnLocations.Clear();
List<Entity> persistentEntities = main.Entities.Where((Func<Entity, bool>)MapExitFactory.isPersistent).ToList();
serializer.Serialize(stream, persistentEntities);
foreach (Entity e in persistentEntities)
e.Delete.Execute();
((GameMain)main).StartSpawnPoint = startSpawnPoint;
}),
new Animation.Execute(((GameMain)main).SaveCurrentMap),
new Animation.Set<string>(main.MapFile, nextMap),
new Animation.Execute(delegate()
{
notification.Visible.Value = false;
stream.Seek(0, SeekOrigin.Begin);
List<Entity> entities = (List<Entity>)serializer.Deserialize(stream);
foreach (Entity entity in entities)
{
Factory factory = Factory.Get(entity.Type);
factory.Bind(entity, main);
main.Add(entity);
}
stream.Dispose();
}),
new Animation.Delay(1.5f),
new Animation.Set<string>(notificationText.Text, "Saving..."),
new Animation.Set<bool>(notification.Visible, true),
new Animation.Delay(0.01f),
new Animation.Execute(((GameMain)main).Save),
new Animation.Set<string>(notificationText.Text, "Saved"),
new Animation.Parallel
(
new Animation.FloatMoveTo(notification.Opacity, 0.0f, 1.0f),
new Animation.FloatMoveTo(notificationText.Opacity, 0.0f, 1.0f)
),
new Animation.Execute(notification.Delete)
));
}));
}
示例8: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
this.InternalBind(result, main, creating, null, true);
if (result.GetOrMakeProperty<bool>("Attached", true))
MapAttachable.MakeAttachable(result, main);
Property<Entity.Handle> target = result.GetOrMakeProperty<Entity.Handle>("Target");
Map map = result.Get<Map>();
Property<float> intervalMultiplier = result.GetOrMakeProperty<float>("IntervalMultiplier", true, 1.0f);
ListProperty<CoordinateEntry> coords = result.GetOrMakeListProperty<CoordinateEntry>("Coordinates");
Property<int> index = result.GetOrMakeProperty<int>("FillIndex");
Action populateCoords = delegate()
{
if (coords.Count == 0)
{
Entity targetEntity = target.Value.Target;
if (targetEntity != null && targetEntity.Active)
{
Map m = targetEntity.Get<Map>();
foreach (CoordinateEntry e in map.Chunks.SelectMany(c => c.Boxes.SelectMany(x => x.GetCoords())).Select(delegate(Map.Coordinate y)
{
Map.Coordinate z = m.GetCoordinate(map.GetAbsolutePosition(y));
z.Data = y.Data;
return new CoordinateEntry { Coord = z, };
}))
coords.Add(e);
}
}
};
if (main.EditorEnabled)
coords.Clear();
else
result.Add(new PostInitialization { populateCoords });
Property<float> blockLifetime = result.GetOrMakeProperty<float>("BlockLifetime", true, 0.25f);
float intervalTimer = 0.0f;
Updater update = new Updater
{
delegate(float dt)
{
intervalTimer += dt;
Entity targetEntity = target.Value.Target;
if (targetEntity != null && targetEntity.Active && index < coords.Count)
{
float interval = 0.03f * intervalMultiplier;
while (intervalTimer > interval && index < coords.Count)
{
EffectBlockFactory factory = Factory.Get<EffectBlockFactory>();
Map m = targetEntity.Get<Map>();
CoordinateEntry entry = coords[index];
Entity block = factory.CreateAndBind(main);
entry.Coord.Data.ApplyToEffectBlock(block.Get<ModelInstance>());
block.GetProperty<bool>("CheckAdjacent").Value = false;
block.GetProperty<Vector3>("Offset").Value = m.GetRelativePosition(entry.Coord);
block.GetProperty<bool>("Scale").Value = true;
block.GetProperty<Vector3>("StartPosition").Value = entry.Position + new Vector3(8.0f, 20.0f, 8.0f) * blockLifetime.Value;
block.GetProperty<Matrix>("StartOrientation").Value = Matrix.CreateRotationX(0.15f * index) * Matrix.CreateRotationY(0.15f * index);
block.GetProperty<float>("TotalLifetime").Value = blockLifetime;
factory.Setup(block, targetEntity, entry.Coord, entry.Coord.Data.ID);
main.Add(block);
index.Value++;
intervalTimer -= interval;
}
}
else
result.Delete.Execute();
}
};
update.Enabled.Value = index > 0;
result.Add("Update", update);
Action fill = delegate()
{
if (index > 0 || update.Enabled)
return; // We're already filling
Entity targetEntity = target.Value.Target;
if (targetEntity != null && targetEntity.Active)
{
populateCoords();
Map m = targetEntity.Get<Map>();
Vector3 focusPoint = main.Camera.Position;
foreach (CoordinateEntry entry in coords)
{
entry.Position = m.GetAbsolutePosition(entry.Coord);
entry.Distance = (focusPoint - entry.Position).LengthSquared();
}
List<CoordinateEntry> coordList = coords.ToList();
//.........这里部分代码省略.........
示例9: explode
private static void explode(Main main, Map map, Map.Coordinate coord, Vector3 pos, int radius, float physicsRadius)
{
// Kaboom
AkSoundEngine.PostEvent("Play_explosion", pos);
Entity lightEntity = Factory.Get<PointLightFactory>().CreateAndBind(main);
lightEntity.Serialize = false;
PointLight light = lightEntity.Get<PointLight>();
light.Color.Value = new Vector3(1.3f, 1.1f, 0.9f);
light.Attenuation.Value = 20.0f;
light.Position.Value = pos;
lightEntity.Add(new Animation
(
new Animation.FloatMoveTo(light.Attenuation, 0.0f, 1.0f),
new Animation.Execute(light.Delete)
));
main.Add(lightEntity);
SmokeFactory smokeFactory = Factory.Get<SmokeFactory>();
for (int i = 0; i < 5; i++)
{
Entity smoke = smokeFactory.CreateAndBind(main);
smoke.Get<Transform>().Position.Value = pos;
main.Add(smoke);
}
ParticleEmitter.Emit(main, "Smoke", pos, physicsRadius * 0.4f, 250);
Entity player = PlayerFactory.Instance;
if (player != null && player.Active)
player.Get<CameraController>().Shake.Execute(pos, 50.0f);
const float physicsImpulse = 70.0f;
const float minPlayerDamage = 0.1f;
const float playerDamageMultiplier = 2.0f;
// Remove the cells
BlockFactory blockFactory = Factory.Get<BlockFactory>();
foreach (Map m in Map.ActiveMaps.ToList())
{
List<Map.Coordinate> removals = new List<Map.Coordinate>();
Map.Coordinate c = m.GetCoordinate(pos);
Vector3 relativePos = m.GetRelativePosition(c);
Quaternion quat = m.Entity.Get<Transform>().Quaternion;
for (Map.Coordinate x = c.Move(Direction.NegativeX, radius - 1); x.X < c.X + radius; x.X++)
{
for (Map.Coordinate y = x.Move(Direction.NegativeY, radius - 1); y.Y < c.Y + radius; y.Y++)
{
for (Map.Coordinate z = y.Move(Direction.NegativeZ, radius - 1); z.Z < c.Z + radius; z.Z++)
{
Map.CellState s = m[z];
if (s.ID == 0 || s.Permanent)
continue;
Vector3 cellPos = m.GetRelativePosition(z);
if ((cellPos - relativePos).Length() < radius - 1)
{
removals.Add(z);
if (random.NextDouble() > 0.5)
{
Entity block = blockFactory.CreateAndBind(main);
Transform blockTransform = block.Get<Transform>();
blockTransform.Position.Value = m.GetAbsolutePosition(cellPos);
blockTransform.Quaternion.Value = quat;
s.ApplyToBlock(block);
main.Add(block);
}
}
}
}
}
if (removals.Count > 0)
{
m.Empty(removals);
m.Regenerate();
}
}
// Damage the player
if (player != null && player.Active)
{
float d = (player.Get<Transform>().Position - pos).Length();
if (d < physicsRadius)
player.Get<Player>().Health.Value -= minPlayerDamage + (1.0f - (d / physicsRadius)) * playerDamageMultiplier;
}
// Apply impulse to dynamic maps
foreach (Map m in Map.ActiveMaps)
{
DynamicMap dm = m as DynamicMap;
if (dm == null)
continue;
Vector3 toMap = dm.Transform.Value.Translation - pos;
float distanceToMap = toMap.Length();
toMap /= distanceToMap;
//.........这里部分代码省略.........
示例10: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
result.CannotSuspend = true;
Transform transform = result.Get<Transform>();
PhysicsBlock physics = result.Get<PhysicsBlock>();
Model model = result.Get<Model>();
Sound loopSound = result.Get<Sound>("LoopSound");
PointLight light = result.Get<PointLight>();
ParticleEmitter emitter = result.Get<ParticleEmitter>("Particles");
physics.Add(new TwoWayBinding<Matrix>(transform.Matrix, physics.Transform));
light.Add(new Binding<Vector3>(light.Position, transform.Position));
emitter.Add(new Binding<Vector3>(emitter.Position, transform.Position));
model.Add(new Binding<Matrix>(model.Transform, transform.Matrix));
loopSound.Add(new Binding<Vector3>(loopSound.Position, transform.Position));
loopSound.Add(new Binding<Vector3>(loopSound.Velocity, physics.LinearVelocity));
loopSound.Position.Value = transform.Position;
physics.Add(new CommandBinding<Collidable, ContactCollection>(physics.Collided, delegate(Collidable collidable, ContactCollection contacts)
{
if (result.Active)
{
result.Delete.Execute();
Sound.PlayCue(main, "Explosion", transform.Position);
if (collidable is EntityCollidable)
{
if (((EntityCollidable)collidable).Entity.Tag is Map)
{
ContactInformation contact = contacts.First();
Vector3 pos = contact.Contact.Position - (contact.Contact.Normal * 0.5f);
Map map = (Map)((EntityCollidable)collidable).Entity.Tag;
Map.Coordinate center = map.GetCoordinate(pos);
int radius = 3;
Random random = new Random();
for (Map.Coordinate x = center.Move(Direction.NegativeX, radius - 1); x.X < center.X + radius; x.X++)
{
for (Map.Coordinate y = x.Move(Direction.NegativeY, radius - 1); y.Y < center.Y + radius; y.Y++)
{
for (Map.Coordinate z = y.Move(Direction.NegativeZ, radius - 1); z.Z < center.Z + radius; z.Z++)
{
Vector3 cellPos = map.GetAbsolutePosition(z);
Vector3 toCell = cellPos - pos;
if (toCell.Length() < radius - 1)
{
Map.CellState state = map[z];
if (map.Empty(z))
{
Entity block = Factory.CreateAndBind(main, "Block");
block.Get<Transform>().Position.Value = cellPos;
block.Get<Transform>().Quaternion.Value = map.Entity.Get<Transform>().Quaternion;
state.ApplyToBlock(block);
block.Get<ModelInstance>().GetVector3Parameter("Offset").Value = map.GetRelativePosition(z);
toCell += contact.Contact.Normal * 4.0f;
toCell.Normalize();
block.Get<PhysicsBlock>().LinearVelocity.Value = toCell * 15.0f;
block.Get<PhysicsBlock>().AngularVelocity.Value = new Vector3(((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f);
main.Add(block);
}
}
}
}
}
map.Regenerate();
}
else if (((EntityCollidable)collidable).Entity.Tag is Player)
{
Player player = (Player)((EntityCollidable)collidable).Entity.Tag;
player.Health.Value -= 0.75f;
}
}
}
}));
this.SetMain(result, main);
loopSound.Play.Execute();
}
示例11: Consolidate
public static void Consolidate(Main main, DynamicVoxel voxel, Voxel targetVoxel, Voxel.Coord targetCoord, float interval = 1.0f)
{
if (targetVoxel != null)
{
// Combine this map with the other one
Direction x = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Right));
Direction y = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Up));
Direction z = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Backward));
if (x.IsParallel(y))
x = y.Cross(z);
else if (y.IsParallel(z))
y = x.Cross(z);
Voxel.Coord offset = new Voxel.Coord();
float closestCoordDistance = float.MaxValue;
Vector3 closestCoordPosition = targetVoxel.GetAbsolutePosition(targetCoord);
lock (voxel.MutationLock)
{
foreach (Voxel.Coord c in voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()))
{
float distance = (voxel.GetAbsolutePosition(c) - closestCoordPosition).LengthSquared();
if (distance < closestCoordDistance)
{
closestCoordDistance = distance;
offset = c;
}
}
}
Vector3 toLevitatingMap = voxel.Transform.Value.Translation - targetVoxel.GetAbsolutePosition(targetCoord);
offset = offset.Move(voxel.GetRelativeDirection(-toLevitatingMap));
Quaternion orientation = Quaternion.CreateFromRotationMatrix(voxel.Transform.Value);
EffectBlockFactory blockFactory = Factory.Get<EffectBlockFactory>();
int index = 0;
List<Voxel.Coord> coords;
lock (voxel.MutationLock)
coords = voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()).ToList();
Voxel.Coord camera = voxel.GetCoordinate(main.Camera.Position);
foreach (Voxel.Coord c in coords.OrderBy(c2 => new Vector3(c2.X - camera.X, c2.Y - camera.Y, c2.Z - camera.Z).LengthSquared()))
{
Voxel.Coord offsetFromCenter = c.Move(-offset.X, -offset.Y, -offset.Z);
Voxel.Coord targetCoord2 = new Voxel.Coord();
targetCoord2.SetComponent(x, offsetFromCenter.GetComponent(Direction.PositiveX));
targetCoord2.SetComponent(y, offsetFromCenter.GetComponent(Direction.PositiveY));
targetCoord2.SetComponent(z, offsetFromCenter.GetComponent(Direction.PositiveZ));
targetCoord2 = targetCoord2.Move(targetCoord.X, targetCoord.Y, targetCoord.Z);
if (targetVoxel[targetCoord2].ID == 0)
{
Entity blockEntity = blockFactory.CreateAndBind(main);
c.Data.ApplyToEffectBlock(blockEntity.Get<ModelInstance>());
EffectBlock effectBlock = blockEntity.Get<EffectBlock>();
effectBlock.Offset.Value = targetVoxel.GetRelativePosition(targetCoord2);
effectBlock.DoScale = false;
effectBlock.StartPosition = voxel.GetAbsolutePosition(c);
effectBlock.StartOrientation = orientation;
effectBlock.TotalLifetime = (0.05f + (index * 0.0075f)) * interval;
effectBlock.Setup(targetVoxel.Entity, targetCoord2, c.Data.ID);
main.Add(blockEntity);
index++;
}
}
// Delete the map
voxel.Entity.Delete.Execute();
}
}
示例12: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
PointLight light = result.GetOrCreate<PointLight>("PointLight");
light.Serialize = false;
const float defaultLightAttenuation = 15.0f;
light.Attenuation.Value = defaultLightAttenuation;
Transform transform = result.GetOrCreate<Transform>("Transform");
light.Add(new Binding<Vector3>(light.Position, transform.Position));
VoxelChaseAI chase = result.GetOrCreate<VoxelChaseAI>("VoxelChaseAI");
chase.Filter = delegate(Map.CellState state)
{
return state.ID == 0 ? VoxelChaseAI.Cell.Empty : VoxelChaseAI.Cell.Filled;
};
chase.Add(new TwoWayBinding<Vector3>(transform.Position, chase.Position));
result.Add(new CommandBinding(chase.Delete, result.Delete));
Sound sound = result.GetOrCreate<Sound>("LoopSound");
sound.Serialize = false;
sound.Cue.Value = "Orb Loop";
sound.Is3D.Value = true;
sound.IsPlaying.Value = true;
sound.Add(new Binding<Vector3>(sound.Position, chase.Position));
Property<float> volume = sound.GetProperty("Volume");
Property<float> pitch = sound.GetProperty("Pitch");
const float defaultVolume = 0.5f;
volume.Value = defaultVolume;
AI ai = result.GetOrCreate<AI>();
Model model = result.GetOrCreate<Model>();
model.Add(new Binding<Matrix>(model.Transform, transform.Matrix));
model.Filename.Value = "Models\\sphere";
model.Editable = false;
model.Serialize = false;
const float defaultModelScale = 0.25f;
model.Scale.Value = new Vector3(defaultModelScale);
model.Add(new Binding<Vector3, string>(model.Color, delegate(string state)
{
switch (state)
{
case "Alert":
return new Vector3(1.5f, 1.5f, 0.5f);
case "Chase":
return new Vector3(1.5f, 0.5f, 0.5f);
case "Levitating":
return new Vector3(2.0f, 1.0f, 0.5f);
case "Idle":
return new Vector3(1.0f, 1.0f, 1.0f);
default:
return new Vector3(0.0f, 0.0f, 0.0f);
}
}, ai.CurrentState));
Random random = new Random();
result.Add(new Updater
{
delegate(float dt)
{
float source = ((float)random.NextDouble() - 0.5f) * 2.0f;
model.Scale.Value = new Vector3(defaultModelScale * (1.0f + (source * 0.5f)));
light.Attenuation.Value = defaultLightAttenuation * (1.0f + (source * 0.05f));
}
});
model.Add(new Binding<bool, string>(model.Enabled, x => x != "Exploding", ai.CurrentState));
light.Add(new Binding<Vector3>(light.Color, model.Color));
Agent agent = result.GetOrCreate<Agent>();
agent.Add(new Binding<Vector3>(agent.Position, chase.Position));
Property<int> operationalRadius = result.GetOrMakeProperty<int>("OperationalRadius", true, 100);
AI.Task checkOperationalRadius = new AI.Task
{
Interval = 2.0f,
Action = delegate()
{
bool shouldBeActive = (chase.Position.Value - main.Camera.Position).Length() < operationalRadius;
if (shouldBeActive && ai.CurrentState == "Suspended")
ai.CurrentState.Value = "Idle";
else if (!shouldBeActive && ai.CurrentState != "Suspended")
ai.CurrentState.Value = "Suspended";
},
};
const float sightDistance = 30.0f;
const float hearingDistance = 15.0f;
ai.Add(new AI.State
{
Name = "Idle",
//.........这里部分代码省略.........
示例13: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
Factory.Get<DynamicMapFactory>().Bind(result, main);
Transform transform = result.Get<Transform>();
DynamicMap map = result.Get<DynamicMap>();
PointLight light = result.Get<PointLight>();
Sound blastFireSound = result.Get<Sound>("BlastFireSound");
blastFireSound.Add(new Binding<Vector3>(blastFireSound.Position, transform.Position));
blastFireSound.Add(new Binding<Vector3>(blastFireSound.Velocity, map.LinearVelocity));
Sound blastChargeSound = result.Get<Sound>("BlastChargeSound");
blastChargeSound.Add(new Binding<Vector3>(blastChargeSound.Position, transform.Position));
blastChargeSound.Add(new Binding<Vector3>(blastChargeSound.Velocity, map.LinearVelocity));
map.Add(new CommandBinding(map.CompletelyEmptied, delegate()
{
if (!main.EditorEnabled)
result.Delete.Execute();
}));
EntityRotator rotator = null;
EntityMover mover = null;
if (!main.EditorEnabled)
{
rotator = new EntityRotator(map.PhysicsEntity);
main.Space.Add(rotator);
mover = new EntityMover(map.PhysicsEntity);
mover.TargetPosition = transform.Position;
main.Space.Add(mover);
}
Map.Coordinate blastSource = map.GetCoordinate(0, 0, 0);
Map.Coordinate blastPosition = blastSource;
Map.CellState criticalMaterial = WorldFactory.StatesByName["Critical"];
foreach (Map.Box box in map.Chunks.SelectMany(x => x.Boxes))
{
if (box.Type == criticalMaterial)
{
blastSource = map.GetCoordinate(box.X, box.Y, box.Z);
blastPosition = map.GetCoordinate(box.X, box.Y, box.Z - 3);
break;
}
}
Property<float> blastIntervalTime = result.GetProperty<float>("BlastInterval");
float blastInterval = 0.0f;
Property<float> playerPositionMemoryTime = result.GetProperty<float>("PlayerPositionMemoryTime");
float timeSinceLastSpottedPlayer = playerPositionMemoryTime;
Property<float> visibilityCheckInterval = result.GetProperty<float>("VisibilityCheckInterval");
float timeSinceLastVisibilityCheck = 0.0f;
Property<float> blastChargeTime = result.GetProperty<float>("BlastChargeTime");
float blastCharge = 0.0f;
Property<float> blastSpeed = result.GetProperty<float>("BlastSpeed");
Property<float> playerDetectionRadius = result.GetProperty<float>("PlayerDetectionRadius");
Updater update = new Updater();
update.Add(delegate(float dt)
{
if (map[blastSource].ID == 0)
{
update.Delete.Execute();
if (rotator != null)
{
main.Space.Remove(rotator);
main.Space.Remove(mover);
}
light.Delete.Execute();
return;
}
Entity player = PlayerFactory.Instance;
if (player != null)
{
Vector3 playerPosition = player.Get<Transform>().Position.Value;
Vector3 rayStart = map.GetAbsolutePosition(blastPosition);
Vector3 rayDirection = playerPosition - rayStart;
rayDirection.Normalize();
timeSinceLastVisibilityCheck += dt;
if (timeSinceLastVisibilityCheck > visibilityCheckInterval)
{
if ((playerPosition - transform.Position).Length() < playerDetectionRadius)
timeSinceLastSpottedPlayer = 0.0f;
else if (Vector3.Dot(rayDirection, map.GetAbsoluteVector(Vector3.Forward)) > 0)
{
RayCastResult hit;
if (main.Space.RayCast(new Ray(rayStart, rayDirection), out hit))
{
EntityCollidable collidable = hit.HitObject as EntityCollidable;
if (collidable != null && collidable.Entity.Tag is Player)
timeSinceLastSpottedPlayer = 0.0f;
}
//.........这里部分代码省略.........
示例14: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
PointLight light = result.GetOrCreate<PointLight>("PointLight");
light.Serialize = false;
const float defaultLightAttenuation = 15.0f;
light.Attenuation.Value = defaultLightAttenuation;
Transform transform = result.GetOrCreate<Transform>("Transform");
light.Add(new Binding<Vector3>(light.Position, transform.Position));
VoxelChaseAI chase = result.GetOrCreate<VoxelChaseAI>("VoxelChaseAI");
chase.Filter = delegate(Map.CellState state)
{
return state.ID == 0 ? VoxelChaseAI.Cell.Empty : VoxelChaseAI.Cell.Filled;
};
chase.Add(new TwoWayBinding<Vector3>(transform.Position, chase.Position));
result.Add(new CommandBinding(chase.Delete, result.Delete));
Sound sound = result.GetOrCreate<Sound>("LoopSound");
sound.Serialize = false;
sound.Cue.Value = "Orb Loop";
sound.Is3D.Value = true;
sound.IsPlaying.Value = true;
sound.Add(new Binding<Vector3>(sound.Position, chase.Position));
Property<float> volume = sound.GetProperty("Volume");
Property<float> pitch = sound.GetProperty("Pitch");
const float defaultVolume = 0.5f;
volume.Value = defaultVolume;
AI ai = result.GetOrCreate<AI>();
Model model = result.GetOrCreate<Model>();
model.Add(new Binding<Matrix>(model.Transform, transform.Matrix));
model.Filename.Value = "Models\\sphere";
model.Editable = false;
model.Serialize = false;
const float defaultModelScale = 0.25f;
model.Scale.Value = new Vector3(defaultModelScale);
model.Add(new Binding<Vector3, string>(model.Color, delegate(string state)
{
switch (state)
{
case "Alert":
return new Vector3(1.5f, 1.5f, 0.5f);
case "Chase":
return new Vector3(1.5f, 0.5f, 0.5f);
case "Explode":
return new Vector3(2.0f, 1.0f, 0.5f);
case "Idle":
return new Vector3(1.0f, 1.0f, 1.0f);
default:
return new Vector3(0.0f, 0.0f, 0.0f);
}
}, ai.CurrentState));
Random random = new Random();
result.Add(new Updater
{
delegate(float dt)
{
float source = ((float)random.NextDouble() - 0.5f) * 2.0f;
model.Scale.Value = new Vector3(defaultModelScale * (1.0f + (source * 0.5f)));
light.Attenuation.Value = defaultLightAttenuation * (1.0f + (source * 0.05f));
}
});
model.Add(new Binding<bool, string>(model.Enabled, x => x != "Exploding", ai.CurrentState));
light.Add(new Binding<Vector3>(light.Color, model.Color));
Agent agent = result.GetOrCreate<Agent>();
agent.Add(new Binding<Vector3>(agent.Position, chase.Position));
Property<int> operationalRadius = result.GetOrMakeProperty<int>("OperationalRadius", true, 100);
AI.Task checkOperationalRadius = new AI.Task
{
Interval = 2.0f,
Action = delegate()
{
bool shouldBeActive = (chase.Position.Value - main.Camera.Position).Length() < operationalRadius;
if (shouldBeActive && ai.CurrentState == "Suspended")
ai.CurrentState.Value = "Idle";
else if (!shouldBeActive && ai.CurrentState != "Suspended")
ai.CurrentState.Value = "Suspended";
},
};
const float sightDistance = 30.0f;
const float hearingDistance = 15.0f;
ai.Add(new AI.State
{
Name = "Idle",
//.........这里部分代码省略.........