Example #1
0
        public override void OnInspectorGUI()
        {
            if (PreviewSceneManager == null)
            {
                return;
            }
            serializedObject.Update();

            if (m_serializedEditor == null)
            {
                m_serializedEditor = new SerializedBlendShapeEditor(serializedObject, PreviewSceneManager);
            }

            EditorGUILayout.BeginHorizontal();

            var changed = false;

            EditorGUILayout.BeginVertical();
            base.OnInspectorGUI();
            EditorGUILayout.LabelField("Preview Weight");
            var previewSlider = EditorGUILayout.Slider(m_previewSlider, 0, 1.0f);

            EditorGUILayout.EndVertical();

            if (m_serializedEditor.IsBinary)
            {
                previewSlider = Mathf.Round(previewSlider);
            }

            if (previewSlider != m_previewSlider)
            {
                m_previewSlider = previewSlider;
                changed         = true;
            }

            EditorGUILayout.EndHorizontal();
            Separator();
            // EditorGUILayout.Space();

            if (m_serializedEditor.Draw(out BlendShapeClip bakeValue))
            {
                changed = true;
            }

            if (changed && PreviewSceneManager != null)
            {
                PreviewSceneManager.Bake(bakeValue, m_previewSlider);
            }
        }
Example #2
0
 void OnSelected(BlendShapeClip clip)
 {
     if (PreviewSceneManager == null)
     {
         m_clipEditor = null;
     }
     else if (clip != null)
     {
         m_clipEditor = new SerializedBlendShapeEditor(clip, PreviewSceneManager);
         PreviewSceneManager.Bake(new PreviewSceneManager.BakeValue
         {
             BlendShapeBindings    = clip.Values,
             MaterialValueBindings = clip.MaterialValues,
             Weight = 1.0f
         });
     }
     else
     {
         m_clipEditor = null;
         PreviewSceneManager.Bake(new PreviewSceneManager.BakeValue());
     }
 }
        void OnSelected(BlendShapeClip clip)
        {
            if (PreviewSceneManager == null)
            {
                m_serializedEditor = null;
                return;
            }

            if (clip != null)
            {
                // select clip
                var status = SerializedBlendShapeEditor.EditorStatus.Default;
                if (m_serializedEditor != null)
                {
                    status = m_serializedEditor.Status;
                }
                m_serializedEditor = new SerializedBlendShapeEditor(clip, PreviewSceneManager, status);
            }
            else
            {
                // clear selection
                m_serializedEditor = null;
                PreviewSceneManager.Bake(default, 1.0f);
        public override void OnInspectorGUI()
        {
            if (PreviewSceneManager == null)
            {
                return;
            }
            serializedObject.Update();

            if (m_serializedEditor == null)
            {
                m_serializedEditor = new SerializedBlendShapeEditor(serializedObject, PreviewSceneManager);
                //m_thumbnailProp = serializedObject.FindProperty("Thumbnail");
                m_isBinaryProp = serializedObject.FindProperty("IsBinary");
            }

            EditorGUILayout.BeginHorizontal();

            /*
             * int thumbnailSize = 96;
             * var objectReferenceValue = EditorGUILayout.ObjectField(m_thumbnailProp.objectReferenceValue, typeof(Texture), false,
             *  GUILayout.Width(thumbnailSize), GUILayout.Height(thumbnailSize));
             * if (m_thumbnailProp.objectReferenceValue != objectReferenceValue)
             * {
             *  m_thumbnailProp.objectReferenceValue = objectReferenceValue;
             *  serializedObject.ApplyModifiedProperties();
             * }
             */

            var changed = false;

            EditorGUILayout.BeginVertical();
            base.OnInspectorGUI();
            EditorGUILayout.LabelField("Preview Weight");
            var previewSlider = EditorGUILayout.Slider(m_previewSlider, 0, 1.0f);

            GUI.enabled = PreviewTexture != null;

            /*
             * if (GUILayout.Button("save thumbnail"))
             * {
             *  //var ext = "jpg";
             *  var ext = "png";
             *  var asset = UnityPath.FromAsset(target);
             *  var path = EditorUtility.SaveFilePanel(
             *                 "save thumbnail",
             *                 asset.Parent.FullPath,
             *                 string.Format("{0}.{1}", asset.FileNameWithoutExtension, ext),
             *                 ext);
             *  if (!string.IsNullOrEmpty(path))
             *  {
             *      var thumbnail = SaveResizedImage(PreviewTexture, UnityPath.FromFullpath(path),
             *      BlendShapeClipDrawer.ThumbnailSize);
             *      m_thumbnailProp.objectReferenceValue = thumbnail;
             *      serializedObject.ApplyModifiedProperties();
             *  }
             * }
             */
            GUI.enabled = true;
            EditorGUILayout.EndVertical();

            if (m_isBinaryProp.boolValue)
            {
                previewSlider = Mathf.Round(previewSlider);
            }
            if (previewSlider != m_previewSlider)
            {
                m_previewSlider = previewSlider;
                changed         = true;
            }

            EditorGUILayout.EndHorizontal();
            Separator();
            EditorGUILayout.Space();

            var result = m_serializedEditor.Draw();

            if ((changed || result.Changed) && PreviewSceneManager != null)
            {
                PreviewSceneManager.Bake(new PreviewSceneManager.BakeValue
                {
                    BlendShapeBindings    = result.BlendShapeBindings,
                    MaterialValueBindings = result.MaterialValueBindings,
                    Weight = m_previewSlider
                });
            }
        }