public void OnDrop(IControllable dropped, ControllerHitInfo hitInfo) { if (dropped is BakableFood) { AddFood(dropped as BakableFood); } }
private bool HandleUIRaycast(out ControllerHitInfo hitInfo) { var pointerEventData = new PointerEventData(_eventSystem); pointerEventData.position = Input.mousePosition; var results = new List <RaycastResult>(); _graphicRaycaster.Raycast(pointerEventData, results); RaycastResult result; IControllable controllable = null; for (var i = 0; i < results.Count; ++i) { if (results[i].gameObject.TryGetComponent <IControllable>(out controllable)) { HitControllable(controllable, new ControllerHitInfo(controllable, results[i])); result = results[i]; hitInfo = new ControllerHitInfo(controllable, result); return(true); } } //don't reset press, maybe world objects are hit hitInfo = new ControllerHitInfo(true); return(false); }
public void OnDrop(IControllable dropped, ControllerHitInfo hitInfo) { if (dropped is FryableFood) { TrySetFood(dropped as FryableFood); } }
public void OnDragDrop(Vector3 position, IControllable droppedOn, ControllerHitInfo hitInfo) { if (droppedOn is Dish) { droppedOn.OnDrop(this, hitInfo); } }
public void OnDragDrop(Vector3 position, IControllable droppedOn, ControllerHitInfo hitInfo) { if (_food != null) { droppedOn.OnDrop(_food.GetComponent <IControllable>(), hitInfo); } }
public void OnHold(float holdTime, ControllerHitInfo hitInfo) { if (hitInfo.uiElement || !_doHoldFeedback) { return; } _pressFeedback.transform.position = hitInfo.point + hitInfo.normal * 0.1f; _pressFeedback.transform.forward = hitInfo.normal; _pressFeedback.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f); if (!_isHeld) { _pressFeedback.transform.DOComplete(); _pressFeedback.transform.DOScale(new Vector3(2.0f, 2.0f, 2.0f), 0.2f); var main = _pressFeedback.main; main.loop = true; _isHeld = true; } else if (!DOTween.IsTweening(_pressFeedback.transform)) { _pressFeedback.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f); _pressFeedback.transform.DOPunchScale(new Vector3(1.0f, 1.0f, 1.0f), 1.0f, 0); } if (!_pressFeedback.isPlaying) { _pressFeedback.Play(); } }
public void OnDrag(Vector3 position, IControllable dragged, ControllerHitInfo hitInfo) { if (_dragCopy == null) { _dragCopy = dragged.GetDragCopy(); if (_dragCopy != null && !hitInfo.uiElement) { var originalPos = position; var toCamera = Camera.main.transform.position - position; position = Camera.main.transform.position - toCamera.normalized; _dragCopy.transform.position = position; _dragCopy.transform.localScale /= (Camera.main.transform.position - originalPos).magnitude; } } if (_dragCopy != null) // else would not call this if _dragCopy had just been set { if (hitInfo.uiElement) { _dragCopy.transform.position = Input.mousePosition; } else { var originalPos = position; var toCamera = Camera.main.transform.position - position; position = Camera.main.transform.position - toCamera.normalized; _dragCopy.transform.position = position; } } }
public void OnDrag(Vector3 position, IControllable dragged, ControllerHitInfo hitInfo) { dragged.OnDrag(position); for (var i = 0; i < _observers.Count; ++i) { _observers[i].OnDrag(position, dragged, hitInfo); } }
public void OnSwipe(Vector3 direction, Vector3 lastPoint, IControllable swiped, ControllerHitInfo hitInfo) { swiped?.OnSwipe(direction, lastPoint); for (var i = 0; i < _observers.Count; ++i) { _observers[i].OnSwipe(direction, lastPoint, hitInfo); } }
public void OnHold(float holdTime, IControllable held, ControllerHitInfo hitInfo) { held?.OnHold(holdTime, hitInfo.point); for (var i = 0; i < _observers.Count; ++i) { _observers[i].OnHold(holdTime, hitInfo); } }
public void OnPress(IControllable pressed, ControllerHitInfo hitInfo) { pressed?.OnPress(hitInfo.point); for (var i = 0; i < _observers.Count; ++i) { _observers[i].OnPress(hitInfo); } }
public void SetFrom(ControllerHitInfo hitInfo) { groundPoint = hitInfo.HitPoint; groundNormal = hitInfo.HitNormal; groundDistance = Mathf.Max(0.0f, hitInfo.MoveLength); groundCollider = hitInfo.HitCollider; groundRigidbody = hitInfo.Rigidbody; surfaceNormal = hitInfo.HitNormal; }
public override bool ComputeGroundHit(Vector3 position, Quaternion rotation, ControllerHitInfo controllerHitInfo, ref GroundHit groundHitInfo, float distance = Mathf.Infinity) { // Downward cast from campsule's bottom sphere (filter any 'wall') RaycastHit hitInfo; if (BottomSphereCast(position, rotation, out hitInfo, distance) && Vector3.Angle(hitInfo.normal, rotation * Vector3.up) < 89.0f) { // Update ground hit info groundHitInfo.SetFrom(hitInfo); // Check if standing on a ledge or step DetectLedgeAndSteps(position, rotation, ref groundHitInfo, distance, hitInfo.point, hitInfo.normal); // Inform we found 'ground' and if is valid groundHitInfo.isOnGround = true; groundHitInfo.isValidGround = !groundHitInfo.isOnLedgeEmptySide && Vector3.Angle(groundHitInfo.surfaceNormal, Vector3.up) < groundLimit; return(true); } // If initial sphere cast fails, or found a 'wall', // fallback to a raycast from character's bottom position if (!BottomRaycast(position, rotation, out hitInfo, distance)) { if (!controllerHitInfo.Valid) { return(false); } groundHitInfo.SetFrom(controllerHitInfo); groundHitInfo.surfaceNormal = controllerHitInfo.HitNormal; groundHitInfo.isOnGround = true; groundHitInfo.isValidGround = Vector3.Angle(groundHitInfo.surfaceNormal, Vector3.up) < groundLimit; //DebugDraw.DebugArrow(controllerHitInfo.HitPoint, controllerHitInfo.HitNormal * 2, Color.magenta, 0, false); } else { // If found 'ground', update ground info and return groundHitInfo.SetFrom(hitInfo); groundHitInfo.surfaceNormal = hitInfo.normal; groundHitInfo.isOnGround = true; groundHitInfo.isValidGround = Vector3.Angle(groundHitInfo.surfaceNormal, Vector3.up) < groundLimit; } return(true); }
public void OnDrop(IControllable dropped, ControllerHitInfo hitInfo) { if (dropped is FarmPlot) { var plot = (FarmPlot)dropped; if (plot.Harvest()) { CollectPotato(); } } }
public void OnDragDrop(Vector3 position, IControllable droppedOn, ControllerHitInfo hitInfo) { if (_food != null && _food.Count > 0) { for (var i = _food.Count - 1; i >= 0; --i) { var food = _food[i]; food.OnDragDrop(position, droppedOn, hitInfo); droppedOn.OnDrop(food.GetComponent <IControllable>(), hitInfo); } } }
public void OnSwipe(Vector3 direction, Vector3 lastPoint, ControllerHitInfo hitInfo) { var screenPoint = lastPoint + direction; //screenPoint.z = 1; //Vector3 mouse3d = Camera.main.ScreenToWorldPoint(screenPoint); if (_dragCopy == null) { DoSwipeParticle(screenPoint); } }
public void OnDrop(IControllable dropped, ControllerHitInfo hitInfo) { if (dropped is CuttableFood && _selected == null) { var food = dropped as CuttableFood; _selected = food; food.cuttingBoard = this; food.transform.position = _cutPosition.transform.position; food.transform.rotation = _cutPosition.transform.rotation; Notify(new CuttableOnCuttingBoardEvent(this, food)); } }
public void OnPress(ControllerHitInfo hitInfo) { if (hitInfo.uiElement || !_doPressFeedback) { return; } _pressFeedback.transform.position = hitInfo.point + hitInfo.normal * 0.1f; _pressFeedback.transform.forward = hitInfo.normal; _pressFeedback.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f); _pressFeedback.transform.DOComplete(); _pressFeedback.transform.DOPunchScale(new Vector3(3.0f, 3.0f, 3.0f), 0.3f, 0); _pressFeedback.Play(); }
public void OnDrag(Vector3 position, IControllable dragged, ControllerHitInfo hitInfo) { if (!active) { return; } if (!_dragging && _controllableScriptRef == dragged) { var renderers = _controllable.GetComponentsInChildren <Renderer>(); for (var i = 0; i < renderers.Length; ++i) { renderers[i].enabled = false; } _enabledDragCopy = TryEnableDragCopyRenderer(); _dragging = true; } }
private void HitNonControllable(ControllerHitInfo hitInfo) { OnClick(null, hitInfo); if (!_isDragging) // Not dragging nor swiping { if (_selected != null) { StartDrag(); } else { _selected = null; } //if (_selected != null) //{ // StartDrag(); // if (_timeHeld >= _holdTime) // { // OnHoldRelease(_timeHeld, _selected); // } // else // { // if (!_swipeStarted && !_isDragging) OnPress(_selected, hitInfo); // } // _timeHeld = 0; //} _hitInfo = hitInfo; _selectedGameObject = hitInfo.gameObject; _timeHeld += Time.deltaTime; if (_timeHeld >= _holdTime && !_swipeStarted) { OnHold(_timeHeld, _selected, hitInfo); } } }
private void HitControllable(IControllable controllable, ControllerHitInfo hitInfo) { _hitInfo = hitInfo; OnClick(controllable, hitInfo); if (_swipeStarted) { OnSwipe(GetLastSwipeDirection(), _lastMousePosition, controllable, hitInfo); } else if (!_isDragging) // Not dragging nor swiping { //only if not swiping if (_selected != null && _selected != controllable) { StartDrag(); if (_timeHeld >= _holdTime) { OnHoldRelease(_timeHeld, _selected); } else { if (!_swipeStarted && !_isDragging) { OnPress(_selected, hitInfo); } } _timeHeld = 0; } _selected = controllable; _selectedGameObject = hitInfo.gameObject; _timeHeld += Time.unscaledDeltaTime; if (_timeHeld >= _holdTime) { OnHold(_timeHeld, _selected, hitInfo); } } }
public void OnDragDrop(Vector3 position, IControllable droppedOn, ControllerHitInfo hitInfo) { if (!_isOnCooldown) { FarmPlot plot; if (hitInfo.gameObject.TryGetComponent <FarmPlot>(out plot)) { if (_functionaliesHandler(plot, _farmPlotCooldown, this)) { OnUse(); } else { Wiggle(); } } } else { Notify(new ToolOnCooldownWarningEvent(this)); Wiggle(); Debug.Log("Use is on cooldown"); } }
public void OnDrop(IControllable dropped, ControllerHitInfo hitInfo) { }
public void OnDragDrop(Vector3 position, IControllable droppedOn, ControllerHitInfo hitInfo) { }
public void OnDrop(IControllable dropped, ControllerHitInfo hitInfo) { if (_debugLog) { Debug.Log(dropped + " dropped"); } if (dropped is IIngredient) { var ingredient = dropped as IIngredient; if (ingredient.ReadyForDish()) { if (_debugLog) { Debug.Log(dropped + " is ready for dish"); } if (TryAddIngredient(ingredient)) { if (_debugLog) { Debug.Log(dropped + " was added to dish"); } ingredient.AddedToDish(); } } } else if (dropped is Dish) { var dish = dropped as Dish; if (dish != null && dish.IsFinished(true)) { for (var i = 0; i < _sideDishesLeft.Count; ++i) { if (_sideDishesLeft[i] as Dish == dish) { Destroy(dish.gameObject); if (_debugLog) { Debug.Log("enabling " + _sideDishMeshesToEnable[i].Count + " meshes"); } for (var j = 0; j < _sideDishMeshesToEnable[i].Count; ++j) { if (_debugLog) { Debug.Log("Enabling " + _sideDishMeshesToEnable[i][j]); } _sideDishMeshesToEnable[i][j].SetActive(true); } _sideDishMeshesToEnable.RemoveAt(i); _sideDishesLeft.RemoveAt(i); Notify(new SideDishDraggedToMain(this, dish)); } } } if (IsFinished(true)) { InformObserversFinish(); } } }
public void OnDragDrop(Vector3 position, IControllable dragged, IControllable droppedOn, ControllerHitInfo hitInfo) { if (!active) { return; } if (dragged == _controllableScriptRef) { var renderers = _controllable.GetComponentsInChildren <Renderer>(); for (var i = 0; i < renderers.Length; ++i) { renderers[i].enabled = true; } _enabledDragCopy = false; _dragging = false; } }
public void OnClick(ControllerHitInfo hitInfo) { }
public void OnSwipe(Vector3 direction, Vector3 lastPoint, ControllerHitInfo hitInfo) { }
public void OnPress(ControllerHitInfo hitInfo) { }
public void OnHold(float holdTime, ControllerHitInfo hitInfo) { }