private GameObject MakeBackground() { GameObject g = new GameObject(); g.name = "Background"; g.transform.position = new Vector3(0, 0, 5); g.AddComponent <BoxCollider2D>().size = new Vector2(30, 30); ClickComponent c = g.AddComponent <ClickComponent>().Init(); c.OnLeftClick = () => { if (GameManager.instance.mMouseMode != GameManager.MouseMode.Selecting) { return; } Selected = null; }; c.OnRightClick = () => { if (GameManager.instance.mMouseMode != GameManager.MouseMode.Selecting) { return; } Selected = null; }; return(g); }
private void ReplaceChange(ClickComponent input) { foreach (var e in _contexts.game.GetEntitiesWithMove(new IntVector2(input.x, input.y)).Where(e => e.isInteractive)) { e.ReplaceExchange(ExchangeState.START); } }
public Button(Renderer2D r2D, Rectangle bounds) : base(r2D) { ClickComponent cc = new ClickComponent(this, bounds); cc.click += new ClickComponent.Click(cc_click); cc.press += new ClickComponent.Press(cc_press); cc.release += new ClickComponent.Release(cc_release); cc.enter += new ClickComponent.Enter(cc_enter); cc.exit += new ClickComponent.Exit(cc_exit); cc.hover += new ClickComponent.Hover(cc_hover); addComponent(cc); this.state = ButtonStates.NORMAL; this.Color = this.defaultColor = this.hoverColor = this.pressColor = Color.White; Bounds = bounds; this.position = new Vector3(Bounds.X, Bounds.Y, 0); this.dimensions = new Vector3(Bounds.Width, Bounds.Height, 0); this.textPosition = Vector2.Zero; this.useText = true; this.enabled = true; this.FontSize = 20; this.textures = new Texture2D[3]; ColorModifier = 1f; }
protected override void Execute(List <InputEntity> entities) { var inputEntity = entities.SingleEntity(); var click = inputEntity.click; bool canMove = _contexts.game.GetEntitiesWithMove(new IntVector2(click.x, click.y)).SingleEntity().isMovable; if (canMove) { if (_lastInputComponent != null) { //检测当前操作的是否是上下左右四个点中的一个 if ((click.x == _lastInputComponent.x - 1 && click.y == _lastInputComponent.y) || (click.x == _lastInputComponent.x + 1 && click.y == _lastInputComponent.y) || (click.y == _lastInputComponent.y - 1 && click.x == _lastInputComponent.x) || (click.y == _lastInputComponent.y + 1 && click.x == _lastInputComponent.x)) { ReplaceChange(click); ReplaceChange(_lastInputComponent); _lastInputComponent = null; } } else { _lastInputComponent = new ClickComponent(); } if (_lastInputComponent != null) { _lastInputComponent.x = click.x; _lastInputComponent.y = click.y; } } }
internal override void Update() { clickComponents = EntityManager.Instance.GetEntitiesComponents <ClickComponent>(); if (clickComponents.Length == 0) { return; } for (int i = 0; i < clickComponents.Length; i++) { if (!clickComponents[i].Entity.EntityEnabled) { continue; } if (!clickComponents[i].ComponentEnabled) { continue; } ClickComponent curComp = clickComponents[i]; // Check if the entity has been clicked if (!curComp.IsClicked) { if (curComp.Entity.GetComponent <HoverCollisionComponent>().IsHovering) { if (Application.Input.GetMouseButton(curComp.MouseButton) == Application.Input.InputAction.Pressed) { curComp.IsClicked = true; Debug.Log(curComp.Entity.EntityName + " has been clicked with " + curComp.MouseButton, Debug.DebugLayer.Entity, Debug.DebugLevel.Information); } } } else { curComp.Timer += Application.Time.DeltaTime; if (curComp.ClickingMethod == ClickMethod.SingleClick) { if (curComp.Timer <= multiClickTime) { if (Application.Input.GetMouseButton(Application.Input.MouseButtons.button1) == Application.Input.InputAction.Released) { if (curComp.ClickFunc == null) { Debug.Log("ClickHandlers method was null", Debug.DebugLayer.Entity, Debug.DebugLevel.Error); curComp.IsClicked = false; curComp.Timer = 0; continue; } curComp.ClickFunc(curComp.Entity); curComp.IsClicked = false; curComp.Timer = 0; } } else { curComp.IsClicked = false; curComp.Timer = 0; } } } } }