private void TakeTrashCall(TrashModel trashModel) { if (TakeTrashEvent != null) { TakeTrashEvent.Invoke(trashModel); } }
/// <summary> /// Accepts reports of the fact of drop garbage out of hand. /// </summary> /// <param name="trash"></param> public void DropTrash(TrashModel trash) { if (trash == CurrentTrash) { Destroy(_currentTrashJoint); CurrentTrash = null; //check if the tuoch position is on garbage can RaycastHit hitInfo; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, _garbageTankLayer)) { var garbageCanModel = hitInfo.transform.GetComponentInParent <GarbageTankModel>(); //is there a GarbageTankModel component in the object? If is, is the garbage equals the trash can. if (garbageCanModel && garbageCanModel.GarbageTankColor == trash.GarbageTankColor) { //throw garbage in the tank trash.Rigidbody.velocity = Helper.Physics.PassToPosition(trash.Rigidbody, garbageCanModel.CenterCast.position); } else { DropTrashCall(trash); } } else { DropTrashCall(trash); } } else { Debug.LogError(Const.LogicError); } }
private void DropTrashCall(TrashModel trashModel) { if (DropTrashEvent != null) { DropTrashEvent.Invoke(trashModel); } }
private void Awake() { var view = GetComponent <TouchView>(); view.IsTakeEvent += IsTake; view.MouseDragEvent += MouseDrag; _model = GetComponent <TrashModel>(); }
/// <summary> /// It works when the garbage touches the garbage tank inside. /// Starts the closing animation garbage tank. /// Increases the amount of garbage count. /// </summary> /// <param name="trash">Garbage model</param> private void TrashTrigger(TrashModel trash) { if (!Controller.TouchManager.CurrentTrash) { _model.Animator.SetBool(Const.IsOpen, false); if (!trash.IsInGarbageCan) { _model.AddTrash(); AddTrashEvent.Invoke(_model); } trash.IsInGarbageCan = true; } }
/// <summary> /// Accepts reports of the fact of taking garbage in hand. /// Attaches a physical joint to the garbage object to control the movement of garbage. /// </summary> /// <param name="trash"></param> public void TakeTrash(TrashModel trash) { Vector3 castPos; if (Helper.RayCast.ScreenMouseToRay(_trashLayer, out castPos)) { CurrentTrash = trash; TakeTrashCall(CurrentTrash); _currentTrashJoint = Helper.Physics.InitTakeJoint( CurrentTrash.gameObject.AddComponent <ConfigurableJoint>()); _currentTrashJoint.anchor = CurrentTrash.Transform.InverseTransformPoint(castPos); } }
/// <summary> /// It works when the trash take in hand. /// Starts the opening/closing animation garbage tank. /// </summary> /// <param name="trashModel">Garbage model</param> private void TakeTrash(TrashModel trashModel) { if (trashModel.GarbageTankColor == _model.GarbageTankColor) { if (!_model.IsTrashFull) { _model.Animator.SetBool(Const.IsOpen, true); } } else { _model.Animator.SetBool(Const.IsOpen, false); } }
/// <summary> /// Play take trash audio. /// </summary> /// <param name="trashModel"></param> private static void TakeTrash(TrashModel trashModel) { AudioSource.PlayClipAtPoint(Model.Audio.TakeTrashClip, trashModel.Transform.position); }
/// <summary> /// It works when the garbage drop out of hand. /// Starts the closing animation garbage tank. /// </summary> /// <param name="trashModel">Garbage model</param> private void DropTrash(TrashModel trashModel) { _model.Animator.SetBool(Const.IsOpen, false); }