PhotographView.cs 28 KB

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