本文整理汇总了C#中Main.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Main.AddComponent方法的具体用法?C# Main.AddComponent怎么用?C# Main.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Main
的用法示例。
在下文中一共展示了Main.AddComponent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlayCue
public static Sound PlayCue(Main main, string cue, float volume = 1.0f, float minimumTimeBetweenSounds = 0.25f)
{
float lastSoundPlayedTime = minimumTimeBetweenSounds * -2.0f;
Sound.lastSoundPlayedTimes.TryGetValue(cue, out lastSoundPlayedTime);
float time = main.TotalTime;
if (time > lastSoundPlayedTime + minimumTimeBetweenSounds)
{
Sound.lastSoundPlayedTimes[cue] = time;
Sound sound = new Sound();
sound.Cue.Value = cue;
sound.Is3D.Value = false;
if (volume != 1.0f)
sound.GetProperty("Volume").Value = volume;
sound.DeleteWhenDone.Value = true;
sound.DeleteStopOption.Value = AudioStopOptions.AsAuthored;
main.AddComponent(sound);
sound.Play.Execute();
return sound;
}
return null;
}
示例2: 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);
}
示例3: 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)
));
}));
}
示例4: Bind
public override void Bind(Entity result, Main main, bool creating = false)
{
this.SetMain(result, main);
Editor editor = result.Get<Editor>();
EditorUI ui = result.Get<EditorUI>();
Model model = result.Get<Model>("Model");
FPSInput input = result.Get<FPSInput>("Input");
UIRenderer uiRenderer = result.Get<UIRenderer>();
ModelAlpha radiusVisual = new ModelAlpha();
radiusVisual.Filename.Value = "Models\\alpha-sphere";
radiusVisual.Color.Value = new Vector3(1.0f);
radiusVisual.Alpha.Value = 0.1f;
radiusVisual.Editable = false;
radiusVisual.Serialize = false;
radiusVisual.DrawOrder.Value = 11; // In front of water
radiusVisual.DisableCulling.Value = true;
result.Add(radiusVisual);
radiusVisual.Add(new Binding<Matrix, Vector3>(radiusVisual.Transform, x => Matrix.CreateTranslation(x), editor.Position));
radiusVisual.Add(new Binding<Vector3, int>(radiusVisual.Scale, x => new Vector3(x), editor.BrushSize));
radiusVisual.Add(new Binding<bool>(radiusVisual.Enabled, () => editor.BrushSize > 1 && editor.MapEditMode, editor.BrushSize, editor.MapEditMode));
radiusVisual.CullBoundingBox.Value = false;
ModelAlpha selection = new ModelAlpha();
selection.Filename.Value = "Models\\alpha-box";
selection.Color.Value = new Vector3(1.0f, 0.7f, 0.4f);
selection.Alpha.Value = 0.25f;
selection.Editable = false;
selection.Serialize = false;
selection.DrawOrder.Value = 12; // In front of water and radius visualizer
selection.DisableCulling.Value = true;
result.Add(selection);
selection.Add(new Binding<bool>(selection.Enabled, editor.VoxelSelectionActive));
selection.Add(new Binding<Matrix>(selection.Transform, delegate()
{
const float padding = 0.1f;
Map map = editor.SelectedEntities[0].Get<Map>();
Vector3 start = map.GetRelativePosition(editor.VoxelSelectionStart) - new Vector3(0.5f), end = map.GetRelativePosition(editor.VoxelSelectionEnd) - new Vector3(0.5f);
return Matrix.CreateScale((end - start) + new Vector3(padding)) * Matrix.CreateTranslation((start + end) * 0.5f) * map.Transform;
}, () => selection.Enabled, editor.VoxelSelectionStart, editor.VoxelSelectionEnd));
selection.CullBoundingBox.Value = false;
Action<string, PCInput.Chord, Func<bool>, Command> addCommand = delegate(string description, PCInput.Chord chord, Func<bool> enabled, Command action)
{
ui.PopupCommands.Add(new EditorUI.PopupCommand { Description = description, Chord = chord, Enabled = enabled, Action = action });
if (chord.Modifier != Keys.None)
input.Add(new CommandBinding(input.GetChord(chord), () => enabled() && !ui.StringPropertyLocked, action));
else
input.Add(new CommandBinding(input.GetKeyDown(chord.Key), () => enabled() && !ui.StringPropertyLocked, action));
ui.Add(new CommandBinding(action, delegate()
{
Container container = new Container();
container.Tint.Value = Microsoft.Xna.Framework.Color.Black;
container.Opacity.Value = 0.2f;
container.AnchorPoint.Value = new Vector2(1.0f, 0.0f);
container.Add(new Binding<Vector2, Point>(container.Position, x => new Vector2(x.X - 10.0f, 10.0f), main.ScreenSize));
TextElement display = new TextElement();
display.FontFile.Value = "Font";
display.Text.Value = description;
container.Children.Add(display);
uiRenderer.Root.Children.Add(container);
main.AddComponent(new Animation
(
new Animation.Parallel
(
new Animation.FloatMoveTo(container.Opacity, 0.0f, 1.0f),
new Animation.FloatMoveTo(display.Opacity, 0.0f, 1.0f)
),
new Animation.Execute(delegate() { uiRenderer.Root.Children.Remove(container); })
));
}));
};
foreach (string key in Factory.factories.Keys)
{
string entityType = key;
ui.PopupCommands.Add(new EditorUI.PopupCommand
{
Description = "Add " + entityType,
Enabled = () => editor.SelectedEntities.Count == 0 && !editor.MapEditMode,
Action = new Command { Action = () => editor.Spawn.Execute(entityType) },
});
}
Scroller scroller = (Scroller)uiRenderer.Root.GetChildByName("Scroller");
Container popup = (Container)uiRenderer.Root.GetChildByName("Popup");
ListContainer popupList = (ListContainer)popup.GetChildByName("PopupList");
input.Add(new CommandBinding(input.GetKeyUp(Keys.Space), () => !editor.MapEditMode && !ui.StringPropertyLocked && !editor.MovementEnabled, delegate()
{
Vector2 pos = input.Mouse;
pos.X = Math.Min(main.ScreenSize.Value.X - popup.Size.Value.X, pos.X);
pos.Y = Math.Min(main.ScreenSize.Value.Y - popup.Size.Value.Y, pos.Y);
popup.Position.Value = pos;
ui.PopupVisible.Value = true;
}));
//.........这里部分代码省略.........
示例5: Attach
//.........这里部分代码省略.........
msgList.Size.Value = new Vector2(messageWidth, 0.0f);
phoneScroll.Children.Add(msgList);
Container answerContainer = new Container();
answerContainer.PaddingBottom.Value = answerContainer.PaddingLeft.Value = answerContainer.PaddingRight.Value = answerContainer.PaddingTop.Value = padding;
answerContainer.Tint.Value = incomingColor;
answerContainer.AnchorPoint.Value = new Vector2(1.0f, 1.0f);
answerContainer.Add(new Binding<Vector2>(answerContainer.Position, () => composeAlign.Position.Value + new Vector2(composeAlign.ScaledSize.Value.X + padding, padding * 3.0f), composeAlign.Position, composeAlign.ScaledSize));
phoneUi.Root.Children.Add(answerContainer);
answerContainer.Visible.Value = false;
ListContainer answerList = new ListContainer();
answerList.Orientation.Value = ListContainer.ListOrientation.Vertical;
answerList.Alignment.Value = ListContainer.ListAlignment.Max;
answerContainer.Children.Add(answerList);
int selectedAnswer = 0;
composeButton.Add(new CommandBinding<Point>(composeButton.MouseLeftUp, delegate(Point p)
{
answerContainer.Visible.Value = !answerContainer.Visible;
if (answerContainer.Visible && main.GamePadConnected)
{
selectedAnswer = 0;
foreach (UIComponent answer in answerList.Children)
answer.Highlighted.Value = false;
answerList.Children[0].Highlighted.Value = true;
}
}));
Action scrollToBottom = delegate()
{
// HACK
main.AddComponent(new Animation
(
new Animation.Delay(0.01f),
new Animation.Execute(delegate()
{
phoneScroll.ScrollToBottom();
})
));
};
// Note
UIRenderer noteUi = result.GetOrCreate<UIRenderer>("NoteUI");
const float noteWidth = 400.0f;
const float noteScale = 0.0009f;
noteUi.RenderTargetBackground.Value = new Microsoft.Xna.Framework.Color(1.0f, 0.95f, 0.9f);
noteUi.RenderTargetSize.Value = new Point((int)noteWidth, (int)(noteWidth * 1.29f)); // 8.5x11 aspect ratio
noteUi.Serialize = false;
noteUi.Enabled.Value = false;
Model noteModel = result.GetOrCreate<Model>("Note");
noteModel.Filename.Value = "Models\\plane";
noteModel.EffectFile.Value = "Effects\\Default";
noteModel.Add(new Binding<Microsoft.Xna.Framework.Graphics.RenderTarget2D>(noteModel.GetRenderTarget2DParameter("Diffuse" + Model.SamplerPostfix), noteUi.RenderTarget));
noteModel.Add(new Binding<Matrix>(noteModel.Transform, x => Matrix.CreateTranslation(-0.005f, 0.05f, 0.08f) * x, phoneModel.Transform));
noteModel.Scale.Value = new Vector3(1.0f, (float)noteUi.RenderTargetSize.Value.Y * noteScale, (float)noteUi.RenderTargetSize.Value.X * noteScale);
noteModel.Serialize = false;
noteModel.Enabled.Value = false;
Property<Entity.Handle> note = result.GetOrMakeProperty<Entity.Handle>("Note");
Container togglePhoneMessage = null;
示例6: Add
public static ParticleSystem Add(Main main, string type, ParticleSystem.ParticleSettings settings)
{
ParticleSystem system = new ParticleSystem();
system.Type.Value = type;
system.Settings.Value = settings;
if (ParticleSystem.systems == null)
{
ParticleSystem.systems = new Dictionary<string, ParticleSystem>();
ParticleSystem.initialize(main);
}
ParticleSystem.systems.Add(system.Type, system);
main.AddComponent(system);
return system;
}