Ejemplo n.º 1
0
        /// <summary>
        /// Handles file drops.
        /// </summary>
        /// <param name="sender">Event source.</param>
        /// <param name="absolutePath">Absolute path of dropped file.</param>
        private void HandleFileDrop(CubismViewer sender, string absolutePath)
        {
            // Skip non-motion files.
            if (!absolutePath.EndsWith("motion3.json"))
            {
                return;
            }


            var model = sender.Model;


            // Make sure animation component is attached to model.
            var animator = model.GetComponent <Animation>();


            if (animator == null)
            {
                animator = model.gameObject.AddComponent <Animation>();
            }


            // Deserialize animation.
            var model3Json = CubismMotion3Json.LoadFrom(CubismViewerIo.LoadAsset <string>(absolutePath));
            var clipName   = CubismViewerIo.GetFileName(absolutePath);
            var clip       = model3Json.ToAnimationClip();

            clip.wrapMode = WrapMode.Loop;
            clip.legacy   = true;


            // Play animation.
            animator.AddClip(clip, clipName);
            animator.Play(clipName);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when animation is selected in dropdown.
        /// </summary>
        private void DropdownSelected()
        {
            var model = viewer.Model;

            // Make sure animation component is attached to model.
            var animator = model.GetComponent <Animation>();

            if (animator == null)
            {
                animator = model.gameObject.AddComponent <Animation>();
            }

            // Check if "no animation" entry is selected.
            if (animDropdown.value == 0)
            {
                animator.Stop();
                animator.clip = null;
                return;
            }

            string absolutePath = files[animDropdown.value - 1];

            // Deserialize animation.
            var model3Json = CubismMotion3Json.LoadFrom(CubismViewerIo.LoadAsset <string>(absolutePath));
            var clipName   = CubismViewerIo.GetFileName(absolutePath);
            var clip       = model3Json.ToAnimationClip();

            clip.wrapMode = WrapMode.Loop;
            clip.legacy   = true;

            // Set clip info in animator (needed for recording with CubismRecorder).
            clip.name     = clipName;
            animator.clip = clip;

            // Play animation.
            animator.AddClip(clip, clipName);
            animator.Play(clipName);
        }