12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using UnityEngine.EventSystems;
- /// <summary>
- /// 龙骨英雄动画管理
- /// </summary>
- public class DragonBonesBGControler : MonoBehaviour
- {
- /// <summary>
- /// 单键
- /// </summary>
- private static DragonBonesBGControler pInit = null;
- /// <summary>
- /// 人物节点
- /// </summary>
- private GameObject mHeroModelRoot = null;
- /// <summary>
- /// 人物 控制节点
- /// </summary>
- public InputTouchContorler mInputTouchContorler = null;
- /// <summary>
- /// 相机映射图片
- /// </summary>
- private RenderTexture renderTexture;
- /// <summary>
- ///
- /// </summary>
- private Camera mHeroModelCamera;
- /// <summary>
- /// 相机动态render图片(人物角色)
- /// </summary>
- public RenderTexture CameraRenderTexture
- {
- get { return renderTexture; }
- }
- ///// <summary>
- ///// 人物节点
- ///// </summary>
- //private GameObject mShopWindow_HeroModelRoot = null;
- ///// <summary>
- ///// 商店界面的 相机映射图片
- ///// </summary>
- //private RenderTexture shopWindow_renderTexture;
- ///// <summary>
- ///// 商店界面的 动态人物角色
- ///// </summary>
- //public RenderTexture mShopWindow_HeroRenderTexture
- //{
- // get { return shopWindow_renderTexture; }
- //}
- //---------------------抽奖 start---------------------------
- private GameObject mLuckDrawRoot = null;
- /// <summary>
- /// 抽奖人物节点
- /// </summary>
- private GameObject mLuckDrawWindow_HeroModelRoot = null;
- /// <summary>
- /// 抽奖界面的 相机映射图片
- /// </summary>
- private RenderTexture LuckDrawWindow_renderTexture;
- /// <summary>
- /// 抽奖界面的 动态人物角色
- /// </summary>
- public RenderTexture mLuckDrawWindow_HeroRenderTexture
- {
- get { return LuckDrawWindow_renderTexture; }
- }
- //---------------------抽奖 end---------------------------
- //---------------------对话 start---------------------------
- private GameObject mDialogRoot = null;
- /// <summary>
- /// 对话人物节点
- /// </summary>
- private GameObject mDialogWindow_HeroModelRoot = null;
- /// <summary>
- /// 对话界面的 相机映射图片
- /// </summary>
- private RenderTexture DialogWindow_renderTexture;
- /// <summary>
- /// 对话界面的 动态人物角色
- /// </summary>
- public RenderTexture mDialogWindow_HeroRenderTexture
- {
- get { return DialogWindow_renderTexture; }
- }
- //---------------------对话 end---------------------------
- //---------------------引导 start---------------------------
- private GameObject mGuideRoot = null;
- /// <summary>
- /// 引导人物节点
- /// </summary>
- private GameObject mGuideWindow_HeroModelRoot = null;
- /// <summary>
- /// 引导界面的 相机映射图片
- /// </summary>
- private RenderTexture GuideWindow_renderTexture;
- /// <summary>
- /// 引导界面的 动态人物角色
- /// </summary>
- public RenderTexture mGuideWindow_HeroRenderTexture
- {
- get { return GuideWindow_renderTexture; }
- }
- //---------------------引导 end---------------------------
- /// <summary>
- /// 游戏内 展示的英雄模型列表
- /// </summary>
- public Dictionary<string, GameObject> existMainDisplayHeroModelDic = new Dictionary<string, GameObject>();
- /// <summary>
- /// 获取管理者
- /// </summary>
- /// <returns>单键实例</returns>
- public static DragonBonesBGControler Instance()
- {
- if (pInit == null)
- {
- GameObject obj = GameObject.Find("ForeverUI/DragonBonesBG");
- pInit = obj.AddComponent<DragonBonesBGControler>();
- }
- return pInit;
- }
- /// <summary>
- /// start
- /// </summary>
- private void Awake()
- {
- //renderTexure赋值
- mHeroModelCamera = this.transform.Find("Camera").GetComponent<Camera>();
- if (mHeroModelCamera.GetComponent<AudioListener>() != null)
- {
- Destroy(mHeroModelCamera.GetComponent<AudioListener>());
- }
- renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
- mHeroModelRoot = this.transform.Find("Model").gameObject;
- mHeroModelCamera.targetTexture = renderTexture;
- mInputTouchContorler = mHeroModelRoot.GetComponent<InputTouchContorler>();
- if (mInputTouchContorler == null)
- {
- AssemblyHelper.Instance.BindScript("InputTouchContorler", mHeroModelRoot);
- mInputTouchContorler = mHeroModelRoot.GetComponent<InputTouchContorler>();
- }
- //shopWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
- //Camera shopWindowCamera = this.transform.Find("ShopDragonBones/Camera").GetComponent<Camera>();
- //shopWindowCamera.targetTexture = shopWindow_renderTexture;
- //mShopWindow_HeroModelRoot = this.transform.Find("ShopDragonBones/Model").gameObject;
- mLuckDrawRoot = this.transform.Find("LuckDrawDragonBones").gameObject;
- LuckDrawWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
- Camera LuckDrawWindowCamera = this.transform.Find("LuckDrawDragonBones/Camera").GetComponent<Camera>();
- LuckDrawWindowCamera.targetTexture = LuckDrawWindow_renderTexture;
- mLuckDrawWindow_HeroModelRoot = this.transform.Find("LuckDrawDragonBones/Model").gameObject;
- mLuckDrawRoot.SetActive(false);
- mDialogRoot = this.transform.Find("DialogDragonBones").gameObject;
- DialogWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
- Camera DialogWindowCamera = this.transform.Find("DialogDragonBones/Camera").GetComponent<Camera>();
- DialogWindowCamera.targetTexture = DialogWindow_renderTexture;
- mDialogWindow_HeroModelRoot = this.transform.Find("DialogDragonBones/Model").gameObject;
- mDialogRoot.SetActive(false);
- mGuideRoot = this.transform.Find("GuideDragonBones").gameObject;
- GuideWindow_renderTexture = new RenderTexture(1080, 1920, 24, RenderTextureFormat.ARGB32);
- Camera GuideWindowCamera = this.transform.Find("GuideDragonBones/Camera").GetComponent<Camera>();
- GuideWindowCamera.targetTexture = GuideWindow_renderTexture;
- mGuideWindow_HeroModelRoot = this.transform.Find("GuideDragonBones/Model").gameObject;
- mGuideRoot.SetActive(false);
- }
- /// <summary>
- ///
- /// </summary>
- public void Clear()
- {
- Transform[] allChild = mHeroModelRoot.GetComponentsInChildren<Transform>(true);
- foreach (Transform ele in allChild)
- {
- if (ele != mHeroModelRoot.transform)
- {
- Destroy(ele.gameObject);
- }
- }
- existMainDisplayHeroModelDic.Clear();
- }
- public string CurrentShowHeroModel { get; set; }
- /// <summary>
- /// 显示某哦英雄
- /// </summary>
- /// <param name="heromodel">模型ID</param>
- /// <param name="callBack">回调</param>
- public void ShowHeroModel(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
- {
- if (existMainDisplayHeroModelDic.ContainsKey(heromodel))
- {
- GameObject ani = existMainDisplayHeroModelDic[heromodel];
- DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- if (armatureComponent != null)
- {
- if (armatureComponent.name != CurrentShowHeroModel)
- {
- armatureComponent.gameObject.SetActive(false);
- armatureComponent.enabled = false;
- }
- else
- {
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- }
- }
- }
- else
- {
- # region 加载方式二:独立factory
- //DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
- // {
- // DragonBones.UnityFactory temp = new DragonBones.UnityFactory();
- // temp.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
- // temp.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
- // //temp.LoadDragonBonesData(model.mSkeletonJson, heromodel);
- // //temp.LoadTextureAtlasData(model.mTextureJson, textureAtlas, heromodel);
- // var armatureComponent = temp.BuildArmatureComponent(heromodel, heromodel);
- // ////以后这个y去读取数据库的表~~
- // ////LogHelper.LogError("MainShowPositionOffset::" + y);
- // ////armatureComponent.armature.GetBone(heromodel).offset.y = y*-1;
- // ////armatureComponent.armature.InvalidUpdate(heromodel);
- // ////armatureComponent.gameObject.name = heromodel;
- // armatureComponent.transform.SetParent(mModel.transform);
- // armatureComponent.transform.localPosition = Vector3.zero + new Vector3(posOffset.x, posOffset.y, 0);
- // armatureComponent.transform.localScale = new Vector3(1, 1, 1);
- // UnityEngine.Transform[] all = armatureComponent.GetComponentsInChildren<UnityEngine.Transform>(true);
- // foreach (UnityEngine.Transform rc in all)
- // {
- // rc.gameObject.layer = LayerMask.NameToLayer("DragonBonesLayer"); //指定Layer
- // }
- // if (!existModelDic.ContainsKey(heromodel))
- // {
- // existModelDic.Add(heromodel, armatureComponent.gameObject);
- // }
- // else
- // {
- // existModelDic[heromodel] = armatureComponent.gameObject;
- // }
- // if (callBack != null)
- // {
- // callBack(armatureComponent);
- // }
- // });
- #endregion
- #region 加载方式一: 统一factory 会出现一个问题~~
- DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
- {
- DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
- DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
- var armatureComponent = CreateDragonModel(heromodel, "DragonBonesLayer");
- SetDragonModelNode(armatureComponent, mHeroModelRoot.transform, posOffset);
- if (!existMainDisplayHeroModelDic.ContainsKey(heromodel))
- {
- existMainDisplayHeroModelDic.Add(heromodel, armatureComponent.gameObject);
- }
- else
- {
- existMainDisplayHeroModelDic[heromodel] = armatureComponent.gameObject;
- }
- if (armatureComponent.name != CurrentShowHeroModel)
- {
- armatureComponent.gameObject.SetActive(false);
- armatureComponent.enabled = false;
- }
- else
- {
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- }
- });
- #endregion
- }
- }
- /// <summary>
- /// 设置人物模型展示的时候的偏移
- /// </summary>
- /// <param name="arm"></param>
- /// <param name="posOffset"></param>
- private void SetDragonModelNode(DragonBones.UnityArmatureComponent arm, Transform parentRoot, Vector2 posOffset)
- {
- arm.transform.SetParent(parentRoot);
- //// Change armatureposition.
- arm.transform.localPosition = Vector3.zero + new Vector3(posOffset.x, posOffset.y, 0);
- arm.transform.localScale = new Vector3(2, 2, 2); // Vector3.one;
- }
- /// <summary>
- /// 创建一个真实的龙骨动画在scene中
- /// </summary>
- /// <param name="heroModel"></param>
- /// <returns></returns>
- public DragonBones.UnityArmatureComponent CreateDragonModel(string heromodel, string layerName)
- {
- if (DragonBones.UnityFactory.factory.GetDragonBonesData(heromodel) == null)
- {
- return null;
- }
- if (DragonBones.UnityFactory.factory.GetTextureAtlasData(heromodel) == null)
- {
- return null;
- }
- var armatureComponent = DragonBones.UnityFactory.factory.BuildArmatureComponent(heromodel, heromodel);
- armatureComponent.gameObject.SetActive(false);
- armatureComponent.enabled = false;
- armatureComponent.gameObject.name = heromodel;
- armatureComponent.transform.localScale = new Vector3(2, 2, 2);
- UnityEngine.Transform[] all = armatureComponent.GetComponentsInChildren<UnityEngine.Transform>(true);
- foreach (UnityEngine.Transform rc in all)
- {
- rc.gameObject.layer = LayerMask.NameToLayer(layerName); //指定Layer
- }
- //////////////////记录 记录 记录//////////////////////////
- if (DragonBonesManager.Instance.loadDBDataRecord.ContainsKey(heromodel))
- {
- UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[heromodel];
- id2.createGameObjectList.Add(armatureComponent.gameObject);
- id2.lastUseDbDataTs = DateTime.Now.ToUnixTimeStamp();
- id2.useDbDataCount += 1;
- }
- return armatureComponent;
- }
- /// <summary>
- ///【 检查函数】 判断某个模型的龙骨数据是否已经加载进去了。
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool CheckFactoryIsExistSomeModelData(string model)
- {
- if (DragonBones.UnityFactory.factory.GetDragonBonesData(model) == null)
- {
- return false;
- }
- if (DragonBones.UnityFactory.factory.GetTextureAtlasData(model) == null)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="model"></param>
- public void AddDragonBoneDataUse(string model)
- {
- if (DragonBonesManager.Instance.loadDBDataRecord.ContainsKey(model))
- {
- UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[model];
- id2.lastUseDbDataTs = DateTime.Now.ToUnixTimeStamp();
- }
- }
- /// <summary>
- /// 关闭某个英雄的模型
- /// </summary>
- /// <param name="heromodel">模型ID</param>
- public void SetHeroModelEnabled(string heromodel)
- {
- if (existMainDisplayHeroModelDic.ContainsKey(heromodel))
- {
- GameObject ani = existMainDisplayHeroModelDic[heromodel];
- if (ani == null)
- return;
- DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- if (armatureComponent != null)
- {
- armatureComponent.RemoveAllEventListener();
- }
- armatureComponent.enabled = false;
- ani.SetActive(false);
- }
- }
- /// <summary>
- /// 关闭所有 展示的英雄的模型
- /// </summary>
- public void SetAllDisplayHeroEnabled()
- {
- foreach (string heromodel in existMainDisplayHeroModelDic.Keys)
- {
- SetHeroModelEnabled(heromodel);
- }
- ResetCamera();
- }
- /// <summary>
- /// 根据英雄的龙骨数据,查找scne场景中已经创建对应的对象
- /// </summary>
- /// <param name="heromodel"></param>
- /// <returns></returns>
- public DragonBones.UnityArmatureComponent QuerySomeHeroArmature(string heromodel)
- {
- if (existMainDisplayHeroModelDic.ContainsKey(heromodel))
- {
- GameObject ani = existMainDisplayHeroModelDic[heromodel];
- DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- if (armatureComponent != null)
- {
- return armatureComponent;
- }
- return null;
- }
- return null;
- }
- /// <summary>
- /// 查找当前激活的展示龙骨模型
- /// </summary>
- /// <returns></returns>
- public string GetActiveHeroModel()
- {
- string result = string.Empty;
- foreach (string heromodel in existMainDisplayHeroModelDic.Keys)
- {
- GameObject ani = existMainDisplayHeroModelDic[heromodel];
- if (ani.activeSelf)
- {
- result += heromodel + ";";
- }
- }
- return result;
- }
- /// <summary>
- /// 默认相机的正交大小
- /// </summary>
- private const float CurCameraSize = 13.0f;
- /// <summary>
- /// 模型缩放
- /// </summary>
- internal void OnChangeCameraSize(float cameraSize)
- {
- mHeroModelCamera.GetComponent<Camera>().orthographicSize = cameraSize;
- }
- /// <summary>
- /// 模型被拖动
- /// </summary>
- internal void OnChangeModelPosition(Vector2 delta)
- {
- Vector2 temp = new Vector2(12 * (delta.x / 1080), 16 * (delta.y / 1920));
- float x = 0, y = 0;
- RectTransform tempRect = mHeroModelRoot.GetComponent<RectTransform>();
- Vector2 tempPos = tempRect.anchoredPosition + temp;
- x = tempPos.x;
- y = tempPos.y;
- if (tempPos.x > 12)
- {
- x = 12;
- }
- if (tempPos.x < -12)
- {
- x = -12;
- }
- if (tempPos.y > 16)
- {
- y = 12;
- }
- if (tempPos.y < -16)
- {
- y = -12;
- }
- Vector2 destPos = new Vector2(x, y);
- ////LogHelper.LogError("affffffffff::"+ destPos.ToString());
- tempRect.anchoredPosition = destPos;
- }
- /// <summary>
- /// 充值龙骨相机的大小 以及模型的展示位置
- /// </summary>
- internal void ResetCamera()
- {
- mHeroModelCamera.orthographicSize = CurCameraSize;
- mHeroModelRoot.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
- }
- ///// <summary>
- ///// 打开指定角色在商店的动画
- ///// </summary>
- //internal void ShowShopDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
- //{
- // bool checkHasLoad = false;
- // if (mShopWindow_HeroModelRoot.transform.childCount > 0)
- // {
- // Transform s = mShopWindow_HeroModelRoot.transform.Find(heromodel);
- // if (s != null)
- // {
- // checkHasLoad = true;
- // if (callBack != null)
- // {
- // callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
- // }
- // return;
- // }
- // }
- // if (!checkHasLoad)
- // {
- // var armatureComponent = CreateDragonModel(heromodel, "ShopDragon");
- // if (armatureComponent == null)
- // {
- // DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
- // {
- // DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
- // DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
- // armatureComponent = CreateDragonModel(heromodel, "ShopDragon");
- // SetDragonModelNode(armatureComponent, mShopWindow_HeroModelRoot.transform, posOffset);
- // if (callBack != null)
- // {
- // callBack(armatureComponent);
- // }
- // });
- // }
- // else
- // {
- // SetDragonModelNode(armatureComponent, mShopWindow_HeroModelRoot.transform, posOffset);
- // if (callBack != null)
- // {
- // callBack(armatureComponent);
- // }
- // }
- // }
- //}
- ///// <summary>
- ///// 关闭所有商店动画
- ///// </summary>
- //internal void CloseAllShopDragonBones()
- //{
- // if (mShopWindow_HeroModelRoot.transform.childCount > 0)
- // {
- // for (int i = 0; i < mShopWindow_HeroModelRoot.transform.childCount; i++)
- // {
- // GameObject ani = mShopWindow_HeroModelRoot.transform.GetChild(i).gameObject;
- // DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- // if (armatureComponent != null)
- // {
- // armatureComponent.RemoveAllEventListener();
- // }
- // armatureComponent.enabled = false;
- // ani.SetActive(false);
- // }
- // }
- //}
- /// <summary>
- /// 打开指定角色在抽奖的动画
- /// </summary>
- internal void ShowLuckDrawDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
- {
- if (this.mLuckDrawRoot.activeSelf == false)
- {
- this.mLuckDrawRoot.SetActive(true);
- }
- bool checkHasLoad = false;
- if (mLuckDrawWindow_HeroModelRoot.transform.childCount > 0)
- {
- Transform s = mLuckDrawWindow_HeroModelRoot.transform.Find(heromodel);
- if (s != null)
- {
- checkHasLoad = true;
- if (callBack != null)
- {
- callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
- }
- return;
- }
- }
- if (!checkHasLoad)
- {
- var armatureComponent = CreateDragonModel(heromodel, "LuckDragon");
- if (armatureComponent == null)
- {
- DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
- {
- DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
- DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
- armatureComponent = CreateDragonModel(heromodel, "LuckDragon");
- SetDragonModelNode(armatureComponent, mLuckDrawWindow_HeroModelRoot.transform, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- });
- }
- else
- {
- SetDragonModelNode(armatureComponent, mLuckDrawWindow_HeroModelRoot.transform, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- }
- }
- }
- /// <summary>
- /// 关闭所有抽奖动画
- /// </summary>
- internal void CloseAllLuckDrawDragonBones()
- {
- if (mLuckDrawWindow_HeroModelRoot.transform.childCount > 0)
- {
- for (int i = 0; i < mLuckDrawWindow_HeroModelRoot.transform.childCount; i++)
- {
- GameObject ani = mLuckDrawWindow_HeroModelRoot.transform.GetChild(i).gameObject;
- DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- if (armatureComponent != null)
- {
- armatureComponent.RemoveAllEventListener();
- }
- armatureComponent.enabled = false;
- ani.SetActive(false);
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- internal void CloseLuckDrawCameraDraw()
- {
- this.mLuckDrawRoot.SetActive(false);
- }
- /// <summary>
- /// 打开指定角色在对话里的动画
- /// </summary>
- internal void ShowDialogDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
- {
- if (this.mDialogRoot.activeSelf == false)
- {
- this.mDialogRoot.SetActive(true);
- }
- bool checkHasLoad = false;
- if (mDialogWindow_HeroModelRoot.transform.childCount > 0)
- {
- Transform s = mDialogWindow_HeroModelRoot.transform.Find(heromodel);
- if (s != null)
- {
- checkHasLoad = true;
- if (callBack != null)
- {
- callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
- }
- return;
- }
- }
- if (!checkHasLoad)
- {
- var armatureComponent = CreateDragonModel(heromodel, "DialogDragon");
- if (armatureComponent == null)
- {
- DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
- {
- DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
- DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
- armatureComponent = CreateDragonModel(heromodel, "DialogDragon");
- SetDragonModelNode(armatureComponent, mDialogWindow_HeroModelRoot.transform, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- });
- }
- else
- {
- SetDragonModelNode(armatureComponent, mDialogWindow_HeroModelRoot.transform, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- }
- }
- }
- /// <summary>
- /// 关闭所有对话动画
- /// </summary>
- internal void CloseAllDialogDragonBones()
- {
- if (mDialogWindow_HeroModelRoot.transform.childCount > 0)
- {
- for (int i = 0; i < mDialogWindow_HeroModelRoot.transform.childCount; i++)
- {
- GameObject ani = mDialogWindow_HeroModelRoot.transform.GetChild(i).gameObject;
- DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- if (armatureComponent != null)
- {
- armatureComponent.RemoveAllEventListener();
- }
- armatureComponent.enabled = false;
- ani.SetActive(false);
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- internal void CloseDialogCameraDraw()
- {
- this.mDialogRoot.SetActive(false);
- }
- /// <summary>
- /// 打开指定角色在对话里的动画
- /// </summary>
- internal void ShowGuideDragonBones(string heromodel, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
- {
- if (!this.mGuideRoot.activeSelf)
- {
- this.mGuideRoot.SetActive(true);
- }
- bool checkHasLoad = false;
- if (mGuideWindow_HeroModelRoot.transform.childCount > 0)
- {
- Transform s = mGuideWindow_HeroModelRoot.transform.Find(heromodel);
- if (s != null)
- {
- checkHasLoad = true;
- if (callBack != null)
- {
- callBack(s.GetComponent<DragonBones.UnityArmatureComponent>());
- }
- return;
- }
- }
- if (!checkHasLoad)
- {
- var armatureComponent = CreateDragonModel(heromodel, "GuideDragon");
- if (armatureComponent == null)
- {
- DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
- {
- DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
- DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
- armatureComponent = CreateDragonModel(heromodel, "GuideDragon");
- if (armatureComponent == null)
- {
- LogHelper.LogError("出错啦。。。。。。。。。。。。。。" + heromodel);
- }
- SetDragonModelNode(armatureComponent, mGuideWindow_HeroModelRoot.transform, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- });
- }
- else
- {
- SetDragonModelNode(armatureComponent, mGuideWindow_HeroModelRoot.transform, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- }
- }
- }
- /// <summary>
- /// 打开指定角色在战斗中的动画
- /// </summary>
- internal void ShowBattleDragonBones(string heromodel, Transform targetTran, Vector2 posOffset, Action<DragonBones.UnityArmatureComponent> callBack = null)
- {
- var armatureComponent = CreateDragonModel(heromodel, "DragonBonesLayer");
- if (armatureComponent == null)
- {
- DragonBonesManager.Instance.QueryAsset(heromodel, (model, textureAtlas) =>
- {
- DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), heromodel, 0.01f);
- DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, heromodel);
- armatureComponent = CreateDragonModel(heromodel, "GuideDragon");
- if (armatureComponent == null)
- {
- LogHelper.LogError("出错啦。。。。。。。。。。。。。。" + heromodel);
- }
- SetDragonModelNode(armatureComponent, targetTran, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- });
- }
- else
- {
- SetDragonModelNode(armatureComponent, targetTran, posOffset);
- if (callBack != null)
- {
- callBack(armatureComponent);
- }
- }
- }
- internal void CloseGuideDragonBonesByName(string dname)
- {
- if (mGuideWindow_HeroModelRoot.transform.childCount > 0)
- {
- for (int i = 0; i < mGuideWindow_HeroModelRoot.transform.childCount; i++)
- {
- GameObject ani = mGuideWindow_HeroModelRoot.transform.GetChild(i).gameObject;
- if (ani.gameObject.name == dname)
- {
- DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- if (armatureComponent != null)
- {
- armatureComponent.RemoveAllEventListener();
- }
- armatureComponent.enabled = false;
- ani.SetActive(false);
- break;
- }
- }
- }
- }
- /// <summary>
- /// 关闭所有对话动画
- /// </summary>
- internal void CloseAllGuideDragonBones()
- {
- if (mGuideWindow_HeroModelRoot.transform.childCount > 0)
- {
- for (int i = 0; i < mGuideWindow_HeroModelRoot.transform.childCount; i++)
- {
- GameObject ani = mGuideWindow_HeroModelRoot.transform.GetChild(i).gameObject;
- DragonBones.UnityArmatureComponent armatureComponent = ani.GetComponent<DragonBones.UnityArmatureComponent>();
- if (armatureComponent != null)
- {
- armatureComponent.RemoveAllEventListener();
- }
- armatureComponent.enabled = false;
- ani.SetActive(false);
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- internal void CloseGuideCameraDraw()
- {
- this.mGuideRoot.SetActive(false);
- }
- /// <summary>
- ///
- /// </summary>
- internal void OpenGuideCameraDraw()
- {
- this.mGuideRoot.SetActive(true);
- }
- #region
- /// <summary>
- ///
- /// </summary>
- public List<ControlerWindowdData> mRecordWindowControleList = new List<ControlerWindowdData>();
- /////////// <summary>
- ///////////
- /////////// </summary>
- /////////// <param name="isContrl"></param>
- ////////public void AddTouchControl(string window, bool isControl)
- ////////{
- //////// foreach (ControlerWindowdData data in mRecordWindowControleList)
- //////// {
- //////// if (data.windowName == window)
- //////// {
- //////// data.controle = isControl;
- //////// return;
- //////// }
- //////// }
- //////// ControlerWindowdData temp = new ControlerWindowdData();
- //////// temp.windowName = window;
- //////// temp.controle = isControl;
- //////// mRecordWindowControleList.Add(temp);
- //////// ResetChangeControlerState();
- ////////}
- /////////// <summary>
- ///////////
- /////////// </summary>
- /////////// <param name="window"></param>
- /////////// <param name="isControl"></param>
- ////////public void RemoveTouchControl(string window)
- ////////{
- //////// for (int i = mRecordWindowControleList.Count - 1; i >= 0; i--)
- //////// {
- //////// ControlerWindowdData data = mRecordWindowControleList[i];
- //////// if (data.windowName == window)
- //////// {
- //////// mRecordWindowControleList.RemoveAt(i);
- //////// }
- //////// }
- //////// ResetChangeControlerState();
- ////////}
- /// <summary>
- /// 重置 触控操作展示英雄操作
- /// </summary>
- public void ResetChangeControlerState()
- {
- IsOpenTouchOperateHero = false;
- ResetCamera();
- if (mInputTouchContorler != null)
- {
- mInputTouchContorler.Reset();
- }
- else
- {
- LogHelper.LogError(" Warnning !!!!!!!!!!!!!mInputTouchContorler == null ");
- }
- if (mRecordWindowControleList.Count > 0)
- {
- ControlerWindowdData data = mRecordWindowControleList[mRecordWindowControleList.Count - 1];
- IsOpenTouchOperateHero = data.controle;
- }
- else
- {
- IsOpenTouchOperateHero = false;
- }
- }
- /// <summary>
- /// 是否开启 触控操作展示英雄操作
- /// </summary>
- public static bool IsOpenTouchOperateHero = false;
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public bool CheckIsOpenTouchOperatehero()
- {
- //////WJ屏蔽
- //return UI_DBControlWindow.Instance().GetCurrentIsSupprotDragDB();
- ////return IsReadyOpenTouch;
- //if (IsOpenTouchOperateHero && IsReadyOpenTouch)
- //{
- // return true;
- //}
- ////////if (!IsOpenTouchOperateHero)
- ////////{
- //////// return false;
- ////////}
- ////////else
- ////////{
- ////////PointerEventData data = ExtendedStandaloneInputModule.GetPointerEventData(0) ;
- ////////RaycastResult s = data.pointerPressRaycast ;
- ////////RaycastResult c = data.pointerCurrentRaycast;
- //////// if(s.gameObject!=null)
- //////// Debug.LogError("AAAA::::" + s.gameObject.name);
- //////// if (c.gameObject != null)
- //////// Debug.LogError("BBBB::::" + c.gameObject.name);
- //////// GameObject go = EventSystem.current.currentSelectedGameObject;
- //////if (go != null)
- //////{
- ////// Canvas canvas = go.GetComponentInParent<Canvas>();
- ////// if (canvas != null)
- ////// {
- ////// foreach (ControlerWindowdData data in mRecordWindowControleList)
- ////// {
- ////// if (canvas.name.Contains(data.windowName))
- ////// {
- ////// return true;
- ////// }
- ////// }
- ////// }
- //////}
- ////////}
- return false;
- }
- /// <summary>
- /// 检查 是否正在进行 触控操作展示英雄
- /// </summary>
- /// <returns></returns>
- public bool CheckIsEnterDragOrScaleOperate()
- {
- if (mInputTouchContorler != null)
- {
- return mInputTouchContorler.IsEnterDragHeroOperate || mInputTouchContorler.IsEnterScaleHeroOperate;
- }
- return false;
- }
- ////////private bool IsReadyOpenTouch = false;
- ////////public void OnEnterReayDragOrScaleOperate()
- ////////{
- //////// IsReadyOpenTouch = true;
- ////////}
- ////////public void OnExitReayDragOrScaleOperate()
- ////////{
- //////// IsReadyOpenTouch = false;
- ////////}
- #endregion
- public void Update()
- {
- if (DragonBonesManager.Instance.loadDBDataRecord.Count > 15)
- {
- List<string> xList = new List<string>();
- xList.AddRange(DragonBonesManager.Instance.loadDBDataRecord.Keys);
- foreach (string x in xList)
- {
- UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[x];
- for (int kkk = id2.createGameObjectList.Count - 1; kkk >= 0; kkk--)
- {
- GameObject tp = id2.createGameObjectList[kkk];
- if (tp == null)
- {
- id2.createGameObjectList.RemoveAt(kkk);
- }
- }
- id2.useDbDataCount = (uint)id2.createGameObjectList.Count;
- }
- xList.Clear();
- xList.AddRange(DragonBonesManager.Instance.loadDBDataRecord.Keys);
- xList.Sort(DragonBonesManager.Instance.SortDB);
- for (int i = 0; i < xList.Count; i++)
- {
- UseDragonBoneRecordVo id2 = DragonBonesManager.Instance.loadDBDataRecord[xList[i]];
- //LogHelper.LogError("排后" + id2.dragonBoneName + ":::createTs: " + id2.createTs + " lastUseTs: " + id2.lastUseDbDataTs + " useCount: " + id2.useDbDataCount);
- if (i >= 15)
- {
- LogHelper.LogError("卸载:::" + xList[i]);
- DragonBonesManager.Instance.UnloadDragonBoneBundle(xList[i]);
- if (existMainDisplayHeroModelDic.ContainsKey(xList[i]))
- {
- existMainDisplayHeroModelDic.Remove(xList[i]);
- }
- }
- }
- }
- }
- }
|