PhotographView.cs 26 KB

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