本文整理汇总了C#中Main.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Main.Get方法的具体用法?C# Main.Get怎么用?C# Main.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Main
的用法示例。
在下文中一共展示了Main.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
if (result.GetOrMakeProperty<bool>("Attach", true))
MapAttachable.MakeAttachable(result, main);
this.SetMain(result, main);
if (main.EditorEnabled)
{
result.Add("Spawn Here", new Command
{
Action = delegate()
{
((GameMain)main).StartSpawnPoint.Value = result.ID;
Editor editor = main.Get("Editor").First().Get<Editor>();
if (editor.NeedsSave)
editor.Save.Execute();
main.EditorEnabled.Value = false;
IO.MapLoader.Load(main, null, main.MapFile);
},
ShowInEditor = true,
});
}
Transform transform = result.Get<Transform>();
PlayerSpawn spawn = result.Get<PlayerSpawn>();
spawn.Add(new TwoWayBinding<Vector3>(transform.Position, spawn.Position));
spawn.Add(new Binding<float, Vector3>(spawn.Rotation, x => ((float)Math.PI * -0.5f) - (float)Math.Atan2(x.Z, x.X), transform.Forward));
PlayerTrigger trigger = result.Get<PlayerTrigger>();
trigger.Enabled.Editable = true;
trigger.Add(new TwoWayBinding<Vector3>(transform.Position, trigger.Position));
trigger.Add(new CommandBinding<Entity>(trigger.PlayerEntered, delegate(Entity player) { spawn.Activate.Execute(); }));
}
示例2: 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;
//.........这里部分代码省略.........
示例3: InternalBind
public void InternalBind(Entity result, Main main, bool creating = false, Transform transform = null)
{
if (transform == null)
transform = result.GetOrCreate<Transform>("Transform");
result.CannotSuspend = false;
Map map = result.Get<Map>();
// Apply the position and orientation components to the map
map.Add(new TwoWayBinding<Matrix>(transform.Matrix, map.Transform));
map.Add(new CommandBinding(map.CompletelyEmptied, delegate()
{
if (!main.EditorEnabled)
result.Delete.Execute();
}));
Entity world = main.Get("World").FirstOrDefault();
map.Chunks.ItemAdded += delegate(int index, Map.Chunk chunk)
{
Dictionary<int, bool> models = new Dictionary<int, bool>();
Action<Map.CellState> createModel = delegate(Map.CellState state)
{
if (state.ID == 0)
return; // 0 = empty
DynamicModel<Map.MapVertex> model = new DynamicModel<Map.MapVertex>(Map.MapVertex.VertexDeclaration);
model.EffectFile.Value = "Effects\\Environment";
model.Lock = map.Lock;
state.ApplyTo(model);
/*
ModelAlpha debug = new ModelAlpha { Serialize = false };
debug.Alpha.Value = 0.01f;
debug.DrawOrder.Value = 11; // In front of water
debug.Color.Value = new Vector3(1.0f, 0.8f, 0.6f);
debug.Filename.Value = "Models\\alpha-box";
debug.CullBoundingBox.Value = false;
debug.DisableCulling.Value = true;
debug.Add(new Binding<Matrix>(debug.Transform, delegate()
{
BoundingBox box = model.BoundingBox;
return Matrix.CreateScale(box.Max - box.Min) * Matrix.CreateTranslation((box.Max + box.Min) * 0.5f) * transform.Matrix;
}, transform.Matrix, model.BoundingBox));
result.Add(debug);
*/
model.Add(new Binding<Matrix>(model.Transform, transform.Matrix));
Vector3 min = new Vector3(chunk.X, chunk.Y, chunk.Z);
Vector3 max = min + new Vector3(map.ChunkSize);
model.Add(new Binding<Vector3>(model.GetVector3Parameter("Offset"), map.Offset));
Map.CellState s = state;
if (!s.ShadowCast)
model.UnsupportedTechniques.Add(new[] { Technique.Shadow, Technique.PointLightShadow });
model.Add(new ListBinding<Map.MapVertex, Map.Box>
(
model.Vertices,
chunk.Boxes,
delegate(Map.Box box)
{
Map.MapVertex[] vertices = new Map.MapVertex[box.Surfaces.Where(x => x.HasArea).Count() * 4];
int i = 0;
foreach (Map.Surface surface in box.Surfaces)
{
if (surface.HasArea)
{
Array.Copy(surface.Vertices, 0, vertices, i, 4);
i += 4;
}
}
return vertices;
},
x => x.Type == s
));
result.Add(model);
// We have to create this binding after adding the model to the entity
// Because when the model loads, it automatically calculates a bounding box for it.
model.Add(new Binding<BoundingBox, Vector3>(model.BoundingBox, x => new BoundingBox(min - x, max - x), map.Offset));
models[state.ID] = true;
};
chunk.Boxes.ItemAdded += delegate(int i, Map.Box box)
{
if ((!box.Type.Invisible || main.EditorEnabled) && !models.ContainsKey(box.Type.ID))
createModel(box.Type);
};
chunk.Boxes.ItemChanged += delegate(int i, Map.Box oldBox, Map.Box newBox)
{
//.........这里部分代码省略.........