PhotographView.cs 24 KB

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