Esempio n. 1
0
    void OnTouchBegan(Touch touch)
    {
        int fingerId = touch.fingerId;

        if (touch.phase == TouchPhase.Began)
        {
            GameObject selectedObject = _objectSelector.DetermineSelection(touch.position);

            //assigning current touch objects
            if (!_currentSelection.ContainsKey(fingerId))
            {
                _currentSelection.Add(fingerId, selectedObject);
            }
            else
            {
                _currentSelection[fingerId] = selectedObject;
            }

            //assign selected object as beginning object selected
            _selectedOnTouchBegan[fingerId] = _currentSelection[fingerId];
            //selection respond to object being actively selected
            if (_currentSelection[fingerId])
            {
                //change it here TODO
                //if (!_currentSelection[fingerId].GetComponent<DragSnapSelectionResponse>())
                _selectionResponse.IsSelected(_currentSelection[fingerId], touch.position);
            }
        }
    }
Esempio n. 2
0
    //public virtual GameObject DetermineSelection(Vector3 inputPosition)
    //{
    //    //create ray
    //    Ray ray = Camera.main.ScreenPointToRay(inputPosition);
    //    //draw raycast
    //    Debug.DrawLine(ray.origin, ray.direction, Color.red);

    //    RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
    //    //check that it hit something
    //    if (!hit)
    //        return null;

    //    return hit.collider.gameObject;
    //}

    public virtual void IsSelected(GameObject gameObject, Vector3 inputPosition)
    {
        //check it exists
        if (gameObject)
        {
            //check if it has its own selection response
            ISelectionResponse selectionResponse = gameObject.GetComponent <ISelectionResponse>();
            if (selectionResponse != null)
            {
                selectionResponse.IsSelected(gameObject, inputPosition);
            }
            else
            {
                //use default implementation
                //follow input position
                //var position = Camera.main.ScreenToWorldPoint(inputPosition);
                //gameObject.transform.position = new Vector2(position.x, position.y);
            }
        }
    }