PhotographView.cs 25 KB

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