public override void Init()
        {
            try
            {
                // make atom selector
                atomJSON = new JSONStorableStringChooser("atom", SuperController.singleton.GetAtomUIDs(), null, "Atom", SyncAtom);
                RegisterStringChooser(atomJSON);
                SyncAtomChocies();
                UIDynamicPopup dp = CreateScrollablePopup(atomJSON);
                dp.popupPanelHeight = 1100f;
                // want to always resync the atom choices on opening popup since atoms can be added/removed
                dp.popup.onOpenPopupHandlers += SyncAtomChocies;

                // make receiver selector
                receiverJSON = new JSONStorableStringChooser("receiver", null, null, "Receiver", SyncReceiver);
                RegisterStringChooser(receiverJSON);
                dp = CreateScrollablePopup(receiverJSON);
                dp.popupPanelHeight = 960f;

                // make receiver target selector
                receiverTargetJSON = new JSONStorableStringChooser("receiverTarget", null, null, "Target", SyncReceiverTarget);
                RegisterStringChooser(receiverTargetJSON);
                dp = CreateScrollablePopup(receiverTargetJSON);
                dp.popupPanelHeight = 820f;

                // set atom to current atom to initialize
                atomJSON.val = containingAtom.uid;

                redirectTrigger = new JSONStorableAction("Redirect Action", () =>
                {
                    float durationSinceLastTrigger = Time.time - lastTriggerTime;
                    if (durationSinceLastTrigger < delayBetweenTrigger.val)
                    {
                        return;
                    }

                    if (UnityEngine.Random.Range(0, 100) < chance.val)
                    {
                        receiver.CallAction(_receiverTargetName);
                        lastTriggerTime = Time.time;
                    }
                });
                RegisterAction(redirectTrigger);

                chance = new JSONStorableFloat("chance", 50, 0, 100, true, true);
                RegisterFloat(chance);
                CreateSlider(chance, true);

                delayBetweenTrigger = new JSONStorableFloat("delay", 0, 0, 10, false, true);
                RegisterFloat(delayBetweenTrigger);
                CreateSlider(delayBetweenTrigger, true);
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Beispiel #2
0
        void LoadPreset(string presetType, string path)
        {
            PresetManager pm = containingAtom.GetComponentInChildren <PresetManager>(includeInactive: true);

            pm.itemType = PresetManager.ItemType.Atom;

            JSONStorable    js             = containingAtom.GetStorableByID(presetType);
            JSONStorableUrl presetPathJSON = js.GetUrlJSONParam("presetBrowsePath");

            presetPathJSON.val = SuperController.singleton.NormalizePath(path);
            js.CallAction("LoadPreset");
        }
Beispiel #3
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);
            }
        }
        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);
            }
        }