PhotographView.cs 26 KB

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