public virtual void WasSelected(GameObject gameObject, Vector3 inputPosition) { //check if it has its own selection response ISelectionResponse selectionResponse = gameObject.GetComponent <ISelectionResponse>(); if (selectionResponse != null) { selectionResponse.WasSelected(gameObject, inputPosition); } else { //use default implementation //no implementation yet } }
void OnTouchMove(Touch touch) { int fingerId = touch.fingerId; if (touch.phase == TouchPhase.Moved) { GameObject selectedObject = _objectSelector.DetermineSelection(touch.position); ////TODO //if (_currentSelection.ContainsKey(fingerId)) //{ // if (_currentSelection[fingerId]) // { // var controlOption = _currentSelection[fingerId].GetComponent<ITouchControlOptions>().TouchOption; // if (controlOption) // { // if (controlOption.enableDiselectOnlyOnTouchOff) // { // //_selectionResponse.IsSelected(_currentSelection[fingerId], touch.position); // selectedObject = null; // selectedObject = _currentSelection[fingerId]; // } // else // { // selectedObject= _objectSelector.DetermineSelection(touch.position); // } // } // else // { // if (enableDiselectOnlyOnTouchOff) // { // //_selectionResponse.IsSelected(_currentSelection[fingerId], touch.position); // selectedObject = null; // selectedObject = _currentSelection[fingerId]; // } // else // { // selectedObject= _objectSelector.DetermineSelection(touch.position); // } // } // } // else // { // selectedObject = _objectSelector.DetermineSelection(touch.position); // } //} //else //{ // selectedObject = _objectSelector.DetermineSelection(touch.position); //} //determine if touch control option exist if (selectedObject) { if (_currentSelection[fingerId]) { bool useSelectedObjectOption = true; var option = _currentSelection[fingerId].GetComponent <ITouchControlOptions>(); if (option != null) { if (option.enableDiselectOnlyOnTouchOff) { useSelectedObjectOption = false; } } else { if (enableDiselectOnlyOnTouchOff) { useSelectedObjectOption = false; } } if (useSelectedObjectOption) { _touchControlOptions = selectedObject.GetComponent <ITouchControlOptions>(); } else { if (option != null) { _touchControlOptions = option; } } } else { _touchControlOptions = selectedObject.GetComponent <ITouchControlOptions>(); } } else { if (_currentSelection[fingerId]) { _touchControlOptions = _currentSelection[fingerId].GetComponent <ITouchControlOptions>(); } } //predetermine if keys already exists if (!_selectedOnTouchMove.ContainsKey(fingerId)) { _selectedOnTouchMove.Add(fingerId, new List <GameObject>()); } if (!_currentSelection.ContainsKey(fingerId)) { _currentSelection.Add(fingerId, null); } //determine response on touch move if (selectedObject) { if (_currentSelection[fingerId]) { if (_currentSelection[fingerId] != selectedObject) { if (_touchControlOptions == null) { if (enablePassiveSelection) { _selectionResponse.WasSelected(_currentSelection[fingerId], touch.position); } else { if (!enableDiselectOnlyOnTouchOff) { _selectionResponse.Deselected(_currentSelection[fingerId], touch.position); } } } else { if (_touchControlOptions.enablePassiveSelection) { _selectionResponse.WasSelected(_currentSelection[fingerId], touch.position); } else { if (!_touchControlOptions.enableDiselectOnlyOnTouchOff) { _selectionResponse.Deselected(_currentSelection[fingerId], touch.position); } } } //add current to touch move if (_currentSelection[fingerId] && !_selectedOnTouchMove[fingerId].Contains(_currentSelection[fingerId])) { _selectedOnTouchMove[fingerId].Add(_currentSelection[fingerId]); } //assign selected as the new current object if (_touchControlOptions == null) { if (!enableDiselectOnlyOnTouchOff) { _currentSelection[fingerId] = selectedObject; } } else { if (!_touchControlOptions.enableDiselectOnlyOnTouchOff) { _currentSelection[fingerId] = selectedObject; } } } //touch response _selectionResponse.IsSelected(_currentSelection[fingerId], touch.position); //add selected object to current if (!_selectedOnTouchMove[fingerId].Contains(selectedObject)) { _selectedOnTouchMove[fingerId].Add(selectedObject); } } else { _selectionResponse.IsSelected(selectedObject, touch.position); _currentSelection[fingerId] = selectedObject; } // add current to touch move if (_currentSelection[fingerId] && !_selectedOnTouchMove[fingerId].Contains(_currentSelection[fingerId])) { _selectedOnTouchMove[fingerId].Add(_currentSelection[fingerId]); } } else { if (_touchControlOptions == null) { if (enableDiselectOnlyOnTouchOff) { //look for most recent item selected and make it current //if (!_currentSelection[fingerId]) //{ // int selectedOnTouchMoveCount = _selectedOnTouchMove[fingerId].Count; // if (selectedOnTouchMoveCount > 0) // { // _currentSelection[fingerId] = _selectedOnTouchMove[fingerId][selectedOnTouchMoveCount - 1]; // } //} if (enablePassiveSelection) { if (_currentSelection[fingerId]) { _selectionResponse.WasSelected(_currentSelection[fingerId], touch.position); } } else { if (_currentSelection[fingerId]) { _selectionResponse.IsSelected(_currentSelection[fingerId], touch.position); } } } else { if (enablePassiveSelection) { if (_currentSelection[fingerId]) { _selectionResponse.WasSelected(_currentSelection[fingerId], touch.position); } } else { if (_currentSelection[fingerId]) { _selectionResponse.Deselected(_currentSelection[fingerId], touch.position); } } //Allow null current selection _currentSelection[fingerId] = selectedObject; } } else { if (_touchControlOptions.enableDiselectOnlyOnTouchOff) { if (_touchControlOptions.enablePassiveSelection) { if (_currentSelection[fingerId]) { _selectionResponse.WasSelected(_currentSelection[fingerId], touch.position); } } else { if (_currentSelection[fingerId]) { _selectionResponse.IsSelected(_currentSelection[fingerId], touch.position); } } } else { if (_touchControlOptions.enablePassiveSelection) { if (_currentSelection[fingerId]) { _selectionResponse.WasSelected(_currentSelection[fingerId], touch.position); } } else { if (_currentSelection[fingerId]) { _selectionResponse.Deselected(_currentSelection[fingerId], touch.position); } } //Allow null current selection _currentSelection[fingerId] = selectedObject; } } //add current to touch move if (_currentSelection[fingerId] && !_selectedOnTouchMove[fingerId].Contains(_currentSelection[fingerId])) { _selectedOnTouchMove[fingerId].Add(_currentSelection[fingerId]); } } } }