PhotographView.cs 23 KB

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