public override void _Ready() { _collisionShape2d = GetNode <CollisionShape2D>("CollisionShape2D"); _animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer"); _blinkAnimationPlayer = GetNode <AnimationPlayer>("BlinkAnimationPlayer"); _deathTimer = GetNode <Timer>("DeathTimer"); _selectableComponent = GetNode <SelectableComponent>("SelectableComponent"); _sprite = GetNode <Sprite>("Sprite"); _sprite.Texture = _spriteTexture; _velocity = Vector2.Right.Rotated(Mathf.Deg2Rad(Main.RNG.RandfRange(MIN_ANGLE, MAX_ANGLE))); _velocity *= Main.RNG.RandfRange(MIN_SPEED, MAX_SPEED); _stateMachine.AddState(State.BOUNCING, StateBouncing); _stateMachine.AddState(State.SEPARATE, StateSeparate); _stateMachine.AddState(State.SETTLED, StateSettled); _stateMachine.AddState(State.PICKED_UP, StatePickedUp); _stateMachine.SetInitialState(State.BOUNCING); AddToGroup(GROUP); _deathTimer.Connect("timeout", this, nameof(OnDeathTimerTimeout)); _selectableComponent.Connect(nameof(SelectableComponent.Selected), this, nameof(OnSelected)); _selectableComponent.Connect(nameof(SelectableComponent.SelectEnter), this, nameof(OnSelectEnter)); _selectableComponent.Connect(nameof(SelectableComponent.SelectLeave), this, nameof(OnSelectLeave)); }
protected void EndDrag() { selectionImage.enabled = false; RaycastHit hit = RaycastToGround(); dragEndPos = hit.point; if (dragStartPos != null && dragEndPos != null) { Vector3 midPoint = (dragStartPos + dragEndPos) / 2; Vector3 extents = new Vector3(Mathf.Abs((dragStartPos - midPoint).x), 100, Mathf.Abs((dragStartPos - midPoint).z)); Collider[] objectsHoveredOver = Physics.OverlapBox(midPoint, extents); foreach (Collider c in objectsHoveredOver) { SelectableComponent selectableComponent = c.GetComponent <SelectableComponent>(); if (selectableComponent != null) { selectedObjects.Add(selectableComponent); selectableComponent.GetComponent <MyObject>().OnGameObjectDisabled += Deselect; selectableComponent.Select(); } } } }
private void Start() { SelectableComponent selectableComponent = GetComponentInChildren <SelectableComponent>(); selectableComponent.UpdateName("PlayerBase"); selectableComponent.SetScale(0.06f); selectableComponent.SetShown(true); }
private void Awake() { agentMovementController = GetComponent <AgentMovementController>(); select = GetComponentInChildren <SelectableComponent>(); agentUI = FindObjectOfType <AgentUI>(); abilityController = FindObjectOfType <AbilityController>(); renderer = GetComponentInChildren <MeshRenderer>(); }
private void Awake() { movementController = GetComponent <MovementController>(); movementController.onReachedSystem += OnReachedSystem; movementController.onLeaveSystem += OnLeaveSystem; movementController.SetInternalMovementOnly(false); selectableComponent = GetComponentInChildren <SelectableComponent>(); selectableComponent.UpdateName("Fleet"); selectableComponent.SetScale(0.04f); }
public void Start() { m_universe = FindObjectOfType <Universe>(); m_universe.onDayChanged += ProcessDayChange; SelectableComponent select = GetComponentInChildren <SelectableComponent>(); select.UpdateName(m_name); select.SetUnitSelectorText("0"); select.SetScale(0.06f); select.SetShown(true); name = m_name; FindNearbySystems(); outline.SetActive(false); }
public List <SelectableComponent> GetSelectableInArea(Vector2 start, Vector2 end) { Collider2D[] colliders = Physics2D.OverlapAreaAll(start, end); List <SelectableComponent> selectable = new List <SelectableComponent>(); foreach (Collider2D collider in colliders) { SelectableComponent sc = collider.gameObject.GetComponent <SelectableComponent>(); if (sc is null || !_settings.selectionMask.Contains(sc.selectable.GetType())) { continue; } selectable.Add(sc); } return(selectable); }
private void UpdateVisibility(Transform objectTransform) { if (objectTransform.gameObject.layer == 9) { objectTransform.gameObject.layer = 10; foreach (Transform trans in objectTransform.GetComponentsInChildren <Transform>(true)) { trans.gameObject.layer = 10; } } SelectableComponent select = objectTransform.GetComponentInChildren <SelectableComponent>(); if (select) { select.SetVisible(true); } }
private void Awake() { units = new List <Unit>(); selectableComponent = GetComponentInChildren <SelectableComponent>(); selectableComponent.UpdateName(armyName); selectableComponent.SetScale(0.04f); meshRenderer = GetComponentInChildren <MeshRenderer>(); capsuleCollider = GetComponentInChildren <CapsuleCollider>(); movementController = GetComponent <MovementController>(); movementController.onReachedSystem += OnReachedSystem; movementController.onLeaveSystem += OnLeaveSystem; if (movementController.GetSystemLocation()) { movementController.GetSystemLocation().AddArmy(this); } movementController.SetBlocking(true); SetArmyStatus(armyStatus); }
void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { GameObject objectHit = hit.transform.gameObject; SelectableComponent selectableComponent = objectHit.GetComponent <SelectableComponent>(); if (selectableComponent == null) { return; } if (selectableComponent.Select()) { selectableComponent.gameObject.GetComponent <ColorLerpComponent>().Activate(); } } }
private void UnHighlight(SelectableComponent selectableComponent) { if (selectableComponent == null) { return; } var renderer = selectableComponent.GetComponent <Renderer>(); // previously selected object have a renderer - unhighlight it if (renderer != null) { if (!_rendererOriginalMaterials.ContainsKey(renderer)) { return; } // restore original material on previously selected object var originalMaterial = _rendererOriginalMaterials[renderer]; _rendererOriginalMaterials.Remove(renderer); renderer.material = originalMaterial; } }
private void SelectionManagerOnSelectedObjectChanged(SelectableComponent selectableComponent) { HighlightedObject = selectableComponent; }
private void SelectionManagerOnSelectedObjectChanged(SelectableComponent selectableComponent) { SelectedInteractable = GameManager.Instance.SelectionManager.SelectedObject?.gameObject .GetComponent <IInteractable>(); }
public void Select(SelectableComponent selectableComponent) { _selected.Add(selectableComponent); selectableComponent.Select(); }
private void OnSelectedObjectChanged(SelectableComponent selectableComponent) { this.gameObject.SetActive(selectableComponent != null); }