示例#1
0
        public override void Init()
        {
            try
            {
                var addAnimationButton = CreateButton("Add Animation");
                addAnimationButton.buttonColor = new Color(0.75f, 0.44f, 0.1f);
                addAnimationButton.button.onClick.AddListener(() =>
                {
                    string folder = lastDir;
                    SuperController.singleton.GetMediaPathDialog((string path) =>
                    {
                        if (String.IsNullOrEmpty(path))
                        {
                            return;
                        }

                        Animation animation = new Animation(path, this)
                        {
                            loop = true,
                            restartOnAnimationChange = true,
                            rootMotionXZ             = true,
                            rootMotionY = true,
                        };
                        animations.Add(animation);


                        idleAnimation.choices  = animations.GetIdList();
                        walkAnimation.choices  = animations.GetIdList();
                        forceAnimation.choices = animations.GetIdList();

                        int startIndex         = 0;
                        int endIndex           = path.LastIndexOf("\\");
                        int length             = endIndex - startIndex + 1;
                        string pathWithoutFile = path.Substring(startIndex, length);
                        lastDir = pathWithoutFile;
                    }, "bvh", folder, false);
                });

                #region Default Animations
                animations = new AnimationBank(this);
                string ANIMATION_PATH = GetPluginPath() + "/Animations/";

                animations.Add(new Animation(ANIMATION_PATH + "Look.bvh", this, "Idle")
                {
                    loop       = true,
                    startFrame = 2,
                });

                animations.Add(new Animation(ANIMATION_PATH + "StandToWalk.bvh", this, "Walk")
                {
                    loop = true,
                    restartOnAnimationChange = true,
                    rootMotionXZ             = true,
                    rootMotionY = false,
                    startFrame  = 67,
                    endFrame    = 150,
                });
                #endregion


                playbackSpeed = new JSONStorableFloat("playback speed", 1, (float speed) =>
                {
                    animator.playbackMultiplier = speed;
                }, 0, 4, false);
                RegisterFloat(playbackSpeed);
                CreateSlider(playbackSpeed, true);

                #region Walk Cycle
                moveToTarget = new JSONStorableBool("walk to target", true);
                RegisterBool(moveToTarget);
                CreateToggle(moveToTarget, true);

                idleAnimation = new JSONStorableStringChooser("idleAnimation", animations.GetIdList(), "Idle", "Idle Animation");
                RegisterStringChooser(idleAnimation);
                idlePopup = CreatePopup(idleAnimation, true);
                idlePopup.popup.onOpenPopupHandlers += () => {
                    idleAnimation.choices = animations.GetIdList();
                };

                walkAnimation = new JSONStorableStringChooser("walkAnimation", animations.GetIdList(), "Walk", "Walk Animation");
                RegisterStringChooser(walkAnimation);
                walkPopup = CreatePopup(walkAnimation, true);
                walkPopup.popup.onOpenPopupHandlers += () => {
                    walkAnimation.choices = animations.GetIdList();
                };

                forceAnimation = new JSONStorableStringChooser("forcedAnimationChoice", animations.GetIdList(), "Idle", "Trigger Force Animation", (string choice) =>
                {
                    ForcePlayAnimation(animations.Get(choice));
                });
                RegisterStringChooser(forceAnimation);

                turnRate = new JSONStorableFloat("turn rate", 6, 0.01f, 12f, false);
                RegisterFloat(turnRate);
                CreateSlider(turnRate, true);

                heelHeight = new JSONStorableFloat("heel height", 0, SetHeelHeight, 0, 0.2f, true);
                RegisterFloat(heelHeight);
                CreateSlider(heelHeight, true);

                heelAngle = new JSONStorableFloat("heel angle", 30, SetHeelAngle, 0, 120, true);
                RegisterFloat(heelAngle);
                CreateSlider(heelAngle, true);

                ignoreFeetCollisions = new JSONStorableBool("ignore feet collisions", true, SetIgnoreFeetCollisions);
                RegisterBool(ignoreFeetCollisions);
                CreateToggle(ignoreFeetCollisions, true);

                useRecommendedPhyics = new JSONStorableBool("use recommended physics", false, SetRecommendedPhysics);
                RegisterBool(useRecommendedPhyics);
                CreateToggle(useRecommendedPhyics, true);

                showTarget = new JSONStorableBool("show target", true, SetTargetVisibility);
                RegisterBool(showTarget);
                CreateToggle(showTarget, true);
                goalMarker = CreateMarker(containingAtom.transform);

                selectRandomAnimations = new JSONStorableBool("select random animations", false);
                RegisterBool(selectRandomAnimations);
                CreateToggle(selectRandomAnimations, true);

                #endregion



                //var instructions = CreateTextField(new JSONStorableString("instructions", INSTRUCTIONS), true);
                //instructions.height = 1100;
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }