PhotographView.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. using ET;
  2. using FairyGUI;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Linq;
  8. using UI.DressUp;
  9. using UnityEditor;
  10. using UnityEngine;
  11. using UnityEngine.EventSystems;
  12. using System.Threading.Tasks;
  13. using cfg.GfgCfg;
  14. namespace GFGGame
  15. {
  16. public class PhotographView : BaseView
  17. {
  18. private UI_PhotographUI _ui;
  19. private GameObject _sceneObject;
  20. private const int MAX_COUNT = 20;
  21. private const float MaxScale = 2;
  22. private const float MinScale = 0.1f;
  23. // private const string BgResPath = "Bg/BgRes";
  24. // private const string BorderResPath = "Border/BorderRes";
  25. // private const string NpcResPath = "Scene/Npc/NpcRes";
  26. private const string RolePath = "Scene/Role";
  27. private const string RoleName = "Role";
  28. private const string BodyResName = "Body";
  29. private const string BodyResName1 = "Body_a";
  30. // private const string NpcPath = "Scene/Npc";
  31. private const string NpcName = "Npc";
  32. private const string BgResName = "BgRes";
  33. private const string Border = "Border";
  34. private List<int> _listData = null; //当前选择的资源数据
  35. private List<GameObject> _itemGameObjs; // = new List<GameObject>();
  36. public Dictionary<int, List<int>> _equipSceneData = new Dictionary<int, List<int>>(); //当前穿戴的场景数据
  37. private Dictionary<GameObject, float> _equipDistance = new Dictionary<GameObject, float>();
  38. private GameObject hitGameObj; //当前选中的物体(单指拖动,双指缩放旋转)
  39. private GameObject memoryHitGameObj; //当前选中的物体(单指缩放旋转)
  40. private Vector3 distance = Vector3.zero; //点击位置和点击物体原点的距离,用于
  41. private Vector2 lastPos = Vector2.zero; //上一次移动后从物体中心到鼠标位置的方向
  42. private float lastDistance = 0; //上一次移动后从物体中心到鼠标位置的方向
  43. // private float _startDistance;//从物体中心到缩放按钮的距离
  44. private SwipeGesture swipeGesture;
  45. private PinchGesture pinchGesture;
  46. private RotationGesture rotationGesture;
  47. // 以下两个属于单选,单独保存
  48. private int lastChooseBorder; // 上一次选择的边框
  49. private int lastChooseBg; // 上一次选择的背景
  50. public override void Dispose()
  51. {
  52. if (_sceneObject != null)
  53. {
  54. PrefabManager.Instance.Restore(_sceneObject);
  55. _sceneObject = null;
  56. }
  57. if (_ui != null)
  58. {
  59. _ui.Dispose();
  60. _ui = null;
  61. }
  62. base.Dispose();
  63. }
  64. protected override void OnInit()
  65. {
  66. base.OnInit();
  67. packageName = UI_PhotographUI.PACKAGE_NAME;
  68. _ui = UI_PhotographUI.Create();
  69. viewCom = _ui.target;
  70. isfullScreen = true;
  71. //isReturnView = true;
  72. _ui.m_btnBg.onClick.Add(OnClickBtnBg);
  73. _ui.m_btnChoose.onClick.Add(OnClickBtnChoose);
  74. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  75. _ui.m_btnPhotograph.onClick.Add(OnClickBtnPhotograph);
  76. _ui.m_btnGalleryJoin.onClick.Add(OnClickBtnGalleryJoin);
  77. _ui.m_ComSelectRes.m_list.itemRenderer = RenderListItem;
  78. _ui.m_ComSelectRes.m_list.onClickItem.Add(OnListItemClick);
  79. _ui.m_ComSelectRes.m_comBtnTab.m_c1.onChanged.Add(OnContorllerChanged);
  80. _ui.target.onTouchBegin.Add(OnTouchUIBegin);
  81. _ui.target.onTouchMove.Add(OnTouchUIMove);
  82. _ui.target.onTouchEnd.Add(OnTouchUIEnd);
  83. _ui.m_comSelectBox.m_btnSize.onTouchBegin.Add(OnTouchBtnSizeBegin);
  84. _ui.m_comSelectBox.m_btnSize.onTouchMove.Add(OnTouchBtnSizeMove);
  85. _ui.m_comSelectBox.m_btnSize.onTouchEnd.Add(OnTouchBtnSizeEnd);
  86. _ui.m_comSelectBox.m_btnFlip.onTouchBegin.Add(OnTouchBtnFlipBegin);
  87. // _ui.m_comSelectBox.m_btnFlip.onTouchEnd.Add(OnTouchBtnFlipEnd);
  88. _ui.m_comSelectBox.m_btnDelete.onTouchBegin.Add(OnTouchBtnDeleteBegin);
  89. _ui.m_btnUp.onClick.Add(OnClickBtnUp);
  90. _ui.m_btnDown.onClick.Add(OnClickBtnDown);
  91. _ui.m_btnDelete.onTouchBegin.Add(OnClickBtnDelete);
  92. }
  93. protected override async void OnShown()
  94. {
  95. base.OnShown();
  96. Input.multiTouchEnabled = true;
  97. if (this.viewData != null)
  98. {
  99. _ui.m_c1.selectedIndex = (int)this.viewData;
  100. }
  101. PhotographDataManager.Instance.ClassifyEquipData();
  102. _equipSceneData = PhotographDataManager.Instance._equipSceneData;
  103. PhotographDataManager.Instance.itemGameObjs.Clear();
  104. MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.Clear();
  105. _itemGameObjs = PhotographDataManager.Instance.itemGameObjs;
  106. void SetupAfterInstantiate()
  107. {
  108. PhotographSceneManager.Instance.sceneObject = _sceneObject;
  109. pinchGesture = new PinchGesture(_ui.target);
  110. pinchGesture.onAction.Add(OnPinch);
  111. rotationGesture = new RotationGesture(_ui.target);
  112. rotationGesture.onAction.Add(OnRotate);
  113. _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex = 0;
  114. MatchingCompetitionDataManager.Instance.itemGameObjs.Clear();
  115. RefreshList(EnumPhotographType.BG);
  116. SetUIView();
  117. PhotographSceneManager.Instance.AddBgItem(
  118. CommonDataManager.Tables.TblItemCfg.GetOrDefault(MyDressUpHelper.dressUpObj.bgId));
  119. SetListScrollByID(MyDressUpHelper.dressUpObj.bgId);
  120. PhotographSceneManager.Instance.AddBodyItem();
  121. UpdateScene();
  122. PhotographUtil.Instance.SetLayer(null, "refresh");
  123. _ui.m_txtCount.text = string.Format("{0}/{1}", PoemGalleryDataManager.Instance.MyWorksCountOfTheme,
  124. CommonDataManager.Tables.TblGlobalCfg.MaxGalleryWorksCount);
  125. Timers.inst.AddUpdate(CheckGuide);
  126. if (this.viewData != null && (int)this.viewData == 2)
  127. {
  128. if (MyDressUpHelper.dressUpObj.bgId != 0)
  129. {
  130. MatchingCompetitionDataManager.Instance.DressUpBgID = MyDressUpHelper.dressUpObj.bgId;
  131. MatchingCompetitionDataManager.Instance.MathingDressDate.bgId =
  132. MatchingCompetitionDataManager.Instance.DressUpBgID;
  133. }
  134. }
  135. }
  136. if (_sceneObject == null)
  137. {
  138. PrefabManager.Instance.InstantiateAsync(
  139. ResPathUtil.GetPrefabPath("ScenePhotograph"),
  140. (go) =>
  141. {
  142. if (go != null)
  143. {
  144. _sceneObject = go;
  145. SetupAfterInstantiate();
  146. }
  147. else
  148. {
  149. Debug.LogError("场景对象异步加载失败: ScenePhotograph");
  150. }
  151. });
  152. }
  153. else
  154. {
  155. SetupAfterInstantiate();
  156. }
  157. }
  158. /************************************************************UI界面*********************************************************/
  159. private void OnContorllerChanged(EventContext context)
  160. {
  161. int index = _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  162. RefreshList((EnumPhotographType)index);
  163. }
  164. private void RefreshList(EnumPhotographType index)
  165. {
  166. _ui.m_ComSelectRes.m_list.numItems = 0;
  167. _listData = PhotographDataManager.Instance.GetListData(index);
  168. _ui.m_ComSelectRes.m_list.numItems = _listData.Count;
  169. bool setTop = false;
  170. switch (index)
  171. {
  172. case EnumPhotographType.BORDER:
  173. _ui.m_ComSelectRes.m_list.selectedIndex = lastChooseBorder;
  174. break;
  175. case EnumPhotographType.BG:
  176. _ui.m_ComSelectRes.m_list.selectedIndex = lastChooseBg;
  177. break;
  178. default:
  179. setTop = true;
  180. break;
  181. }
  182. if (!setTop)
  183. {
  184. if (_ui.m_ComSelectRes.m_list.selectedIndex >= 0)
  185. {
  186. _ui.m_ComSelectRes.m_list.ScrollToView(_ui.m_ComSelectRes.m_list.selectedIndex);
  187. }
  188. }
  189. else
  190. {
  191. _ui.m_ComSelectRes.m_list.scrollPane.ScrollTop();
  192. }
  193. //if (index == EnumPhotographType.BORDER || index == EnumPhotographType.EFFECT)
  194. //{
  195. // _ui.m_ComSelectRes.m_list.selectedIndex = 0;
  196. //}
  197. }
  198. private void SetListScrollByID(int id)
  199. {
  200. for (int i = 0; i < _listData.Count; i++)
  201. {
  202. if (id == _listData[i])
  203. {
  204. _ui.m_ComSelectRes.m_list.selectedIndex = i;
  205. _ui.m_ComSelectRes.m_list.ScrollToView(_ui.m_ComSelectRes.m_list.selectedIndex);
  206. lastChooseBg = i;
  207. }
  208. }
  209. }
  210. private void RenderListItem(int index, GObject obj)
  211. {
  212. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_listData[index]);
  213. string resPath = ResPathUtil.GetIconPath(itemCfg);
  214. UI_ListItem item = UI_ListItem.Proxy(obj);
  215. item.target.data = _listData[index];
  216. item.m_loaIcon.url = resPath;
  217. item.m_txtName.text = itemCfg.Name;
  218. UI_ListItem.ProxyEnd();
  219. }
  220. private void OnListItemClick(EventContext context)
  221. {
  222. EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  223. if (type == EnumPhotographType.SCENE && _itemGameObjs.Count >= MAX_COUNT)
  224. {
  225. PromptController.Instance.ShowFloatTextPrompt("最多穿戴" + MAX_COUNT + "件物品");
  226. return;
  227. }
  228. switch (type)
  229. {
  230. case EnumPhotographType.BORDER:
  231. lastChooseBorder = _ui.m_ComSelectRes.m_list.selectedIndex;
  232. break;
  233. case EnumPhotographType.BG:
  234. lastChooseBg = _ui.m_ComSelectRes.m_list.selectedIndex;
  235. break;
  236. }
  237. int itemID = (int)((context.data as GObject).data);
  238. ChangeItem(itemID);
  239. }
  240. private void ChangeItem(int itemID)
  241. {
  242. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemID);
  243. EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  244. switch (type)
  245. {
  246. case EnumPhotographType.BG:
  247. MatchingCompetitionDataManager.Instance.DressUpBgID = itemCfg.Id;
  248. MatchingCompetitionDataManager.Instance.MathingDressDate.bgId = itemCfg.Id;
  249. PhotographSceneManager.Instance.AddBgItem(itemCfg);
  250. break;
  251. case EnumPhotographType.BORDER:
  252. if (itemCfg.Id != ConstItemID.BORDERID)
  253. {
  254. MatchingCompetitionDataManager.Instance.BorderID = itemCfg.Id;
  255. }
  256. else
  257. {
  258. MatchingCompetitionDataManager.Instance.BorderID = 0;
  259. }
  260. PhotographSceneManager.Instance.AddBorderItem(itemCfg);
  261. break;
  262. case EnumPhotographType.NPC:
  263. MatchingCompetitionDataManager.Instance.NpcID = itemCfg.Id;
  264. PhotographSceneManager.Instance.AddNpcItem(itemCfg);
  265. break;
  266. case EnumPhotographType.SCENE:
  267. if (this.viewData == null || (int)this.viewData != 2)
  268. {
  269. AddSceneItem(itemCfg, true);
  270. }
  271. else
  272. {
  273. MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, true);
  274. }
  275. break;
  276. case EnumPhotographType.EFFECT:
  277. break;
  278. }
  279. }
  280. //添加初始场景道具
  281. private void UpdateScene()
  282. {
  283. if (this.viewData == null || (int)this.viewData != 2)
  284. {
  285. ICollection keys = _equipSceneData.Keys;
  286. foreach (int key in keys)
  287. {
  288. for (int i = 0; i < _equipSceneData[key].Count; i++)
  289. {
  290. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(key);
  291. AddSceneItem(itemCfg, false);
  292. }
  293. }
  294. }
  295. else
  296. {
  297. ICollection keys = _equipSceneData.Keys;
  298. foreach (int key in keys)
  299. {
  300. for (int i = 0; i < _equipSceneData[key].Count; i++)
  301. {
  302. bool isAdd = false;
  303. foreach (var item in MatchingCompetitionDataManager.Instance.DressPropTransInfoDic)
  304. {
  305. if (MatchingCompetitionDataManager.Instance.GetIDByString(item.Key).ToString() ==
  306. _equipSceneData[key][0].ToString())
  307. {
  308. isAdd = true;
  309. break;
  310. }
  311. }
  312. if (!isAdd)
  313. {
  314. MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.Add(key.ToString(),
  315. new TransformData());
  316. }
  317. }
  318. }
  319. //对搭配赛特殊处理
  320. foreach (var item in MatchingCompetitionDataManager.Instance.DressPropTransInfoDic)
  321. {
  322. if (item.Key == MatchingCompetitionDataManager.Instance.roleID)
  323. {
  324. continue;
  325. }
  326. else
  327. {
  328. List<int> idList = MatchingCompetitionDataManager.Instance.GetIDListByString(item.Key);
  329. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(idList[0]);
  330. if (itemCfg.ItemType == ConstItemType.PHOTOGRAPH &&
  331. itemCfg.SubType == ConstItemSubType.PHOTOGRAPH_BOREDR)
  332. {
  333. PhotographSceneManager.Instance.AddBorderItem(itemCfg);
  334. }
  335. else if (itemCfg.ItemType == ConstItemType.PHOTOGRAPH &&
  336. itemCfg.SubType == ConstItemSubType.PHOTOGRAPH_NPC)
  337. {
  338. PhotographSceneManager.Instance.AddNpcItem(itemCfg);
  339. }
  340. else
  341. {
  342. if (idList.Count > 1)
  343. {
  344. MatchingCompetitionDataManager.Instance.AddSceneItemOne(itemCfg, idList[1], idList[2]);
  345. }
  346. else
  347. {
  348. MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, false);
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. public async Task UpdateSceneTransform()
  356. {
  357. //int time = 5 * (MatchingCompetitionDataManager.Instance.TransformDataList.Count+1);
  358. if (MatchingCompetitionDataManager.Instance.DressUpBgID == 0)
  359. {
  360. PhotographSceneManager.Instance.AddBgItem(CommonDataManager.Tables.TblItemCfg.GetOrDefault(180001));
  361. }
  362. else
  363. {
  364. PhotographSceneManager.Instance.AddBgItem(
  365. CommonDataManager.Tables.TblItemCfg.GetOrDefault(
  366. MatchingCompetitionDataManager.Instance.DressUpBgID));
  367. }
  368. await Task.Delay(100);
  369. if (MatchingCompetitionDataManager.Instance.BorderID != 0)
  370. {
  371. GameObject borderGameObj =
  372. PhotographSceneManager.Instance.sceneObject.transform.Find("Border").gameObject;
  373. MatchingCompetitionDataManager.Instance.itemGameObjs.Add(borderGameObj);
  374. }
  375. if (MatchingCompetitionDataManager.Instance.NpcID != 0)
  376. {
  377. GameObject NpcGameObj =
  378. PhotographSceneManager.Instance.sceneObject.transform.Find("Scene/Npc").gameObject;
  379. MatchingCompetitionDataManager.Instance.itemGameObjs.Add(NpcGameObj);
  380. }
  381. MatchingCompetitionDataManager.Instance.InsertGameObjectList();
  382. for (int i = 0; i < MatchingCompetitionDataManager.Instance.itemGameObjs.Count; i++)
  383. {
  384. GameObject itemGObj = MatchingCompetitionDataManager.Instance.itemGameObjs[i];
  385. TransformData itemdata = new TransformData();
  386. if (MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.ContainsKey(itemGObj.name))
  387. {
  388. itemdata = MatchingCompetitionDataManager.Instance.DressPropTransInfoDic[itemGObj.name];
  389. }
  390. MatchingCompetitionDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
  391. MatchingCompetitionDataManager.Instance.itemGameObjs[i].transform.Rotate(
  392. itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
  393. MatchingCompetitionDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
  394. PhotographUtil.Instance.ChangeLayer(MatchingCompetitionDataManager.Instance.itemGameObjs[i],
  395. i * PhotographDataManager.layerCount, "up");
  396. }
  397. }
  398. private async void AddSceneItem(ItemCfg itemCfg, bool setLayer)
  399. {
  400. Vector3 pos = Vector3.zero;
  401. if (!string.IsNullOrEmpty(itemCfg.ResLayer3))
  402. {
  403. GameObject parentGameObj3 = new GameObject(string.Format("{0}_{1}", itemCfg.Id, 3));
  404. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj3, itemCfg, 3, setLayer);
  405. if (setLayer)
  406. {
  407. if (parentGameObj3.transform.childCount > 0)
  408. {
  409. parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
  410. pos = parentGameObj3.transform.localPosition;
  411. }
  412. }
  413. }
  414. if (!string.IsNullOrEmpty(itemCfg.ResLayer2))
  415. {
  416. GameObject parentGameObj2 = new GameObject(string.Format("{0}_{1}", itemCfg.Id, 2));
  417. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj2, itemCfg, 2, setLayer);
  418. if (setLayer)
  419. {
  420. if (parentGameObj2.transform.childCount > 0)
  421. {
  422. parentGameObj2.transform.localPosition = pos == Vector3.zero
  423. ? -parentGameObj2.transform.GetChild(0).localPosition
  424. : pos;
  425. pos = parentGameObj2.transform.localPosition;
  426. }
  427. }
  428. }
  429. if (!string.IsNullOrEmpty(itemCfg.ResLayer1))
  430. {
  431. GameObject parentGameObj1 = new GameObject(string.Format("{0}_{1}", itemCfg.Id, 1));
  432. await PhotographSceneManager.Instance.AddSceneItem(parentGameObj1, itemCfg, 1, setLayer);
  433. if (setLayer)
  434. {
  435. if (parentGameObj1.transform.childCount > 0)
  436. {
  437. parentGameObj1.transform.localPosition = pos == Vector3.zero
  438. ? -parentGameObj1.transform.GetChild(0).localPosition
  439. : pos;
  440. pos = parentGameObj1.transform.localPosition;
  441. }
  442. }
  443. }
  444. }
  445. /************************************************************场景*********************************************************/
  446. private void OnTouchUIBegin(EventContext context)
  447. {
  448. context.CaptureTouch();
  449. if (_ui.m_ComSelectRes.target.visible == true) return; //添加道具不监听场景点击
  450. if (Stage.inst.touchCount > 1 && hitGameObj != null ||
  451. Stage.inst.touchCount == 1 && context.inputEvent.touchId != 0) return; //两根手指&&两指不是同时按下||一根手指但属于中途换指
  452. if (PhotographUtil.Instance.IsTouchUI(this.viewCom)) return;
  453. RaycastHit2D[] hit2Ds =
  454. Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  455. if (hit2Ds.Length > 0)
  456. {
  457. lastPos = Vector2.zero;
  458. hitGameObj = PhotographUtil.Instance.GetFirstHitObj(hit2Ds);
  459. _ui.m_comSelectBox.m_btnDelete.visible = true;
  460. if (hitGameObj.transform.parent.name == RoleName) //主角不可删除
  461. {
  462. _ui.m_comSelectBox.m_btnDelete.visible = false;
  463. }
  464. _ui.m_comSelectBox.target.visible = false;
  465. if (hitGameObj.name != BgResName) //背景不可改动层级
  466. {
  467. hitGameObj = hitGameObj.transform.parent.gameObject;
  468. _ui.m_comSelectBox.target.visible = true;
  469. if (hitGameObj.name != Border)
  470. {
  471. PhotographUtil.Instance.SetLayer(hitGameObj, "top");
  472. }
  473. }
  474. memoryHitGameObj = hitGameObj;
  475. distance = Input.mousePosition - Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  476. Vector3 localEulerAngles = hitGameObj.transform.localEulerAngles;
  477. float rotation = 0;
  478. if (localEulerAngles.y == 0)
  479. {
  480. rotation = -hitGameObj.transform.localEulerAngles.z;
  481. }
  482. else
  483. {
  484. if (hitGameObj.transform.localEulerAngles.z > 180)
  485. {
  486. rotation = hitGameObj.transform.localEulerAngles.z - 360;
  487. }
  488. else
  489. {
  490. rotation = hitGameObj.transform.localEulerAngles.z;
  491. }
  492. }
  493. _ui.m_comSelectBox.target.rotation = rotation;
  494. _ui.m_comSelectBox.target.size = PhotographUtil.Instance.GetGameObjectBoundsSize(hitGameObj);
  495. ControllerSelectBoxPos();
  496. }
  497. }
  498. private void OnTouchUIMove(EventContext context)
  499. {
  500. if (hitGameObj == null) return; //未选中任何物体
  501. if (Stage.inst.touchCount > 1) return; //只监听1根手指
  502. if (PhotographUtil.Instance.IsTouchUI(this.viewCom)) return;
  503. ControllerObjectPos();
  504. ControllerSelectBoxPos();
  505. }
  506. private void OnTouchUIEnd(EventContext context)
  507. {
  508. hitGameObj = null;
  509. }
  510. //选中物体的位置
  511. private void ControllerObjectPos()
  512. {
  513. hitGameObj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition - distance);
  514. if (hitGameObj.name == BgResName)
  515. {
  516. PhotographUtil.Instance.SetBgPos(hitGameObj, _ui.target.size);
  517. }
  518. }
  519. //选中框的位置
  520. private void ControllerSelectBoxPos()
  521. {
  522. Vector2 objScreenPos = Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  523. Vector2 localPos =
  524. this.viewCom.GlobalToLocal(new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y)));
  525. _ui.m_comSelectBox.target.position = localPos;
  526. }
  527. private void OnTouchBtnSizeBegin(EventContext context)
  528. {
  529. InputEvent inputEvent = (InputEvent)context.data;
  530. Vector2 pt0 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
  531. Vector2 screenPos = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.m_btnSize.LocalToGlobal(Vector2.zero));
  532. Vector2 pt1 = new Vector2(screenPos.x, screenPos.y);
  533. Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
  534. lastDistance = Vector2.Distance(pt0, pt2);
  535. if (!_equipDistance.ContainsKey(memoryHitGameObj))
  536. {
  537. float distance = Vector2.Distance(pt1, pt2) / memoryHitGameObj.transform.localScale.x;
  538. Debug.Log("distance:" + distance + " pt1:" + pt1 + " pt2:" + pt2);
  539. _equipDistance.Add(memoryHitGameObj, distance);
  540. }
  541. }
  542. private void OnTouchBtnSizeMove(EventContext context)
  543. {
  544. if (memoryHitGameObj == null) return;
  545. InputEvent inputEvent = (InputEvent)context.data;
  546. Vector2 pt1 = this.viewCom.GlobalToLocal(inputEvent.position);
  547. Vector2 pt2 = _ui.m_comSelectBox.target.xy;
  548. Vector2 curPos = pt1 - pt2;
  549. float angle = Vector3.Angle(lastPos, curPos); //求出两向量之间的夹角
  550. Vector3 normal = Vector3.Cross(lastPos, curPos); //叉乘求出法线向量
  551. angle *= Mathf.Sign(Vector3.Dot(normal,
  552. Vector3.forward)); //Mathf.Sign()求符号,Vector3.Dot()求方向,求法线向量与物体上方向向量点乘,结果为1或-1,修正旋转方向
  553. lastPos = curPos;
  554. ControllerRotate(angle, memoryHitGameObj);
  555. float dist = Vector2.Distance(pt1, pt2);
  556. float ss = dist / lastDistance;
  557. float curValue = Math.Abs(memoryHitGameObj.transform.localScale.x);
  558. float newValue = Mathf.Clamp(ss * curValue, 0.1f, 2);
  559. ControllerScale(newValue, memoryHitGameObj, Math.Sign(memoryHitGameObj.transform.localScale.x));
  560. if (newValue <= 0.1f)
  561. {
  562. lastDistance = Vector2.Distance(_ui.m_comSelectBox.m_btnDelete.xy, _ui.m_comSelectBox.m_btnSize.xy) / 2;
  563. }
  564. else
  565. {
  566. lastDistance = dist;
  567. }
  568. }
  569. private void OnTouchBtnSizeEnd(EventContext context)
  570. {
  571. lastPos = Vector2.zero;
  572. }
  573. //双指缩放
  574. private void OnPinch(EventContext context)
  575. {
  576. if (hitGameObj == null) return;
  577. if (hitGameObj.name == BgResName) return; //背景不可以缩放、旋转
  578. GTween.Kill(hitGameObj);
  579. PinchGesture gesture = (PinchGesture)context.sender;
  580. float newValue = Mathf.Clamp(hitGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
  581. Debug.Log("双指缩放:" + newValue);
  582. ControllerScale(newValue, hitGameObj, Math.Sign(hitGameObj.transform.localScale.x));
  583. }
  584. //双指旋转
  585. private void OnRotate(EventContext context)
  586. {
  587. Debug.Log("双指旋转hitGameObj:" + hitGameObj);
  588. if (hitGameObj == null) return;
  589. Debug.Log("双指旋转name:" + hitGameObj.name);
  590. if (hitGameObj.name == BgResName) return; //背景不可以缩放、旋转
  591. // isTwoTouchPoint = true;
  592. GTween.Kill(hitGameObj.transform);
  593. RotationGesture gesture = (RotationGesture)context.sender;
  594. Debug.Log("双指旋转:" + gesture.delta);
  595. ControllerRotate(gesture.delta, hitGameObj);
  596. }
  597. private void ControllerScale(float value, GameObject gameObject, int sign)
  598. {
  599. if (value > MaxScale || value < MinScale) return;
  600. gameObject.transform.localScale = new Vector3(value * sign, value, value);
  601. Vector2 size = PhotographUtil.Instance.GetGameObjectBoundsSize(gameObject);
  602. _ui.m_comSelectBox.target.size = size;
  603. }
  604. private void ControllerRotate(float value, GameObject gameObject)
  605. {
  606. gameObject.transform.Rotate(Vector3.forward, -value, Space.World);
  607. _ui.m_comSelectBox.target.rotation += value;
  608. }
  609. private void OnClickBtnBg()
  610. {
  611. _ui.m_ComSelectRes.target.visible = false;
  612. }
  613. private void OnTouchBtnFlipBegin() //翻转
  614. {
  615. Transform transform = memoryHitGameObj.transform;
  616. var value = Math.Abs(transform.localScale.x);
  617. // transform.localScale = new Vector3(-value, Math.Abs(value), 1);
  618. ControllerScale(value, memoryHitGameObj, -Math.Sign(transform.localScale.x));
  619. }
  620. private void OnTouchBtnDeleteBegin() //删除
  621. {
  622. if (memoryHitGameObj.transform.name == RolePath)
  623. {
  624. return;
  625. }
  626. else if (memoryHitGameObj.transform.name == Border || memoryHitGameObj.transform.name == NpcName)
  627. {
  628. memoryHitGameObj.transform.localPosition = Vector3.zero;
  629. memoryHitGameObj.transform.localRotation = Quaternion.Euler(Vector3.zero);
  630. memoryHitGameObj.transform.localScale = Vector3.one;
  631. GameObject gameObject = memoryHitGameObj.transform.GetChild(0).gameObject;
  632. PhotographSceneManager.Instance.DeleteSpriteRendererFromGameObject(gameObject);
  633. PhotographSceneManager.Instance.DeleteBoxCollider2DFromGameObject(gameObject);
  634. }
  635. else
  636. {
  637. MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.Remove(memoryHitGameObj.name);
  638. GameObject.DestroyImmediate(memoryHitGameObj);
  639. }
  640. _itemGameObjs.Remove(memoryHitGameObj);
  641. _ui.m_comSelectBox.target.visible = false;
  642. }
  643. private void SetUIView()
  644. {
  645. _ui.m_ComSelectRes.target.visible = true;
  646. _ui.m_comSelectBox.target.visible = false;
  647. hitGameObj = null;
  648. memoryHitGameObj = null;
  649. lastChooseBorder = 0;
  650. lastChooseBg = 0;
  651. _ui.m_ComSelectRes.m_comBtnTab.target.scrollPane.SetPercX(0, false);
  652. _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex = 0;
  653. if (_ui.m_ComSelectRes.m_list.numItems > 0)
  654. {
  655. _ui.m_ComSelectRes.m_list.ScrollToView(0);
  656. _ui.m_ComSelectRes.m_list.selectedIndex = 0;
  657. }
  658. }
  659. private void OnClickBtnChoose()
  660. {
  661. _ui.m_ComSelectRes.target.visible = true;
  662. _ui.m_comSelectBox.target.visible = false;
  663. hitGameObj = null;
  664. memoryHitGameObj = null;
  665. }
  666. private void OnClickBtnUp()
  667. {
  668. PhotographUtil.Instance.SetLayer(memoryHitGameObj, "up");
  669. }
  670. private void OnClickBtnDown()
  671. {
  672. PhotographUtil.Instance.SetLayer(memoryHitGameObj, "down");
  673. }
  674. private void OnClickBtnDelete()
  675. {
  676. if (memoryHitGameObj == null || !_ui.m_comSelectBox.target.visible ||
  677. !_ui.m_comSelectBox.m_btnDelete.visible)
  678. {
  679. return;
  680. }
  681. OnTouchBtnDeleteBegin();
  682. }
  683. private void OnClickBtnPhotograph()
  684. {
  685. // GRoot.inst.visible = false;
  686. Timers.inst.StartCoroutine(ScreenShotTex()); // ();
  687. }
  688. private void OnClickBtnGalleryJoin()
  689. {
  690. // GRoot.inst.visible = false;
  691. Timers.inst.StartCoroutine(ScreenShotTex()); // ();
  692. }
  693. private IEnumerator ScreenShotTex()
  694. {
  695. GRoot.inst.visible = false;
  696. yield return new WaitForEndOfFrame();
  697. Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
  698. Texture2D tex =
  699. new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false); //新建一个Texture2D对象
  700. tex.ReadPixels(rect, 0, 0); //读取像素,屏幕左下角为0点
  701. tex.Apply(); //保存像素信息
  702. GRoot.inst.visible = true;
  703. if (_ui.m_c1.selectedIndex == 0)
  704. {
  705. ViewManager.Show<PhotographSaveView>(tex);
  706. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.PAI_ZHAO, 2);
  707. }
  708. else if (_ui.m_c1.selectedIndex == 1)
  709. {
  710. AlertUI.Show("是否确认上传此作品?")
  711. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  712. {
  713. ViewManager.Show<ModalStatusView>("上传中...");
  714. object[] rsp = await PoemGallerySProxy.ReqUpLoadGalleryWorks();
  715. if (rsp == null) return;
  716. byte[] bytes = tex.EncodeToJPG();
  717. bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
  718. if (!pushResult) return;
  719. bool result = await PoemGallerySProxy.ReqNoticeGalleryWorksUploaded((long)(rsp[1]), tex);
  720. if (result)
  721. {
  722. _ui.m_txtCount.text = string.Format("{0}/{1}",
  723. PoemGalleryDataManager.Instance.MyWorksCountOfTheme,
  724. CommonDataManager.Tables.TblGlobalCfg.MaxGalleryWorksCount);
  725. ViewManager.Hide<ModalStatusView>();
  726. OnClickBtnBack();
  727. ViewManager.GoBackFrom(typeof(DressUpView).FullName);
  728. }
  729. });
  730. }
  731. else if (_ui.m_c1.selectedIndex == 2)
  732. {
  733. MatchingCompetitionDataManager.Instance.itemGameObjs = _itemGameObjs.ToList();
  734. if (MatchingCompetitionDataManager.Instance.BorderID != 0)
  735. {
  736. GameObject borderGameObj =
  737. PhotographSceneManager.Instance.sceneObject.transform.Find("Border").gameObject;
  738. MatchingCompetitionDataManager.Instance.itemGameObjs.Add(borderGameObj);
  739. }
  740. if (MatchingCompetitionDataManager.Instance.NpcID != 0)
  741. {
  742. GameObject NpcGameObj = PhotographSceneManager.Instance.sceneObject.transform.Find("Scene/Npc")
  743. .gameObject;
  744. //MatchingCompetitionDataManager.Instance.itemGameObjs.Add(NpcGameObj);
  745. }
  746. MatchingCompetitionDataManager.Instance.MathingDressDate =
  747. MyDressUpHelper.dressUpObj.DressUpDataClone();
  748. MatchingCompetitionDataManager.Instance.SetTransformData();
  749. if (MatchingCompetitionDataManager.Instance.WorksID == 0)
  750. {
  751. OnUpLoad(tex);
  752. }
  753. else
  754. {
  755. AlertUI.Show("作品已保存,是否确认上传并替换作品?")
  756. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  757. {
  758. ViewManager.Show<ModalStatusView>("上传中...");
  759. //await MatchingCompetitionSproxy.ReqMatchingCompetitionInfo();
  760. object[] rsp = await MatchingCompetitionSproxy.UpLoadMatchingCompetitionDressData();
  761. if (rsp == null) return;
  762. byte[] bytes = tex.EncodeToJPG();
  763. MatchingCompetitionDataManager.Instance.MyNtextture = new NTexture(tex);
  764. if (rsp[0] == null)
  765. {
  766. ViewManager.Hide<ModalStatusView>();
  767. PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
  768. return;
  769. }
  770. bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
  771. if (!pushResult)
  772. {
  773. ViewManager.Hide<ModalStatusView>();
  774. PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
  775. return;
  776. }
  777. bool result = await MatchingCompetitionSproxy.UploadSuccess();
  778. if (result)
  779. {
  780. ViewManager.Hide<ModalStatusView>();
  781. PromptController.Instance.ShowFloatTextPrompt("上传成功!");
  782. this.Hide();
  783. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  784. ViewManager.GoBackFrom(typeof(DressUpView).FullName);
  785. }
  786. ViewManager.Hide<ModalStatusView>();
  787. });
  788. }
  789. }
  790. }
  791. private async void OnUpLoad(Texture2D tex)
  792. {
  793. ViewManager.Show<ModalStatusView>("上传中...");
  794. object[] rsp = await MatchingCompetitionSproxy.UpLoadMatchingCompetitionDressData();
  795. if (rsp == null) return;
  796. byte[] bytes = tex.EncodeToJPG();
  797. MatchingCompetitionDataManager.Instance.MyNtextture = new NTexture(tex);
  798. if (rsp[0] == null)
  799. {
  800. ViewManager.Hide<ModalStatusView>();
  801. PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
  802. return;
  803. }
  804. bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
  805. if (!pushResult)
  806. {
  807. ViewManager.Hide<ModalStatusView>();
  808. PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
  809. return;
  810. }
  811. bool result = await MatchingCompetitionSproxy.UploadSuccess();
  812. if (result)
  813. {
  814. ViewManager.Hide<ModalStatusView>();
  815. PromptController.Instance.ShowFloatTextPrompt("上传成功!");
  816. this.Hide();
  817. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  818. ViewManager.GoBackFrom(typeof(DressUpView).FullName);
  819. }
  820. ViewManager.Hide<ModalStatusView>();
  821. }
  822. private void OnClickBtnBack()
  823. {
  824. //ViewManager.Show<DressUpView>();
  825. if (_ui.m_c1.selectedIndex == 2)
  826. {
  827. AlertUI.Show("返回将清空搭配道具,是否确定返回?")
  828. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  829. {
  830. this.Hide();
  831. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  832. ViewManager.GoBackFrom(typeof(PhotographView).FullName);
  833. });
  834. }
  835. else
  836. {
  837. this.Hide();
  838. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  839. }
  840. }
  841. protected override void OnHide()
  842. {
  843. base.OnHide();
  844. if (_sceneObject != null)
  845. {
  846. PrefabManager.Instance.Restore(_sceneObject);
  847. _sceneObject = null;
  848. }
  849. MatchingCompetitionDataManager.Instance.DressPropIndex = 0;
  850. _equipSceneData.Clear();
  851. hitGameObj = null;
  852. memoryHitGameObj = null;
  853. pinchGesture.onAction.Remove(OnPinch);
  854. rotationGesture.onAction.Remove(OnRotate);
  855. pinchGesture = null;
  856. rotationGesture = null;
  857. _ui.m_c1.selectedIndex = 0;
  858. Timers.inst.Remove(CheckGuide);
  859. //Timers.inst.Remove(UpdateSceneTransform);
  860. }
  861. private void CheckGuide(object param)
  862. {
  863. if (GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0 ||
  864. GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER) <= 0)
  865. {
  866. UpdateToCheckGuide(null);
  867. }
  868. else
  869. {
  870. Timers.inst.Remove(CheckGuide);
  871. }
  872. }
  873. protected override void UpdateToCheckGuide(object param)
  874. {
  875. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  876. GuideController.TryGuide(null, ConstGuideId.FREEDOM_DRESS, 7, "在这里可以选择已获得的背景、道具等,也可以放大缩小物品,增加画面丰富度。", -1,
  877. true, _ui.target.height - _ui.m_ComSelectRes.target.height - 250);
  878. GuideController.TryGuide(_ui.m_btnPhotograph, ConstGuideId.FREEDOM_DRESS, 8, "来记录下这一刻吧。");
  879. // GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 8);
  880. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.ENTER_CHAPTER, 1, "");
  881. }
  882. protected override void TryCompleteGuide()
  883. {
  884. base.TryCompleteGuide();
  885. // GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 8);
  886. }
  887. }
  888. }