public override void LoadContent() { font = CM.Load <SpriteFont>("font"); button = CM.Load <Texture2D>("button"); singleplayer = new Button(); multiplayer = new Button(); quit = new Button(); singleplayer.Text = "Singleplayer"; multiplayer.Text = "Multiplayer"; quit.Text = "Quit"; singleplayer.Click += ButtonClick; multiplayer.Click += ButtonClick; quit.Click += ButtonClick; singleplayer.Position = new Vector2(graphicsDevice.Viewport.Width / 2 - 16 * 5, graphicsDevice.Viewport.Height / 2 - 64); multiplayer.Position = new Vector2(graphicsDevice.Viewport.Width / 2 - 16 * 5, graphicsDevice.Viewport.Height / 2 - 16); quit.Position = new Vector2(graphicsDevice.Viewport.Width / 2 - 16 * 5, graphicsDevice.Viewport.Height / 2 + 32); compManager.AddComponent(singleplayer); compManager.AddComponent(multiplayer); compManager.AddComponent(quit); }
public override void LoadContent() { username = new InputBox(); host = new InputBox(); connect = new Button(); back = new Button(); connect.Text = "Connect"; back.Text = "Back"; connect.Click += HandleClicks; back.Click += HandleClicks; username.Hint = "Username"; host.Hint = "Host's IP Address"; username.Position = new Vector2(graphicsDevice.Viewport.Width / 2 - 16 * 5, graphicsDevice.Viewport.Height / 2 - 64); host.Position = new Vector2(graphicsDevice.Viewport.Width / 2 - 16 * 5, graphicsDevice.Viewport.Height / 2 - 16); connect.Position = new Vector2(graphicsDevice.Viewport.Width / 2 - 16 * 5, graphicsDevice.Viewport.Height / 2 + 32); back.Position = new Vector2(graphicsDevice.Viewport.Width / 2 - 16 * 5, graphicsDevice.Viewport.Height / 2 + 96); compManager.AddComponent(username); compManager.AddComponent(host); compManager.AddComponent(connect); compManager.AddComponent(back); compManager.ClearFocuses(); }
public static void AddComponent <T>(Entity entity, T component) { componentManager.AddComponent(entity, component); var componentSignature = componentManager.GetComponentSignature <T>(); entity.Signature.AddSignature(componentSignature); systemManager.EntitySignatureChanged(entity); }
public void ReEnumerate() { var componentManager = new ComponentManager(new StubSetManager()); var entity = new StubEntity(); using (var enumerator = componentManager.GetEnumerator(entity)) { componentManager.AddComponent(entity, new AComponent("modified components")); Assert.IsFalse(enumerator.MoveNext()); componentManager.AddComponent(entity, new AComponent("modified components")); Assert.IsFalse(enumerator.MoveNext()); } // check again for dispose crash using (var enumerator = componentManager.GetEnumerator(new StubEntity())) { Assert.IsFalse(enumerator.MoveNext()); } }
public ModStatComponent(ComponentManager manager, string s, int x, int y, bool defaultState, double min, double max, double def) { _text = s; Label = new CompLabel(s, 11, new Vector2(x, y), Vector2.Zero, 0.94F, true, Color.White, true); manager.AddComponent(Label); Slider = new CompSlider(manager, min, max, def, new Vector2(x + 6, y + 20), 200); Checkbox = new CompCheckbox("Enable " + s + " Mod", 0.7f, new Vector2(x + 6, y + 28), 1, defaultState); Checkbox.AddToggleCallback(OnCheckboxChecked); Slider.SliderCallbacks += OnSliderChange; }
public ComponentBenchmarks() { ECSWorld world = new ECSWorld(false); cm = world.ComponentManager; entities = new Entity[numEntities]; for (int i = 0; i < numEntities; i++) { Entity e = new Entity(i + 1, 0); entities[i] = e; cm.AddEntity(e, EntityArchetype.Empty); cm.AddComponent(e, new TestComponent()); } }
public static int CreatePlayer() { if (playerCreated == false) { //Player = CreateEntity(); //Create Player playerCreated = true; int Player = 0; _entities[0] = Player; CellAppearance ca = new CellAppearance(Colors.Player, Colors.FloorBackgroundFov, 64); RenderComponent rc = new RenderComponent(Player, ca, 2); ComponentManager.AddComponent(Player, rc); PositionComponent pc = new PositionComponent(Player, new Point(0, 0)); ComponentManager.AddComponent(Player, pc); PlayerControlComponent pcc = new PlayerControlComponent(Player); ComponentManager.AddComponent(Player, pcc); } return(0); }
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args) { // TODO ATMOS: Don't use Owner to get the UI. if (canister.Owner.GetUIOrNull(GasCanisterUiKey.Key) is {} ui) { ui.OnReceiveMessage += msg => OnCanisterUIMessage(uid, canister, msg); } // Ensure container manager. if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)) { containerManager = ComponentManager.AddComponent <ContainerManagerComponent>(EntityManager.GetEntity(uid)); } // Ensure container. if (!containerManager.TryGetContainer(canister.ContainerName, out _)) { containerManager.MakeContainer <ContainerSlot>(canister.ContainerName); } }
private void OnActorPlayerAttach(AttachPlayerEvent args) { // Cannot attach to a deleted entity. if (args.Entity.Deleted) { args.Result = false; return; } var uid = args.Entity.Uid; // Check if there was a player attached to the entity already... if (ComponentManager.TryGetComponent(uid, out ActorComponent actor)) { // If we're not forcing the attach, this fails. if (!args.Force) { args.Result = false; return; } // Set the event's force-kicked session before detaching it. args.ForceKicked = actor.PlayerSession; // This detach cannot fail, as a player is attached to this entity. // It's important to note that detaching the player removes the component. RaiseLocalEvent(uid, new DetachPlayerEvent()); } // We add the actor component. actor = ComponentManager.AddComponent <ActorComponent>(args.Entity); actor.PlayerSession = args.Player; args.Player.SetAttachedEntity(args.Entity); args.Result = true; // TODO: Remove component message. args.Entity.SendMessage(actor, new PlayerAttachedMsg(args.Player)); // The player is fully attached now, raise an event! RaiseLocalEvent(uid, new PlayerAttachedEvent(args.Entity, args.Player)); }
/// <summary> /// Attaches a player session to an entity, optionally kicking any sessions already attached to it. /// </summary> /// <param name="entity">The entity to attach the player to</param> /// <param name="player">The player to attach to the entity</param> /// <param name="force">Whether to kick any existing players from the entity</param> /// <param name="forceKicked">The player that was forcefully kicked, or null.</param> /// <returns>Whether the attach succeeded, or not.</returns> public bool Attach(IEntity entity, IPlayerSession player, bool force, out IPlayerSession?forceKicked) { // Null by default. forceKicked = null; // Cannot attach to a deleted entity. if (entity.Deleted) { return(false); } var uid = entity.Uid; // Check if there was a player attached to the entity already... if (ComponentManager.TryGetComponent(uid, out ActorComponent actor)) { // If we're not forcing the attach, this fails. if (!force) { return(false); } // Set the event's force-kicked session before detaching it. forceKicked = actor.PlayerSession; // This detach cannot fail, as a player is attached to this entity. // It's important to note that detaching the player removes the component. RaiseLocalEvent(uid, new DetachPlayerEvent()); } // We add the actor component. actor = ComponentManager.AddComponent <ActorComponent>(entity); actor.PlayerSession = player; player.SetAttachedEntity(entity); // The player is fully attached now, raise an event! RaiseLocalEvent(uid, new PlayerAttachedEvent(entity, player, forceKicked)); return(true); }
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args) { // TODO ATMOS: Don't use Owner to get the UI. if (canister.Owner.GetUIOrNull(GasCanisterUiKey.Key) is {} ui) { ui.OnReceiveMessage += msg => OnCanisterUIMessage(uid, canister, msg); } // Ensure container manager. if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)) { containerManager = ComponentManager.AddComponent <ContainerManagerComponent>(EntityManager.GetEntity(uid)); } // Ensure container. if (!containerManager.TryGetContainer(canister.ContainerName, out _)) { containerManager.MakeContainer <ContainerSlot>(canister.ContainerName); } if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) { return; } if (!nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode)) { return; } // Create a pipenet if we don't have one already. portNode.TryAssignGroupIfNeeded(); Get <AtmosphereSystem>().Merge(portNode.Air, canister.InitialMixture); portNode.Air.Temperature = canister.InitialMixture.Temperature; portNode.Volume = canister.InitialMixture.Volume; }
public override void OnInspectorGUI() { if (target == null) { return; } Entity e = (Entity)target; if (EntityManager.Instance == null || ComponentManager.Instance == null) { return; } PlayerManager playerManager = PlayerManager.Instance; EntityManager entityManager = EntityManager.Instance; ComponentManager componentManager = ComponentManager.Instance; if (e.id == 0 || entityManager.entities.ContainsKey(e.id) == false) { if (GUILayout.Button("Create Entity")) { e.id = entityManager.GenerateEntityID(); e.components = new List <ComponentType>(); entityManager.entities.Add(e.id, e); componentManager.entityGameObjects.Add(e.id, e.gameObject); componentManager.entityTransforms.Add(e.id, e.transform); componentManager.rigidbodies.Add(e.id, e.GetComponent <Rigidbody>()); } return; } else { if (GUILayout.Button("Delete Entity")) { entityManager.DeleteEntity(e.id); return; } } EditorGUILayout.IntField("EntityID", e.id); EditorGUILayout.BeginHorizontal(); componentTypeToSet = (Fudo.Enums.ComponentType)EditorGUILayout.EnumPopup("Component to create:", componentTypeToSet); if (GUILayout.Button("Create")) { if (e.components.Contains(componentTypeToSet) == false) { switch (componentTypeToSet) { case Enums.ComponentType.Position: componentManager.AddComponent(Enums.ComponentType.Position, Vector3.zero, e.id); break; case Enums.ComponentType.Scale: componentManager.AddComponent(Enums.ComponentType.Scale, Vector3.one, e.id); break; case Enums.ComponentType.Rotation: componentManager.AddComponent(Enums.ComponentType.Rotation, Quaternion.identity, e.id); break; case Enums.ComponentType.Direction: componentManager.AddComponent(Enums.ComponentType.Direction, Vector3.forward, e.id); break; case Enums.ComponentType.MaxSpeed: componentManager.AddComponent(Enums.ComponentType.MaxSpeed, 5.0f, e.id); break; case Enums.ComponentType.Movement: componentManager.AddComponent(Enums.ComponentType.Movement, new Components.Movement(), e.id); break; case Enums.ComponentType.InputToMovement: componentManager.AddComponent(Enums.ComponentType.InputToMovement, new Components.MovementInput(), e.id); break; } } } if (GUILayout.Button("Remove")) { if (e.components.Contains(componentTypeToSet)) { componentManager.RemoveComponent(componentTypeToSet, e.id); } } EditorGUILayout.EndHorizontal(); foreach (Enums.ComponentType componentType in e.components) { EditorGUILayout.Space(); Rect rect = EditorGUILayout.BeginVertical(); EditorGUI.DrawRect(rect, Color.gray); switch (componentType) { default: Debug.LogWarning("Component draw not implemented for: " + componentType); break; case Enums.ComponentType.MaxSpeed: float f = componentManager.ReturnFloatComponent(componentType, e.id); f = EditorGUILayout.FloatField(componentType.ToString(), f); componentManager.SetComponent(componentType, f, e.id); break; case Enums.ComponentType.IsVisible: bool b = componentManager.ReturnBooleanComponent(componentType, e.id); b = EditorGUILayout.Toggle(componentType.ToString(), b); componentManager.SetComponent(componentType, b, e.id); break; case Enums.ComponentType.Position: case Enums.ComponentType.Direction: case Enums.ComponentType.Scale: Vector3 v = componentManager.ReturnVector3Component(componentType, e.id); v = EditorGUILayout.Vector3Field(componentType.ToString(), v); componentManager.SetComponent(componentType, v, e.id); break; case Enums.ComponentType.Rotation: Quaternion qt = componentManager.ReturnQuaternionComponent(componentType, e.id); qt = Quaternion.Euler(EditorGUILayout.Vector3Field(componentType.ToString(), qt.eulerAngles)); componentManager.SetComponent(componentType, qt, e.id); break; case Enums.ComponentType.Movement: case Enums.ComponentType.PreviousFrameMovement: EditorGUILayout.LabelField(componentType.ToString()); Components.Movement mv = componentManager.ReturnMovementComponent(componentType, e.id); mv.velocity = EditorGUILayout.Vector3Field("Velocity", mv.velocity); break; case Enums.ComponentType.Controllable: Components.Controllable controllable; if (componentManager.controllableComponents.TryGetValue(e.id, out controllable)) { EditorGUILayout.LabelField(componentType.ToString()); } break; } EditorGUILayout.EndVertical(); } }
public void AddComponent(int num) { componentManager.AddComponent(selectedPos, num); }
public void SetTile(Point tile, TileType type) { switch (type) { case TileType.Floor: { isWalkable[tile.X, tile.Y] = true; isTransparent[tile.X, tile.Y] = true; permanentLight[tile.X, tile.Y] = 100; tileType[tile.X, tile.Y] = TileType.Floor; break; } case TileType.Wall: { isWalkable[tile.X, tile.Y] = false; isTransparent[tile.X, tile.Y] = false; tileType[tile.X, tile.Y] = TileType.Wall; break; } case TileType.Corridor: { isWalkable[tile.X, tile.Y] = true; isTransparent[tile.X, tile.Y] = true; permanentLight[tile.X, tile.Y] = 40; tileType[tile.X, tile.Y] = TileType.Corridor; break; } case TileType.Door: { isWalkable[tile.X, tile.Y] = true; isTransparent[tile.X, tile.Y] = true; permanentLight[tile.X, tile.Y] = 100; tileType[tile.X, tile.Y] = TileType.Floor; int e = EntityManager.CreateEntity(); ComponentManager.AddComponent(e, new PositionComponent(e, tile)); ComponentManager.AddComponent(e, new RenderComponent(e, CellAppearances.DoorOpenFov, 1)); ComponentManager.AddComponent(e, new PhysicalAttributes(e, false, false, EntitySizes.OccupiesCell)); ComponentManager.AddComponent(e, new DoorComponent(e)); //map.Add( tile, e ); break; } case TileType.StairsUp: { isWalkable[tile.X, tile.Y] = true; isTransparent[tile.X, tile.Y] = true; permanentLight[tile.X, tile.Y] = 100; tileType[tile.X, tile.Y] = TileType.Floor; int e = EntityManager.CreateEntity(); ComponentManager.AddComponent(e, new PositionComponent(e, tile)); ComponentManager.AddComponent(e, new RenderComponent(e, CellAppearances.StairsUpFov, 1)); break; } case TileType.None: { isWalkable[tile.X, tile.Y] = false; isTransparent[tile.X, tile.Y] = false; permanentLight[tile.X, tile.Y] = 0; tileType[tile.X, tile.Y] = TileType.None; break; } } }
public bool AddComponent(string type, string name, string path, Orrb.RendererComponentConfig config, bool enabled) { return(component_manager_.AddComponent(type, name, path, config, enabled)); }