コード例 #1
0
ファイル: InputManager.cs プロジェクト: Debarquer/URTS
    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();
                }
            }
        }
    }
コード例 #2
0
        private void Highlight(SelectableComponent selectableComponent)
        {
            if (selectableComponent == null)
            {
                return;
            }

            var renderer = selectableComponent.GetComponent <Renderer>();

            // selected object have a renderer - highlight it
            if (renderer != null)
            {
                // memorize original material for selected object
                _rendererOriginalMaterials[renderer] = renderer.material;

                renderer.material = _highlightMaterial;
            }
        }
コード例 #3
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;
            }
        }