//处理剧情层的资源加载请求 static public void REV_CHARRES_LINKER(GameObject[] linker, PLOT_CHARRES_TYPE res_type, int id, string[] anim_list) { //debug.Log("加载场景剧情模型"); string str_id = id.ToString(); int nanim_count = anim_list.Length; if (0 == nanim_count) { REV_CHARRES_LINKER_GO(linker, res_type, str_id, null, null); return; } Dictionary <string, AnimationClip> anim_loop = new Dictionary <string, AnimationClip>(); //先加载相关的动作,最后加入模型 string strfirst_anim = null; for (int i = 0; i < anim_list.Length; i++) { string curanim = anim_list[i]; if (0 == i) { strfirst_anim = curanim; } string anim_url = "null"; switch (res_type) { case PLOT_CHARRES_TYPE.PCRT_HERO: anim_url = "QSMY/character/hero/" + str_id + "/" + curanim; break; case PLOT_CHARRES_TYPE.PCRT_MONSTER: anim_url = "QSMY/character/monster/" + str_id + "/" + curanim; break; case PLOT_CHARRES_TYPE.PCRT_NPC: anim_url = "QSMY/character/npc/" + str_id + "/" + curanim; break; case PLOT_CHARRES_TYPE.PCRT_MOUNT: anim_url = "QSMY/character/mount/" + str_id + "/" + curanim; break; //case PLOT_CHARRES_TYPE.PCRT_AVATAR: anim_url = "QSMY/character/avatar/" + str_id + "/" + curanim; break; } IAsset sk_anim = os.asset.getAsset <IAssetSkAnimation>(anim_url, (IAsset ast) => { nanim_count--; anim_loop[curanim] = (ast as AssetSkAnimationImpl).anim; Debug.Log(nanim_count + "成功加载了动作 " + anim_url); if (0 == nanim_count) { REV_CHARRES_LINKER_GO(linker, res_type, str_id, anim_loop, strfirst_anim); } }, null, (IAsset ast, string err) => { //加载失败 Debug.Log("加载动作失败 " + anim_url); nanim_count--; }); (sk_anim as AssetImpl).loadImpl(false); } }
static private void REV_CHARRES_LINKER_GO(GameObject[] linker, PLOT_CHARRES_TYPE res_type, string str_id, Dictionary <string, AnimationClip> anim_loop, string first_anim) { string res_url = "null"; switch (res_type) { case PLOT_CHARRES_TYPE.PCRT_HERO: res_url = "QSMY/character/hero/" + str_id + "/" + str_id + ".res"; break; case PLOT_CHARRES_TYPE.PCRT_MONSTER: res_url = "QSMY/character/monster/" + str_id + "/" + str_id + ".res"; break; case PLOT_CHARRES_TYPE.PCRT_NPC: res_url = "QSMY/character/npc/" + str_id + "/" + str_id + ".res"; break; case PLOT_CHARRES_TYPE.PCRT_MOUNT: res_url = "QSMY/character/mount/" + str_id + "/" + str_id + ".res"; break; case PLOT_CHARRES_TYPE.PCRT_AVATAR: res_url = "QSMY/character/avatar/" + str_id + ".res"; break; } IAsset res_mesh = os.asset.getAsset <IAssetMesh>(res_url, (IAsset ast) => { for (int i = 0; i < linker.Length; i++) { GameObject one_link = linker[i]; if (one_link == null) { continue; } GameObject res_obj = (ast as AssetMeshImpl).assetObj; GameObject the_obj = GameObject.Instantiate(res_obj) as GameObject; the_obj.transform.SetParent(one_link.transform, false); //SkAniMeshBehaviour behaviour = the_obj.AddComponent<SkAniMeshBehaviour>(); //behaviour.obj = ast as SkAniMeshImpl; //the_obj.AddComponent<Plot_SkAniBehaviour>(); Animation animation = the_obj.GetComponent <Animation>(); if (animation == null) { animation = the_obj.AddComponent <Animation>(); } if (animation != null && anim_loop != null) { foreach (string key in anim_loop.Keys) { //anim_loop[key].wrapMode = WrapMode.Loop; animation.AddClip(anim_loop[key], key); } //animation[first_anim].speed = 1.0f; animation.Play(first_anim); animation.wrapMode = WrapMode.Loop; } } }, null, (IAsset ast, string err) => { //加载失败 debug.Log("加载剧情Res失败" + res_url); }); (res_mesh as AssetImpl).loadImpl(false); }