コード例 #1
0
        public void UpdateBreathing(float speed)
        {
            breatheCycle += Time.deltaTime * speed;
            float breatheIntensity = 0;     //0, 1
            float stomachPower     = 0.3f;  //0, 1
            float chestDriveMin    = -3.0f; //-20, 20
            float chestDriveMax    = 20.0f; //-20, 20
            float chestSpring      = 90.0f; //0, 250

            if (breatheCycle >= breatheDuration)
            {
                breathePower = UnityEngine.Random.Range(0.8f, 1.2f);
                float v   = 0.2f * (breathEntries.Length - 1);
                float min = Mathf.Max(0 - v - 1.0f, -0.5f);
                float max = Mathf.Min(v + 1.0f, breathEntries.Length - 0.5f);
                if (min < breatheIndex && max > breatheIndex)
                {
                    max -= 1.0f;
                }
                int index = Mathf.RoundToInt(UnityEngine.Random.Range(min, max));
                index           = Mathf.Clamp(index, 0, breathEntries.Length - 2);
                breatheIndex    = index < breatheIndex ? index : index + 1;
                breatheEntry    = breathEntries[breatheIndex];
                breatheDuration = breatheEntry.breatheIn + UnityEngine.Random.Range(breatheEntry.holdInReference * 0.9f, breatheEntry.holdInReference * 1.1f);
                breatheCycle    = 0.0f;
                breatheNeedInit = false;
            }

            if (stomachMorph != null)
            {
                float power = breatheIntensity * 0.7f + 0.3f;
                power *= breathePower;
                float t   = 1.0f - BlendOutIn(0.0f, 0.0f, 0.0f, 0.0f);
                float max = stomachPower * power;
                stomachMorph.val = Mathf.SmoothStep(0.3f, -max, t);
            }

            if (chestController != null)
            {
                float power = breatheIntensity * 0.5f + 0.5f;
                power *= breathePower;
                float t      = 1.0f - BlendOutIn(0.0f, 0.0f, 0.0f, 0.0f);
                float max    = chestDriveMin + power * (chestDriveMax - chestDriveMin);
                float target = Mathf.SmoothStep(chestDriveMin, max, t);
                chestController.jointRotationDriveXTarget = target;
                chestController.jointRotationDriveSpring  = chestSpring;
            }
        }
コード例 #2
0
        public void Update()
        {
            float breatheMorph = 0.0f;

            breatheCycle += Time.deltaTime;
            if (breatheCycle >= breatheDuration)
            {
                breatheIntensity = intensity.val;
                breathePower     = UnityEngine.Random.Range(0.8f, 1.2f);
                float v   = variance.val * (breathEntries.Length - 1);
                float bi  = breatheIntensity * (breathEntries.Length - 1);
                float min = Mathf.Max(bi - v - 1.0f, -0.5f);
                float max = Mathf.Min(bi + v + 1.0f, breathEntries.Length - 0.5f);
                if (min < breatheIndex && max > breatheIndex)
                {
                    max -= 1.0f;
                }
                int index = Mathf.RoundToInt(UnityEngine.Random.Range(min, max));
                index           = Mathf.Clamp(index, 0, breathEntries.Length - 2);
                breatheIndex    = index < breatheIndex ? index : index + 1;
                breatheEntry    = breathEntries[breatheIndex];
                breatheDuration = breatheEntry.breatheIn + UnityEngine.Random.Range(breatheEntry.holdInReference * 0.9f, breatheEntry.holdInReference * 1.1f);
                breatheCycle    = 0.0f;
                breatheNeedInit = false;
                headAudio.CallAction("PlayNow", breatheEntry.audioClip);
            }

            if (stomachMorph != null)
            {
                float power = breatheIntensity * 0.7f + 0.3f;
                power *= breathePower;
                float t   = 1.0f - BlendOutIn(0.0f, 0.0f, 0.0f, 0.0f);
                float max = stomachPower.val * power;
                stomachMorph.morphValue = Mathf.SmoothStep(0.3f, -max, t);
            }

            if (chestController != null)
            {
                float power = breatheIntensity * 0.5f + 0.5f;
                power *= breathePower;
                float t      = 1.0f - BlendOutIn(0.0f, 0.0f, 0.0f, 0.0f);
                float max    = chestDriveMin.val + power * (chestDriveMax.val - chestDriveMin.val);
                float target = Mathf.SmoothStep(chestDriveMin.val, max, t);
                chestController.jointRotationDriveXTarget = target;
                chestController.jointRotationDriveSpring  = chestSpring.val;
            }

            if (mouthMorph != null && nosePinchMorph != null && noseFlareMorph != null)
            {
                float mouth = 0.0f;
                float nose  = 0.0f;
                if (breatheEntry.noseIn)                 // mouth out, nose in
                {
                    mouth = BlendOut(0.0f, 0.05f, 0.25f);
                    nose  = BlendIn(0.0f, 0.0f, 0.25f);
                }
                else                 // mouth only breath
                {
                    mouth = BlendOutIn(0.0f, -0.1f, 0.0f, 0.3f);
                    nose  = 0.0f;
                }

                float power = (breatheIntensity * 0.5f + 0.5f) * breathePower;
                mouth *= power;
                nose  *= power;

                mouthMorph.morphValue     = Mathf.SmoothStep(mouthOpenMin.val, mouthOpenMax.val, mouth);
                nosePinchMorph.morphValue = Mathf.SmoothStep(0.0f, 0.2f, nose);
                noseFlareMorph.morphValue = Mathf.SmoothStep(0.0f, 0.8f, nose);
            }
        }
コード例 #3
0
        protected void FixedUpdate()
        {
            float breatheMorph = 0.0f;

            breatheCycle += Time.fixedDeltaTime;
            if (breatheCycle >= breatheDuration)
            {
                BreathEntry[] entries = allowMoan.val ? breathEntries : breathEntriesNoMoan;

                breatheIntensity = intensity.val;
                breathePower     = UnityEngine.Random.Range(0.8f, 1.2f);
                float v   = variance.val * (entries.Length - 1);
                float bi  = breatheIntensity * (entries.Length - 1);
                float min = Mathf.Max(bi - v - 1.0f, -0.5f);
                float max = Mathf.Min(bi + v + 1.0f, entries.Length - 0.5f);
                if (min < breatheIndex && max > breatheIndex)
                {
                    max -= 1.0f;
                }
                int index = Mathf.RoundToInt(UnityEngine.Random.Range(min, max));
                index        = Mathf.Clamp(index, 0, entries.Length - 2);
                breatheIndex = index < breatheIndex ? index : index + 1;
                breatheEntry = entries[breatheIndex];

                float holdTime = breatheEntry.holdInReference;
                holdTime       *= 1.0f - speedAdjust.val;
                breatheDuration = breatheEntry.breatheIn + Mathf.Max(holdTime, 0.1f);

                if (breatheNeedInit || rhythmAdaptForceOnce.val)
                {
                    breatheDurationAverage   = breatheDuration;
                    rhythmAdaptForceOnce.val = false;
                }
                else
                {
                    breatheDurationAverage = Mathf.Lerp(breatheDuration, breatheDurationAverage, rhythmAdapt.val);
                }

                breatheDuration = Mathf.Max(breatheDurationAverage, breatheEntry.breatheIn + 0.1f);
                breatheCycle    = 0.0f;
                breatheNeedInit = false;
                headAudio.CallAction("PlayNow", breatheEntry.audioClip);
            }

            if (stomachMorph != null)
            {
                float power = breatheIntensity * 0.7f + 0.3f;
                power *= breathePower;
                float t   = 1.0f - BlendOutIn(0.0f, 0.0f, 0.0f, 0.0f);
                float max = stomachPower.val * power;
                stomachMorph.morphValue = Mathf.SmoothStep(0.3f, -max, t);
            }

            if (chestController != null)
            {
                float power = breatheIntensity * 0.5f + 0.5f;
                power *= breathePower;
                float t      = 1.0f - BlendOutIn(0.0f, 0.0f, 0.0f, 0.0f);
                float max    = chestDriveMin.val + power * (chestDriveMax.val - chestDriveMin.val);
                float target = Mathf.SmoothStep(chestDriveMin.val, max, t);
                chestController.jointRotationDriveXTarget = target;
                chestController.jointRotationDriveSpring  = chestSpring.val;
            }

            if (mouthMorph != null && nosePinchMorph != null && noseFlareMorph != null)
            {
                float mouth = 0.0f;
                float nose  = 0.0f;
                if (breatheEntry.noseIn)                 // mouth out, nose in
                {
                    mouth = BlendOut(0.0f, 0.05f, 0.25f);
                    nose  = BlendIn(0.0f, 0.0f, 0.25f);
                }
                else                 // mouth only breath
                {
                    mouth = BlendOutIn(0.0f, -0.1f, 0.0f, 0.3f);
                    nose  = 0.0f;
                }

                float power = (breatheIntensity * 0.5f + 0.5f) * breathePower;
                mouth *= power;
                nose  *= power;

                mouthMorph.morphValue     = Mathf.SmoothStep(mouthOpenMin.val, mouthOpenMax.val, mouth);
                nosePinchMorph.morphValue = Mathf.SmoothStep(0.0f, 0.2f, nose);
                noseFlareMorph.morphValue = Mathf.SmoothStep(0.0f, 0.8f, nose);
            }


            for (int i = 0; i < receivers.Length; ++i)
            {
                receivers[i].Update(this);
            }
        }