PhotographView.cs 25 KB

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