PhotographView.cs 40 KB

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