PhotographView.cs 24 KB

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