public virtual void OnHoverSelected(GameObject gameObject, Vector3 inputPosition) { //check if it has its own selection response ISelectionResponse selectionResponse = gameObject.GetComponent <ISelectionResponse>(); if (selectionResponse != null) { selectionResponse.OnHoverSelected(gameObject, inputPosition); } else { //use default implementation //just follow is selected method and drag object to touch location //this.IsSelected(gameObject, inputPosition); } }
void OnTouchStationary(Touch touch) { int fingerId = touch.fingerId; if (touch.phase == TouchPhase.Began) { //set initial hover time on touch began if (!_hoverTime.ContainsKey(fingerId)) { _hoverTime.Add(fingerId, timeOnHover); } else { _hoverTime[fingerId] = timeOnHover; } } if (touch.phase == TouchPhase.Moved) { //reset hover time _hoverTime[fingerId] = timeOnHover; //reset stationary _selectedOnTouchStationary.Remove(fingerId); } if (touch.phase == TouchPhase.Stationary) { //reduce hover time per tic _hoverTime[fingerId] -= Time.deltaTime; GameObject selectedObject = _objectSelector.DetermineSelection(touch.position); //if (_currentSelection.ContainsKey(fingerId)) //{ // //TODO - not select anything else // if (_currentSelection[fingerId]) // { // var controlOption = _currentSelection[fingerId].GetComponent<ITouchControlOptions>().TouchOption; // if (controlOption) // { // if (controlOption.enableDiselectOnlyOnTouchOff) // { // if (_currentSelection[fingerId]) // { // if (_currentSelection[fingerId] != selectedObject) // { // selectedObject = null; // } // } // } // } // else // { // if (enableDiselectOnlyOnTouchOff) // { // if (_currentSelection[fingerId]) // { // if (_currentSelection[fingerId] != selectedObject) // selectedObject = null; // } // } // } // } //} if (!_currentSelection.ContainsKey(fingerId)) { _currentSelection.Add(fingerId, selectedObject); } else { if (_currentSelection[fingerId]) { var controlOption = _currentSelection[fingerId].GetComponent <ITouchControlOptions>(); if (controlOption != null) { if (!controlOption.enableDiselectOnlyOnTouchOff) { _currentSelection[fingerId] = selectedObject; } } else { if (!enableDiselectOnlyOnTouchOff) { _currentSelection[fingerId] = selectedObject; } } } else { _currentSelection[fingerId] = selectedObject; } } //determine reponse on stationary if (_hoverTime[fingerId] <= 0) { if (_currentSelection[fingerId]) { _selectionResponse.OnHoverSelected(_currentSelection[fingerId], touch.position); } if (!_selectedOnTouchStationary.ContainsKey(fingerId)) { _selectedOnTouchStationary.Add(fingerId, _currentSelection[fingerId]); } else { _selectedOnTouchStationary[fingerId] = _currentSelection[fingerId]; } } } }