PhotographView.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. using FairyGUI;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UI.DressUp;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. namespace GFGGame
  9. {
  10. public class PhotographView : BaseView
  11. {
  12. private UI_PhotographUI _ui;
  13. private GameObject _scenePrefab;
  14. private GameObject _sceneObject;
  15. // private DressUpObjDataCache equipDataCache;
  16. // private const string MOVE = "MOVE";
  17. // private const string SCALE = "SCALE";
  18. // private const string ROTATION = "ROTATION";
  19. private const float MaxScale = 2;
  20. private const float MinScale = 0.1f;
  21. private const string BgResPath = "Bg/BgRes";
  22. private const string BorderResPath = "Border/BorderRes";
  23. private const string NpcResPath = "Scene/Npc/NpcRes";
  24. private const string RolePath = "Scene/Role";
  25. private const string NpcPath = "Scene/Npc";
  26. private const string BgResName = "BgRes";
  27. // private const string BorderResName = "BorderRes";
  28. // private GameObject bodyParent;
  29. // private GameObject bgParent;
  30. // private GameObject npcParent;
  31. // private GameObject borderParent;
  32. // private GameObject sceneParent;
  33. private List<int> _listData = null;//当前选择的资源数据
  34. public List<int> _equipRoleData = new List<int>();//当前穿戴的角色数据
  35. public Dictionary<int, List<int>> _equipSceneData = new Dictionary<int, List<int>>();//当前穿戴的场景数据
  36. private Dictionary<GameObject, float> _equipDistance = new Dictionary<GameObject, float>();
  37. private GameObject hitGameObj;//当前选中的物体(单指拖动,双指缩放旋转)
  38. private GameObject memoryHitGameObj;//当前选中的物体(单指缩放旋转)
  39. private Vector3 distance = Vector3.zero;//点击位置和点击物体原点的距离,用于
  40. private Vector2 lastPos = Vector2.zero;//上一次移动后从物体中心到鼠标位置的方向
  41. // private float _startDistance;//从物体中心到缩放按钮的距离
  42. private SwipeGesture swipeGesture;
  43. private PinchGesture pinchGesture;
  44. private RotationGesture rotationGesture;
  45. private bool isTwoTouchPoint = false;
  46. private int maxLayer = int.MinValue;//最上层的层级数
  47. protected override void OnInit()
  48. {
  49. base.OnInit();
  50. packageName = UI_PhotographUI.PACKAGE_NAME;
  51. _ui = UI_PhotographUI.Create();
  52. viewCom = _ui.target;
  53. isfullScreen = true;
  54. _ui.m_btnBg.onClick.Add(OnClickBtnBg);
  55. _ui.m_btnChoose.onClick.Add(SetUIView);
  56. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  57. _ui.m_btnPhotograph.onClick.Add(OnClickBtnPhotograph);
  58. _ui.m_ComSelectRes.m_list.itemRenderer = RenderListItem;
  59. _ui.m_ComSelectRes.m_list.onClickItem.Add(OnListItemClick);
  60. _ui.m_ComSelectRes.m_comBtnTab.m_c1.onChanged.Add(OnContorllerChanged);
  61. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  62. _ui.target.onTouchBegin.Add(OnTouchUIBegin);
  63. _ui.target.onTouchMove.Add(OnTouchUIMove);
  64. _ui.target.onTouchEnd.Add(OnTouchUIEnd);
  65. _ui.m_comSelectBox.m_btnSize.onTouchBegin.Add(OnTouchBtnSizeBegin);
  66. _ui.m_comSelectBox.m_btnSize.onTouchMove.Add(OnTouchBtnSizeMove);
  67. _ui.m_comSelectBox.m_btnSize.onTouchEnd.Add(OnTouchBtnSizeEnd);
  68. _ui.m_comSelectBox.m_btnFlip.onTouchBegin.Add(OnTouchBtnFlipBegin);
  69. _ui.m_comSelectBox.m_btnFlip.onTouchEnd.Add(OnTouchBtnFlipEnd);
  70. _ui.m_comSelectBox.m_btnDelete.onTouchBegin.Add(OnTouchBtnDeleteBegin);
  71. _ui.m_comSelectBox.m_btnDelete.onTouchEnd.Add(OnTouchBtnDeleteEnd);
  72. }
  73. protected override void OnShown()
  74. {
  75. base.OnShown();
  76. Input.multiTouchEnabled = true;
  77. // equipDataCache = EquipDataCache.cacher;
  78. PhotographDataManager.Instance.ClassifyEquipData();
  79. _equipRoleData = PhotographDataManager.Instance._equipRoleData;
  80. _equipSceneData = PhotographDataManager.Instance._equipSceneData;
  81. if (_sceneObject == null)
  82. {
  83. _sceneObject = GameObject.Instantiate(_scenePrefab);
  84. EquipDataCache.cacher.setSceneObj(_sceneObject);
  85. }
  86. pinchGesture = new PinchGesture(_ui.target);
  87. pinchGesture.onAction.Add(OnPinch);
  88. rotationGesture = new RotationGesture(_ui.target);
  89. rotationGesture.onAction.Add(OnRotate);
  90. _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex = 0;
  91. RefreshList(EnumPhotographType.BG);
  92. SetUIView();
  93. UpdateBg(ItemCfgArray.Instance.GetCfg(EquipDataCache.cacher.bgId));
  94. UpdateBody();
  95. UpdateScene();
  96. }
  97. /************************************************************UI界面*********************************************************/
  98. private void OnContorllerChanged(EventContext context)
  99. {
  100. int index = _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  101. RefreshList((EnumPhotographType)index);
  102. }
  103. private void RefreshList(EnumPhotographType index)
  104. {
  105. _ui.m_ComSelectRes.m_list.numItems = 0;
  106. _listData = PhotographDataManager.Instance.GetListData(index);
  107. _ui.m_ComSelectRes.m_list.numItems = _listData.Count;
  108. }
  109. private void RenderListItem(int index, GObject obj)
  110. {
  111. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listData[index]);
  112. string resPath = ResPathUtil.GetIconPath(itemCfg);
  113. UI_ListItem item = UI_ListItem.Proxy(obj);
  114. item.target.data = _listData[index];
  115. item.m_loaIcon.url = resPath;
  116. item.m_txtName.text = itemCfg.name;
  117. }
  118. private void OnListItemClick(EventContext context)
  119. {
  120. int itemID = (int)((context.data as GObject).data);
  121. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
  122. EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  123. switch (type)
  124. {
  125. case EnumPhotographType.BG:
  126. UpdateBg(itemCfg);
  127. break;
  128. case EnumPhotographType.BORDER:
  129. if (_listData.IndexOf(itemID) == 0)
  130. {
  131. Transform tf = _sceneObject.transform.Find(BorderResPath);
  132. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  133. if (spr != null)
  134. {
  135. GameObject.Destroy(spr);
  136. }
  137. return;
  138. }
  139. UpdateBorder(itemCfg);
  140. break;
  141. case EnumPhotographType.NPC:
  142. UpdateNpc(itemCfg);
  143. break;
  144. case EnumPhotographType.SCENE:
  145. AddSceneItem(itemCfg, false);
  146. break;
  147. case EnumPhotographType.EFFECT:
  148. break;
  149. }
  150. }
  151. /************************************************************场景*********************************************************/
  152. private void OnTouchUIBegin(EventContext context)
  153. {
  154. context.CaptureTouch();
  155. if (_ui.m_ComSelectRes.target.visible == true) return;//添加道具不监听场景点击
  156. if (Stage.inst.touchCount > 1 && hitGameObj != null || Stage.inst.touchCount == 1 && context.inputEvent.touchId != 0) return;//两根手指&&两指不是同时按下||一根手指但属于中途换指
  157. if (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return;
  158. RaycastHit2D[] hit2Ds = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  159. if (hit2Ds.Length > 0)
  160. {
  161. // maxLayer++;
  162. lastPos = Vector2.zero;
  163. hitGameObj = SceneController.GetFirstHitObj(hit2Ds);
  164. _ui.m_comSelectBox.m_btnDelete.visible = true;
  165. if (hitGameObj.name == "Body")//主角不可删除
  166. {
  167. _ui.m_comSelectBox.m_btnDelete.visible = false;
  168. }
  169. _ui.m_comSelectBox.target.visible = false;
  170. if (hitGameObj.name != BgResName)//背景不可改动层级
  171. {
  172. hitGameObj = hitGameObj.transform.parent.gameObject;
  173. PhotographDataManager.Instance.SetItemLayer(hitGameObj, maxLayer);
  174. maxLayer = PhotographDataManager.Instance.GetMaxLayer(hitGameObj, maxLayer) + 1;
  175. _ui.m_comSelectBox.target.visible = true;
  176. SceneController.SetGameObjectCenter(hitGameObj);
  177. }
  178. memoryHitGameObj = hitGameObj;
  179. distance = Input.mousePosition - Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  180. _ui.m_comSelectBox.target.rotation = -hitGameObj.transform.eulerAngles.z;
  181. _ui.m_comSelectBox.target.size = SceneController.GetGameObjectSize(hitGameObj);
  182. ControllerSelectBoxPos();
  183. }
  184. }
  185. private void OnTouchUIMove(EventContext context)
  186. {
  187. if (hitGameObj == null) return;//未选中任何物体
  188. if (Stage.inst.touchCount > 1) return; //只监听1根手指
  189. if (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return;
  190. Debug.Log("拖动");
  191. ControllerObjectPos();
  192. ControllerSelectBoxPos();
  193. }
  194. private void OnTouchUIEnd(EventContext context)
  195. {
  196. // if (Stage.inst.touchCount > 1 || context.inputEvent.touchId != 0) return; //只监听1根手指
  197. hitGameObj = null;
  198. }
  199. //选中物体的位置
  200. private void ControllerObjectPos()
  201. {
  202. hitGameObj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition - distance);
  203. if (hitGameObj.name == BgResName)
  204. {
  205. PhotographDataManager.Instance.SetBgPos(hitGameObj, _ui.target.size);
  206. }
  207. }
  208. //选中框的位置
  209. private void ControllerSelectBoxPos()
  210. {
  211. Vector2 objScreenPos = Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  212. Vector2 localPos = this.viewCom.GlobalToLocal(new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y)));
  213. _ui.m_comSelectBox.target.position = localPos;
  214. }
  215. private void OnTouchBtnSizeBegin(EventContext context)
  216. {
  217. InputEvent inputEvent = (InputEvent)context.data;
  218. Vector2 screenPos = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.m_btnSize.LocalToGlobal(Vector2.zero));
  219. Vector2 pt = new Vector2(screenPos.x, screenPos.y);
  220. Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
  221. if (!_equipDistance.ContainsKey(memoryHitGameObj))
  222. {
  223. float distance = Vector2.Distance(pt, pt2) / memoryHitGameObj.transform.localScale.x;
  224. _equipDistance.Add(memoryHitGameObj, distance);
  225. }
  226. }
  227. private void OnTouchBtnSizeMove(EventContext context)
  228. {
  229. if (memoryHitGameObj == null) return;
  230. InputEvent inputEvent = (InputEvent)context.data;
  231. Vector2 pt1 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
  232. Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
  233. Vector2 curPos = pt1 - pt2;
  234. float angle = Vector3.Angle(lastPos, curPos); //求出两向量之间的夹角
  235. Vector3 normal = Vector3.Cross(lastPos, curPos);//叉乘求出法线向量
  236. angle *= Mathf.Sign(Vector3.Dot(normal, Vector3.forward)); //Mathf.Sign()求符号,Vector3.Dot()求方向,求法线向量与物体上方向向量点乘,结果为1或-1,修正旋转方向
  237. lastPos = curPos;
  238. ControllerRotate(angle, memoryHitGameObj);
  239. float dist = Vector2.Distance(pt1, pt2);
  240. float ss = dist / _equipDistance[memoryHitGameObj];
  241. float newValue = Mathf.Clamp(ss, 0.1f, 2);
  242. ControllerScale(newValue, memoryHitGameObj);
  243. }
  244. private void OnTouchBtnSizeEnd(EventContext context)
  245. {
  246. lastPos = Vector2.zero;
  247. }
  248. //双指缩放
  249. private void OnPinch(EventContext context)
  250. {
  251. if (hitGameObj == null) return;
  252. if (hitGameObj.name == BgResName) return;//背景不可以缩放、旋转
  253. GTween.Kill(hitGameObj);
  254. PinchGesture gesture = (PinchGesture)context.sender;
  255. float newValue = Mathf.Clamp(hitGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
  256. Debug.Log("双指缩放:" + newValue);
  257. ControllerScale(newValue, hitGameObj);
  258. }
  259. //双指旋转
  260. private void OnRotate(EventContext context)
  261. {
  262. Debug.Log("双指旋转hitGameObj:" + hitGameObj);
  263. if (hitGameObj == null) return;
  264. Debug.Log("双指旋转name:" + hitGameObj.name);
  265. if (hitGameObj.name == BgResName) return;//背景不可以缩放、旋转
  266. // isTwoTouchPoint = true;
  267. GTween.Kill(hitGameObj.transform);
  268. RotationGesture gesture = (RotationGesture)context.sender;
  269. Debug.Log("双指旋转:" + gesture.delta);
  270. ControllerRotate(gesture.delta, hitGameObj);
  271. }
  272. private void ControllerScale(float value, GameObject gameObject)
  273. {
  274. if (value > MaxScale || value < MinScale) return;
  275. gameObject.transform.localScale = new Vector3(value, value, 1);
  276. Vector2 size = SceneController.GetGameObjectSize(gameObject);
  277. _ui.m_comSelectBox.target.SetSize(size.x, size.y);
  278. }
  279. private void ControllerRotate(float value, GameObject gameObject)
  280. {
  281. gameObject.transform.Rotate(Vector3.forward, -value, Space.World);
  282. _ui.m_comSelectBox.target.rotation += value;
  283. }
  284. private void UpdateBg(ItemCfg itemCfg)
  285. {
  286. Transform tf = _sceneObject.transform.Find(BgResPath);
  287. string resPath = ResPathUtil.GetDressUpPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
  288. SceneController.SetSpriteRendererToTransform(tf, resPath);
  289. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  290. spr.sortingOrder = ItemTypeCfgArray.Instance.GetCfg(ConstDressUpItemType.BEI_JING).defaultLayer;
  291. SceneController.SetBoxCollider2DToGameObject(tf.gameObject);
  292. }
  293. //主角
  294. private void UpdateBody()
  295. {
  296. GameObject bodyParent = _sceneObject.transform.Find(RolePath).gameObject;
  297. SceneController.UpdatePhotographBody(_equipRoleData.ToArray(), _sceneObject, bodyParent);
  298. // int layer = bodyParent.transform.Find("Body").GetComponent<SpriteRenderer>().sortingOrder;
  299. // maxLayer = layer < maxLayer ? maxLayer : layer;
  300. maxLayer = PhotographDataManager.Instance.GetMaxLayer(bodyParent, maxLayer) + 1;
  301. }
  302. //添加初始场景道具
  303. private void UpdateScene()
  304. {
  305. ICollection keys = _equipSceneData.Keys;
  306. foreach (int key in keys)
  307. {
  308. for (int i = 0; i < _equipSceneData[key].Count; i++)
  309. {
  310. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(key);
  311. int defaultLayer = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType).defaultLayer;
  312. AddSceneItem(itemCfg, true);
  313. }
  314. }
  315. }
  316. private void UpdateNpc(ItemCfg itemCfg)
  317. {
  318. maxLayer++;
  319. Transform tf = _sceneObject.transform.Find(NpcResPath);
  320. string resPath = ResPathUtil.GetNpcPicFPath(itemCfg.res);
  321. SceneController.SetSpriteRendererToTransform(tf, resPath);
  322. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  323. spr.sortingOrder = maxLayer;
  324. tf.localPosition = new Vector2(-spr.bounds.center.x, -spr.bounds.center.y);
  325. SceneController.SetBoxCollider2DToGameObject(tf.gameObject);
  326. }
  327. private void UpdateBorder(ItemCfg itemCfg)
  328. {
  329. Transform tf = _sceneObject.transform.Find(BorderResPath);
  330. string resPath = ResPathUtil.GetPhotographFPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
  331. SceneController.SetSpriteRendererToTransform(tf, resPath);
  332. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  333. spr.sortingOrder = 10000;//边框在所有道具的上边
  334. }
  335. private void UpdateEffect()
  336. {
  337. }
  338. private void AddSceneItem(ItemCfg itemCfg, bool isDefaultLayer)
  339. {
  340. int index = 0;
  341. GameObject parentGameObj;
  342. if (itemCfg.resLayer2 > 0)
  343. {
  344. if (!isDefaultLayer)
  345. {
  346. PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData);
  347. }
  348. index = _equipSceneData[itemCfg.id].Count - 1;
  349. parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 1));
  350. SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, itemCfg.resLayer2);
  351. SpriteRenderer spr = parentGameObj.transform.GetChild(0).GetComponent<SpriteRenderer>();
  352. maxLayer = PhotographDataManager.Instance.GetMaxLayer(parentGameObj, maxLayer) + 1;
  353. if (isDefaultLayer) return;
  354. // maxLayer = maxLayer + 1;
  355. PhotographDataManager.Instance.SetItemLayer(parentGameObj, maxLayer);
  356. }
  357. if (itemCfg.resLayer1 > 0)
  358. {
  359. if (!isDefaultLayer)
  360. {
  361. PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData);
  362. }
  363. index = _equipSceneData[itemCfg.id].Count - 1;
  364. parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 0));
  365. SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, itemCfg.resLayer1);
  366. SpriteRenderer spr = parentGameObj.transform.GetChild(0).GetComponent<SpriteRenderer>();
  367. // ItemTypeCfg itemTypeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
  368. // maxLayer = isDefaultLayer && maxLayer < itemTypeCfg.defaultLayer ? itemTypeCfg.defaultLayer : maxLayer + 1;
  369. // if (!isDefaultLayer)
  370. // {
  371. // // maxLayer = maxLayer + 1;
  372. // PhotographDataManager.Instance.SetItemLayer(parentGameObj, maxLayer);
  373. // }
  374. maxLayer = PhotographDataManager.Instance.GetMaxLayer(parentGameObj, maxLayer) + 1;
  375. if (isDefaultLayer) return;
  376. // maxLayer = PhotographDataManager.Instance.GetLayer(parentGameObj) + maxLayer + 1;
  377. // maxLayer = maxLayer + 1;
  378. PhotographDataManager.Instance.SetItemLayer(parentGameObj, maxLayer);
  379. }
  380. }
  381. private void OnClickBtnBg()
  382. {
  383. _ui.m_ComSelectRes.target.visible = false;
  384. }
  385. private void OnTouchBtnFlipBegin()//翻转
  386. {
  387. Transform transform = memoryHitGameObj.transform;
  388. for (int i = 0; i < transform.childCount; i++)
  389. {
  390. transform.GetChild(i).Rotate(Vector3.up, 180, Space.Self);
  391. }
  392. }
  393. private void OnTouchBtnFlipEnd()
  394. {
  395. }
  396. private void OnTouchBtnDeleteBegin()//删除
  397. {
  398. if (memoryHitGameObj.transform.name == RolePath)
  399. {
  400. return;
  401. }
  402. else if (memoryHitGameObj.transform.name == NpcPath)
  403. {
  404. SpriteRenderer spriteRenderer = memoryHitGameObj.transform.GetChild(0).GetComponent<SpriteRenderer>();
  405. if (spriteRenderer != null)
  406. {
  407. GameObject.Destroy(spriteRenderer);
  408. }
  409. }
  410. else
  411. {
  412. GameObject.DestroyImmediate(memoryHitGameObj);
  413. }
  414. _ui.m_comSelectBox.target.visible = false;
  415. }
  416. private void OnTouchBtnDeleteEnd()
  417. {
  418. }
  419. private void SetUIView()
  420. {
  421. _ui.m_ComSelectRes.target.visible = true;
  422. _ui.m_comSelectBox.target.visible = false;
  423. hitGameObj = null;
  424. memoryHitGameObj = null;
  425. }
  426. private void OnClickBtnPhotograph()
  427. {
  428. _ui.target.visible = false;
  429. Timers.inst.StartCoroutine(ScreenShotTex());// ();
  430. }
  431. private IEnumerator ScreenShotTex()
  432. {
  433. _ui.target.visible = false;
  434. yield return new WaitForEndOfFrame();
  435. Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
  436. Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);//新建一个Texture2D对象
  437. tex.ReadPixels(rect, 0, 0);//读取像素,屏幕左下角为0点
  438. tex.Apply();//保存像素信息
  439. ViewManager.Show<PhotographSaveView>(tex);
  440. _ui.target.visible = true;
  441. }
  442. private void OnClickBtnBack()
  443. {
  444. this.Hide();
  445. // ViewManager.Show(ViewName.DRESS_UP_VIEW);
  446. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  447. }
  448. protected override void OnHide()
  449. {
  450. base.OnHide();
  451. if (_sceneObject != null)
  452. {
  453. GameObject.Destroy(_sceneObject);
  454. _sceneObject = null;
  455. }
  456. // equipDataCache = null;
  457. _equipRoleData.Clear();
  458. _equipSceneData.Clear();
  459. hitGameObj = null;
  460. memoryHitGameObj = null;
  461. pinchGesture.onAction.Remove(OnPinch);
  462. rotationGesture.onAction.Remove(OnRotate);
  463. pinchGesture = null;
  464. rotationGesture = null;
  465. }
  466. public override void Dispose()
  467. {
  468. if (_scenePrefab != null)
  469. {
  470. GameObject.Destroy(_scenePrefab);
  471. _scenePrefab = null;
  472. }
  473. base.Dispose();
  474. }
  475. }
  476. }