/// <summary> /// 将模型列表中的BODY替换成高模 /// </summary> public static List <uint> ReplaceModelList(List <uint> model_list, Actor.EVocationType vocation, bool newList = false) { // 暂时使用之前的model_list return(model_list); List <uint> modelList = null; if (newList) { modelList = new List <uint>(model_list); } else { modelList = model_list; } if (modelList == null) { GameDebug.LogError("[ReplaceModelList]ModelList is null"); return(null); } if (modelList.Count > 0) { for (int k = 0; k < modelList.Count; ++k) { DBAvatarPart dbAvatar = DBManager.GetInstance().GetDB <DBAvatarPart>(); DBAvatarPart.Data data = null; dbAvatar.mData.TryGetValue(modelList[k], out data); if (data != null) { if (data.part == DBAvatarPart.BODY_PART.BODY) { // 替换bodypart modelList[k] = modelList[k] * 100; } } } } else { DBAvatarDefault.Data defaultAvatar = null; if (DBManager.GetInstance().GetDB <DBAvatarDefault>().mData.TryGetValue(vocation, out defaultAvatar)) { modelList.Add(defaultAvatar.bodyId * 100); modelList.Add(defaultAvatar.weaponId); } } return(modelList); }
private static IEnumerator ChangePart(GameObject model, uint partId, bool isLocalPlayer = true) { if (model == null) { yield break; } DBAvatarPart.Data data = DBManager.Instance.GetDB <DBAvatarPart>().mData[partId]; string part_name = data.part == DBAvatarPart.BODY_PART.BODY ? xc.AvatarCtrl.BODY_NAME : xc.AvatarCtrl.WEAPON_NAME; // 查找旧资源中的换装节点 Transform old_part = CommonTool.FindChildInHierarchy(model.transform, part_name); if (old_part == null) { Debug.LogError(string.Format("the model {0} does not have a part named {1}", model.name, part_name)); yield break; } string path = data.SuitablePath(isLocalPlayer); // 加载换装部件的模型 AssetResource ar = new AssetResource(); yield return(ResourceLoader.Instance.StartCoroutine(ResourceLoader.Instance.load_asset(string.Format("{0}/{1}.prefab", xc.AvatarCtrl.AVATAR_PATH_PREFIX, path), typeof(GameObject), ar))); GameObject gameObjectAsset = ar.asset_ as GameObject; if (gameObjectAsset == null) { Debug.LogError(string.Format("the res {0} does not exist", path)); yield break; } if (model == null) { ar.destroy(); yield break; } old_part = CommonTool.FindChildInHierarchy(model.transform, part_name); if (old_part == null) { Debug.LogError(string.Format("the model {0} does not have a part named {1}", model.name, part_name)); ar.destroy(); yield break; } // 将asset资源的生命周期与角色GameObject关联起来 ResourceUtilEx.Instance.host_res_to_gameobj(model, ar); // 查找新资源的换装节点 Transform new_part = CommonTool.FindChildInHierarchy(gameObjectAsset.transform, part_name); if (new_part == null) { Debug.LogError(string.Format("the model {0} does not have a part named {1}", gameObjectAsset.name, part_name)); yield break; } SkinnedMeshRenderer new_mesh_renderer = new_part.GetComponent <SkinnedMeshRenderer>(); SkinnedMeshRenderer old_mesh_renderer = old_part.GetComponent <SkinnedMeshRenderer>(); Transform[] old_bones = (Transform[])old_part.GetComponent <SkinnedMeshRenderer>().bones.Clone(); ReplaceSkinnedMesh(old_bones, model, old_mesh_renderer, new_mesh_renderer); }