private void GetModelsList() { modelsList.Clear(); bodyModelList = bodyModelTable.GetList(true); BodyStructureTable.BodyStructure searchStruct = new BodyStructureTable.BodyStructure(); BodySubtypeTable.BodySubtype searchSubtype = new BodySubtypeTable.BodySubtype(); for (int i = 0; i < bodyModelList.Count; i++) { ListModels toAdd = new ListModels(); toAdd.IDModel = bodyModelList [i].ID; toAdd.Name = bodyModelList [i].Name; searchStruct = bodyStrucList.Find(x => x.ID == bodyModelList [i].IDBodyStructure); if (searchStruct != null) { toAdd.Structure = searchStruct.Name; } searchSubtype = bodySubtList.Find(x => x.ID == bodyModelList [i].IDBodySubtype); if (searchSubtype != null) { toAdd.BodySubtype = searchSubtype.Name; } GameObject prefabToLoad = (GameObject)Resources.Load(_config.GetPathName(CSConfig.PathTypeEnum.BodyModelsPath) + "/" + bodyModelList[i].ModelName); if (prefabToLoad == null) { toAdd.PrefabError = true; } modelsList.Add(toAdd); } }
private void SelectRecord(int id) { flagEdit = 2; selectedRecord = id; SkinsTable.Skin tRec = listSkins.Find(x => x.ID == id); skinName = tRec.Name; bodyModelSelected = bodyModelList.FindIndex(x => x.ID == tRec.IDModel); defSkin = tRec.DefaultSkin; FilterSlots(bodyModelSelected); List <SkinsTable.SkinSlots> tList = skinTable.GetSlotsList(selectedRecord, true); //Fill the material list for (int i = 0; i < tList.Count; i++) { MaterialPrefab tMat = new MaterialPrefab(); tMat = materialList.Find(x => x.IDSlot == tList [i].IDSkinSlot); tMat.PrefabName = tList [i].MaterialName; //Try to find the object Material prefabToLoad = (Material)Resources.Load(_config.GetPathName(CSConfig.PathTypeEnum.SkinsPath) + "/" + tMat.PrefabName); if (prefabToLoad != null) { tMat.Prefab = prefabToLoad; tMat.PrefabSelected = prefabToLoad; } else { tMat.PrefabError = true; } } }
private void SelectRecord(int id) { selectedRecord = id; propRecord = propTable.GetRecord(id); bodyStrucSelected = bodyStrucList.FindIndex(x => x.ID == propRecord.IDBodyStructure); FilterSlots(bodyStrucSelected); selectedSlot = bodyStrucSlots.FindIndex(x => x.IDSlot == propRecord.IDSlot); //Update models list List <PropTable.PropModels> mList = propTable.GetModelsList(selectedRecord); for (int i = 0; i < mList.Count; i++) { ModelPrefab tRec = modelsList.Find(x => x.IDSubtype == mList [i].IDBodySubtype); tRec.PrefabName = mList [i].ModelName; //Try to find the object GameObject prefabToLoad = (GameObject)Resources.Load(_config.GetPathName(CSConfig.PathTypeEnum.PropPath) + "/" + tRec.PrefabName); if (prefabToLoad != null) { tRec.Prefab = prefabToLoad; tRec.PrefabSelected = prefabToLoad; } else { tRec.PrefabError = true; } } flagEdit = 2; }
private void SelectRecord(int id) { flagEdit = 2; selectedRecord = id; int skinIndex = eyeSkinsList.FindIndex(x => x.IDSkin == id); eyeSelected = eyesList.FindIndex(x => x.ID == eyeSkinsList[skinIndex].IDEye); FilterObjects(eyeSelected); List <EyeSkinTable.EyeMaterial> tList = eyeSkinTable.GetMaterialList(selectedRecord, true); if (tList.Count > 0) { for (int i = 0; i < materialList.Count; i++) { materialList [i].PrefabName = tList.Find(x => x.IDObject == materialList [i].IDEyeObject).MaterialName; //try to locate the object Material prefabToLoad = (Material)Resources.Load(_config.GetPathName(CSConfig.PathTypeEnum.SkinsPath) + "/" + materialList[i].PrefabName); if (prefabToLoad != null) { materialList[i].Prefab = prefabToLoad; materialList[i].PrefabSelected = prefabToLoad; } else { materialList[i].PrefabError = true; } } } eyeIndex = -1; skinName = eyeSkinsList [skinIndex].SkinName; }
//** 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."); } }