public async Task <Response <string> > AddToothInfo(CreateToothInfoRequest request)
        {
            var toothInfo = new ToothInfo
            {
                Id       = Guid.NewGuid().ToString(),
                Position = request.Position,
                Number   = request.Number,
                Name     = request.Name,
                GrowTime = request.GrowTime
            };

            await _unitOfWork.ToothInfoRepository.AddAsync(toothInfo);

            await _unitOfWork.SaveAsync();

            return(new Response <string>(toothInfo.Id, $"Thêm thông tin răng thành công, id: {toothInfo.Id}"));
        }
示例#2
0
    /// <summary>
    /// If the new target is different from the previous target, we move to it and then do 1x brush
    /// If the new target is the same as the old target, we just do a 1x brush.
    /// So you need to spam the same command multiple times to brush the tooth more than once.
    /// </summary>
    /// <param name="targetPos"></param>
    public void MoveToTargetAndBrush(ToothInfo targetTooth)
    {
        #region ResetPrevCoroutines
        for (int i = 0; i < m_coroutines.Length; i++)
        {
            if (m_coroutines[i] != null)
            {
                StopCoroutine(m_coroutines[i]);
            }
        }
        m_ToothbrushBrushingChild.localPosition = Vector3.zero;
        m_ToothbrushBrushingChild.localRotation = Quaternion.identity;
        #endregion


        Vector3 targetPos = targetTooth.BrushTarget.position;
        if (targetTooth.UseRandomOffsetToTarget)
        {
            targetPos += new Vector3(
                UnityEngine.Random.Range(-targetTooth.RandomLocalPosOffset.x, targetTooth.RandomLocalPosOffset.x),
                UnityEngine.Random.Range(-targetTooth.RandomLocalPosOffset.y, targetTooth.RandomLocalPosOffset.y),
                UnityEngine.Random.Range(-targetTooth.RandomLocalPosOffset.z, targetTooth.RandomLocalPosOffset.z)
                );
        }
        else
        {
            targetPos += m_BrushStrokeLength * targetTooth.brushStrokeLengthModifier * targetTooth.BrushTarget.up;
        }
        //cache previous values if target is the same
        bool isTargetTheSame = false;
        //Vector3 brushingUpDir = m_ToothbrushBrushingChild.right;//TODO: figure out depending on how hand is held


        if (Vector3.Distance(m_TargetPosLastFrame, targetPos) < 0.01f)
        {
            isTargetTheSame = true;
        }

        if (!isTargetTheSame)
        {
            // calculate keyframe blended rotation
            #region Get Rotation From nearby Keyframes
            Quaternion targetRot = targetTooth.GetClosestBlendedKeyframeRotation(2, false);
            #endregion

            // LerpToTarget pos and rot to target
            m_coroutines[0] = StartCoroutine(LerpToTarget(
                                                 m_ToothbrushPositionerParent,
                                                 m_ToothbrushPositionerParent.position,
                                                 targetPos,
                                                 m_ToothbrushPositionerParent.rotation,
                                                 targetRot,
                                                 m_BrushTravelPosAnimCurve,
                                                 m_BrushTravelRotAnimCurve,
                                                 0, 0, 0,
                                                 animationDuration, m_SpeedModifierMove * targetTooth.brushTravelSpeedhModifier,
                                                 () => {
                //if(targetTooth.BrushAfterMoving == true)
                BrushTooth1x_Toggled(m_ToothbrushBrushingChild, targetTooth);
            }
                                                 ));
        }
        else
        {
            // brush teeth 1x
            //if(targetTooth.BrushAfterMoving == true)
            BrushTooth1x_Toggled(m_ToothbrushBrushingChild, targetTooth);
        }

        m_TargetPosLastFrame = targetPos;
    }
示例#3
0
    /// <summary>
    /// Does one brush action per call (per key press).
    /// So It will do a brush up action then next time brush down then next up again etc.
    /// </summary>
    /// <param name="brushingMoveCurve"></param>
    /// <param name="upDir"></param>
    void BrushTooth1x_Toggled(Transform brushTr, ToothInfo targetTooth)
    {
        float   dir;
        Vector3 brushForward = m_ToothbrushBrushingChild.forward;

        if (targetTooth.useOverrideBrushingAnimDirection)
        {
            brushForward = targetTooth.OverrideBrushingAnimDirWS;
            dir          = 1;
        }
        else
        {
            if (Vector3.Dot(targetTooth.BrushTarget.up, m_ToothbrushBrushingChild.forward) > 0)
            {
                dir = -1;
            }
            else
            {
                dir = 1;
            }
        }

        if (targetTooth.isBrushingTeeth)
        {
            targetTooth.OnStartingToBrush();
        }
        m_coroutines[1] = StartCoroutine(LerpToTarget(
                                             brushTr,
                                             brushTr.position,
                                             brushTr.position + dir * m_BrushStrokeLength * targetTooth.brushStrokeLengthModifier * brushForward * 2,
                                             brushTr.rotation,
                                             brushTr.rotation,
                                             m_BrushTravelPosAnimCurve,
                                             m_BrushTravelRotAnimCurve,
                                             0, 0, 0,
                                             animationDuration, targetTooth.BrushAfterMoving? m_SpeedModifierBrush * targetTooth.brushStrokeSpeedhModifier : 0,
                                             () => {
            if (targetTooth.isBrushingTeeth)
            {
                targetTooth.OnStartingToBrush();
            }
            else
            {
                targetTooth.OnStartingToPokeOnBrushingFail();
            }
            m_coroutines[2] = StartCoroutine(LerpToTarget(
                                                 brushTr,
                                                 brushTr.position,
                                                 brushTr.position - dir * m_BrushStrokeLength * targetTooth.brushStrokeLengthModifier * brushForward * 2,
                                                 brushTr.rotation,
                                                 brushTr.rotation,
                                                 m_BrushTravelPosAnimCurve,
                                                 m_BrushTravelRotAnimCurve,
                                                 0, 0, 0,
                                                 animationDuration, targetTooth.BrushAfterMoving? m_SpeedModifierBrush * targetTooth.brushStrokeSpeedhModifier : 0,
                                                 () => {
                // m_coroutines[3] = StartCoroutine(LerpToTarget(
                //     brushTr,
                //     brushTr.position,
                //     brushTr.position + dir * m_brushingMotionWidth * targetTooth.brushStrokeLengthModifier * brushForward * 2,
                //     brushTr.rotation,
                //     brushTr.rotation,
                //     m_BrushTravelPosAnimCurve,
                //     m_BrushTravelRotAnimCurve,
                //     0, 0, 0,
                //     animationDuration, targetTooth.BrushAfterMoving? m_SpeedModifierBrush * targetTooth.brushStrokeSpeedhModifier : 0,
                //     ()=>{
                targetTooth.OnBrushedInstanceComplete();
                //}
                //));
            }
                                                 ));
        }
                                             ));
    }