Exemplo n.º 1
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;
        }
Exemplo n.º 2
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.º 3
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.º 4
0
        private void InitFrameNav(Transform buttonPrefab, JSONStorableAction previousFrameJSON, JSONStorableAction nextFrameJSON)
        {
            var container = new GameObject();

            container.transform.SetParent(transform, false);

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

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

            CreateSmallButton(buttonPrefab, container.transform, "<\u0192", () => previousFrameJSON.actionCallback());

            CreateSmallButton(buttonPrefab, container.transform, "-1s", () =>
            {
                var time = _animation.Time - 1f;
                if (time < 0)
                {
                    time = 0;
                }
                _animation.Time = time;
            });

            CreateSmallButton(buttonPrefab, container.transform, "-.1s", () =>
            {
                var time = _animation.Time - 0.1f;
                if (time < 0)
                {
                    time = 0;
                }
                _animation.Time = time;
            });

            CreateSmallButton(buttonPrefab, container.transform, ">|<", () =>
            {
                _animation.Time = _animation.Time.Snap(1f);
            });

            CreateSmallButton(buttonPrefab, container.transform, "+.1s", () =>
            {
                var time = _animation.Time + 0.1f;
                if (time >= _animation.Current.animationLength - 0.001f)
                {
                    time = _animation.Current.loop ? _animation.Current.animationLength - 0.1f : _animation.Current.animationLength;
                }
                _animation.Time = time;
            });

            CreateSmallButton(buttonPrefab, container.transform, "+1s", () =>
            {
                var time = _animation.Time + 1f;
                if (time >= _animation.Current.animationLength - 0.001f)
                {
                    time = _animation.Current.loop ? _animation.Current.animationLength - 1f : _animation.Current.animationLength;
                }
                _animation.Time = time;
            });

            CreateSmallButton(buttonPrefab, container.transform, "\u0192>", () => nextFrameJSON.actionCallback());
        }
Exemplo n.º 5
0
        public void InitStorables()
        {
            animationJSON = new JSONStorableStringChooser(StorableNames.Animation, new List <string>(), "", "Animation", val => ChangeAnimation(val))
            {
                isStorable = false
            };
            RegisterStringChooser(animationJSON);

            nextAnimationJSON = new JSONStorableAction(StorableNames.NextAnimation, () =>
            {
                var i = animationJSON.choices.IndexOf(animationJSON.val);
                if (i < 0 || i > animationJSON.choices.Count - 2)
                {
                    return;
                }
                animationJSON.val = animationJSON.choices[i + 1];
            });
            RegisterAction(nextAnimationJSON);

            previousAnimationJSON = new JSONStorableAction(StorableNames.PreviousAnimation, () =>
            {
                var i = animationJSON.choices.IndexOf(animationJSON.val);
                if (i < 1 || i > animationJSON.choices.Count - 1)
                {
                    return;
                }
                animationJSON.val = animationJSON.choices[i - 1];
            });
            RegisterAction(previousAnimationJSON);

            scrubberJSON = new JSONStorableFloat(StorableNames.Scrubber, 0f, v => UpdateTime(v, true), 0f, AtomAnimationClip.DefaultAnimationLength, true)
            {
                isStorable = false
            };
            RegisterFloat(scrubberJSON);

            timeJSON = new JSONStorableFloat(StorableNames.Time, 0f, v => UpdateTime(v, false), 0f, AtomAnimationClip.DefaultAnimationLength, true)
            {
                isStorable = false
            };
            RegisterFloat(timeJSON);

            playJSON = new JSONStorableAction(StorableNames.Play, () =>
            {
                if (animation?.Current == null)
                {
                    SuperController.LogError($"VamTimeline: Cannot play animation, Timeline is still loading");
                    return;
                }
                if (SuperController.singleton.freezeAnimation)
                {
                    _resumePlayOnUnfreeze = true;
                    return;
                }
                animation.Play();
                isPlayingJSON.valNoCallback = true;
                SendToControllers(nameof(IAnimationController.OnTimelineTimeChanged));
            });
            RegisterAction(playJSON);

            playIfNotPlayingJSON = new JSONStorableAction(StorableNames.PlayIfNotPlaying, () =>
            {
                if (animation?.Current == null)
                {
                    SuperController.LogError($"VamTimeline: Cannot play animation, Timeline is still loading");
                    return;
                }
                if (SuperController.singleton.freezeAnimation)
                {
                    _resumePlayOnUnfreeze = true;
                    return;
                }
                if (animation.IsPlaying())
                {
                    return;
                }
                animation.Play();
                isPlayingJSON.valNoCallback = true;
                SendToControllers(nameof(IAnimationController.OnTimelineTimeChanged));
            });
            RegisterAction(playIfNotPlayingJSON);

            isPlayingJSON = new JSONStorableBool(StorableNames.IsPlaying, false, (bool val) =>
            {
                if (val)
                {
                    playIfNotPlayingJSON.actionCallback();
                }
                else
                {
                    stopJSON.actionCallback();
                }
            })
            {
                isStorable = false
            };
            RegisterBool(isPlayingJSON);

            stopJSON = new JSONStorableAction(StorableNames.Stop, () =>
            {
                if (animation.IsPlaying())
                {
                    _resumePlayOnUnfreeze = false;
                    animation.Stop();
                    animation.Time = animation.Time.Snap(snapJSON.val);
                    isPlayingJSON.valNoCallback = false;
                    SendToControllers(nameof(IAnimationController.OnTimelineTimeChanged));
                }
                else
                {
                    animation.Time = 0f;
                }
            });
            RegisterAction(stopJSON);

            stopIfPlayingJSON = new JSONStorableAction(StorableNames.StopIfPlaying, () =>
            {
                if (!animation.IsPlaying())
                {
                    return;
                }
                animation.Stop();
                animation.Time = animation.Time.Snap(snapJSON.val);
                isPlayingJSON.valNoCallback = false;
                SendToControllers(nameof(IAnimationController.OnTimelineTimeChanged));
            });
            RegisterAction(stopIfPlayingJSON);

            nextFrameJSON = new JSONStorableAction(StorableNames.NextFrame, () => NextFrame());
            RegisterAction(nextFrameJSON);

            previousFrameJSON = new JSONStorableAction(StorableNames.PreviousFrame, () => PreviousFrame());
            RegisterAction(previousFrameJSON);

            snapJSON = new JSONStorableFloat(StorableNames.Snap, 0.01f, (float val) =>
            {
                var rounded = val.Snap();
                if (val != rounded)
                {
                    snapJSON.valNoCallback = rounded;
                }
                if (animation != null && animation.Time % rounded != 0)
                {
                    UpdateTime(animation.Time, true);
                }
            }, 0.001f, 1f, true)
            {
                isStorable = true
            };
            RegisterFloat(snapJSON);

            cutJSON   = new JSONStorableAction("Cut", () => Cut());
            copyJSON  = new JSONStorableAction("Copy", () => Copy());
            pasteJSON = new JSONStorableAction("Paste", () => Paste());

            lockedJSON = new JSONStorableBool(StorableNames.Locked, false, (bool val) =>
            {
                _ui.UpdateLocked(val);
                if (_controllerInjectedControlerPanel != null)
                {
                    _controllerInjectedControlerPanel.locked = val;
                }
            });
            RegisterBool(lockedJSON);

            autoKeyframeAllControllersJSON = new JSONStorableBool("Auto Keyframe All Controllers", false)
            {
                isStorable = false
            };

            speedJSON = new JSONStorableFloat(StorableNames.Speed, 1f, v => UpdateAnimationSpeed(v), 0f, 5f, false)
            {
                isStorable = false
            };
            RegisterFloat(speedJSON);
        }
Exemplo n.º 6
0
        public void InitStorables()
        {
            animationLegacyJSON = new JSONStorableStringChooser(StorableNames.Animation, new List <string>(), "", "Animation", ChangeAnimationLegacy)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterStringChooser(animationLegacyJSON);

            nextAnimationLegacyJSON = new JSONStorableAction(StorableNames.NextAnimation, () =>
            {
                if (animationLegacyJSON.choices.Count < 2)
                {
                    return;
                }
                var clip = string.IsNullOrEmpty(animationLegacyJSON.val)
                    ? animation.clips[0]
                    : animation.clips.First(c => c.animationName == animationLegacyJSON.val);
                var inLayer = animation.index.ByLayer(clip.animationLayer);
                var i       = inLayer.IndexOf(clip);
                if (i < 0 || i > inLayer.Count - 2)
                {
                    animationLegacyJSON.val = inLayer[0].animationName;
                }
                else
                {
                    animationLegacyJSON.val = inLayer[i + 1].animationName;
                }
            });
            RegisterAction(nextAnimationLegacyJSON);

            previousAnimationLegacyJSON = new JSONStorableAction(StorableNames.PreviousAnimation, () =>
            {
                if (animationLegacyJSON.choices.Count < 2)
                {
                    return;
                }
                var clip = string.IsNullOrEmpty(animationLegacyJSON.val)
                    ? animation.clips[0]
                    : animation.clips.First(c => c.animationName == animationLegacyJSON.val);
                var inLayer = animation.index.ByLayer(clip.animationLayer);
                var i       = inLayer.IndexOf(clip);
                if (i < 1 || i > inLayer.Count - 1)
                {
                    animationLegacyJSON.val = inLayer[inLayer.Count - 1].animationName;
                }
                else
                {
                    animationLegacyJSON.val = inLayer[i - 1].animationName;
                }
            });
            RegisterAction(previousAnimationLegacyJSON);

            scrubberJSON = new JSONStorableFloat(StorableNames.Scrubber, 0f, v => animationEditContext.clipTime = v.Snap(animationEditContext.snap), 0f, AtomAnimationClip.DefaultAnimationLength)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterFloat(scrubberJSON);

            timeJSON = new JSONStorableFloat(StorableNames.Time, 0f, v => animationEditContext.playTime = v.Snap(), 0f, float.MaxValue)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterFloat(timeJSON);

            playJSON = new JSONStorableAction(StorableNames.Play, () =>
            {
                var selected = string.IsNullOrEmpty(animationLegacyJSON.val) ? animation.GetDefaultClip() : animation.GetClips(animationLegacyJSON.val).FirstOrDefault();
                animation.PlayOneAndOtherMainsInLayers(selected);
            });
            RegisterAction(playJSON);

            playIfNotPlayingJSON = new JSONStorableAction(StorableNames.PlayIfNotPlaying, () =>
            {
                if (animation == null)
                {
                    return;
                }
                var selected = string.IsNullOrEmpty(animationLegacyJSON.val) ? animation.GetDefaultClip() : animation.GetClips(animationLegacyJSON.val).FirstOrDefault();
                if (selected == null)
                {
                    return;
                }
                if (!animation.isPlaying)
                {
                    animation.PlayOneAndOtherMainsInLayers(selected);
                }
                else if (!selected.playbackEnabled)
                {
                    animation.PlayClip(selected, true);
                }
            });
            RegisterAction(playIfNotPlayingJSON);

            isPlayingJSON = new JSONStorableBool(StorableNames.IsPlaying, false, val =>
            {
                if (val)
                {
                    playIfNotPlayingJSON.actionCallback();
                }
                else
                {
                    stopJSON.actionCallback();
                }
            })
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterBool(isPlayingJSON);

            stopJSON = new JSONStorableAction(StorableNames.Stop, () =>
            {
                if (animation == null)
                {
                    return;
                }
                if (animation.isPlaying)
                {
                    animation.StopAll();
                }
                else
                {
                    animation.ResetAll();
                }
            });
            RegisterAction(stopJSON);

            stopIfPlayingJSON = new JSONStorableAction(StorableNames.StopIfPlaying, () =>
            {
                if (animation == null || !animation.isPlaying)
                {
                    return;
                }
                animation.StopAll();
            });
            RegisterAction(stopIfPlayingJSON);

            stopAndResetJSON = new JSONStorableAction(StorableNames.StopAndReset, () =>
            {
                if (animation == null)
                {
                    return;
                }
                animationEditContext.StopAndReset();
                peers.SendStopAndReset();
            });
            RegisterAction(stopAndResetJSON);

            nextFrameJSON = new JSONStorableAction(StorableNames.NextFrame, () => animationEditContext.NextFrame());
            RegisterAction(nextFrameJSON);

            previousFrameJSON = new JSONStorableAction(StorableNames.PreviousFrame, () => animationEditContext.PreviousFrame());
            RegisterAction(previousFrameJSON);

            deleteJSON = new JSONStorableAction("Delete", () => animationEditContext.Delete());
            cutJSON    = new JSONStorableAction("Cut", () => animationEditContext.Cut());
            copyJSON   = new JSONStorableAction("Copy", () => animationEditContext.Copy());
            pasteJSON  = new JSONStorableAction("Paste", () => animationEditContext.Paste());

            speedJSON = new JSONStorableFloat(StorableNames.Speed, 1f, v => animation.speed = v, -1f, 5f, false)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterFloat(speedJSON);

            lockedJSON = new JSONStorableBool(StorableNames.Locked, false, v => animationEditContext.locked = v)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterBool(lockedJSON);

            _scrubberAnalogControlJSON = new JSONStorableFloat("Scrubber", 0f, -1f, 1f);

            pausedJSON = new JSONStorableBool(StorableNames.Paused, false, v => animation.paused = v)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterBool(pausedJSON);
        }
Exemplo n.º 7
0
        public void InitStorables()
        {
            animationJSON = new JSONStorableStringChooser(StorableNames.Animation, new List <string>(), "", "Animation", val => ChangeAnimation(val))
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterStringChooser(animationJSON);

            nextAnimationJSON = new JSONStorableAction(StorableNames.NextAnimation, () =>
            {
                var i = animationJSON.choices.IndexOf(animationJSON.val);
                if (i < 0 || i > animationJSON.choices.Count - 2)
                {
                    return;
                }
                animationJSON.val = animationJSON.choices[i + 1];
            });
            RegisterAction(nextAnimationJSON);

            previousAnimationJSON = new JSONStorableAction(StorableNames.PreviousAnimation, () =>
            {
                var i = animationJSON.choices.IndexOf(animationJSON.val);
                if (i < 1 || i > animationJSON.choices.Count - 1)
                {
                    return;
                }
                animationJSON.val = animationJSON.choices[i - 1];
            });
            RegisterAction(previousAnimationJSON);

            scrubberJSON = new JSONStorableFloat(StorableNames.Scrubber, 0f, v => animation.clipTime = v.Snap(animation.snap), 0f, AtomAnimationClip.DefaultAnimationLength, true)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterFloat(scrubberJSON);

            timeJSON = new JSONStorableFloat(StorableNames.Time, 0f, v => animation.playTime = v.Snap(), 0f, float.MaxValue, true)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterFloat(timeJSON);

            playJSON = new JSONStorableAction(StorableNames.Play, () =>
            {
                animation?.PlayAll();
            });
            RegisterAction(playJSON);

            playIfNotPlayingJSON = new JSONStorableAction(StorableNames.PlayIfNotPlaying, () =>
            {
                if (animation == null || animation.isPlaying == true)
                {
                    return;
                }
                animation.PlayAll();
            });
            RegisterAction(playIfNotPlayingJSON);

            isPlayingJSON = new JSONStorableBool(StorableNames.IsPlaying, false, (bool val) =>
            {
                if (val)
                {
                    playIfNotPlayingJSON.actionCallback();
                }
                else
                {
                    stopJSON.actionCallback();
                }
            })
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterBool(isPlayingJSON);

            stopJSON = new JSONStorableAction(StorableNames.Stop, () =>
            {
                if (animation == null)
                {
                    return;
                }
                if (animation.isPlaying)
                {
                    animation.StopAll();
                }
                else
                {
                    animation.ResetAll();
                }
            });
            RegisterAction(stopJSON);

            stopIfPlayingJSON = new JSONStorableAction(StorableNames.StopIfPlaying, () =>
            {
                if (animation == null || !animation.isPlaying)
                {
                    return;
                }
                animation.StopAll();
            });
            RegisterAction(stopIfPlayingJSON);

            stopAndResetJSON = new JSONStorableAction(StorableNames.StopAndReset, () =>
            {
                if (animation == null)
                {
                    return;
                }
                if (animation.isPlaying)
                {
                    animation.StopAll();
                }
                animation.ResetAll();
            });
            RegisterAction(stopAndResetJSON);

            nextFrameJSON = new JSONStorableAction(StorableNames.NextFrame, () => NextFrame());
            RegisterAction(nextFrameJSON);

            previousFrameJSON = new JSONStorableAction(StorableNames.PreviousFrame, () => PreviousFrame());
            RegisterAction(previousFrameJSON);

            deleteJSON = new JSONStorableAction("Delete", () => Delete());
            cutJSON    = new JSONStorableAction("Cut", () => Cut());
            copyJSON   = new JSONStorableAction("Copy", () => Copy());
            pasteJSON  = new JSONStorableAction("Paste", () => Paste());

            speedJSON = new JSONStorableFloat(StorableNames.Speed, 1f, v => UpdateAnimationSpeed(v), 0f, 5f, false)
            {
                isStorable   = false,
                isRestorable = false
            };
            RegisterFloat(speedJSON);
        }