///// <summary>
        ///// Renders the Morph Panel
        ///// </summary>
        //protected void HandleMorphsPane()
        //{

        //    List<MORPH3D.FOUNDATIONS.Morph> dirtyMorphValues = new List<MORPH3D.FOUNDATIONS.Morph>();
        //    List<MORPH3D.FOUNDATIONS.Morph> dirtyMorphAttachments = new List<MORPH3D.FOUNDATIONS.Morph>();
        //    List<MORPH3D.FOUNDATIONS.Morph> dirtyMorphDettachments = new List<MORPH3D.FOUNDATIONS.Morph>();

        //    for (int i = 0; i < charMan.coreMorphs.morphs.Count; i++)
        //    {
        //        if (selectedBlendShape != "" &&
        //            charMan.coreMorphs.morphs[i].displayName.IndexOf(selectedBlendShape, StringComparison.OrdinalIgnoreCase) < 0)
        //        {
        //            continue;
        //        }

        //        MORPH3D.FOUNDATIONS.Morph morph = charMan.coreMorphs.morphs[i];
        //        EditorMorphState ems = HandleEditorMorphState(morph);

        //        if (ems.dirty)
        //        {
        //            //we need to update this morph

        //            if (ems.dirtyAttached)
        //            {
        //                if (ems.attached)
        //                {
        //                    morph.attached = true;
        //                    dirtyMorphAttachments.Add(morph);
        //                }
        //                else
        //                {
        //                    morph.attached = false;
        //                    dirtyMorphDettachments.Add(morph);
        //                }
        //            }

        //            if (ems.dirtyValue)
        //            {
        //                morph.value = ems.value;

        //                if(!morph.attached && ems.value > 0f)
        //                {
        //                    //if it wasn't attached and the slider is not 0 attach it
        //                    morph.attached = true;
        //                    dirtyMorphAttachments.Add(morph);
        //                }
        //                dirtyMorphValues.Add(morph);
        //            }

        //            //replace the object with our modified one, why doesn't c# support references for local vars.... this is stupid
        //            charMan.coreMorphs.morphs[i] = morph;

        //            //Debug.Log("Morph: " + morph.name + " | " + morph.value + " | " + data.coreMorphs.morphs[i].value + " | " + (ems.dirtyValue ? " DIRTY VALUE " : "") + (ems.dirtyAttached ? " DIRTY ATTACH " : "") );
        //        }
        //    }

        //    if (dirtyMorphDettachments.Count > 0 || dirtyMorphAttachments.Count > 0 || dirtyMorphValues.Count > 0)
        //    {
        //        charMan.coreMorphs.DettachMorphs(dirtyMorphDettachments.ToArray());
        //        charMan.coreMorphs.AttachMorphs(dirtyMorphAttachments.ToArray());
        //        charMan.coreMorphs.SyncMorphValues(dirtyMorphValues.ToArray());
        //        charMan.SyncAllBlendShapes();
        //    }

        //}


        protected EditorMorphState HandleEditorMorphState(MORPH3D.FOUNDATIONS.Morph morph)
        {
            EditorMorphState ems = new EditorMorphState();

            ems.dirty = false;

            GUILayoutOption[] optionsLabel  = new GUILayoutOption[] { GUILayout.MaxWidth(200.0f), GUILayout.MinWidth(25.0f), GUILayout.ExpandWidth(false) };
            GUILayoutOption[] optionsSlider = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
            GUILayoutOption[] optionsKey    = new GUILayoutOption[] { GUILayout.MaxWidth(200.0f), GUILayout.MinWidth(0.0f), GUILayout.Height(EditorGUIUtility.singleLineHeight) };
            GUILayoutOption[] optionsToggle = new GUILayoutOption[] { GUILayout.Width(40f), GUILayout.ExpandWidth(false) };

            EditorGUILayout.BeginHorizontal();
            //Show the slider between 0% and 100% for the morph

            EditorGUILayout.LabelField(morph.displayName, optionsLabel);
            ems.value = EditorGUILayout.Slider(morph.value, 0f, 100f, optionsSlider);
            //Show the checkbox for if this morph should be installed to the figure/mesh
            ems.attached = EditorGUILayout.Toggle(morph.attached, optionsToggle); //most efficient way, but not necessarily the most accurate way
            //ems.attached = EditorGUILayout.Toggle(charMan.coreMorphs.morphGroups["Attached"].Contains(morph)); //most accurate way but not O(1);
            //has a property changed?
            if (ems.attached != morph.attached)
            {
                ems.dirtyAttached = true;
                ems.dirty         = true;
            }
            if (Mathf.Abs(ems.value - morph.value) > 0.001f)
            {
                ems.dirtyValue = true;
                ems.dirty      = true;
            }

            EditorGUILayout.SelectableLabel(morph.localName, EditorStyles.textField, optionsKey);

            EditorGUILayout.EndHorizontal();

            return(ems);
        }
        protected void EditorMorphs(List <MORPH3D.FOUNDATIONS.Morph> morphs, List <MORPH3D.FOUNDATIONS.Morph> dirtyMorphValues, List <MORPH3D.FOUNDATIONS.Morph> dirtyMorphAttachments,
                                    List <MORPH3D.FOUNDATIONS.Morph> dirtyMorphDettachments)
        {
            string searchKey = null;

            if (!String.IsNullOrEmpty(selectedBlendShape))
            {
                searchKey = selectedBlendShape.ToLower();
            }

            for (int i = 0; i < morphs.Count; i++)
            {
                MORPH3D.FOUNDATIONS.Morph morph = morphs[i];

                if (!String.IsNullOrEmpty(selectedBlendShape))
                {
                    if (!morph.name.ToLower().Contains(searchKey) && !morph.displayName.ToLower().Contains(searchKey) && !morph.localName.ToLower().Contains(searchKey))
                    {
                        continue;
                    }
                }

                EditorMorphState ems = HandleEditorMorphState(morph);

                if (ems.dirty)
                {
                    //we need to update this morph
                    if (ems.dirtyAttached)
                    {
                        if (ems.attached)
                        {
                            morph.attached = true;
                            dirtyMorphAttachments.Add(morph);
                        }
                        else
                        {
                            morph.attached = false;
                            dirtyMorphDettachments.Add(morph);
                        }
                    }

                    if (ems.dirtyValue)
                    {
                        morph.value = ems.value;

                        if (!morph.attached && ems.value > 0f)
                        {
                            //if it wasn't attached and the slider is not 0 attach it
                            morph.attached = true;
                            dirtyMorphAttachments.Add(morph);
                        }
                        dirtyMorphValues.Add(morph);
                    }

                    //replace the object with our modified one, why doesn't c# support references for local vars.... this is stupid
                    morphs[i] = morph;

                    //Debug.Log("Morph: " + morph.name + " | " + morph.value + " | " + data.coreMorphs.morphs[i].value + " | " + (ems.dirtyValue ? " DIRTY VALUE " : "") + (ems.dirtyAttached ? " DIRTY ATTACH " : "") );
                }
            }
        }