Beispiel #1
0
 /// <summary>
 /// Called when a new Model is loaded.
 /// </summary>
 /// <param name="sender">The Sender/CubismViewer.</param>
 /// <param name="model">The new Model.</param>
 private void OnNewModel(CubismViewer sender, CubismModel model)
 {
     // Clear animation list when new model is loaded.
     animDropdown.ClearOptions();
     animDropdown.captionText.text = "Load one motion first";
     animDropdown.enabled          = false;
 }
Beispiel #2
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;
            }

            // Save reference to viewer.
            viewer = sender;

            // Get all full file paths of motion files.
            files = System.IO.Directory.GetFiles(Path.GetDirectoryName(absolutePath), "*.motion3.json");

            // Get filenames without path for display.
            List <string> filenames = files.Select(a => Path.GetFileName(a).Replace(".motion3.json", String.Empty)).ToList();

            // Add option for no animation.
            filenames.Insert(0, "--- None ---");

            // Get index of currently selected file.
            int selected = Array.IndexOf(files, absolutePath) + 1;

            // Enable dropdown and show list of filenames.
            animDropdown.ClearOptions();
            animDropdown.AddOptions(filenames);
            animDropdown.enabled = true;
            animDropdown.value   = selected;
        }
        /// <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);
        }
Beispiel #4
0
        /// <summary>
        /// Called when a new Model is loaded.
        /// </summary>
        /// <param name="sender">The Sender/CubismViewer.</param>
        /// <param name="model">The new Model.</param>
        private void OnNewModel(CubismViewer sender, CubismModel model)
        {
            // Check if old model is currently loaded.
            if (CubismParamsInfo != null)
            {
                // Destroy all old UI elements if they exist.
                foreach (CubismParameterInfo param in CubismParamsInfo)
                {
                    GameObject.Destroy(param.Slider.gameObject.transform.parent.gameObject);
                }
            }

            // Get template for parameter entries (find over parent because it's not enabled)
            GameObject paramEntryTemplate = GameObject.Find("paramScroll").transform.Find("paramEntryTemplate").gameObject;

            // Get scroll view content box. Parameter sliders are instantiated inside of this.
            GameObject paramScrollContent = GameObject.Find("paramScrollContent");

            CubismParamsInfo = new List <CubismParameterInfo>();

            // Populate parameter UI scroll view.
            foreach (CubismParameter p in model.Parameters)
            {
                // Instantiate from template.
                GameObject newParam = (GameObject)Instantiate(paramEntryTemplate);
                newParam.transform.SetParent(paramScrollContent.transform);
                newParam.SetActive(true);
                newParam.name = p.Id;

                // Set slider values.
                Slider s = newParam.GetComponentInChildren <Slider>();
                s.maxValue = p.MaximumValue;
                s.minValue = p.MinimumValue;
                s.value    = p.Value;

                // Set text fields.
                Text t = newParam.GetComponentsInChildren <Text>()[3];
                newParam.GetComponentsInChildren <Text>()[0].text = p.Id;
                newParam.GetComponentsInChildren <Text>()[1].text = p.MinimumValue.ToString();
                newParam.GetComponentsInChildren <Text>()[2].text = p.MaximumValue.ToString();
                t.text = p.Value.ToString();

                Toggle to  = newParam.GetComponentInChildren <Toggle>();
                Image  img = newParam.GetComponent <Image>();

                // Create list of all CubismParameters and their respective UI elements/override state.
                CubismParameterInfo param = new CubismParameterInfo(p, to, t, img, s, false, false, p.Value);
                CubismParamsInfo.Add(param);

                // Listeners for slider and toggle button.
                to.onValueChanged.AddListener(delegate(bool newValue) { ParamActiveStatusChanged(newValue, param); });
                s.onValueChanged.AddListener(delegate(float newValue) { ParamValueChanged(newValue, param); });
            }

            // HACK Manually set scroll content height to height of children. Correct way to do this?
            int paramEntryHeight = (int)((RectTransform)paramEntryTemplate.transform).rect.height * model.Parameters.Length;

            ((RectTransform)paramScrollContent.transform).sizeDelta = new Vector2(0, paramEntryHeight);
        }
Beispiel #5
0
        /// <summary>
        /// Called when a new Model is loaded.
        /// </summary>
        /// <param name="sender">The Sender/CubismViewer.</param>
        /// <param name="model">The new Model.</param>
        private void OnNewModel(CubismViewer sender, CubismModel model)
        {
            // Find all trackable parameters in model.
            CubismParams = new List <CubismParameter>();

            foreach (CubismParameter p in model.Parameters)
            {
                foreach (string name in paramNames)
                {
                    if (p.Id == name)
                    {
                        CubismParams.Add(p);
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Called when a new Model is loaded.
        /// </summary>
        /// <param name="sender">The Sender/CubismViewer.</param>
        /// <param name="model">The new Model.</param>
        private void OnNewModel(CubismViewer sender, CubismModel model)
        {
            // Get physics controller for model. NULL if it doesn't have one.
            // This would be the case if no physics file has been found.
            physController = model.GetComponent <CubismPhysicsController>();

            // Disable/Enable physics toggle button depending on whether or not a physics controller is present.
            if (physController == null)
            {
                physicsToggle.isOn         = false;
                physicsToggle.interactable = false;
                PhysicsToggleLabel.text    = "No physics file found";
            }
            else
            {
                physicsToggle.isOn         = true;
                physicsToggle.interactable = true;
                PhysicsToggleLabel.text    = "Physics On/Off";
            }
        }