Ejemplo n.º 1
0
 public override int GetHashCode()
 {
     // combine the hash codes of all members here (e.g. with XOR operator ^)
     return(X.GetHashCode() ^ Y.GetHashCode() ^ Button.GetHashCode() ^ MouseWheel.GetHashCode());
 }
Ejemplo n.º 2
0
    void Update()
    {
        // Released mouse while dragged, confirm selection
        if (Input.GetMouseButtonUp(mouseButton.GetHashCode()) && isDragging)
        {
            isDragging = false;
            if (Vector2.Distance(startPoint, Input.mousePosition) < 8)
            {
                if (!Input.GetKey(multiSelectKey) && !excludedScreenAreas.Contains(Input.mousePosition))
                {
                    DeselectAllObjects();
                }
                PerformMouseClick();
            }
            else if (selectedUnits.Count == 0)
            {
                PerformMouseClick();
            }
        }

        // Check if started dragging
        if (Input.GetMouseButtonDown(mouseButton.GetHashCode()) && !excludedScreenAreas.Contains(Input.mousePosition))
        {
            isDragging = true;
            startPoint = Input.mousePosition;
            if (!Input.GetKey(multiSelectKey))
            {
                DeselectAllObjects();
            }
        }

        // Activelly select all units under selection rect
        if (isDragging)
        {
            if (Vector2.Distance(startPoint, Input.mousePosition) < 8)
            {
                return;
            }

            Rect rect = ConstructSelectionRect();
            IterateAllSelectable((GameObject go) =>
            {
                Vector3 pos = Camera.main.WorldToScreenPoint(go.transform.position);
                pos.y       = Screen.height - pos.y;

                if (rect.Contains(new Vector2(pos.x, pos.y)))
                {
                    MarkObjectAsSelected(go);
                }
                else if (!Input.GetKey(multiSelectKey))
                {
                    DeselectObject(go);
                }
            });
        }

#if UNITY_EDITOR
        // Regression test for bug when same object can be selected multiple times
        if (GetSelectedUnits().Count > Data.GetInstance().GetAllUnits().Length)
        {
            Debug.LogError("Selected unit count is greater than total unit count on field: "
                           + GetSelectedUnits().Count + " > " + Data.GetInstance().GetAllUnits().Length);
        }
#endif
    }