コード例 #1
0
        protected override void Dettach(M3DCharacterManager characterManager)
        {
            var itemsToRemove = characterManager
                                .GetAllHair()
                                .Where(item => item.name == morph3DDefinition.item.name);


            foreach (var item in itemsToRemove)
            {
                UnityEngine.Object.DestroyObject(item.gameObject);
            }

            characterManager.DetectAttachedHair();
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            #region just_stuff
            serializedObject.Update();
            if (charMan == null)
            {
                charMan = (M3DCharacterManager)target;
            }


            if (charMan == null || !charMan.isAwake)
            {
                GUILayout.Label("Your figure must be in the scene to edit settings");
                return;
            }

            #endregion just_stuff


            #region LOD
            float lod;
            lod = EditorGUILayout.Slider("LOD", charMan.currentLODLevel, 0, 1);
            if (lod != charMan.currentLODLevel)
            {
                Undo.RecordObject(charMan, "Change LOD");
                charMan.SetLODLevel(lod);
                EditorUtility.SetDirty(charMan);
            }
            EditorGUILayout.Space();
            #endregion LOD

            #region morphs
            showMorphs = EditorGUILayout.Foldout(showMorphs, "Morphs");
            if (showMorphs)
            {
                charMan.coreMorphs.SortIfNeeded();
                EditorGUI.indentLevel++;

                GUILayout.BeginHorizontal();
                selectedBlendShape = GUILayout.TextField(selectedBlendShape, GUI.skin.FindStyle("ToolbarSeachTextField"));
                if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
                {
                    selectedBlendShape = "";
                    GUI.FocusControl(null);
                }
                GUILayout.EndHorizontal();
                EditorGUILayout.Space();

                if (GUILayout.Button("Reset All"))
                {
                    Undo.RecordObject(charMan, "Change Morph");
                    for (int i = 0; i < charMan.coreMorphs.morphs.Count; i++)
                    {
                        if (charMan.coreMorphs.morphs[i].attached)
                        {
                            charMan.SetBlendshapeValue(charMan.coreMorphs.morphs[i].name, 0);
                        }
                    }
                    EditorUtility.SetDirty(charMan);
                }
                EditorGUILayout.Space();
                if (GUILayout.Button("Detach All"))
                {
                    Undo.RecordObject(charMan, "Detach All Morphs");
                    charMan.RemoveAllMorphs();
                    EditorUtility.SetDirty(charMan);
                }
                EditorGUILayout.Space();

                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>();

                EditorMorphs(charMan.coreMorphs.morphs, dirtyMorphValues, dirtyMorphAttachments, dirtyMorphDettachments);

                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();
                }

                EditorGUILayout.Space();
                EditorGUI.indentLevel--;
            }
            #endregion

            #region Morph Groups

            var morphTypeGroup = FOUNDATIONS.MorphTypeGroupService.GetMorphTypeGroups(charMan.gameObject.name);
            if (morphTypeGroup != null)
            {
                showMorphTypeGroups = EditorGUILayout.Foldout(showMorphTypeGroups, "Morph Groups");
                if (showMorphTypeGroups)
                {
                    charMan.coreMorphs.SortIfNeeded();
                    EditorGUI.indentLevel++;
                    foreach (var group in morphTypeGroup.SubGroups.Values)
                    {
                        ShowMorphTypeGroup(group);
                    }
                    EditorGUI.indentLevel--;
                }
            }

            #endregion

            #region contentPacks
            showContentPacks = EditorGUILayout.Foldout(showContentPacks, "Content Packs");

            if (showContentPacks)
            {
                EditorGUI.indentLevel++;
                List <ContentPack> allPacks = charMan.GetAllContentPacks();
                for (int i = 0; i < allPacks.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(allPacks[i].name);
                    if (GUILayout.Button("X"))
                    {
                        Undo.RecordObject(charMan, "Remove Bundle");
                        charMan.RemoveContentPack(allPacks[i]);
                        EditorUtility.SetDirty(charMan);
                    }
                    EditorGUILayout.EndHorizontal();
                }

                /*
                 * CostumeItem tempPack = null;
                 *              tempPack = (CostumeItem)EditorGUILayout.ObjectField("New", tempPack, typeof(CostumeItem), true);
                 *              if(tempPack != null)
                 *              {
                 *                      ContentPack packScript = new ContentPack(tempPack.gameObject);
                 *                      Undo.RecordObject(charMan, "Add Bundle");
                 *                      charMan.AddContentPack(packScript);
                 *                      EditorUtility.SetDirty(charMan);
                 *              }
                 */
                GameObject tempPack = null;
                tempPack = (GameObject)EditorGUILayout.ObjectField("New", tempPack, typeof(GameObject), true);
                if (tempPack != null)
                {
                    string tPPath = AssetDatabase.GetAssetPath(tempPack);
                    if (tPPath.EndsWith(".fbx"))
                    {
                        //if we dropped an fbx, try replacing it with a matching .prefab instead
                        tPPath = tPPath.Replace(".fbx", ".prefab");
                        GameObject prefabObj = AssetDatabase.LoadAssetAtPath <GameObject>(tPPath);
                        if (prefabObj != null)
                        {
                            tempPack = prefabObj;
                        }
                    }
                    ContentPack packScript = new ContentPack(tempPack);
                    Undo.RecordObject(charMan, "Add Bundle");
                    charMan.AddContentPack(packScript);
                    EditorUtility.SetDirty(charMan);
                }


                if (GUILayout.Button("Import Selected From Project Pane"))
                {
                    string[]      guids = Selection.assetGUIDs;
                    List <string> paths = new List <string>();
                    foreach (string guid in guids)
                    {
                        string path = AssetDatabase.GUIDToAssetPath(guid);

                        if (System.IO.Directory.Exists(path))
                        {
                            string[] prefabPaths = System.IO.Directory.GetFiles(path, "*.prefab", System.IO.SearchOption.AllDirectories);
                            for (int i = 0; i < prefabPaths.Length; i++)
                            {
                                string dirtyPath = prefabPaths[i];
                                dirtyPath = dirtyPath.Replace(@"\", "/");
                                paths.Add(dirtyPath);
                            }
                        }
                    }

                    foreach (string path in paths)
                    {
                        if (path.EndsWith(".prefab"))
                        {
                            GameObject  go = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                            CostumeItem ci = go.GetComponent <CostumeItem>();
                            if (ci != null)
                            {
                                ContentPack packScript = new ContentPack(go);
                                Undo.RecordObject(charMan, "Add Bundle");
                                charMan.AddContentPack(packScript);
                                EditorUtility.SetDirty(charMan);
                            }
                        }
                    }
                }

                EditorGUI.indentLevel--;
            }
            EditorGUILayout.Space();
            #endregion contentPacks

            #region hair
            showHair = EditorGUILayout.Foldout(showHair, "Hair");
            if (showHair)
            {
                EditorGUI.indentLevel++;
                List <MORPH3D.COSTUMING.CIhair> allHair = charMan.GetAllHair();
                foreach (MORPH3D.COSTUMING.CIhair mesh in allHair)
                {
                    if (DisplayHair(mesh))
                    {
                        Undo.RecordObject(charMan, "Toggle Hair");
                        mesh.SetVisibility(!mesh.isVisible);
                        //						data.SetVisibilityOnHairItem(mesh.ID, !mesh.isVisible);
                        EditorUtility.SetDirty(charMan);
                    }
                }
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.Space();
            #endregion hair

            #region clothing
            showAllClothing = EditorGUILayout.Foldout(showAllClothing, "Clothing");
            if (showAllClothing)
            {
                EditorGUI.indentLevel++;

                List <CIclothing> allClothing = null;
                allClothing = charMan.GetAllClothing();
                foreach (CIclothing mesh in allClothing)
                {
//					bool tempLock;
                    bool temp = DisplayClothingMesh(mesh);

//					if(tempLock != mesh.isLocked)
//					{
//						Undo.RecordObject(data, "Lock Clothing");
//						if(tempLock)
                    //							data.LockClothingItem(mesh.ID);
//						else
                    //							data.UnlockClothingItem(mesh.ID);
//						EditorUtility.SetDirty(data);
//					}

                    if (temp)
                    {
                        Undo.RecordObject(charMan, "Toggle Clothing");
                        charMan.SetClothingVisibility(mesh.ID, !mesh.isVisible);
                        EditorUtility.SetDirty(charMan);
                    }
                }
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.Space();
            #endregion clothing

            #region props
            CIattachmentPoint[] attachmentPoints = charMan.GetAllAttachmentPoints();
//			Debug.Log("AP LENGTH:"+attachmentPoints.Length);
            if (showAttachmentPointsGroups == null || showAttachmentPointsGroups.Length != attachmentPoints.Length)
            {
                showAttachmentPointsGroups = new bool[attachmentPoints.Length];
            }

            /*
             * if(selectedProps == null || selectedProps.Length != attachmentPoints.Length)
             *      selectedProps = new int[attachmentPoints.Length];
             */
            if (selectedPropsNames == null || selectedPropsNames.Length != attachmentPoints.Length)
            {
                selectedPropsNames = new string[attachmentPoints.Length];
            }
            List <CIprop> props      = charMan.GetAllLoadedProps();
            string[]      propsNames = new string[] {};
            if (props != null)
            {
                propsNames = new string[props.Count];
            }
            for (int i = 0; i < propsNames.Length; i++)
            {
                propsNames[i] = props[i].ID;
            }

            showAttachmentPoints = EditorGUILayout.Foldout(showAttachmentPoints, "Attachment Points");
            if (showAttachmentPoints)
            {
                int deleteAttachment = -1;
                EditorGUI.indentLevel++;
                for (int i = 0; i < attachmentPoints.Length; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    showAttachmentPointsGroups[i] = EditorGUILayout.Foldout(showAttachmentPointsGroups[i], attachmentPoints[i].attachmentPointName);
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("X", GUILayout.Width(45)))
                    {
                        deleteAttachment = i;
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    if (showAttachmentPointsGroups[i])
                    {
                        EditorGUI.indentLevel++;
                        CIprop[] activeProps = attachmentPoints[i].getAttachmentArray();
                        int      destroyProp = -1;
                        for (int x = 0; x < activeProps.Length; x++)
                        {
                            if (DisplayProp(activeProps[x]))
                            {
                                destroyProp = x;
                            }
                        }
                        if (destroyProp >= 0)
                        {
                            Undo.RecordObject(charMan, "Destroy Prop");
                            charMan.DetachPropFromAttachmentPoint(activeProps[destroyProp].ID, attachmentPoints[i].attachmentPointName);
                            EditorUtility.SetDirty(charMan);
                        }
//						Debug.Log("GF");
                        if (propsNames.Length > 0)
                        {
//							Debug.Log("FDFG");
                            EditorGUILayout.Space();
                            EditorGUILayout.BeginHorizontal();
                            EditorGUILayout.LabelField("Add Prop:", GUILayout.Width(150));
                            EditorGUILayout.LabelField(selectedPropsNames[i], GUILayout.Width(150));
                            if (selectedPropsNames[i] != "" && selectedPropsNames[i] != null && charMan.GetLoadedPropByName(selectedPropsNames[i]) == null)
                            {
                                selectedPropsNames[i] = "";
                            }
                            if (GUILayout.Button("Search"))
                            {
                                int num = i;
                                SearchableWindow.Init(delegate(string newName) { selectedPropsNames[num] = newName; }, propsNames);
                            }
                            if (selectedPropsNames[i] != "" && selectedPropsNames[i] != null && GUILayout.Button("Add"))
                            {
                                Undo.RecordObject(charMan, "Attach Prop");
                                charMan.AttachPropToAttachmentPoint(selectedPropsNames[i], attachmentPoints[i].attachmentPointName);
                                EditorUtility.SetDirty(charMan);
                                selectedPropsNames[i] = "";
                            }
                            GUILayout.FlexibleSpace();
                            EditorGUILayout.EndHorizontal();

                            /*
                             * EditorGUILayout.Space();
                             * EditorGUILayout.BeginHorizontal();
                             * selectedProps[i] = EditorGUILayout.Popup (selectedProps[i], propsNames, GUILayout.Width(150));
                             * if(GUILayout.Button("Add"))
                             * {
                             *      Undo.RecordObject(data, "Attach Prop");
                             *      data.AttachPropToAttachmentPoint(propsNames[selectedProps[i]], attachmentPoints[i].attachmentPointName);
                             *      EditorUtility.SetDirty(data);
                             *      selectedProps[i] = 0;
                             * }
                             * GUILayout.FlexibleSpace();
                             * EditorGUILayout.EndHorizontal();
                             */
                        }
                        EditorGUILayout.Space();
                        EditorGUI.indentLevel--;
                    }
                }

                if (deleteAttachment >= 0)
                {
                    Undo.RecordObject(attachmentPoints[deleteAttachment], "Delete Attachment Point");
                    charMan.DeleteAttachmentPoint(attachmentPoints[deleteAttachment].attachmentPointName);
                }

                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("New Point:", GUILayout.Width(150));
                EditorGUILayout.LabelField(selectedNewAttachmentPointName, GUILayout.Width(150));
                Transform tempBone = charMan.GetBoneByName(selectedNewAttachmentPointName);
                if (selectedNewAttachmentPointName != "" && selectedNewAttachmentPointName != null && tempBone == null)
                {
                    selectedNewAttachmentPointName = "";
                }
                if (GUILayout.Button("Search"))
                {
                    SearchableWindow.Init(delegate(string newName) { selectedNewAttachmentPointName = newName; }, charMan.GetAllBonesNames());
                }
                if (selectedNewAttachmentPointName != "" && selectedNewAttachmentPointName != null && tempBone != null && GUILayout.Button("Add"))
                {
                    Undo.RecordObject(tempBone.gameObject, "New Attachment Point");
                    charMan.CreateAttachmentPointOnBone(selectedNewAttachmentPointName);
                    selectedNewAttachmentPointName = "";
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();

                /*
                 * EditorGUILayout.Space();
                 * EditorGUILayout.BeginHorizontal();
                 * selectedNewAttachmentPointName = EditorGUILayout.TextField("New Point Bone Name", selectedNewAttachmentPointName);
                 * if(GUILayout.Button("Add") && selectedNewAttachmentPointName != "")
                 * {
                 *      Transform bone = data.boneService.getBoneByName (selectedNewAttachmentPointName);
                 *      if(bone != null)
                 *      {
                 *              Undo.RecordObject(bone.gameObject, "New Attachment Point");
                 *              data.CreateAttachmentPointOnBone(selectedNewAttachmentPointName);
                 *      }
                 *      selectedNewAttachmentPointName = "";
                 * }
                 * EditorGUILayout.EndHorizontal();
                 *
                 * EditorGUILayout.BeginHorizontal();
                 * selectedNewAttachmentPoint = (GameObject)EditorGUILayout.ObjectField("New Attachemnt Point", selectedNewAttachmentPoint, typeof(GameObject), true);
                 * if(selectedNewAttachmentPoint != null && !selectedNewAttachmentPoint.activeInHierarchy)
                 *      selectedNewAttachmentPoint = null;
                 * if(GUILayout.Button("Add") && selectedNewAttachmentPoint != null)
                 * {
                 *      if(selectedNewAttachmentPoint.GetComponent<CIattachmentPoint>() == null)
                 *      {
                 *              Undo.RecordObject(selectedNewAttachmentPoint, "New Attachment Point");
                 *              data.CreateAttachmentPointFromGameObject(selectedNewAttachmentPoint);
                 *      }
                 *      selectedNewAttachmentPoint = null;
                 * }
                 * EditorGUILayout.EndHorizontal();
                 */

                EditorGUI.indentLevel--;
            }
            EditorGUILayout.Space();
            #endregion props
        }