DefaultBattleFactory.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. using CommonAI.ZoneClient;
  2. using CommonAIClient.Client;
  3. using CommonAIClient.Unity.Battle;
  4. using CommonAIClient.Unity.Utils;
  5. using CommonLang;
  6. using CommonUnity3D.MFUnity.LoadUtil;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using UnityEngine;
  13. namespace CommonAIClient.Unity
  14. {
  15. public class DefaultBattleScene : BattleScene
  16. {
  17. public DefaultBattleScene(AbstractBattle client) : base(client)
  18. {
  19. }
  20. }
  21. public class DefaultBattleFactroy : BattleFactroy
  22. {
  23. public enum LayerSetting
  24. {
  25. UI = 5,
  26. IconGenerator = 9,
  27. ColliderObject = 10, //用于隐藏遮挡玩家的场景物体
  28. STAGE_NAV = 13,
  29. ColliderValkyrie = 16, //女武神整体
  30. ColliderValkyriePart = 17, //女武神身体部位
  31. }
  32. private DefaultGameObjectAdapter mGameObjectAdapter;
  33. private DefaultTerrainAdapter mTerrainAdapater;
  34. private DefaultSoundAdapter mSoundAdapter;
  35. public DefaultBattleFactroy() : base()
  36. {
  37. mGameObjectAdapter = new DefaultGameObjectAdapter(20);
  38. mTerrainAdapater = new DefaultTerrainAdapter();
  39. mSoundAdapter = new DefaultSoundAdapter(8);
  40. }
  41. public override BattleScene CreateBattleScene(AbstractBattle battle)
  42. {
  43. return new DefaultBattleScene(battle);
  44. }
  45. public override GameObjectAdapter GameObjectAdapter
  46. {
  47. get
  48. {
  49. return mGameObjectAdapter;
  50. }
  51. }
  52. public override SoundAdapter SoundAdapter
  53. {
  54. get
  55. {
  56. return mSoundAdapter;
  57. }
  58. }
  59. public override TerrainAdapter TerrainAdapter
  60. {
  61. get
  62. {
  63. return mTerrainAdapater;
  64. }
  65. }
  66. public override int StageNavLay
  67. {
  68. get
  69. {
  70. return (int)LayerSetting.STAGE_NAV;
  71. }
  72. }
  73. public override DisplayCell CreateDisplayCell(GameObject root, string name)
  74. {
  75. return new DisplayCell(root, name);
  76. }
  77. public override ComAICell CreateComAICell(BattleScene battleScene, CommonAI.ZoneClient.ZoneObject obj)
  78. {
  79. if (obj is ZoneActor)
  80. {
  81. return new ComAIActor(battleScene, obj as ZoneActor);
  82. }
  83. else if (obj is ZoneUnit)
  84. {
  85. return new ComAIUnit(battleScene, obj as ZoneUnit);
  86. }
  87. else if (obj is ZoneItem)
  88. {
  89. return new ComAIItem(battleScene, obj as ZoneItem);
  90. }
  91. else if (obj is ZoneSpell)
  92. {
  93. return new ComAISpell(battleScene, obj as ZoneSpell);
  94. }
  95. return null;
  96. }
  97. public override void OnError(string msg)
  98. {
  99. }
  100. public override void MakeDamplingJoint(GameObject body, GameObject from, GameObject to)
  101. {
  102. //DampingJoint dj = body.transform.GetComponentInChildren<DampingJoint>();
  103. //if (dj != null)
  104. //{
  105. // dj.Hook(from.transform, to.transform);
  106. //}
  107. }
  108. }
  109. public class DefaultGameObjectAdapter : GameObjectAdapter
  110. {
  111. private LRUCache<string, AssetObjectExt> gCache;
  112. private GameObject mCacheNode;
  113. public DefaultGameObjectAdapter(int cacheCount) : base()
  114. {
  115. gCache = new LRUCache<string, AssetObjectExt>(cacheCount, OnCacheRemoveObject);
  116. }
  117. private GameObject CacheNode
  118. {
  119. get
  120. {
  121. if (mCacheNode == null)
  122. {
  123. mCacheNode = new GameObject("GameObjectLoaderCache");
  124. mCacheNode.SetActive(false);
  125. }
  126. return mCacheNode;
  127. }
  128. }
  129. public override void Load(string assetBundleName, string assetName
  130. , Action<bool, AssetObjectExt> callback
  131. , bool bASyncLoadAB = true, bool bASyncLoadAsset = true)
  132. {
  133. if (callback == null)
  134. {
  135. Debug.LogError("callback == null");
  136. return;
  137. }
  138. if (string.IsNullOrEmpty(assetBundleName) || string.IsNullOrEmpty(assetName))
  139. {
  140. Debug.LogError("string.IsNullOrEmpty(assetBundleName) || string.IsNullOrEmpty(assetName)");
  141. callback(false, null);
  142. return;
  143. }
  144. if (gCache.ContainsKey(assetName.ToLower()))
  145. {
  146. AssetObjectExt tmp = gCache.Get(assetName.ToLower());
  147. tmp.transform.parent = null;
  148. tmp.transform.position = Vector3.zero;
  149. tmp.transform.rotation = Quaternion.identity;
  150. tmp.transform.localScale = Vector3.one;
  151. tmp.gameObject.SetActive(true);
  152. callback(true, tmp);
  153. }
  154. else
  155. {
  156. AssetLoader loader = new AssetLoader(assetBundleName.ToLower(), assetName.ToLower()
  157. , (succ_, res_, mfab_) =>
  158. {
  159. if (callback == null)
  160. return;
  161. if (!succ_)
  162. {
  163. callback(false, null);
  164. return;
  165. }
  166. UnityEngine.Object tmp = GameObject.Instantiate(res_);
  167. if (tmp is GameObject)
  168. {
  169. AssetObjectExt aoe = (tmp as GameObject).AddComponent<AssetObjectExt>();
  170. aoe.name = assetName.ToLower();
  171. aoe.AddRef(assetBundleName.ToLower(), mfab_.Version);
  172. callback(true, aoe);
  173. }
  174. else
  175. {
  176. UnityEngine.Object.DestroyImmediate(tmp, true);
  177. callback(false, null);
  178. }
  179. }, bASyncLoadAB, bASyncLoadAsset);
  180. }
  181. }
  182. public override void Unload(AssetObjectExt aoe)
  183. {
  184. if (aoe != null)
  185. {
  186. var script = aoe.gameObject.GetComponent<EffectAutoDestroy>();
  187. aoe.gameObject.SetActive(false);
  188. aoe.transform.parent = CacheNode.transform;
  189. gCache.Add(aoe.name, aoe);
  190. }
  191. }
  192. public void ClearCache()
  193. {
  194. gCache.Clear();
  195. }
  196. private void OnCacheRemoveObject(AssetObjectExt aoe)
  197. {
  198. if (aoe == null || aoe.gameObject.Equals(null))
  199. {
  200. Debug.LogWarning("remove error: null");
  201. }
  202. else
  203. {
  204. aoe.Destroy();
  205. }
  206. }
  207. }
  208. public class DefaultAudio : Audio
  209. {
  210. public string Name { get; set; }
  211. public AudioSource AudioSource { get; private set; }
  212. private static GameObject mSoundRoot;
  213. private static GameObject SoundRoot
  214. {
  215. get
  216. {
  217. if (mSoundRoot == null)
  218. {
  219. mSoundRoot = new GameObject("SoundRoot");
  220. mSoundRoot.SetActive(false);
  221. }
  222. return mSoundRoot;
  223. }
  224. }
  225. public DefaultAudio() : base()
  226. {
  227. GameObject sound = new GameObject("Sound3D");
  228. this.AudioSource = sound.AddComponent<AudioSource>();
  229. }
  230. public void Play()
  231. {
  232. this.AudioSource.gameObject.name = Name;
  233. this.AudioSource.gameObject.Parent(null);
  234. this.AudioSource.gameObject.SetActive(true);
  235. if (this.AudioSource.clip != null)
  236. {
  237. this.AudioSource.Play();
  238. }
  239. }
  240. public void Stop()
  241. {
  242. this.AudioSource.Stop();
  243. this.AudioSource.clip = null;
  244. this.AudioSource.gameObject.Parent(SoundRoot);
  245. this.AudioSource.gameObject.SetActive(false);
  246. }
  247. }
  248. public class SoundLoader
  249. {
  250. private bool mDisposed;
  251. private string mAssetBundleName;
  252. private AudioClip mAudioClip;
  253. private System.Action<bool, AudioClip> mCallbacks;
  254. private bool mLoadFinished;
  255. public string AssetBundleName { get { return mAssetBundleName; } }
  256. public void Load(System.Action<bool, AudioClip> callback)
  257. {
  258. if (mLoadFinished)
  259. {
  260. callback(mAudioClip != null, mAudioClip);
  261. return;
  262. }
  263. mCallbacks += callback;
  264. }
  265. public void Dispose()
  266. {
  267. if (!mDisposed)
  268. {
  269. mDisposed = true;
  270. if (mAudioClip != null)
  271. {
  272. UnityEngine.Object.DestroyImmediate(mAudioClip, true);
  273. mAudioClip = null;
  274. }
  275. if (mCallbacks != null)
  276. {
  277. mCallbacks(false, null);
  278. mCallbacks = null;
  279. }
  280. }
  281. }
  282. public SoundLoader(string assetBundleName)
  283. {
  284. mAssetBundleName = assetBundleName.ToLower();
  285. AssetLoader loader = new AssetLoader(mAssetBundleName
  286. , System.IO.Path.GetFileNameWithoutExtension(mAssetBundleName)
  287. , (succ_, res_, mfab_) =>
  288. {
  289. OnLoadAssetFinish(succ_, res_, mfab_);
  290. }, true, true);
  291. }
  292. private void OnLoadAssetFinish(bool succ, UnityEngine.Object res, MFUnityAssetBundle mfab)
  293. {
  294. if (succ)
  295. {
  296. mAudioClip = res as AudioClip;
  297. MFUnityAssetBundleManager.GetInstance().UnloadAssetBundleImmediate(mAssetBundleName, false);
  298. }
  299. if (mCallbacks != null)
  300. {
  301. mCallbacks(mAudioClip != null, mAudioClip);
  302. mCallbacks = null;
  303. }
  304. mLoadFinished = true;
  305. }
  306. }
  307. public class DefaultSoundAdapter : SoundAdapter
  308. {
  309. private ObjectPool<DefaultAudio> mAudioPoool = new ObjectPool<DefaultAudio>();
  310. private List<DefaultAudio> mLoopAudios = new List<DefaultAudio>();
  311. private Queue<DefaultAudio> mNormalAudios = new Queue<DefaultAudio>();
  312. private int mMaxNormalAudioNum;
  313. private HashMap<string, SoundLoader> mAudioLoaders = new HashMap<string, SoundLoader>();
  314. private DefaultAudio mBGM;
  315. private SoundLoader mBGMLoader;
  316. public override void Clear()
  317. {
  318. foreach (var elem in mAudioLoaders)
  319. {
  320. elem.Value.Dispose();
  321. }
  322. mAudioLoaders.Clear();
  323. }
  324. private void RemoveLoader(string name)
  325. {
  326. SoundLoader loader = mAudioLoaders.RemoveByKey(name.ToLower());
  327. if (loader != null)
  328. {
  329. loader.Dispose();
  330. }
  331. }
  332. private DefaultAudio GetNormalAudio()
  333. {
  334. DefaultAudio audio = null;
  335. if (mNormalAudios.Count >= mMaxNormalAudioNum)
  336. {
  337. audio = mNormalAudios.Dequeue();
  338. audio.Stop();
  339. mAudioPoool.Release(audio);
  340. }
  341. audio = mAudioPoool.Get();
  342. mNormalAudios.Enqueue(audio);
  343. return audio;
  344. }
  345. public DefaultSoundAdapter(int maxNormalAudioNum) : base()
  346. {
  347. mMaxNormalAudioNum = maxNormalAudioNum;
  348. }
  349. private void LoadBGM(string name, System.Action<bool, AudioClip> callback)
  350. {
  351. if (mBGMLoader != null)
  352. {
  353. if (mBGMLoader.AssetBundleName == name.ToLower())
  354. {
  355. mBGMLoader.Load(callback);
  356. return;
  357. }
  358. mBGMLoader.Dispose();
  359. }
  360. mBGMLoader = new SoundLoader(name);
  361. mBGMLoader.Load(callback);
  362. }
  363. private void LoadAudio(string name, System.Action<bool, AudioClip> callback)
  364. {
  365. SoundLoader loader = null;
  366. if (mAudioLoaders.TryGetValue(name.ToLower(), out loader))
  367. {
  368. if (callback != null)
  369. {
  370. loader.Load(callback);
  371. }
  372. return;
  373. }
  374. loader = new SoundLoader(name);
  375. loader.Load(callback);
  376. mAudioLoaders.Add(name.ToLower(), loader);
  377. }
  378. public override void PlayBGM(string name)
  379. {
  380. if (!string.IsNullOrEmpty(name))
  381. {
  382. LoadBGM(name, (succ_, res_) =>
  383. {
  384. if (succ_)
  385. {
  386. if (mBGM == null)
  387. {
  388. mBGM = mAudioPoool.Get();
  389. GameObject.DontDestroyOnLoad(mBGM.AudioSource.gameObject);
  390. }
  391. mBGM.Stop();
  392. RemoveLoader(mBGM.Name);
  393. mBGM.Name = name;
  394. mBGM.AudioSource.clip = res_;
  395. mBGM.AudioSource.loop = true;
  396. mBGM.AudioSource.volume = 1f;
  397. mBGM.AudioSource.spatialBlend = 0f;
  398. mBGM.Play();
  399. }
  400. });
  401. }
  402. }
  403. public override void PlaySound(string name, Vector3 pos, float distance = 20f)
  404. {
  405. LoadAudio(name, (succ_, res_) =>
  406. {
  407. if (succ_)
  408. {
  409. DefaultAudio audio = GetNormalAudio();
  410. audio.Name = name;
  411. audio.AudioSource.gameObject.Position(pos);
  412. audio.AudioSource.clip = res_;
  413. audio.AudioSource.loop = false;
  414. audio.AudioSource.volume = 1f;
  415. audio.AudioSource.spatialBlend = 0.9f;
  416. audio.AudioSource.maxDistance = distance;
  417. AudioAutoStop script = audio.AudioSource.gameObject.GetComponent<AudioAutoStop>();
  418. if (script == null)
  419. {
  420. script = audio.AudioSource.gameObject.AddComponent<AudioAutoStop>();
  421. }
  422. script.Auido = audio;
  423. script.Duration = audio.AudioSource.clip.length;
  424. script.TraceTarget = null;
  425. audio.Play();
  426. }
  427. });
  428. }
  429. public override void PlaySound(string name, int timeMS, Vector3 pos, float distance = 20f)
  430. {
  431. LoadAudio(name, (succ_, res_) =>
  432. {
  433. if (succ_)
  434. {
  435. DefaultAudio audio = GetNormalAudio();
  436. audio.Name = name;
  437. audio.AudioSource.gameObject.Position(pos);
  438. audio.AudioSource.clip = res_ as AudioClip;
  439. audio.AudioSource.loop = true;
  440. audio.AudioSource.volume = 1f;
  441. audio.AudioSource.spatialBlend = 0.9f;
  442. audio.AudioSource.maxDistance = distance;
  443. AudioAutoStop script = audio.AudioSource.gameObject.GetComponent<AudioAutoStop>();
  444. if (script == null)
  445. {
  446. script = audio.AudioSource.gameObject.AddComponent<AudioAutoStop>();
  447. }
  448. script.Auido = audio;
  449. script.Duration = timeMS / 1000f;
  450. script.TraceTarget = null;
  451. audio.Play();
  452. }
  453. });
  454. }
  455. public override Audio PlaySoundLoop(string name, Vector3 pos, float distance = 20f)
  456. {
  457. DefaultAudio audio = mAudioPoool.Get();
  458. LoadAudio(name, (succ_, res_) =>
  459. {
  460. int index = mLoopAudios.IndexOf(audio);
  461. if (index == -1)
  462. {
  463. return;
  464. }
  465. if (succ_)
  466. {
  467. audio.Name = name;
  468. audio.AudioSource.gameObject.Position(pos);
  469. audio.AudioSource.clip = res_ as AudioClip;
  470. audio.AudioSource.loop = true;
  471. audio.AudioSource.volume = 1f;
  472. audio.AudioSource.spatialBlend = 0.9f;
  473. audio.AudioSource.maxDistance = distance;
  474. AudioAutoStop script = audio.AudioSource.gameObject.GetComponent<AudioAutoStop>();
  475. if (script != null)
  476. {
  477. GameObject.Destroy(script);
  478. }
  479. audio.Play();
  480. }
  481. });
  482. return audio;
  483. }
  484. public override void PlaySound(string name, GameObject obj, float distance = 20f)
  485. {
  486. LoadAudio(name, (succ_, res_) =>
  487. {
  488. if (succ_)
  489. {
  490. DefaultAudio audio = GetNormalAudio();
  491. audio.Name = name;
  492. audio.AudioSource.gameObject.Position(obj.Position());
  493. audio.AudioSource.clip = res_ as AudioClip;
  494. audio.AudioSource.loop = false;
  495. audio.AudioSource.volume = 1f;
  496. audio.AudioSource.spatialBlend = 0.9f;
  497. audio.AudioSource.maxDistance = distance;
  498. AudioAutoStop script = audio.AudioSource.gameObject.GetComponent<AudioAutoStop>();
  499. if (script == null)
  500. {
  501. script = audio.AudioSource.gameObject.AddComponent<AudioAutoStop>();
  502. }
  503. script.Auido = audio;
  504. script.Duration = audio.AudioSource.clip.length;
  505. script.TraceTarget = obj;
  506. audio.Play();
  507. }
  508. });
  509. }
  510. public override void PlaySound(string name, int timeMS, GameObject obj, float distance = 20f)
  511. {
  512. LoadAudio(name, (succ_, res_) =>
  513. {
  514. if (succ_)
  515. {
  516. DefaultAudio audio = GetNormalAudio();
  517. audio.Name = name;
  518. audio.AudioSource.gameObject.Position(obj.Position());
  519. audio.AudioSource.clip = res_ as AudioClip;
  520. audio.AudioSource.loop = true;
  521. audio.AudioSource.volume = 1f;
  522. audio.AudioSource.spatialBlend = 0.9f;
  523. audio.AudioSource.maxDistance = distance;
  524. AudioAutoStop script = audio.AudioSource.gameObject.GetComponent<AudioAutoStop>();
  525. if (script == null)
  526. {
  527. script = audio.AudioSource.gameObject.AddComponent<AudioAutoStop>();
  528. }
  529. script.Auido = audio;
  530. script.Duration = timeMS / 1000f;
  531. script.TraceTarget = obj;
  532. audio.Play();
  533. }
  534. });
  535. }
  536. public override Audio PlaySoundLoop(string name, GameObject obj, float distance = 20f)
  537. {
  538. DefaultAudio audio = GetNormalAudio();
  539. LoadAudio(name, (succ_, res_) =>
  540. {
  541. int index = mLoopAudios.IndexOf(audio);
  542. if (index == -1)
  543. {
  544. return;
  545. }
  546. if (succ_)
  547. {
  548. audio.Name = name;
  549. audio.AudioSource.gameObject.Position(obj.Position());
  550. audio.AudioSource.clip = res_ as AudioClip;
  551. audio.AudioSource.loop = true;
  552. audio.AudioSource.volume = 1f;
  553. audio.AudioSource.spatialBlend = 0.9f;
  554. audio.AudioSource.maxDistance = distance;
  555. AudioAutoStop script = audio.AudioSource.gameObject.GetComponent<AudioAutoStop>();
  556. if (script != null)
  557. {
  558. GameObject.Destroy(script);
  559. }
  560. audio.Play();
  561. }
  562. });
  563. return audio;
  564. }
  565. public override void StopSoundLoop(Audio sound)
  566. {
  567. DefaultAudio audio = sound as DefaultAudio;
  568. if (audio != null)
  569. {
  570. int index = mLoopAudios.IndexOf(sound as DefaultAudio);
  571. if (index != -1)
  572. {
  573. mLoopAudios.Remove(audio);
  574. }
  575. audio.Stop();
  576. mAudioPoool.Release(audio);
  577. }
  578. }
  579. }
  580. public class DefaultTerrainAdapter : TerrainAdapter
  581. {
  582. private string mAssetBundleName;
  583. private string mAsssetName;
  584. private AssetLoader mAssetLoader;
  585. private System.Action<bool, GameObject> mCallback;
  586. private GameObject mMapRoot;
  587. public override void Load(string assetBundleName, System.Action<bool, GameObject> callback)
  588. {
  589. if (!string.IsNullOrEmpty(assetBundleName) && callback != null)
  590. {
  591. mMapRoot = new GameObject("MapNode");
  592. mAssetBundleName = assetBundleName;
  593. mAsssetName = Path.GetFileNameWithoutExtension(mAssetBundleName);
  594. mCallback = callback;
  595. mAssetLoader = new AssetLoader(mAssetBundleName, mAsssetName, OnLoadFinish, false, false);
  596. }
  597. }
  598. protected virtual void OnLoadFinish(bool succ, UnityEngine.Object res, MFUnityAssetBundle ab)
  599. {
  600. if (ab == null)
  601. {
  602. mCallback(false, null);
  603. return;
  604. }
  605. GameObject map = GameObject.Instantiate(res) as GameObject;
  606. map.transform.parent = mMapRoot.transform;
  607. LoadLightmap(ab);
  608. LoadNav(ab);
  609. Transform statics = mMapRoot.transform.Find("static");
  610. if (statics != null)
  611. {
  612. StaticBatchingUtility.Combine(statics.gameObject);
  613. }
  614. // fog settings
  615. InitFogParam(mMapRoot);
  616. // camera effect?
  617. GameObject objA = GameObject.Find("filter_a");
  618. GameObject objB = GameObject.Find("filter_b");
  619. if (objA != null && objB != null)
  620. {
  621. objA.transform.parent = Camera.main.gameObject.transform;
  622. objB.transform.parent = Camera.main.gameObject.transform;
  623. //position
  624. objA.transform.localPosition = new Vector3(0, 0, 0.24f);
  625. objB.transform.localPosition = new Vector3(0, 0, 0.24f);
  626. //rotation
  627. objA.transform.localRotation = Quaternion.Euler(270, 0, 0);
  628. objB.transform.localRotation = Quaternion.Euler(270, 0, 0);
  629. //scale
  630. float scaleW = 0.04f;
  631. float scaleH = 0.0225f;
  632. objA.transform.localScale = new Vector3(scaleW, 1, scaleH);
  633. objB.transform.localScale = new Vector3(scaleW, 1, scaleH);
  634. }
  635. mAssetLoader.ForeachDepFile((file) =>
  636. {
  637. if (file.IndexOf("shaderslist") == -1)
  638. {
  639. MFUnityAssetBundleManager.GetInstance().UnloadAssetBundleImmediate(file, false, true);
  640. }
  641. });
  642. MFUnityAssetBundleManager.GetInstance().UnloadAssetBundleImmediate(mAssetBundleName, false, true);
  643. mCallback(true, mMapRoot);
  644. }
  645. protected virtual bool InitFogParam(GameObject mMapRoot)
  646. {
  647. // FogAmbientColorSetting fs = mMapRoot.GetComponent<FogAmbientColorSetting>();
  648. // if (null != fs && fs.fog)
  649. // {
  650. // RenderSettings.fog = true;
  651. // RenderSettings.fogColor = fs.fogColor;
  652. // RenderSettings.fogDensity = fs.fogDensity;
  653. // RenderSettings.fogMode = fs.fogMode;
  654. // }
  655. // else
  656. // {
  657. // RenderSettings.fog = false;
  658. // }
  659. return false;
  660. }
  661. private void LoadLightmap(MFUnityAssetBundle ab)
  662. {
  663. List<UnityEngine.Object> lms = new List<UnityEngine.Object>();
  664. int count = 0;
  665. UnityEngine.Object lightMapObj;
  666. do
  667. {
  668. string reslight = "Lightmap-" + count + "_comp_light";
  669. lightMapObj = ab.AssetBundle.LoadAsset(reslight);
  670. if (lightMapObj != null)
  671. {
  672. lms.Add(lightMapObj);
  673. ++count;
  674. }
  675. else
  676. {
  677. break;
  678. }
  679. }
  680. while (true);
  681. if (lms.Count > 0)
  682. {
  683. LightmapSettings.lightmapsMode = LightmapsMode.NonDirectional;
  684. UnityEngine.LightmapData[] lmDataSet = new UnityEngine.LightmapData[lms.Count];
  685. for (int i = 0; i < lms.Count; i++)
  686. {
  687. Texture2D tex = lms[i] as Texture2D;
  688. if (tex != null)
  689. {
  690. UnityEngine.LightmapData lmData = new UnityEngine.LightmapData();
  691. lmData.lightmapFar = (Texture2D)tex;
  692. lmDataSet[i] = lmData;
  693. }
  694. }
  695. LightmapSettings.lightmaps = lmDataSet;
  696. }
  697. InitLightMapParam(mMapRoot);
  698. }
  699. protected virtual bool InitLightMapParam(GameObject mMapRoot)
  700. {
  701. // LightmapParam[] lmd = mMapRoot.GetComponentsInChildren<LightmapParam>(true);
  702. // for (int i = 0; i < lmd.Length; i++)
  703. // {
  704. // Renderer r = lmd[i].gameObject.GetComponent<Renderer>();
  705. // r.gameObject.isStatic = true;
  706. // r.lightmapIndex = lmd[i].lightmapIndex;
  707. // r.lightmapScaleOffset = lmd[i].lightmapScaleOffset;
  708. // }
  709. return false;
  710. }
  711. private void LoadNav(MFUnityAssetBundle ab)
  712. {
  713. string resnav = mAsssetName + "_nav";
  714. UnityEngine.Object navObj = ab.AssetBundle.LoadAsset(resnav);
  715. if (navObj != null)
  716. {
  717. GameObject nav = (GameObject)GameObject.Instantiate(navObj);
  718. nav.layer = BattleFactroy.Instance.StageNavLay;
  719. nav.transform.parent = mMapRoot.transform;
  720. foreach (Transform e in nav.GetComponentInChildren<Transform>())
  721. {
  722. MeshCollider bc = e.gameObject.GetComponent<MeshCollider>();
  723. if (bc == null)
  724. {
  725. bc = e.gameObject.AddComponent<MeshCollider>();
  726. }
  727. bc.gameObject.layer = nav.layer;
  728. }
  729. }
  730. }
  731. }
  732. }