DragonBonesBGControler.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. using UnityEngine.EventSystems;
  6. /// <summary>
  7. /// 龙骨英雄动画管理
  8. /// </summary>
  9. public class DragonBonesBGControler : MonoBehaviour
  10. {
  11. /// <summary>
  12. /// 单键
  13. /// </summary>
  14. private static DragonBonesBGControler pInit = null;
  15. /// <summary>
  16. /// 人物节点
  17. /// </summary>
  18. private GameObject mHeroModelRoot = null;
  19. /// <summary>
  20. /// 人物 控制节点
  21. /// </summary>
  22. public InputTouchContorler mInputTouchContorler = null;
  23. /// <summary>
  24. /// 相机映射图片
  25. /// </summary>
  26. private RenderTexture renderTexture;
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. private Camera mHeroModelCamera;
  31. /// <summary>
  32. /// 相机动态render图片(人物角色)
  33. /// </summary>
  34. public RenderTexture CameraRenderTexture
  35. {
  36. get { return renderTexture; }
  37. }
  38. ///// <summary>
  39. ///// 人物节点
  40. ///// </summary>
  41. //private GameObject mShopWindow_HeroModelRoot = null;
  42. ///// <summary>
  43. ///// 商店界面的 相机映射图片
  44. ///// </summary>
  45. //private RenderTexture shopWindow_renderTexture;
  46. ///// <summary>
  47. ///// 商店界面的 动态人物角色
  48. ///// </summary>
  49. //public RenderTexture mShopWindow_HeroRenderTexture
  50. //{
  51. // get { return shopWindow_renderTexture; }
  52. //}
  53. //---------------------抽奖 start---------------------------
  54. private GameObject mLuckDrawRoot = null;
  55. /// <summary>
  56. /// 抽奖人物节点
  57. /// </summary>
  58. private GameObject mLuckDrawWindow_HeroModelRoot = null;
  59. /// <summary>
  60. /// 抽奖界面的 相机映射图片
  61. /// </summary>
  62. private RenderTexture LuckDrawWindow_renderTexture;
  63. /// <summary>
  64. /// 抽奖界面的 动态人物角色
  65. /// </summary>
  66. public RenderTexture mLuckDrawWindow_HeroRenderTexture
  67. {
  68. get { return LuckDrawWindow_renderTexture; }
  69. }
  70. //---------------------抽奖 end---------------------------
  71. //---------------------对话 start---------------------------
  72. private GameObject mDialogRoot = null;
  73. /// <summary>
  74. /// 对话人物节点
  75. /// </summary>
  76. private GameObject mDialogWindow_HeroModelRoot = null;
  77. /// <summary>
  78. /// 对话界面的 相机映射图片
  79. /// </summary>
  80. private RenderTexture DialogWindow_renderTexture;
  81. /// <summary>
  82. /// 对话界面的 动态人物角色
  83. /// </summary>
  84. public RenderTexture mDialogWindow_HeroRenderTexture
  85. {
  86. get { return DialogWindow_renderTexture; }
  87. }
  88. //---------------------对话 end---------------------------
  89. //---------------------引导 start---------------------------
  90. private GameObject mGuideRoot = null;
  91. /// <summary>
  92. /// 引导人物节点
  93. /// </summary>
  94. private GameObject mGuideWindow_HeroModelRoot = null;
  95. /// <summary>
  96. /// 引导界面的 相机映射图片
  97. /// </summary>
  98. private RenderTexture GuideWindow_renderTexture;
  99. /// <summary>
  100. /// 引导界面的 动态人物角色
  101. /// </summary>
  102. public RenderTexture mGuideWindow_HeroRenderTexture
  103. {
  104. get { return GuideWindow_renderTexture; }
  105. }
  106. //---------------------引导 end---------------------------
  107. /// <summary>
  108. /// 游戏内 展示的英雄模型列表
  109. /// </summary>
  110. public Dictionary<string, GameObject> existMainDisplayHeroModelDic = new Dictionary<string, GameObject>();
  111. /// <summary>
  112. /// 获取管理者
  113. /// </summary>
  114. /// <returns>单键实例</returns>
  115. public static DragonBonesBGControler Instance()
  116. {
  117. if (pInit == null)
  118. {
  119. GameObject obj = GameObject.Find("ForeverUI/DragonBonesBG");
  120. pInit = obj.AddComponent<DragonBonesBGControler>();
  121. }
  122. return pInit;
  123. }
  124. /// <summary>
  125. /// start
  126. /// </summary>
  127. private void Awake()
  128. {
  129. //renderTexure赋值
  130. mHeroModelCamera = this.transform.Find("Camera").GetComponent<Camera>();
  131. if (mHeroModelCamera.GetComponent<AudioListener>() != null)
  132. {
  133. Destroy(mHeroModelCamera.GetComponent<AudioListener>());
  134. }
  135. renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
  136. mHeroModelRoot = this.transform.Find("Model").gameObject;
  137. mHeroModelCamera.targetTexture = renderTexture;
  138. mInputTouchContorler = mHeroModelRoot.GetComponent<InputTouchContorler>();
  139. if (mInputTouchContorler == null)
  140. {
  141. AssemblyHelper.Instance.BindScript("InputTouchContorler", mHeroModelRoot);
  142. mInputTouchContorler = mHeroModelRoot.GetComponent<InputTouchContorler>();
  143. }
  144. //shopWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
  145. //Camera shopWindowCamera = this.transform.Find("ShopDragonBones/Camera").GetComponent<Camera>();
  146. //shopWindowCamera.targetTexture = shopWindow_renderTexture;
  147. //mShopWindow_HeroModelRoot = this.transform.Find("ShopDragonBones/Model").gameObject;
  148. mLuckDrawRoot = this.transform.Find("LuckDrawDragonBones").gameObject;
  149. LuckDrawWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
  150. Camera LuckDrawWindowCamera = this.transform.Find("LuckDrawDragonBones/Camera").GetComponent<Camera>();
  151. LuckDrawWindowCamera.targetTexture = LuckDrawWindow_renderTexture;
  152. mLuckDrawWindow_HeroModelRoot = this.transform.Find("LuckDrawDragonBones/Model").gameObject;
  153. mLuckDrawRoot.SetActive(false);
  154. mDialogRoot = this.transform.Find("DialogDragonBones").gameObject;
  155. DialogWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
  156. Camera DialogWindowCamera = this.transform.Find("DialogDragonBones/Camera").GetComponent<Camera>();
  157. DialogWindowCamera.targetTexture = DialogWindow_renderTexture;
  158. mDialogWindow_HeroModelRoot = this.transform.Find("DialogDragonBones/Model").gameObject;
  159. mDialogRoot.SetActive(false);
  160. mGuideRoot = this.transform.Find("GuideDragonBones").gameObject;
  161. GuideWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
  162. Camera GuideWindowCamera = this.transform.Find("GuideDragonBones/Camera").GetComponent<Camera>();
  163. GuideWindowCamera.targetTexture = GuideWindow_renderTexture;
  164. mGuideWindow_HeroModelRoot = this.transform.Find("GuideDragonBones/Model").gameObject;
  165. mGuideRoot.SetActive(false);
  166. }
  167. /// <summary>
  168. ///
  169. /// </summary>
  170. public void Clear()
  171. {
  172. Transform[] allChild = mHeroModelRoot.GetComponentsInChildren<Transform>(true);
  173. foreach (Transform ele in allChild)
  174. {
  175. if (ele != mHeroModelRoot.transform)
  176. {
  177. Destroy(ele.gameObject);
  178. }
  179. }
  180. existMainDisplayHeroModelDic.Clear();
  181. }
  182. public string CurrentShowHeroModel { get; set; }
  183. /// <summary>
  184. /// 显示某哦英雄
  185. /// </summary>
  186. /// <param name="heromodel">模型ID</param>
  187. /// <param name="callBack">回调</param>
  188. public void ShowHeroModel(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
  189. {
  190. if (existMainDisplayHeroModelDic.ContainsKey(heromodel))
  191. {
  192. GameObject ani = existMainDisplayHeroModelDic[heromodel];
  193. DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  194. if (armatureComponent != null)
  195. {
  196. if (armatureComponent.name != CurrentShowHeroModel)
  197. {
  198. armatureComponent.gameObject.SetActive(false);
  199. armatureComponent.enabled = false;
  200. }
  201. else
  202. {
  203. if (callBack != null)
  204. {
  205. callBack(armatureComponent);
  206. }
  207. }
  208. }
  209. }
  210. else
  211. {
  212. # region 加载方式二:独立factory
  213. //DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
  214. // {
  215. // DragonBones.UnityFactory temp = new DragonBones.UnityFactory();
  216. // temp.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
  217. // temp.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
  218. // //temp.LoadDragonBonesData(model.mSkeletonJson, heromodel);
  219. // //temp.LoadTextureAtlasData(model.mTextureJson, textureAtlas, heromodel);
  220. // var armatureComponent = temp.BuildArmatureComponent(heromodel, heromodel);
  221. // ////以后这个y去读取数据库的表~~
  222. // ////LogHelper.LogError("MainShowPositionOffset::" + y);
  223. // ////armatureComponent.armature.GetBone(heromodel).offset.y = y*-1;
  224. // ////armatureComponent.armature.InvalidUpdate(heromodel);
  225. // ////armatureComponent.gameObject.name = heromodel;
  226. // armatureComponent.transform.SetParent(mModel.transform);
  227. // armatureComponent.transform.localPosition = Vector3.zero + new Vector3(posOffset.x, posOffset.y, 0);
  228. // armatureComponent.transform.localScale = new Vector3(1, 1, 1);
  229. // UnityEngine.Transform[] all = armatureComponent.GetComponentsInChildren<UnityEngine.Transform>(true);
  230. // foreach (UnityEngine.Transform rc in all)
  231. // {
  232. // rc.gameObject.layer = LayerMask.NameToLayer("DragonBonesLayer"); //指定Layer
  233. // }
  234. // if (!existModelDic.ContainsKey(heromodel))
  235. // {
  236. // existModelDic.Add(heromodel, armatureComponent.gameObject);
  237. // }
  238. // else
  239. // {
  240. // existModelDic[heromodel] = armatureComponent.gameObject;
  241. // }
  242. // if (callBack != null)
  243. // {
  244. // callBack(armatureComponent);
  245. // }
  246. // });
  247. #endregion
  248. #region 加载方式一: 统一factory 会出现一个问题~~
  249. DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
  250. {
  251. DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
  252. DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
  253. var armatureComponent = CreateDragonModel(heromodel, "DragonBonesLayer");
  254. SetDragonModelNode(armatureComponent, mHeroModelRoot.transform, posOffset);
  255. if (!existMainDisplayHeroModelDic.ContainsKey(heromodel))
  256. {
  257. existMainDisplayHeroModelDic.Add(heromodel, armatureComponent.gameObject);
  258. }
  259. else
  260. {
  261. existMainDisplayHeroModelDic[heromodel] = armatureComponent.gameObject;
  262. }
  263. if (armatureComponent.name != CurrentShowHeroModel)
  264. {
  265. armatureComponent.gameObject.SetActive(false);
  266. armatureComponent.enabled = false;
  267. }
  268. else
  269. {
  270. if (callBack != null)
  271. {
  272. callBack(armatureComponent);
  273. }
  274. }
  275. });
  276. #endregion
  277. }
  278. }
  279. /// <summary>
  280. /// 设置人物模型展示的时候的偏移
  281. /// </summary>
  282. /// <param name="arm"></param>
  283. /// <param name="posOffset"></param>
  284. private void SetDragonModelNode(DragonBones.UnityArmatureComponent arm, Transform parentRoot, Vector2 posOffset)
  285. {
  286. arm.transform.SetParent(parentRoot);
  287. //// Change armatureposition.
  288. arm.transform.localPosition = Vector3.zero + new Vector3(posOffset.x, posOffset.y, 0);
  289. arm.transform.localScale = new Vector3(2, 2, 2); // Vector3.one;
  290. }
  291. /// <summary>
  292. /// 创建一个真实的龙骨动画在scene中
  293. /// </summary>
  294. /// <param name="heroModel"></param>
  295. /// <returns></returns>
  296. public DragonBones.UnityArmatureComponent CreateDragonModel(string heromodel, string layerName)
  297. {
  298. if (DragonBones.UnityFactory.factory.GetDragonBonesData(heromodel) == null)
  299. {
  300. return null;
  301. }
  302. if (DragonBones.UnityFactory.factory.GetTextureAtlasData(heromodel) == null)
  303. {
  304. return null;
  305. }
  306. var armatureComponent = DragonBones.UnityFactory.factory.BuildArmatureComponent(heromodel, heromodel);
  307. armatureComponent.gameObject.SetActive(false);
  308. armatureComponent.enabled = false;
  309. armatureComponent.gameObject.name = heromodel;
  310. armatureComponent.transform.localScale = new Vector3(2, 2, 2);
  311. UnityEngine.Transform[] all = armatureComponent.GetComponentsInChildren<UnityEngine.Transform>(true);
  312. foreach (UnityEngine.Transform rc in all)
  313. {
  314. rc.gameObject.layer = LayerMask.NameToLayer(layerName); //指定Layer
  315. }
  316. //////////////////记录 记录 记录//////////////////////////
  317. if (DragonBonesManager.Instance.loadDBDataRecord.ContainsKey(heromodel))
  318. {
  319. UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[heromodel];
  320. id2.createGameObjectList.Add(armatureComponent.gameObject);
  321. id2.lastUseDbDataTs = DateTime.Now.ToUnixTimeStamp();
  322. id2.useDbDataCount += 1;
  323. }
  324. return armatureComponent;
  325. }
  326. /// <summary>
  327. ///【 检查函数】 判断某个模型的龙骨数据是否已经加载进去了。
  328. /// </summary>
  329. /// <param name="model"></param>
  330. /// <returns></returns>
  331. public bool CheckFactoryIsExistSomeModelData(string model)
  332. {
  333. if (DragonBones.UnityFactory.factory.GetDragonBonesData(model) == null)
  334. {
  335. return false;
  336. }
  337. if (DragonBones.UnityFactory.factory.GetTextureAtlasData(model) == null)
  338. {
  339. return false;
  340. }
  341. return true;
  342. }
  343. /// <summary>
  344. ///
  345. /// </summary>
  346. /// <param name="model"></param>
  347. public void AddDragonBoneDataUse(string model)
  348. {
  349. if (DragonBonesManager.Instance.loadDBDataRecord.ContainsKey(model))
  350. {
  351. UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[model];
  352. id2.lastUseDbDataTs = DateTime.Now.ToUnixTimeStamp();
  353. }
  354. }
  355. /// <summary>
  356. /// 关闭某个英雄的模型
  357. /// </summary>
  358. /// <param name="heromodel">模型ID</param>
  359. public void SetHeroModelEnabled(string heromodel)
  360. {
  361. if (existMainDisplayHeroModelDic.ContainsKey(heromodel))
  362. {
  363. GameObject ani = existMainDisplayHeroModelDic[heromodel];
  364. if (ani == null)
  365. return;
  366. DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  367. if (armatureComponent != null)
  368. {
  369. armatureComponent.RemoveAllEventListener();
  370. }
  371. armatureComponent.enabled = false;
  372. ani.SetActive(false);
  373. }
  374. }
  375. /// <summary>
  376. /// 关闭所有 展示的英雄的模型
  377. /// </summary>
  378. public void SetAllDisplayHeroEnabled()
  379. {
  380. foreach (string heromodel in existMainDisplayHeroModelDic.Keys)
  381. {
  382. SetHeroModelEnabled(heromodel);
  383. }
  384. ResetCamera();
  385. }
  386. /// <summary>
  387. /// 根据英雄的龙骨数据,查找scne场景中已经创建对应的对象
  388. /// </summary>
  389. /// <param name="heromodel"></param>
  390. /// <returns></returns>
  391. public DragonBones.UnityArmatureComponent QuerySomeHeroArmature(string heromodel)
  392. {
  393. if (existMainDisplayHeroModelDic.ContainsKey(heromodel))
  394. {
  395. GameObject ani = existMainDisplayHeroModelDic[heromodel];
  396. DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  397. if (armatureComponent != null)
  398. {
  399. return armatureComponent;
  400. }
  401. return null;
  402. }
  403. return null;
  404. }
  405. /// <summary>
  406. /// 查找当前激活的展示龙骨模型
  407. /// </summary>
  408. /// <returns></returns>
  409. public string GetActiveHeroModel()
  410. {
  411. string result = string.Empty;
  412. foreach (string heromodel in existMainDisplayHeroModelDic.Keys)
  413. {
  414. GameObject ani = existMainDisplayHeroModelDic[heromodel];
  415. if (ani.activeSelf)
  416. {
  417. result += heromodel + ";";
  418. }
  419. }
  420. return result;
  421. }
  422. /// <summary>
  423. /// 默认相机的正交大小
  424. /// </summary>
  425. private const float CurCameraSize = 13.0f;
  426. /// <summary>
  427. /// 模型缩放
  428. /// </summary>
  429. internal void OnChangeCameraSize(float cameraSize)
  430. {
  431. mHeroModelCamera.GetComponent<Camera>().orthographicSize = cameraSize;
  432. }
  433. /// <summary>
  434. /// 模型被拖动
  435. /// </summary>
  436. internal void OnChangeModelPosition(Vector2 delta)
  437. {
  438. Vector2 temp = new Vector2(12 * (delta.x / 1080), 16 * (delta.y / 1920));
  439. float x = 0, y = 0;
  440. RectTransform tempRect = mHeroModelRoot.GetComponent<RectTransform>();
  441. Vector2 tempPos = tempRect.anchoredPosition + temp;
  442. x = tempPos.x;
  443. y = tempPos.y;
  444. if (tempPos.x > 12)
  445. {
  446. x = 12;
  447. }
  448. if (tempPos.x < -12)
  449. {
  450. x = -12;
  451. }
  452. if (tempPos.y > 16)
  453. {
  454. y = 12;
  455. }
  456. if (tempPos.y < -16)
  457. {
  458. y = -12;
  459. }
  460. Vector2 destPos = new Vector2(x, y);
  461. ////LogHelper.LogError("affffffffff::"+ destPos.ToString());
  462. tempRect.anchoredPosition = destPos;
  463. }
  464. /// <summary>
  465. /// 充值龙骨相机的大小 以及模型的展示位置
  466. /// </summary>
  467. internal void ResetCamera()
  468. {
  469. mHeroModelCamera.orthographicSize = CurCameraSize;
  470. mHeroModelRoot.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
  471. }
  472. ///// <summary>
  473. ///// 打开指定角色在商店的动画
  474. ///// </summary>
  475. //internal void ShowShopDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
  476. //{
  477. // bool checkHasLoad = false;
  478. // if (mShopWindow_HeroModelRoot.transform.childCount > 0)
  479. // {
  480. // Transform s = mShopWindow_HeroModelRoot.transform.Find(heromodel);
  481. // if (s != null)
  482. // {
  483. // checkHasLoad = true;
  484. // if (callBack != null)
  485. // {
  486. // callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
  487. // }
  488. // return;
  489. // }
  490. // }
  491. // if (!checkHasLoad)
  492. // {
  493. // var armatureComponent = CreateDragonModel(heromodel, "ShopDragon");
  494. // if (armatureComponent == null)
  495. // {
  496. // DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
  497. // {
  498. // DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
  499. // DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
  500. // armatureComponent = CreateDragonModel(heromodel, "ShopDragon");
  501. // SetDragonModelNode(armatureComponent, mShopWindow_HeroModelRoot.transform, posOffset);
  502. // if (callBack != null)
  503. // {
  504. // callBack(armatureComponent);
  505. // }
  506. // });
  507. // }
  508. // else
  509. // {
  510. // SetDragonModelNode(armatureComponent, mShopWindow_HeroModelRoot.transform, posOffset);
  511. // if (callBack != null)
  512. // {
  513. // callBack(armatureComponent);
  514. // }
  515. // }
  516. // }
  517. //}
  518. ///// <summary>
  519. ///// 关闭所有商店动画
  520. ///// </summary>
  521. //internal void CloseAllShopDragonBones()
  522. //{
  523. // if (mShopWindow_HeroModelRoot.transform.childCount > 0)
  524. // {
  525. // for (int i = 0; i < mShopWindow_HeroModelRoot.transform.childCount; i++)
  526. // {
  527. // GameObject ani = mShopWindow_HeroModelRoot.transform.GetChild(i).gameObject;
  528. // DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  529. // if (armatureComponent != null)
  530. // {
  531. // armatureComponent.RemoveAllEventListener();
  532. // }
  533. // armatureComponent.enabled = false;
  534. // ani.SetActive(false);
  535. // }
  536. // }
  537. //}
  538. /// <summary>
  539. /// 打开指定角色在抽奖的动画
  540. /// </summary>
  541. internal void ShowLuckDrawDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
  542. {
  543. if (this.mLuckDrawRoot.activeSelf == false)
  544. {
  545. this.mLuckDrawRoot.SetActive(true);
  546. }
  547. bool checkHasLoad = false;
  548. if (mLuckDrawWindow_HeroModelRoot.transform.childCount > 0)
  549. {
  550. Transform s = mLuckDrawWindow_HeroModelRoot.transform.Find(heromodel);
  551. if (s != null)
  552. {
  553. checkHasLoad = true;
  554. if (callBack != null)
  555. {
  556. callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
  557. }
  558. return;
  559. }
  560. }
  561. if (!checkHasLoad)
  562. {
  563. var armatureComponent = CreateDragonModel(heromodel, "LuckDragon");
  564. if (armatureComponent == null)
  565. {
  566. DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
  567. {
  568. DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
  569. DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
  570. armatureComponent = CreateDragonModel(heromodel, "LuckDragon");
  571. SetDragonModelNode(armatureComponent, mLuckDrawWindow_HeroModelRoot.transform, posOffset);
  572. if (callBack != null)
  573. {
  574. callBack(armatureComponent);
  575. }
  576. });
  577. }
  578. else
  579. {
  580. SetDragonModelNode(armatureComponent, mLuckDrawWindow_HeroModelRoot.transform, posOffset);
  581. if (callBack != null)
  582. {
  583. callBack(armatureComponent);
  584. }
  585. }
  586. }
  587. }
  588. /// <summary>
  589. /// 关闭所有抽奖动画
  590. /// </summary>
  591. internal void CloseAllLuckDrawDragonBones()
  592. {
  593. if (mLuckDrawWindow_HeroModelRoot.transform.childCount > 0)
  594. {
  595. for (int i = 0; i < mLuckDrawWindow_HeroModelRoot.transform.childCount; i++)
  596. {
  597. GameObject ani = mLuckDrawWindow_HeroModelRoot.transform.GetChild(i).gameObject;
  598. DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  599. if (armatureComponent != null)
  600. {
  601. armatureComponent.RemoveAllEventListener();
  602. }
  603. armatureComponent.enabled = false;
  604. ani.SetActive(false);
  605. }
  606. }
  607. }
  608. /// <summary>
  609. ///
  610. /// </summary>
  611. internal void CloseLuckDrawCameraDraw()
  612. {
  613. this.mLuckDrawRoot.SetActive(false);
  614. }
  615. /// <summary>
  616. /// 打开指定角色在对话里的动画
  617. /// </summary>
  618. internal void ShowDialogDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
  619. {
  620. if (this.mDialogRoot.activeSelf == false)
  621. {
  622. this.mDialogRoot.SetActive(true);
  623. }
  624. bool checkHasLoad = false;
  625. if (mDialogWindow_HeroModelRoot.transform.childCount > 0)
  626. {
  627. Transform s = mDialogWindow_HeroModelRoot.transform.Find(heromodel);
  628. if (s != null)
  629. {
  630. checkHasLoad = true;
  631. if (callBack != null)
  632. {
  633. callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
  634. }
  635. return;
  636. }
  637. }
  638. if (!checkHasLoad)
  639. {
  640. var armatureComponent = CreateDragonModel(heromodel, "DialogDragon");
  641. if (armatureComponent == null)
  642. {
  643. DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
  644. {
  645. DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
  646. DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
  647. armatureComponent = CreateDragonModel(heromodel, "DialogDragon");
  648. SetDragonModelNode(armatureComponent, mDialogWindow_HeroModelRoot.transform, posOffset);
  649. if (callBack != null)
  650. {
  651. callBack(armatureComponent);
  652. }
  653. });
  654. }
  655. else
  656. {
  657. SetDragonModelNode(armatureComponent, mDialogWindow_HeroModelRoot.transform, posOffset);
  658. if (callBack != null)
  659. {
  660. callBack(armatureComponent);
  661. }
  662. }
  663. }
  664. }
  665. /// <summary>
  666. /// 关闭所有对话动画
  667. /// </summary>
  668. internal void CloseAllDialogDragonBones()
  669. {
  670. if (mDialogWindow_HeroModelRoot.transform.childCount > 0)
  671. {
  672. for (int i = 0; i < mDialogWindow_HeroModelRoot.transform.childCount; i++)
  673. {
  674. GameObject ani = mDialogWindow_HeroModelRoot.transform.GetChild(i).gameObject;
  675. DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  676. if (armatureComponent != null)
  677. {
  678. armatureComponent.RemoveAllEventListener();
  679. }
  680. armatureComponent.enabled = false;
  681. ani.SetActive(false);
  682. }
  683. }
  684. }
  685. /// <summary>
  686. ///
  687. /// </summary>
  688. internal void CloseDialogCameraDraw()
  689. {
  690. this.mDialogRoot.SetActive(false);
  691. }
  692. /// <summary>
  693. /// 打开指定角色在对话里的动画
  694. /// </summary>
  695. internal void ShowGuideDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
  696. {
  697. if (!this.mGuideRoot.activeSelf)
  698. {
  699. this.mGuideRoot.SetActive(true);
  700. }
  701. bool checkHasLoad = false;
  702. if (mGuideWindow_HeroModelRoot.transform.childCount > 0)
  703. {
  704. Transform s = mGuideWindow_HeroModelRoot.transform.Find(heromodel);
  705. if (s != null)
  706. {
  707. checkHasLoad = true;
  708. if (callBack != null)
  709. {
  710. callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
  711. }
  712. return;
  713. }
  714. }
  715. if (!checkHasLoad)
  716. {
  717. var armatureComponent = CreateDragonModel(heromodel, "GuideDragon");
  718. if (armatureComponent == null)
  719. {
  720. DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
  721. {
  722. DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
  723. DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
  724. armatureComponent = CreateDragonModel(heromodel, "GuideDragon");
  725. if (armatureComponent == null)
  726. {
  727. LogHelper.LogError("出错啦。。。。。。。。。。。。。。" + heromodel);
  728. }
  729. SetDragonModelNode(armatureComponent, mGuideWindow_HeroModelRoot.transform, posOffset);
  730. if (callBack != null)
  731. {
  732. callBack(armatureComponent);
  733. }
  734. });
  735. }
  736. else
  737. {
  738. SetDragonModelNode(armatureComponent, mGuideWindow_HeroModelRoot.transform, posOffset);
  739. if (callBack != null)
  740. {
  741. callBack(armatureComponent);
  742. }
  743. }
  744. }
  745. }
  746. /// <summary>
  747. /// 打开指定角色在战斗中的动画
  748. /// </summary>
  749. internal void ShowBattleDragonBones(string heromodel, Transform targetTran, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
  750. {
  751. var armatureComponent = CreateDragonModel(heromodel, "DragonBonesLayer");
  752. if (armatureComponent == null)
  753. {
  754. DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
  755. {
  756. DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
  757. DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
  758. armatureComponent = CreateDragonModel(heromodel, "GuideDragon");
  759. if (armatureComponent == null)
  760. {
  761. LogHelper.LogError("出错啦。。。。。。。。。。。。。。" + heromodel);
  762. }
  763. SetDragonModelNode(armatureComponent, targetTran, posOffset);
  764. if (callBack != null)
  765. {
  766. callBack(armatureComponent);
  767. }
  768. });
  769. }
  770. else
  771. {
  772. SetDragonModelNode(armatureComponent, targetTran, posOffset);
  773. if (callBack != null)
  774. {
  775. callBack(armatureComponent);
  776. }
  777. }
  778. }
  779. internal void CloseGuideDragonBonesByName(string dname)
  780. {
  781. if (mGuideWindow_HeroModelRoot.transform.childCount > 0)
  782. {
  783. for (int i = 0; i < mGuideWindow_HeroModelRoot.transform.childCount; i++)
  784. {
  785. GameObject ani = mGuideWindow_HeroModelRoot.transform.GetChild(i).gameObject;
  786. if (ani.gameObject.name == dname)
  787. {
  788. DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  789. if (armatureComponent != null)
  790. {
  791. armatureComponent.RemoveAllEventListener();
  792. }
  793. armatureComponent.enabled = false;
  794. ani.SetActive(false);
  795. break;
  796. }
  797. }
  798. }
  799. }
  800. /// <summary>
  801. /// 关闭所有对话动画
  802. /// </summary>
  803. internal void CloseAllGuideDragonBones()
  804. {
  805. if (mGuideWindow_HeroModelRoot.transform.childCount > 0)
  806. {
  807. for (int i = 0; i < mGuideWindow_HeroModelRoot.transform.childCount; i++)
  808. {
  809. GameObject ani = mGuideWindow_HeroModelRoot.transform.GetChild(i).gameObject;
  810. DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
  811. if (armatureComponent != null)
  812. {
  813. armatureComponent.RemoveAllEventListener();
  814. }
  815. armatureComponent.enabled = false;
  816. ani.SetActive(false);
  817. }
  818. }
  819. }
  820. /// <summary>
  821. ///
  822. /// </summary>
  823. internal void CloseGuideCameraDraw()
  824. {
  825. this.mGuideRoot.SetActive(false);
  826. }
  827. /// <summary>
  828. ///
  829. /// </summary>
  830. internal void OpenGuideCameraDraw()
  831. {
  832. this.mGuideRoot.SetActive(true);
  833. }
  834. #region
  835. /// <summary>
  836. ///
  837. /// </summary>
  838. public List<ControlerWindowdData> mRecordWindowControleList = new List<ControlerWindowdData>();
  839. /////////// <summary>
  840. ///////////
  841. /////////// </summary>
  842. /////////// <param name="isContrl"></param>
  843. ////////public void AddTouchControl(string window, bool isControl)
  844. ////////{
  845. //////// foreach (ControlerWindowdData data in mRecordWindowControleList)
  846. //////// {
  847. //////// if (data.windowName == window)
  848. //////// {
  849. //////// data.controle = isControl;
  850. //////// return;
  851. //////// }
  852. //////// }
  853. //////// ControlerWindowdData temp = new ControlerWindowdData();
  854. //////// temp.windowName = window;
  855. //////// temp.controle = isControl;
  856. //////// mRecordWindowControleList.Add(temp);
  857. //////// ResetChangeControlerState();
  858. ////////}
  859. /////////// <summary>
  860. ///////////
  861. /////////// </summary>
  862. /////////// <param name="window"></param>
  863. /////////// <param name="isControl"></param>
  864. ////////public void RemoveTouchControl(string window)
  865. ////////{
  866. //////// for (int i = mRecordWindowControleList.Count - 1; i >= 0; i--)
  867. //////// {
  868. //////// ControlerWindowdData data = mRecordWindowControleList[i];
  869. //////// if (data.windowName == window)
  870. //////// {
  871. //////// mRecordWindowControleList.RemoveAt(i);
  872. //////// }
  873. //////// }
  874. //////// ResetChangeControlerState();
  875. ////////}
  876. /// <summary>
  877. /// 重置 触控操作展示英雄操作
  878. /// </summary>
  879. public void ResetChangeControlerState()
  880. {
  881. IsOpenTouchOperateHero = false;
  882. ResetCamera();
  883. if (mInputTouchContorler != null)
  884. {
  885. mInputTouchContorler.Reset();
  886. }
  887. else
  888. {
  889. LogHelper.LogError(" Warnning !!!!!!!!!!!!!mInputTouchContorler == null ");
  890. }
  891. if (mRecordWindowControleList.Count > 0)
  892. {
  893. ControlerWindowdData data = mRecordWindowControleList[mRecordWindowControleList.Count - 1];
  894. IsOpenTouchOperateHero = data.controle;
  895. }
  896. else
  897. {
  898. IsOpenTouchOperateHero = false;
  899. }
  900. }
  901. /// <summary>
  902. /// 是否开启 触控操作展示英雄操作
  903. /// </summary>
  904. public static bool IsOpenTouchOperateHero = false;
  905. /// <summary>
  906. ///
  907. /// </summary>
  908. /// <returns></returns>
  909. public bool CheckIsOpenTouchOperatehero()
  910. {
  911. //////WJ屏蔽
  912. //return UI_DBControlWindow.Instance().GetCurrentIsSupprotDragDB();
  913. ////return IsReadyOpenTouch;
  914. //if (IsOpenTouchOperateHero && IsReadyOpenTouch)
  915. //{
  916. // return true;
  917. //}
  918. ////////if (!IsOpenTouchOperateHero)
  919. ////////{
  920. //////// return false;
  921. ////////}
  922. ////////else
  923. ////////{
  924. ////////PointerEventData data = ExtendedStandaloneInputModule.GetPointerEventData(0) ;
  925. ////////RaycastResult s = data.pointerPressRaycast ;
  926. ////////RaycastResult c = data.pointerCurrentRaycast;
  927. //////// if(s.gameObject!=null)
  928. //////// Debug.LogError("AAAA::::" + s.gameObject.name);
  929. //////// if (c.gameObject != null)
  930. //////// Debug.LogError("BBBB::::" + c.gameObject.name);
  931. //////// GameObject go = EventSystem.current.currentSelectedGameObject;
  932. //////if (go != null)
  933. //////{
  934. ////// Canvas canvas = go.GetComponentInParent<Canvas>();
  935. ////// if (canvas != null)
  936. ////// {
  937. ////// foreach (ControlerWindowdData data in mRecordWindowControleList)
  938. ////// {
  939. ////// if (canvas.name.Contains(data.windowName))
  940. ////// {
  941. ////// return true;
  942. ////// }
  943. ////// }
  944. ////// }
  945. //////}
  946. ////////}
  947. return false;
  948. }
  949. /// <summary>
  950. /// 检查 是否正在进行 触控操作展示英雄
  951. /// </summary>
  952. /// <returns></returns>
  953. public bool CheckIsEnterDragOrScaleOperate()
  954. {
  955. if (mInputTouchContorler != null)
  956. {
  957. return mInputTouchContorler.IsEnterDragHeroOperate || mInputTouchContorler.IsEnterScaleHeroOperate;
  958. }
  959. return false;
  960. }
  961. ////////private bool IsReadyOpenTouch = false;
  962. ////////public void OnEnterReayDragOrScaleOperate()
  963. ////////{
  964. //////// IsReadyOpenTouch = true;
  965. ////////}
  966. ////////public void OnExitReayDragOrScaleOperate()
  967. ////////{
  968. //////// IsReadyOpenTouch = false;
  969. ////////}
  970. #endregion
  971. public void Update()
  972. {
  973. if (DragonBonesManager.Instance.loadDBDataRecord.Count > 15)
  974. {
  975. List<string> xList = new List<string>();
  976. xList.AddRange(DragonBonesManager.Instance.loadDBDataRecord.Keys);
  977. foreach (string x in xList)
  978. {
  979. UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[x];
  980. for (int kkk = id2.createGameObjectList.Count - 1; kkk >= 0; kkk--)
  981. {
  982. GameObject tp = id2.createGameObjectList[kkk];
  983. if (tp == null)
  984. {
  985. id2.createGameObjectList.RemoveAt(kkk);
  986. }
  987. }
  988. id2.useDbDataCount = (uint)id2.createGameObjectList.Count;
  989. }
  990. xList.Clear();
  991. xList.AddRange(DragonBonesManager.Instance.loadDBDataRecord.Keys);
  992. xList.Sort(DragonBonesManager.Instance.SortDB);
  993. for (int i = 0; i < xList.Count; i++)
  994. {
  995. UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[xList[i]];
  996. //LogHelper.LogError("排后" + id2.dragonBoneName + ":::createTs: " + id2.createTs + " lastUseTs: " + id2.lastUseDbDataTs + " useCount: " + id2.useDbDataCount);
  997. if (i >= 15)
  998. {
  999. LogHelper.LogError("卸载:::" + xList[i]);
  1000. DragonBonesManager.Instance.UnloadDragonBoneBundle(xList[i]);
  1001. if (existMainDisplayHeroModelDic.ContainsKey(xList[i]))
  1002. {
  1003. existMainDisplayHeroModelDic.Remove(xList[i]);
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }