Exemplo n.º 1
0
        ExpressionAnimationUI CreateUIFromExpressionPath(string path, JSONStorableString store)
        {
            string fileName = PathExt.GetFileNameWithoutExtension(path);

            store.SetVal(sc.NormalizePath(path));

            string jsonString = sc.ReadFileIntoString(path);

            ExpressionAnimation animation = new ExpressionAnimation(morphControl, jsonString);

            JSONStorableAction action = new JSONStorableAction("Play " + fileName, () =>
            {
                PlayExpression(animation);
            });

            RegisterAction(action);

            ExpressionAnimationUI ui = null;

            ui = new ExpressionAnimationUI(this, fileName, animation, () =>
            {
                store.SetVal("");
                uiList.Remove(ui);
                animationLookup.Remove(fileName);
                DeregisterAction(action);
            });



            animationLookup[fileName] = animation;
            expressionChooser.choices = animationLookup.Keys.ToList();
            uiList.Add(ui);
            return(ui);
        }
 private void InitCollections()
 {
     if ((UnityEngine.Object)collections != (UnityEngine.Object)null)
     {
         return;
     }
     Log("### InitCollections ###");
     try
     {
         collections = gameObject.AddComponent <AudioMateCollectionManager>();
         collections.OnActiveCollectionSelected.RemoveAllListeners();
         collections.OnActiveCollectionSelected.AddListener(OnActiveCollectionSelected);
         collections.OnActiveCollectionNameChanged.RemoveAllListeners();
         collections.OnActiveCollectionNameChanged.AddListener(OnActiveCollectionNameChanged);
         _playRandomClipActionJSON = new JSONStorableAction(Storables.PlayRandomClipAction,
                                                            () => collections.PlayRandomClipAction());
         RegisterAction(_playRandomClipActionJSON);
         _queueRandomClipActionJSON = new JSONStorableAction(Storables.QueueRandomClipAction,
                                                             () => collections.QueueRandomClipAction());
         RegisterAction(_queueRandomClipActionJSON);
         collections.Init(this);
     }
     catch (Exception e)
     {
         SuperController.LogError($"AudioMate.{nameof(AudioMateController)}.{nameof(InitCollections)}: {e}");
     }
 }
Exemplo n.º 3
0
        void RegisterActions()
        {
            JSONStorableAction emotionTrigger = new JSONStorableAction("emotionTrigger", () =>
            {
                ForcePlayExpression();
            });

            RegisterAction(emotionTrigger);

            CreateButton("Test Emotion Trigger", true).button.onClick.AddListener(() =>
            {
                emotionTrigger.actionCallback();
            });

            JSONStorableAction climaxTrigger = new JSONStorableAction("climaxTrigger", () =>
            {
                arousal.MaxOut();
            });

            RegisterAction(climaxTrigger);

            CreateButton("Test Climax Trigger", true).button.onClick.AddListener(() =>
            {
                climaxTrigger.actionCallback();
            });


            CreateSpacer(true);

            CreateButton("Zero Pose Morphs", true).button.onClick.AddListener(() =>
            {
                ExpressionController.ZeroPoseMorphs(containingAtom);
            });
        }
Exemplo n.º 4
0
        public static JSONStorableAction CreateAction(string name, Action callback)
        {
            var action = new JSONStorableAction(name, new JSONStorableAction.ActionCallback(callback));

            Instance.plugin.RegisterAction(action);
            return(action);
        }
Exemplo n.º 5
0
        private void InitPlaybackButtons(Transform buttonPrefab, JSONStorableAction playJSON, JSONStorableAction stopJSON)
        {
            var container = new GameObject();

            container.transform.SetParent(transform, false);

            var gridLayout = container.AddComponent <HorizontalLayoutGroup>();

            gridLayout.spacing = 4f;
            gridLayout.childForceExpandWidth = false;
            gridLayout.childControlWidth     = true;

            var play = Instantiate(buttonPrefab);

            play.SetParent(container.transform, false);
            play.GetComponent <UIDynamicButton>().label = "\u25B6 Play";
            play.GetComponent <UIDynamicButton>().button.onClick.AddListener(() => playJSON.actionCallback());
            play.GetComponent <LayoutElement>().preferredWidth = 0;
            play.GetComponent <LayoutElement>().flexibleWidth  = 100;

            var stop = Instantiate(buttonPrefab);

            stop.SetParent(container.transform, false);
            stop.GetComponent <UIDynamicButton>().label = "\u25A0 Stop";
            stop.GetComponent <UIDynamicButton>().button.onClick.AddListener(() => stopJSON.actionCallback());
            stop.GetComponent <LayoutElement>().preferredWidth = 0;
            stop.GetComponent <LayoutElement>().flexibleWidth  = 30;
        }
    public override void Init()
    {
        _actionBindingExampleJSON = new JSONStorableAction(
            "my-action-binding",
            () => SuperController.LogMessage($"Hi from {containingAtom.name}!")
            );

        SuperController.singleton.BroadcastMessage("OnActionsProviderAvailable", this, SendMessageOptions.DontRequireReceiver);
    }
Exemplo n.º 7
0
    public override void Init()
    {
        try
        {
            _targetControllerJSON = new JSONStorableStringChooser("Target Controller", containingAtom.freeControllers.Select(fc => fc.name).ToList(), containingAtom.linkableRigidbodies.FirstOrDefault()?.name, "Target Controller", OnTargetControllerUpdated);
            RegisterStringChooser(_targetControllerJSON);
            CreateScrollablePopup(_targetControllerJSON, false).popupPanelHeight = 1000;

            _parentAtomJSON = new JSONStorableStringChooser("Parent Atom", _emptyStringsList, null, "Parent Atom", SyncDropDowns);
            RegisterStringChooser(_parentAtomJSON);
            CreateScrollablePopup(_parentAtomJSON, false).popupPanelHeight = 900;

            _parentRigidbodyJSON = new JSONStorableStringChooser("Parent Rigidbody", _emptyStringsList, null, "Parent Rigidbody", OnParentRigidbodyUpdated);
            RegisterStringChooser(_parentRigidbodyJSON);
            CreateScrollablePopup(_parentRigidbodyJSON, false).popupPanelHeight = 800;

            _parentTransformJSON = new JSONStorableStringChooser("Parent Transform", new List <string> {
                _both, _rotationOnly, _positionOnly, _none
            }, _both, "Parent Transform");
            RegisterStringChooser(_parentTransformJSON);
            CreateScrollablePopup(_parentTransformJSON, false).popupPanelHeight = 300;

            _weightJSON = new JSONStorableFloat("Weight", 0f, (float val) => _scaledWeight = ExponentialScale(val, 0.1f, 1f), 0f, 1f, true);
            RegisterFloat(_weightJSON);
            CreateSlider(_weightJSON, true);

            _posXJSON = new JSONStorableFloat("PosX", 0f, OnOffsetUpdated, -10f, 10f, false);
            RegisterFloat(_posXJSON);
            _posYJSON = new JSONStorableFloat("PosY", 0f, OnOffsetUpdated, -10f, 10f, false);
            RegisterFloat(_posYJSON);
            _posZJSON = new JSONStorableFloat("PosZ", 0f, OnOffsetUpdated, -10f, 10f, false);
            RegisterFloat(_posZJSON);
            _rotXJSON = new JSONStorableFloat("RotX", 0f, OnOffsetUpdated, -10f, 10f, false);
            RegisterFloat(_rotXJSON);
            _rotYJSON = new JSONStorableFloat("RotY", 0f, OnOffsetUpdated, -10f, 10f, false);
            RegisterFloat(_rotYJSON);
            _rotZJSON = new JSONStorableFloat("RotZ", 0f, OnOffsetUpdated, -10f, 10f, false);
            RegisterFloat(_rotZJSON);
            _rotWJSON = new JSONStorableFloat("RotW", 0f, OnOffsetUpdated, -10f, 10f, false);
            RegisterFloat(_rotWJSON);

            var recordJSON = new JSONStorableAction("Record Current Position", OnRecordCurrentPosition);
            RegisterAction(recordJSON);

            _recordButton = CreateButton("Record current position");
            _recordButton.button.onClick.AddListener(OnRecordCurrentPosition);
            _recordButton.button.interactable = false;

            OnTargetControllerUpdated(_targetControllerJSON.val);
            SyncDropDowns(_parentAtomJSON.val);
            OnParentRigidbodyUpdated(_parentRigidbodyJSON.val);
        }
        catch (Exception e)
        {
            SuperController.LogError($"{nameof(RubberLeash)}.{nameof(Init)}: {e}");
        }
    }
Exemplo n.º 8
0
 public StorableActionList(MVRScript script, string prefix)
 {
     for (int i = 0; i < maxCount; i++)
     {
         JSONStorableAction store = new JSONStorableAction(prefix + i, null);
         storables.Add(store);
         script.RegisterAction(store);
     }
 }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
 public void SetParameter(JSONStorableAction a)
 {
     if (Parameter is ActionStorableParameter)
     {
         ((ActionStorableParameter)Parameter).Parameter = a;
     }
     else
     {
         Parameter = new ActionStorableParameter(a);
     }
 }
Exemplo n.º 11
0
 private bool TryGetSpawnPoint(out JSONStorableAction spawnAction)
 {
     if (string.IsNullOrEmpty(returnToSpawnPoint.val))
     {
         spawnAction = null;
         return(false);
     }
     return(returnToSpawnPoint.val == _returnToClosestSpawnPointValue
         ? TryGetClosestSpawnPoint(out spawnAction)
         : TryGetSpecificSpawnPoint(out spawnAction));
 }
Exemplo n.º 12
0
        public override void Init()
        {
            if (containingAtom.type != "Person")
            {
                SuperController.LogError($"This plugin needs to be put on a 'Person' atom only, not a '{containingAtom.type}'");
                return;
            }

            var targetChoices = new List <string>()
            {
                LOOK_AT_PLAYER,
                LOOK_AT_TARGET
            };

            // header row 1
            var spacer = CreateSpacer(rightSide: false);

            EyesRelativeToStorable = new JSONStorableStringChooser("Eyes Relative To", targetChoices, LOOK_AT_PLAYER, "Eyes Relative To", (string value) => {
                LookMode = value;
            });
            var eyeChooserPopup = CreatePopup(EyesRelativeToStorable, rightSide: true);

            eyeChooserPopup.height = spacer.height;
            RegisterStringChooser(EyesRelativeToStorable);
            LookMode = LOOK_AT_PLAYER;

            // left eye settings
            LEyeUpDownStorable = new JSONStorableFloat("lEyeUpDown", 0, -30, 30);
            var lEyeUpDownSlider = CreateSlider(LEyeUpDownStorable);

            RegisterFloat(LEyeUpDownStorable);

            LEyeRightLeftStorable = new JSONStorableFloat("lEyeRightLeft", 0, -45, 45);
            var lEyeInOutSlider = CreateSlider(LEyeRightLeftStorable);

            RegisterFloat(LEyeRightLeftStorable);

            // right eye settin
            REyeUpDownStorable = new JSONStorableFloat("rEyeUpDown", 0, -30, 30);
            var rEyeUpDownSlider = CreateSlider(REyeUpDownStorable, rightSide: true);

            RegisterFloat(REyeUpDownStorable);

            REyeRightLeftStorable = new JSONStorableFloat("rEyeRightLeft", 0, -45, 45);
            var rEyeRightLeftSlider = CreateSlider(REyeRightLeftStorable, rightSide: true);

            RegisterFloat(REyeRightLeftStorable);

            var resetAction = new JSONStorableAction("Reset", Reset);

            RegisterAction(resetAction);
        }
Exemplo n.º 13
0
        public JSONStorableAction GetNext()
        {
            int nextIndex = FindNextOpen();

            if (nextIndex < 0)
            {
                Debug.LogWarning("Ran out of space in storable string list");
                return(null);
            }
            JSONStorableAction next = storables[nextIndex];

            return(next);
        }
Exemplo n.º 14
0
    public override void Init()
    {
        SuperController.singleton.playerHeightAdjustSlider.onValueChanged.AddListener(OnPlayerHeightChanged);

        _playerHeightJSON = new JSONStorableFloat("Player Height", 0f, -1f, 5f, false)
        {
            setCallbackFunction = val =>
            {
                SuperController.singleton.playerHeightAdjust = val;
            },
            valNoCallback = SuperController.singleton.playerHeightAdjust,
            defaultVal    = SuperController.singleton.playerHeightAdjust,
        };
        RegisterFloat(_playerHeightJSON);
        CreateSlider(_playerHeightJSON);

        _playerBaseHeightJSON = new JSONStorableFloat("[Relative] Player Base Height", 0f, -1f, 5f, false)
        {
            setCallbackFunction = val =>
            {
                _playerHeightJSON.val = val + _playerRelativeHeightJSON.val;
            },
            isStorable    = false,
            valNoCallback = SuperController.singleton.playerHeightAdjust,
            defaultVal    = SuperController.singleton.playerHeightAdjust
        };
        RegisterFloat(_playerBaseHeightJSON);
        CreateSlider(_playerBaseHeightJSON);

        _playerRelativeHeightJSON = new JSONStorableFloat("[Relative] Player Relative Height", 0f, -1f, 5f, false)
        {
            setCallbackFunction = val =>
            {
                _playerHeightJSON.val = _playerBaseHeightJSON.val + val;
            },
            isStorable = false
        };
        RegisterFloat(_playerRelativeHeightJSON);
        CreateSlider(_playerRelativeHeightJSON);

        _setPlayerBaseHeight = new JSONStorableAction("[Relative] Set Player Base Height", () =>
        {
            _playerBaseHeightJSON.valNoCallback     = SuperController.singleton.playerHeightAdjust;
            _playerBaseHeightJSON.defaultVal        = SuperController.singleton.playerHeightAdjust;
            _playerRelativeHeightJSON.valNoCallback = 0;
        });
        RegisterAction(_setPlayerBaseHeight);
        CreateButton(_setPlayerBaseHeight.name).button.onClick.AddListener(() => _setPlayerBaseHeight.actionCallback.Invoke());
    }
Exemplo n.º 15
0
        private void CreateAndRegisterClipStorables(string animationName)
        {
            var clip = animation.GetClip(animationName);

            if (clip == null)
            {
                return;
            }

            var playJSON = new JSONStorableAction($"Play {animationName}", () =>
            {
                animation.PlayClip(animationName, true);
            });

            RegisterAction(playJSON);

            var speedJSON = new JSONStorableFloat($"Speed {animationName}", 1f, (float val) =>
            {
                clip.speed = val;
            }, 0.1f, 10f)
            {
                valNoCallback = clip.speed,
                isStorable    = false,
                isRestorable  = false
            };

            RegisterFloat(speedJSON);

            var weightJSON = new JSONStorableFloat($"Weight {animationName}", 1f, (float val) =>
            {
                clip.weight = val;
            }, 0f, 1f)
            {
                valNoCallback = clip.weight,
                isStorable    = false,
                isRestorable  = false
            };

            RegisterFloat(weightJSON);

            _clipStorables.Add(new AnimStorableActionMap
            {
                animationName = animationName,
                playJSON      = playJSON,
                speedJSON     = speedJSON,
                weightJSON    = weightJSON,
            });
        }
Exemplo n.º 16
0
        public override void PostLoad(JSONStorable s)
        {
            if (!string.IsNullOrEmpty(paramName_))
            {
                param_ = s.GetAction(paramName_);

                if (param_ == null)
                {
                    Synergy.LogError(
                        $"PostLoad: action name {paramName_} not in " +
                        $"storable {s.storeId}");
                }

                paramName_ = null;
            }
        }
Exemplo n.º 17
0
        private void CreateAndRegisterClipStorables(string animationName)
        {
            var playClipJSON = new JSONStorableAction($"Play {animationName}", () =>
            {
                animation.PlayClips(animationName, true);
            });

            RegisterAction(playClipJSON);

            var speedClipJSON = new JSONStorableFloat($"Speed {animationName}", 1f, val =>
            {
                foreach (var clip in animation.GetClips(animationName))
                {
                    clip.speed = val;
                }
            }, -1f, 5f, false)
            {
                valNoCallback = animation.GetClips(animationName).First().speed,
                isStorable    = false,
                isRestorable  = false
            };

            RegisterFloat(speedClipJSON);

            var weightJSON = new JSONStorableFloat($"Weight {animationName}", 1f, val =>
            {
                foreach (var clip in animation.GetClips(animationName))
                {
                    clip.weight = val;
                }
            }, 0f, 1f)
            {
                valNoCallback = animation.GetClips(animationName).First().weight,
                isStorable    = false,
                isRestorable  = false
            };

            RegisterFloat(weightJSON);

            _clipStorables.Add(new AnimStorableActionMap
            {
                animationName = animationName,
                playJSON      = playClipJSON,
                speedJSON     = speedClipJSON,
                weightJSON    = weightJSON
            });
        }
 public DiscreteTriggerCommand(Atom defaultAtom, IPrefabManager prefabManager)
     : base(prefabManager)
 {
     _triggerActionDiscrete = trigger.CreateDiscreteActionStartInternal();
     if (_triggerActionDiscrete.receiverAtom == null)
     {
         _triggerActionDiscrete.receiverAtom = defaultAtom;
     }
     if (_triggerActionDiscrete.receiver == null)
     {
         var defaultStorableId = defaultAtom.GetStorableIDs().FirstOrDefault(s => s.EndsWith("BindableActions"));
         if (defaultStorableId != null)
         {
             _triggerActionDiscrete.receiver = defaultAtom.GetStorableByID(defaultStorableId);
         }
     }
     _invokingJsonStorableAction = new JSONStorableAction("", Invoke);
 }
        public virtual void CreateUI(IUIBuilder builder)
        {
            RefreshButton = builder.CreateButton("Refresh", () =>
            {
                ComponentCache.Clear();
                RefreshButtonCallback();
            });
            RefreshButton.buttonColor = new Color(0, 0.75f, 1f) * 0.8f;
            RefreshButton.textColor   = Color.white;

            Spacer = builder.CreateSpacer(200);

            RefreshAction = UIManager.CreateAction("Refresh Motion Source", () =>
            {
                ComponentCache.Clear();
                RefreshButtonCallback();
            });
        }
Exemplo n.º 20
0
        public void CreateUI(IUIBuilder builder)
        {
            ComPortChooser = builder.CreatePopup("OutputTarget:Serial:ComPortChooser", "Select COM port", SerialPort.GetPortNames().ToList(), "None", null);

            ButtonGroup = builder.CreateHorizontalGroup(510, 50, new Vector2(10, 0), 2, idx => builder.CreateButtonEx());
            var startSerialButton = ButtonGroup.items[0].GetComponent <UIDynamicButton>();

            startSerialButton.label = "Start Serial";
            startSerialButton.button.onClick.AddListener(StartSerial);

            var stopSerialButton = ButtonGroup.items[1].GetComponent <UIDynamicButton>();

            stopSerialButton.label = "Stop Serial";
            stopSerialButton.button.onClick.AddListener(StopSerial);

            StartSerialAction = UIManager.CreateAction("Start Serial", StartSerial);
            StopSerialAction  = UIManager.CreateAction("Stop Serial", StopSerial);
        }
Exemplo n.º 21
0
        public override void Init()
        {
            try
            {
                AudioSourceControl source = containingAtom.GetStorableByID("AudioSource") as AudioSourceControl;
                if (source == null)
                {
                    SuperController.LogError("This plugin only works on AudioSource");
                    return;
                }

                clipCount = new JSONStorableFloat("clipCount", 0, 0, 100, false, false);
                RegisterFloat(clipCount);

                JSONStorableAction audioClipAction = new JSONStorableAction("Play Random", () => {
                    if (clips.Count == 0)
                    {
                        return;
                    }
                    source.PlayNow(clips[UnityEngine.Random.Range(0, clips.Count)]);
                });
                CreateButton("Play Random").button.onClick.AddListener(() =>
                {
                    audioClipAction.actionCallback();
                });
                RegisterAction(audioClipAction);

                UIDynamicButton addClipButton = CreateButton("Add Clip");
                addClipButton.buttonColor = new Color(0, 1, 0);
                addClipButton.button.onClick.AddListener(() =>
                {
                    BuildClipUI(clips.Count);
                });


                //GetStringParamNames().ForEach((s) => Debug.Log(s));
                //Debug.Log(GetStringChooserParamNames().Count);
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Exemplo n.º 22
0
        public void OnTimelineAnimationParametersChanged(JSONStorable storable)
        {
            _animationJSON.choices = _links
                                     .ToList()
                                     .Select(l => GetOrDispose(l))
                                     .Where(l => l != null)
                                     .SelectMany(l => l.animation.choices)
                                     .Distinct()
                                     .ToList();
            foreach (var a in _playActions)
            {
                DeregisterAction(a.Value);
            }
            _playActions.Clear();

            foreach (var a in _animationJSON.choices)
            {
                if (!_playActions.Any(kvp => kvp.Key == a))
                {
                    var playJSON = new JSONStorableAction($"Play {a}", () => Play(a));
                    RegisterAction(playJSON);
                    _playActions.Add(new KeyValuePair <string, JSONStorableAction>(a, playJSON));
                }
            }

            var proxy = GetOrDispose(_selectedLink);

            if (proxy == null || proxy.storable != storable)
            {
                return;
            }

            OnTimelineTimeChanged(storable);

            var remoteTime = proxy.time;

            _timeJSON.max           = remoteTime.max;
            _timeJSON.valNoCallback = remoteTime.val;
            var remoteAnimation = proxy.animation;

            _animationJSON.valNoCallback = remoteAnimation.val;
        }
Exemplo n.º 23
0
        public void CreateUI(IUIBuilder builder)
        {
            AddressInput = builder.CreateTextInput("OutputTarget:Udp:Address", "Address:", "127.0.0.1", 50);
            PortInput    = builder.CreateTextInput("OutputTarget:Udp:Port", "Port:", "8889", 50);
            IpText       = AddressInput.storable;
            PortText     = PortInput.storable;

            ButtonGroup = builder.CreateHorizontalGroup(510, 50, new Vector2(10, 0), 2, idx => builder.CreateButtonEx());
            var startSerialButton = ButtonGroup.items[0].GetComponent <UIDynamicButton>();

            startSerialButton.label = "Start Udp";
            startSerialButton.button.onClick.AddListener(StartUdp);

            var stopSerialButton = ButtonGroup.items[1].GetComponent <UIDynamicButton>();

            stopSerialButton.label = "Stop Udp";
            stopSerialButton.button.onClick.AddListener(StopUdp);

            StartUdpAction = UIManager.CreateAction("Start Udp", StartUdp);
            StopUdpAction  = UIManager.CreateAction("Stop Udp", StopUdp);
        }
Exemplo n.º 24
0
        public override void Init()
        {
            try
            {
                ui = new UI(this, 0.001f);
                ui.canvas.transform.SetParent(containingAtom.mainController.transform, false);
                ui.canvas.transform.localPosition = new Vector3(0, -0.15f, 0);

                arousalValue = new JSONStorableFloat("arousal", 0, 0, SLIDER_MAX, false, false);
                RegisterFloat(arousalValue);

                UIDynamicSlider arousalSlider = ui.CreateSlider("❤", 300, 120);
                arousalSlider.valueFormat = "n0";
                arousalValue.slider       = arousalSlider.slider;

                arousalRate = new JSONStorableFloat("arousalRate", 1, 0.01f, 10, false, true);
                RegisterFloat(arousalRate);
                CreateSlider(arousalRate);

                arousalDecay = new JSONStorableFloat("arousalDecay", 0.1f, 0.01f, 10, false, true);
                RegisterFloat(arousalDecay);
                CreateSlider(arousalDecay);

                timeToDecay = new JSONStorableFloat("timeToDecay", 4, 0, 60, false, true);
                RegisterFloat(timeToDecay);
                CreateSlider(timeToDecay);

                JSONStorableAction arousalAction = new JSONStorableAction("arouse", () =>
                {
                    arousalValue.val += arousalRate.val;
                    lastArousalTime   = Time.time;
                });
                RegisterAction(arousalAction);
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Exemplo n.º 25
0
    private bool TryGetClosestSpawnPoint(out JSONStorableAction spawnAction)
    {
        Atom closestSpawnPoint = null;
        var  closestDistance   = float.MaxValue;
        var  cameraPosition    = SuperController.singleton.centerCameraTarget.transform.position;

        foreach (var spawnPointAtom in GetSpawnPointAtoms())
        {
            var distance = Mathf.Abs(Vector3.SqrMagnitude(cameraPosition - spawnPointAtom.mainController.control.position));
            if (!(distance < closestDistance))
            {
                continue;
            }
            closestDistance   = distance;
            closestSpawnPoint = spawnPointAtom;
        }

        if (closestSpawnPoint == null)
        {
            SuperController.LogError($"Embody '{containingAtom.uid}' could not find any SpawnPoint in the scene to return to");
            spawnAction = null;
            return(false);
        }

        spawnAction = closestSpawnPoint
                      .GetStorableIDs()
                      .Select(id => closestSpawnPoint.GetStorableByID(id))
                      .Select(s => s.GetAction("Spawn Now"))
                      .FirstOrDefault(s => s != null);

        if (spawnAction == null)
        {
            SuperController.LogError($"Embody '{containingAtom.uid}' cannot find an action storable in '{closestSpawnPoint.uid}' named 'Spawn Now'");
            return(false);
        }

        return(true);
    }
Exemplo n.º 26
0
        private void InitActions()
        {
            JSONStorableAction startLaunchAction = new JSONStorableAction("startLaunch", () =>
            {
                _pauseLaunchMessages.SetVal(false);
            });

            RegisterAction(startLaunchAction);

            JSONStorableAction stopLaunchAction = new JSONStorableAction("stopLaunch", () =>
            {
                _pauseLaunchMessages.SetVal(true);
            });

            RegisterAction(stopLaunchAction);

            JSONStorableAction toggleLaunchAction = new JSONStorableAction("toggleLaunch", () =>
            {
                _pauseLaunchMessages.SetVal(!_pauseLaunchMessages.val);
            });

            RegisterAction(toggleLaunchAction);
        }
Exemplo n.º 27
0
    private bool TryGetSpecificSpawnPoint(out JSONStorableAction spawnAction)
    {
        var spawnPointAtom = SuperController.singleton.GetAtoms().FirstOrDefault(a => a.uid == returnToSpawnPoint.val);

        if (spawnPointAtom == null)
        {
            SuperController.LogError($"Embody '{containingAtom.uid}' cannot restore to SpawnPoint '{returnToSpawnPoint.val}' because this atom does not exist in the scene");
            spawnAction = null;
            return(false);
        }

        spawnAction = spawnPointAtom
                      .GetStorableIDs()
                      .Select(id => spawnPointAtom.GetStorableByID(id))
                      .Select(s => s.GetAction("Spawn Now"))
                      .FirstOrDefault(act => act != null);
        if (spawnAction != null)
        {
            return(true);
        }

        SuperController.LogError($"Embody '{containingAtom.uid}' cannot find an action storable in '{spawnPointAtom.uid}' named 'Spawn Now'");
        return(false);
    }
Exemplo n.º 28
0
    public override void Init()
    {
        _containingAtom = containingAtom;

        var spawnNow = new JSONStorableAction("Spawn Now", SpawnNow);

        RegisterAction(spawnNow);
        var btn = CreateButton("Spawn Now");

        spawnNow.dynamicButton = btn;

        _spawnOnEnable = new JSONStorableBool("Spawn On Enable", false);
        RegisterBool(_spawnOnEnable);
        CreateToggle(_spawnOnEnable, true);

        SuperController.singleton.BroadcastMessage("OnActionsProviderAvailable", this, SendMessageOptions.DontRequireReceiver);

        StartCoroutine(InitDeferred());

        if (enabled)
        {
            OnEnable();
        }
    }
Exemplo n.º 29
0
    private void InitControls()
    {
        // Left side

        _activeJSON = new JSONStorableBool(
            "Active",
            false,
            new JSONStorableBool.SetBoolCallback(val => UpdateActivation())
            );
        RegisterBool(_activeJSON);
        CreateToggle(_activeJSON, false);

        var defaultMode = Modes.None;

#if (VAM_DIAGNOSTICS)
        defaultMode = Modes.WindowCamera;
#endif
        _modeJSON = new JSONStorableStringChooser(
            "Mode",
            (new[] { Modes.None, Modes.NavigationRig, Modes.WindowCamera }).ToList(),
            defaultMode,
            "Mode",
            new JSONStorableStringChooser.SetStringCallback(val => UpdateActivation())
            );
        RegisterStringChooser(_modeJSON);
        var activePopup = CreateScrollablePopup(_modeJSON, false);
        activePopup.popupPanelHeight = 600f;

        _transitionTimeJSON = new JSONStorableFloat("Transition Time", 0.6f, 0f, 1f, false);
        RegisterFloat(_transitionTimeJSON);
        CreateSlider(_transitionTimeJSON, false);

        _extendTransitionTime = new JSONStorableFloat("Extend Transition Time", 0.2f, 0f, 1f, false);
        RegisterFloat(_extendTransitionTime);
        CreateSlider(_extendTransitionTime, false);

        // Right side

        _playOnceFromBeginningActionJSON = new JSONStorableAction("Play From Beginning", () => PlayOnceFromBeginning());
        RegisterAction(_playOnceFromBeginningActionJSON);
        CreateButton("Play Once From Beginning", true).button.onClick.AddListener(() => PlayOnceFromBeginning());
        CreateButton("Play", true).button.onClick.AddListener(() => _pattern.Play());
        CreateButton("Pause", true).button.onClick.AddListener(() => _pattern.Pause());
        CreateButton("Previous Step", true).button.onClick.AddListener(() =>
        {
            var previousStep = _pattern.steps.Reverse().SkipWhile(s => !s.active).Skip(1).FirstOrDefault();
            if (previousStep != null)
            {
                _currentTimeJSON.val = previousStep.timeStep == 0 ? float.Epsilon : previousStep.timeStep;
            }
            else if (_pattern.steps.Length > 0f)
            {
                _currentTimeJSON.val = 0.1f;
                _currentTimeJSON.val = 0f;
            }
        });
        CreateButton("Next Step", true).button.onClick.AddListener(() =>
        {
            var nextStep = _pattern.steps.SkipWhile(s => !s.active).Skip(1).FirstOrDefault();
            if (nextStep != null)
            {
                _currentTimeJSON.val = nextStep.timeStep;
            }
            else if (_pattern.steps.Length > 0f && !_pattern.steps.Any(s => s.active))
            {
                _currentTimeJSON.val = 0.1f;
                _currentTimeJSON.val = 0f;
            }
        });
        CreateButton("Teleport to Current Step", true).button.onClick.AddListener(() =>
        {
            var step = _pattern.steps.FirstOrDefault(s => s.active) ?? _pattern.steps.FirstOrDefault();
            if (step == null)
            {
                return;
            }
            UpdateNavigationRigPosition(step);
            UpdateNavigationRigRotation(step);
            Transform navigationRig   = SuperController.singleton.navigationRig;
            navigationRig.eulerAngles = new Vector3(navigationRig.eulerAngles.x, navigationRig.eulerAngles.y, 0f);
            navigationRig.Translate(Vector3.back * 1f + Vector3.up * 0.2f, Space.Self);
        });
        CreateButton("Select Current Step", true).button.onClick.AddListener(() =>
        {
            var step = _pattern.steps.FirstOrDefault(s => s.active) ?? _pattern.steps.FirstOrDefault();
            if (step == null)
            {
                return;
            }
            SuperController.singleton.SelectController(step.containingAtom.freeControllers.FirstOrDefault(fc => fc.name == "control"));
        });
    }
    private void CreateAction(string jsaName, JSONStorableAction.ActionCallback fn)
    {
        var jsa = new JSONStorableAction(jsaName, fn);

        _script.RegisterAction(jsa);
    }