PhotographView.cs 25 KB

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