PhotographView.cs 26 KB

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