Пример #1
0
        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));
        }
Пример #2
0
    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();
                }
            }
        }
    }
Пример #3
0
    private void Start()
    {
        SelectableComponent selectableComponent = GetComponentInChildren <SelectableComponent>();

        selectableComponent.UpdateName("PlayerBase");
        selectableComponent.SetScale(0.06f);
        selectableComponent.SetShown(true);
    }
Пример #4
0
 private void Awake()
 {
     agentMovementController = GetComponent <AgentMovementController>();
     select            = GetComponentInChildren <SelectableComponent>();
     agentUI           = FindObjectOfType <AgentUI>();
     abilityController = FindObjectOfType <AbilityController>();
     renderer          = GetComponentInChildren <MeshRenderer>();
 }
Пример #5
0
 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);
 }
Пример #6
0
    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);
    }
Пример #7
0
    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);
    }
Пример #8
0
    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);
        }
    }
Пример #9
0
    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);
    }
Пример #10
0
        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();
                }
            }
        }
Пример #11
0
        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;
            }
        }
Пример #12
0
 private void SelectionManagerOnSelectedObjectChanged(SelectableComponent selectableComponent)
 {
     HighlightedObject = selectableComponent;
 }
Пример #13
0
 private void SelectionManagerOnSelectedObjectChanged(SelectableComponent selectableComponent)
 {
     SelectedInteractable = GameManager.Instance.SelectionManager.SelectedObject?.gameObject
                            .GetComponent <IInteractable>();
 }
Пример #14
0
 public void Select(SelectableComponent selectableComponent)
 {
     _selected.Add(selectableComponent);
     selectableComponent.Select();
 }
 private void OnSelectedObjectChanged(SelectableComponent selectableComponent)
 {
     this.gameObject.SetActive(selectableComponent != null);
 }