private void SelectRecord(int id) { record = bodyModelTable.GetModel(id); bodyStrucSelected = bodyStrucList.FindIndex(x => x.ID == record.IDBodyStructure); eyeSelected = eyesList.FindIndex(x => x.ID == record.IDEye) + 1; FilterSlots(bodyStrucSelected); for (int i = 0; i < bodyStrucList [bodyStrucSelected].IDBodySubtype.Count; i++) { if (bodyStrucList [bodyStrucSelected].IDBodySubtype [i] == record.IDBodySubtype) { bodySubtypeSelected = i; } } GameObject prefabToLoad = (GameObject)Resources.Load(_config.GetPathName(CSConfig.PathTypeEnum.BodyModelsPath) + "/" + record.ModelName); if (prefabToLoad != null) { prefab = prefabToLoad; prefabSelected = prefabToLoad; prefabError = false; } else { prefabError = true; } flagEdit = 2; }
//** ApplyBodyModel ** //Change the actual model used by the actor public void ApplyBodyModel(int modelID) { if (_config == null) { return; } //Get the name of the prefab to be used BodyModelTable.BodyModel model = tableBodyModel.GetModel(modelID); if (model == null) { Debug.LogError("Cannot retrieve the prefab of Body Model."); } //Assembly the full name with the path where the models are stored string modelPath = _config.GetPathName(CSConfig.PathTypeEnum.BodyModelsPath) + "/" + model.ModelName; //Load the model prefab GameObject objModel = (GameObject)Resources.Load(modelPath); if (objModel == null) { //Cannot load the model. Don't continue Debug.LogError("Cannot retrieve the prefab of Body Model. Prefab not found."); } //Retrieve the bone estructure that need to be used SkinnedMeshRenderer bSource = bonesSource.GetComponent <SkinnedMeshRenderer> (); //Remove actual model from actor if (actorBody.ActorModel != null) { Destroy(actorBody.ActorModel); } //Assign the new model to actor controller actorBody.ActorModel = GameObject.Instantiate(objModel) as GameObject; actorBody.ActorModel.transform.SetParent(this.gameObject.transform, false); //For each sub object of the model set the bone structure to be used foreach (Transform child in actorBody.ActorModel.transform) { SkinnedMeshRenderer bDest = child.GetComponent <SkinnedMeshRenderer> (); bDest.bones = bSource.bones; } oldBodySubtype = actorBody.BodySubtype; //Update information about the actor's body model actorBody.BodyID = modelID; actorBody.BodyStructure = model.IDBodyStructure; actorBody.BodySubtype = model.IDBodySubtype; actorBody.BodyModel = modelPath; actorBody.EyeID = model.IDEye; //Find the bone structure object actorBody.BonesArmature = transform.Find(model.ArmatureName); //Retrieve the clothing method used by this model / body structure tableBodyStructure.GetList(); actorBody.ClothingType = tableBodyStructure.GetRecord(model.IDBodyStructure).ClothingMethod; if (AutoChangeCloth) { ChangeClothesForModel(); } //Apply the default skin SkinsTable.Skin tSkin = tableSkins.GetDefaultSkin(actorBody.BodyID); if (tSkin != null) { actorBody.SkinID = tSkin.ID; ApplyBodySkin(actorBody.SkinID); } else { Debug.LogWarning("Body model doesn't have a default skin."); } }
private void ShowItems() { int contItems = 0; GUILayout.Label("Table of Body Models", EditorStyles.boldLabel); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(25)); GUILayout.Label("Model name", GUILayout.Width(200)); GUILayout.Label("Body Structure", GUILayout.Width(150)); GUILayout.Label("Body Subtype", GUILayout.Width(150)); GUILayout.Label("Prefab status", GUILayout.Width(100)); GUILayout.EndHorizontal(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); for (int iLoopItems = 0; iLoopItems < modelsList.Count; iLoopItems++) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(modelsList[iLoopItems].IDModel.ToString(), GUILayout.Width(25)); if (GUILayout.Button(modelsList[iLoopItems].Name, GUILayout.Width(200))) { SelectRecord(modelsList[iLoopItems].IDModel); } GUILayout.Label(modelsList [iLoopItems].Structure, GUILayout.Width(150)); GUILayout.Label(modelsList [iLoopItems].BodySubtype, GUILayout.Width(150)); Color oldColor = GUI.contentColor; if (modelsList [iLoopItems].PrefabError) { GUI.contentColor = Color.red; GUILayout.Label("Not found", GUILayout.Width(100)); } else { GUI.contentColor = Color.blue; GUILayout.Label("OK", GUILayout.Width(100)); } GUI.contentColor = oldColor; if (GUILayout.Button("-", GUILayout.Width(25))) { int canDelete = bodyModelTable.DeleteModel(bodyModelList [iLoopItems].ID); if (canDelete > 0) { this.ShowNotification(new GUIContent(EditorGUILayout.TextField("Cannot delete model. There is a skin attached to it."))); } } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); contItems++; } EditorGUILayout.EndScrollView(); if (contItems == 0) { EditorGUILayout.HelpBox("This table is empty", MessageType.Info); } GUILayout.Space(15); if (flagEdit > 0) { GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); GUILayout.Label("Model name:", GUILayout.Width(150)); record.Name = GUILayout.TextField(record.Name, GUILayout.Width(250)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Model prefab:", GUILayout.Width(150)); record.ModelName = GUILayout.TextField(record.ModelName, GUILayout.Width(150)); prefab = (GameObject)EditorGUILayout.ObjectField(prefab, typeof(GameObject), false, GUILayout.Width(150)); if (prefab != null && prefab != prefabSelected) { record.ModelName = _config.GetPrefabPath(CSConfig.PathTypeEnum.BodyModelsPath, AssetDatabase.GetAssetPath(prefab)); prefabSelected = prefab; prefabError = false; } GUILayout.EndHorizontal(); if (prefabError) { EditorGUILayout.HelpBox("Prefab cannot be found. Load it again to update the [Prefab name] field.", MessageType.Error); } GUILayout.BeginHorizontal(); GUILayout.Label("Bone Structure name:", GUILayout.Width(150)); record.ArmatureName = GUILayout.TextField(record.ArmatureName, GUILayout.Width(250)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Body structure:", GUILayout.Width(150)); bodyStructIndex = EditorGUILayout.Popup(bodyStrucSelected, bodyStructOptions, GUILayout.Width(150)); if (bodyStructIndex != bodyStrucSelected) { FilterSlots(bodyStructIndex); bodyStrucSelected = bodyStructIndex; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Body subtype:", GUILayout.Width(150)); bodySubtypeSelected = EditorGUILayout.Popup(bodySubtypeSelected, bodySubtypeOptions, GUILayout.Width(150)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Eyes:", GUILayout.Width(150)); eyeSelected = EditorGUILayout.Popup(eyeSelected, optEyes, GUILayout.Width(150)); if (GUILayout.Button("Save", GUILayout.Width(55))) { SaveRecord(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add model", GUILayout.Width(155))) { flagEdit = 1; record = new BodyModelTable.BodyModel(); } //Add button to save the table if (GUILayout.Button("Save table", GUILayout.Width(155))) { bodyModelTable.SaveList(); } GUILayout.EndHorizontal(); }