private void UpdateUnitInfo(Selectable selected)
    {
        actionButtonsController.ClearSelection();
        unitSelectionText.enabled = true;
        unitPortrait.SetActive(true);
        _selectionEntityInfo   = selected.GetComponentInParent <EntityInfo>();
        unitSelectionText.text = _selectionEntityInfo.entityName;
        _singleSelection       = selected.gameObject;
        _singleSelectionCamera = _singleSelection.GetComponentInChildren <Camera>();
        UpdateDynamicUnitInfo();

        var workerUnitManager = _singleSelection.GetComponent <WorkerUnitManager>();

        Debug.Log($"Selected {selected}");
        if (workerUnitManager)
        {
            actionButtonsController.ConstructionUnitSelected(_selectionEntityInfo.race);
        }

        if (_singleSelectionCamera)
        {
            _singleSelectionCamera.enabled = true;
        }
    }
Ejemplo n.º 2
0
        protected override void OnUpdate()
        {
            // raycast from mouse position
            Ray  ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            bool hit = Physics.Raycast(ray, out var hitInfo);

            for (int i = 0; i < SelectableComponents.Length; i++)
            {
                Selectable selectable = SelectableComponents.Selectables[i];
                Transform  transform  = SelectableComponents.Transforms[i];

                if (selectable != null && transform != null)
                {
                    if (selectable.Enabled)
                    {
                        float distance;
                        if (hit)
                        {
                            Vector3 pos    = transform.position;
                            Vector3 hitPos = hitInfo.point;
                            distance = Vector3.Distance(pos, hitPos);
                        }
                        else
                        {
                            distance = float.MaxValue;
                        }

                        foreach (var selectableObject in selectable.SelectionIndicators)
                        {
                            float alpha;
                            if (hit)
                            {
                                float lerp = 1f - Mathf.Clamp(
                                    Mathf.Max(distance - selectableObject.DistanceBeforeFade, 0f)
                                    / selectableObject.DistanceToFullFade,
                                    0f, 1f);
                                alpha = selectableObject.MaxOpacity * Easing.Smoothstep2(lerp);
                                alpha = alpha <= SelectableInactiveEpsilon ? 0 : alpha;
                            }
                            else
                            {
                                alpha = 0f;
                            }

                            var renderers = selectableObject.SelectionRenderers;
                            for (int j = 0; j < renderers.Count; j++)
                            {
                                var renderer = renderers[j];

                                Color color = renderer.material.color;
                                color.a = alpha;
                                renderer.material.color = color;
                            }
                        }
                    }
                    else
                    {
                        // nothing to do
                    }
                }
            }
        }