public void OnSelectionConfirm(GameObject gameObject, Vector3 inputPosition, List <GameObject> wasSelectedGameObjects) { //check if it has its own selection response ISelectionResponse selectionResponse = gameObject.GetComponent <ISelectionResponse>(); if (selectionResponse != null) { selectionResponse.OnSelectionConfirm(gameObject, inputPosition, wasSelectedGameObjects); } else { //use default implementation //no implementation yet } }
void OnTouchOff(Touch touch) { int fingerId = touch.fingerId; if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { GameObject selectedObject = _objectSelector.DetermineSelection(touch.position); 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); if (_currentSelection[fingerId]) { selectedObject = _currentSelection[fingerId]; } } } else { if (enableDiselectOnlyOnTouchOff) { //_selectionResponse.IsSelected(_currentSelection[fingerId], touch.position); if (_currentSelection[fingerId]) { selectedObject = _currentSelection[fingerId]; } } } } } else { if (enableDiselectOnlyOnTouchOff) { //_selectionResponse.IsSelected(_currentSelection[fingerId], touch.position); selectedObject = null; } } if (selectedObject) { _touchControlOptions = selectedObject.GetComponent <ITouchControlOptions>(); } else { if (_currentSelection.ContainsKey(fingerId)) { if (_currentSelection[fingerId]) { _touchControlOptions = _currentSelection[fingerId].GetComponent <ITouchControlOptions>(); } } } if (!_selectedOnTouchOff.ContainsKey(fingerId)) { _selectedOnTouchOff.Add(fingerId, selectedObject); } else { _selectedOnTouchOff[fingerId] = selectedObject; } //check it exist - touch off might happen before you could move - like taps if (_selectedOnTouchMove.ContainsKey(fingerId)) { if (_selectedOnTouchMove[fingerId] != null) { //clean was selected responses to deselected responses if (_selectedOnTouchMove[fingerId].Count > 0) { foreach (var gameObject in _selectedOnTouchMove[fingerId]) { //on deselect if (gameObject) { _selectionResponse.Deselected(gameObject, touch.position); } } } } } else { _selectedOnTouchMove.Add(fingerId, new List <GameObject>()); } //Determine response to touch ended && touch phase cancelled if (_selectedOnTouchOff[fingerId]) { if (_touchControlOptions == null) { if (enableLastTouchConfirm && !enableDiselectOnlyOnTouchOff) { if (_selectedOnTouchMove[fingerId].Count > 0) { _selectionResponse.OnSelectionConfirm(_selectedOnTouchOff[fingerId], touch.position, _selectedOnTouchMove[fingerId]); } else { _selectionResponse.OnSelectionConfirm(_selectedOnTouchOff[fingerId], touch.position); } } else { _selectionResponse.Deselected(_selectedOnTouchOff[fingerId], touch.position); } } else { if (_touchControlOptions.enableLastTouchConfirm && !_touchControlOptions.enableDiselectOnlyOnTouchOff) { if (_selectedOnTouchMove[fingerId].Count > 0) { _selectionResponse.OnSelectionConfirm(_selectedOnTouchOff[fingerId], touch.position, _selectedOnTouchMove[fingerId]); } else { _selectionResponse.OnSelectionConfirm(_selectedOnTouchOff[fingerId], touch.position); } } else { _selectionResponse.Deselected(_selectedOnTouchOff[fingerId], touch.position); } } } else { if (_currentSelection.ContainsKey(fingerId)) { if (_currentSelection[fingerId]) { if (_touchControlOptions == null) { if (enableLastTouchConfirm && !enableDiselectOnlyOnTouchOff) { if (_selectedOnTouchMove[fingerId].Count > 0) { _selectionResponse.OnSelectionConfirm(_currentSelection[fingerId], touch.position, _selectedOnTouchMove[fingerId]); } else { _selectionResponse.OnSelectionConfirm(_currentSelection[fingerId], touch.position); } } else { _selectionResponse.Deselected(_currentSelection[fingerId], touch.position); } } else { if (_touchControlOptions.enableLastTouchConfirm && !enableDiselectOnlyOnTouchOff) { if (_selectedOnTouchMove[fingerId].Count > 0) { _selectionResponse.OnSelectionConfirm(_currentSelection[fingerId], touch.position, _selectedOnTouchMove[fingerId]); } else { _selectionResponse.OnSelectionConfirm(_currentSelection[fingerId], touch.position); } } else { _selectionResponse.Deselected(_currentSelection[fingerId], touch.position); } } } } } //determine touch end response confirmation if (_selectedOnTouchBegan.ContainsKey(fingerId) && _selectedOnTouchOff.ContainsKey(fingerId)) { if (_selectedOnTouchBegan[fingerId] && _selectedOnTouchBegan[fingerId] == _selectedOnTouchOff[fingerId]) { if (_selectedOnTouchMove[fingerId].Count > 0) { _selectionResponse.OnSelectionConfirm(_selectedOnTouchOff[fingerId], touch.position, _selectedOnTouchMove[fingerId]); } else { _selectionResponse.OnSelectionConfirm(_selectedOnTouchOff[fingerId], touch.position); } } } if (_touchControlOptions == null) { if (enableUnniqueSelection) { if (_selectedOnTouchBegan[fingerId] && _selectedOnTouchBegan[fingerId] == _selectedOnTouchOff[fingerId] && _selectedOnTouchMove[fingerId].Count <= 1) { _selectionResponse.IsSelectedUnique(_selectedOnTouchBegan[fingerId], touch.position); } } } else { if (_touchControlOptions.enableUnniqueSelection) { if (_selectedOnTouchBegan.ContainsKey(fingerId) && _selectedOnTouchOff.ContainsKey(fingerId) && _selectedOnTouchMove.ContainsKey(fingerId)) { if (_selectedOnTouchBegan[fingerId] && _selectedOnTouchBegan[fingerId] == _selectedOnTouchOff[fingerId] && _selectedOnTouchMove[fingerId].Count <= 1) { _selectionResponse.IsSelectedUnique(_selectedOnTouchBegan[fingerId], touch.position); } } } } //reset on touch off //clear all previously assigned touches. _currentSelection[fingerId] = null; _selectedOnTouchBegan[fingerId] = null; _selectedOnTouchStationary[fingerId] = null; _selectedOnTouchMove[fingerId].Clear(); _selectedOnTouchOff[fingerId] = null; } }