PhotographView.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. using FairyGUI;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using UI.DressUp;
  7. using UnityEditor;
  8. using UnityEngine;
  9. using UnityEngine.EventSystems;
  10. namespace GFGGame
  11. {
  12. public class PhotographView : BaseView
  13. {
  14. private UI_PhotographUI _ui;
  15. private GameObject _scenePrefab;
  16. private GameObject _sceneObject;
  17. private const int MAX_COUNT = 20;
  18. private const float MaxScale = 2;
  19. private const float MinScale = 0.1f;
  20. private const string BgResPath = "Bg/BgRes";
  21. private const string BorderResPath = "Border/BorderRes";
  22. private const string NpcResPath = "Scene/Npc/NpcRes";
  23. private const string RolePath = "Scene/Role";
  24. private const string RoleName = "Role";
  25. private const string NpcPath = "Scene/Npc";
  26. private const string BgResName = "BgRes";
  27. private List<int> _listData = null;//当前选择的资源数据
  28. private List<GameObject> _itemGameObjs = new List<GameObject>();
  29. public Dictionary<int, List<int>> _equipSceneData = new Dictionary<int, List<int>>();//当前穿戴的场景数据
  30. private Dictionary<GameObject, float> _equipDistance = new Dictionary<GameObject, float>();
  31. private GameObject hitGameObj;//当前选中的物体(单指拖动,双指缩放旋转)
  32. private GameObject memoryHitGameObj;//当前选中的物体(单指缩放旋转)
  33. private Vector3 distance = Vector3.zero;//点击位置和点击物体原点的距离,用于
  34. private Vector2 lastPos = Vector2.zero;//上一次移动后从物体中心到鼠标位置的方向
  35. private float lastDistance = 0;//上一次移动后从物体中心到鼠标位置的方向
  36. // private float _startDistance;//从物体中心到缩放按钮的距离
  37. private SwipeGesture swipeGesture;
  38. private PinchGesture pinchGesture;
  39. private RotationGesture rotationGesture;
  40. // private int maxLayer = int.MinValue;//最上层的层级数
  41. protected override void OnInit()
  42. {
  43. base.OnInit();
  44. packageName = UI_PhotographUI.PACKAGE_NAME;
  45. _ui = UI_PhotographUI.Create();
  46. viewCom = _ui.target;
  47. isfullScreen = true;
  48. _ui.m_btnBg.onClick.Add(OnClickBtnBg);
  49. _ui.m_loaGuide.onClick.Add(OnClickLoaGuide);
  50. _ui.m_loaGuide1.onClick.Add(OnClickLoaGuide1);
  51. _ui.m_btnChoose.onClick.Add(SetUIView);
  52. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  53. _ui.m_btnPhotograph.onClick.Add(OnClickBtnPhotograph);
  54. _ui.m_ComSelectRes.m_list.itemRenderer = RenderListItem;
  55. _ui.m_ComSelectRes.m_list.onClickItem.Add(OnListItemClick);
  56. _ui.m_ComSelectRes.m_comBtnTab.m_c1.onChanged.Add(OnContorllerChanged);
  57. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  58. _ui.target.onTouchBegin.Add(OnTouchUIBegin);
  59. _ui.target.onTouchMove.Add(OnTouchUIMove);
  60. _ui.target.onTouchEnd.Add(OnTouchUIEnd);
  61. _ui.m_comSelectBox.m_btnSize.onTouchBegin.Add(OnTouchBtnSizeBegin);
  62. _ui.m_comSelectBox.m_btnSize.onTouchMove.Add(OnTouchBtnSizeMove);
  63. _ui.m_comSelectBox.m_btnSize.onTouchEnd.Add(OnTouchBtnSizeEnd);
  64. _ui.m_comSelectBox.m_btnFlip.onTouchBegin.Add(OnTouchBtnFlipBegin);
  65. _ui.m_comSelectBox.m_btnFlip.onTouchEnd.Add(OnTouchBtnFlipEnd);
  66. _ui.m_comSelectBox.m_btnDelete.onTouchBegin.Add(OnTouchBtnDeleteBegin);
  67. _ui.m_comSelectBox.m_btnDelete.onTouchEnd.Add(OnTouchBtnDeleteEnd);
  68. _ui.m_btnUp.onClick.Add(OnClickBtnUp);
  69. _ui.m_btnDown.onClick.Add(OnClickBtnDown);
  70. }
  71. protected override void OnShown()
  72. {
  73. base.OnShown();
  74. Input.multiTouchEnabled = true;
  75. PhotographDataManager.Instance.ClassifyEquipData();
  76. _equipSceneData = PhotographDataManager.Instance._equipSceneData;
  77. _itemGameObjs.Clear();
  78. if (_sceneObject == null)
  79. {
  80. _sceneObject = GameObject.Instantiate(_scenePrefab);
  81. EquipDataCache.cacher.setSceneObj(_sceneObject);
  82. }
  83. pinchGesture = new PinchGesture(_ui.target);
  84. pinchGesture.onAction.Add(OnPinch);
  85. rotationGesture = new RotationGesture(_ui.target);
  86. rotationGesture.onAction.Add(OnRotate);
  87. _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex = 0;
  88. RefreshList(EnumPhotographType.BG);
  89. SetUIView();
  90. UpdateBg(ItemCfgArray.Instance.GetCfg(EquipDataCache.cacher.bgId));
  91. UpdateBody();
  92. UpdateScene();
  93. for (int i = 0; i < _itemGameObjs.Count; i++)
  94. {
  95. PhotographDataManager.Instance.SetLayer(_itemGameObjs[i], i * 100, "up");
  96. }
  97. if (GuideDataManager.GetGuideCountCopy(ConstGuideId.PHOTOGRAPH) > 0)
  98. {
  99. _ui.m_loaGuide.enabled = false;
  100. _ui.m_loaGuide1.enabled = false;
  101. }
  102. else
  103. {
  104. _ui.m_loaGuide.enabled = true;
  105. _ui.m_loaGuide1.enabled = false;
  106. }
  107. // CreatTex();
  108. }
  109. /************************************************************UI界面*********************************************************/
  110. private void OnContorllerChanged(EventContext context)
  111. {
  112. int index = _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  113. RefreshList((EnumPhotographType)index);
  114. }
  115. private void RefreshList(EnumPhotographType index)
  116. {
  117. _ui.m_ComSelectRes.m_list.numItems = 0;
  118. _listData = PhotographDataManager.Instance.GetListData(index);
  119. _ui.m_ComSelectRes.m_list.numItems = _listData.Count;
  120. }
  121. private void RenderListItem(int index, GObject obj)
  122. {
  123. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listData[index]);
  124. string resPath = ResPathUtil.GetIconPath(itemCfg);
  125. UI_ListItem item = UI_ListItem.Proxy(obj);
  126. item.target.data = _listData[index];
  127. item.m_loaIcon.url = resPath;
  128. item.m_txtName.text = itemCfg.name;
  129. }
  130. private void OnListItemClick(EventContext context)
  131. {
  132. if (_itemGameObjs.Count >= MAX_COUNT)
  133. {
  134. PromptController.Instance.ShowFloatTextPrompt("最多穿戴" + MAX_COUNT + "件物品");
  135. return;
  136. }
  137. int itemID = (int)((context.data as GObject).data);
  138. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
  139. EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  140. switch (type)
  141. {
  142. case EnumPhotographType.BG:
  143. UpdateBg(itemCfg);
  144. break;
  145. case EnumPhotographType.BORDER:
  146. if (_listData.IndexOf(itemID) == 0)
  147. {
  148. Transform tf = _sceneObject.transform.Find(BorderResPath);
  149. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  150. if (spr != null)
  151. {
  152. GameObject.Destroy(spr);
  153. }
  154. return;
  155. }
  156. UpdateBorder(itemCfg);
  157. break;
  158. case EnumPhotographType.NPC:
  159. UpdateNpc(itemCfg);
  160. break;
  161. case EnumPhotographType.SCENE:
  162. AddSceneItem(itemCfg, false, true);
  163. break;
  164. case EnumPhotographType.EFFECT:
  165. break;
  166. }
  167. }
  168. /************************************************************场景*********************************************************/
  169. private void OnTouchUIBegin(EventContext context)
  170. {
  171. context.CaptureTouch();
  172. if (_ui.m_ComSelectRes.target.visible == true) return;//添加道具不监听场景点击
  173. if (Stage.inst.touchCount > 1 && hitGameObj != null || Stage.inst.touchCount == 1 && context.inputEvent.touchId != 0) return;//两根手指&&两指不是同时按下||一根手指但属于中途换指
  174. if (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return;
  175. RaycastHit2D[] hit2Ds = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  176. if (hit2Ds.Length > 0)
  177. {
  178. lastPos = Vector2.zero;
  179. hitGameObj = SceneController.GetFirstHitObj(hit2Ds);
  180. _ui.m_comSelectBox.m_btnDelete.visible = true;
  181. if (hitGameObj.name == "Body")//主角不可删除
  182. {
  183. _ui.m_comSelectBox.m_btnDelete.visible = false;
  184. }
  185. _ui.m_comSelectBox.target.visible = false;
  186. if (hitGameObj.name != BgResName)//背景不可改动层级
  187. {
  188. hitGameObj = hitGameObj.transform.parent.gameObject;
  189. _ui.m_comSelectBox.target.visible = true;
  190. int index = _itemGameObjs.IndexOf(hitGameObj);
  191. GameObject gameObject = _itemGameObjs[index];
  192. _itemGameObjs.RemoveAt(index);
  193. _itemGameObjs.Add(gameObject);
  194. for (int i = 0; i < _itemGameObjs.Count; i++)
  195. {
  196. PhotographDataManager.Instance.SetLayer(_itemGameObjs[i], i * 100, "up");
  197. }
  198. if (!_equipDistance.ContainsKey(hitGameObj))
  199. {
  200. SceneController.SetGameObjectCenter(hitGameObj);
  201. }
  202. }
  203. memoryHitGameObj = hitGameObj;
  204. distance = Input.mousePosition - Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  205. Vector3 localEulerAngles = hitGameObj.transform.localEulerAngles;
  206. float rotation = 0;
  207. if (localEulerAngles.y == 0)
  208. {
  209. rotation = -hitGameObj.transform.localEulerAngles.z;
  210. }
  211. else
  212. {
  213. if (hitGameObj.transform.localEulerAngles.z > 180)
  214. {
  215. rotation = hitGameObj.transform.localEulerAngles.z - 360;
  216. }
  217. else
  218. {
  219. rotation = hitGameObj.transform.localEulerAngles.z;
  220. }
  221. }
  222. _ui.m_comSelectBox.target.rotation = rotation;// localEulerAngles.y != 0 ? hitGameObj.transform.localEulerAngles.z : -hitGameObj.transform.localEulerAngles.z;
  223. Debug.Log("rotation:" + _ui.m_comSelectBox.target.rotation + " " + _ui.m_comSelectBox.target.rotationX + " " + _ui.m_comSelectBox.target.rotationY);
  224. _ui.m_comSelectBox.target.size = SceneController.GetGameObjectSize(hitGameObj);
  225. ControllerSelectBoxPos();
  226. }
  227. }
  228. private void OnTouchUIMove(EventContext context)
  229. {
  230. if (hitGameObj == null) return;//未选中任何物体
  231. if (Stage.inst.touchCount > 1) return; //只监听1根手指
  232. if (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return;
  233. Debug.Log("拖动");
  234. ControllerObjectPos();
  235. ControllerSelectBoxPos();
  236. }
  237. private void OnTouchUIEnd(EventContext context)
  238. {
  239. // if (Stage.inst.touchCount > 1 || context.inputEvent.touchId != 0) return; //只监听1根手指
  240. hitGameObj = null;
  241. }
  242. //选中物体的位置
  243. private void ControllerObjectPos()
  244. {
  245. hitGameObj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition - distance);
  246. if (hitGameObj.name == BgResName)
  247. {
  248. PhotographDataManager.Instance.SetBgPos(hitGameObj, _ui.target.size);
  249. }
  250. }
  251. //选中框的位置
  252. private void ControllerSelectBoxPos()
  253. {
  254. Vector2 objScreenPos = Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  255. Vector2 localPos = this.viewCom.GlobalToLocal(new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y)));
  256. _ui.m_comSelectBox.target.position = localPos;
  257. }
  258. private void OnTouchBtnSizeBegin(EventContext context)
  259. {
  260. InputEvent inputEvent = (InputEvent)context.data;
  261. Vector2 pt0 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
  262. Vector2 screenPos = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.m_btnSize.LocalToGlobal(Vector2.zero));
  263. Vector2 pt1 = new Vector2(screenPos.x, screenPos.y);
  264. Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
  265. lastDistance = Vector2.Distance(pt0, pt2);
  266. if (!_equipDistance.ContainsKey(memoryHitGameObj))
  267. {
  268. float distance = Vector2.Distance(pt1, pt2) / memoryHitGameObj.transform.localScale.x;
  269. Debug.Log("distance:" + distance + " pt1:" + pt1 + " pt2:" + pt2);
  270. _equipDistance.Add(memoryHitGameObj, distance);
  271. }
  272. }
  273. private void OnTouchBtnSizeMove(EventContext context)
  274. {
  275. if (memoryHitGameObj == null) return;
  276. InputEvent inputEvent = (InputEvent)context.data;
  277. Vector2 pt1 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
  278. Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
  279. Vector2 curPos = pt1 - pt2;
  280. float angle = Vector3.Angle(lastPos, curPos); //求出两向量之间的夹角
  281. Vector3 normal = Vector3.Cross(lastPos, curPos);//叉乘求出法线向量
  282. angle *= Mathf.Sign(Vector3.Dot(normal, Vector3.forward)); //Mathf.Sign()求符号,Vector3.Dot()求方向,求法线向量与物体上方向向量点乘,结果为1或-1,修正旋转方向
  283. lastPos = curPos;
  284. ControllerRotate(angle, memoryHitGameObj);
  285. float dist = Vector2.Distance(pt1, pt2);
  286. float ss = dist / lastDistance;
  287. Debug.Log("dist:" + dist + " lastDistance:" + lastDistance + " ss:" + ss);
  288. float newValue = Mathf.Clamp(ss * memoryHitGameObj.transform.localScale.x, 0.1f, 2);
  289. ControllerScale(newValue, memoryHitGameObj);
  290. if (newValue <= 0.1f) return;
  291. Debug.Log("ss:" + ss + " newValue:" + newValue);
  292. lastDistance = dist;
  293. Debug.Log("newValue:" + newValue);
  294. }
  295. private void OnTouchBtnSizeEnd(EventContext context)
  296. {
  297. lastPos = Vector2.zero;
  298. }
  299. //双指缩放
  300. private void OnPinch(EventContext context)
  301. {
  302. if (hitGameObj == null) return;
  303. if (hitGameObj.name == BgResName) return;//背景不可以缩放、旋转
  304. GTween.Kill(hitGameObj);
  305. PinchGesture gesture = (PinchGesture)context.sender;
  306. float newValue = Mathf.Clamp(hitGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
  307. Debug.Log("双指缩放:" + newValue);
  308. ControllerScale(newValue, hitGameObj);
  309. }
  310. //双指旋转
  311. private void OnRotate(EventContext context)
  312. {
  313. Debug.Log("双指旋转hitGameObj:" + hitGameObj);
  314. if (hitGameObj == null) return;
  315. Debug.Log("双指旋转name:" + hitGameObj.name);
  316. if (hitGameObj.name == BgResName) return;//背景不可以缩放、旋转
  317. // isTwoTouchPoint = true;
  318. GTween.Kill(hitGameObj.transform);
  319. RotationGesture gesture = (RotationGesture)context.sender;
  320. Debug.Log("双指旋转:" + gesture.delta);
  321. ControllerRotate(gesture.delta, hitGameObj);
  322. }
  323. private void ControllerScale(float value, GameObject gameObject)
  324. {
  325. if (value > MaxScale || value < MinScale) return;
  326. gameObject.transform.localScale = new Vector3(value, value, 1);
  327. Vector2 size = SceneController.GetGameObjectSize(gameObject);
  328. _ui.m_comSelectBox.target.size = size;
  329. }
  330. private void ControllerRotate(float value, GameObject gameObject)
  331. {
  332. gameObject.transform.Rotate(Vector3.forward, -value, Space.World);
  333. _ui.m_comSelectBox.target.rotation += value;
  334. }
  335. private void UpdateBg(ItemCfg itemCfg)
  336. {
  337. Transform tf = _sceneObject.transform.Find(BgResPath);
  338. string resPath = ResPathUtil.GetDressUpPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
  339. SceneController.SetSpriteRendererToTransform(tf, resPath);
  340. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  341. spr.sortingOrder = ItemTypeCfgArray.Instance.GetCfg(ConstDressUpItemType.BEI_JING).defaultLayer;
  342. SceneController.SetBoxCollider2DToGameObject(tf.gameObject);
  343. }
  344. //主角
  345. private void UpdateBody()
  346. {
  347. GameObject bodyParent = _sceneObject.transform.Find(RolePath).gameObject;
  348. SceneController.UpdatePhotographBody(PhotographDataManager.Instance._equipRoleData.ToArray(), _sceneObject, bodyParent);
  349. AddItemGameObject(bodyParent, false);
  350. }
  351. //添加初始场景道具
  352. private void UpdateScene()
  353. {
  354. ICollection keys = _equipSceneData.Keys;
  355. foreach (int key in keys)
  356. {
  357. for (int i = 0; i < _equipSceneData[key].Count; i++)
  358. {
  359. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(key);
  360. int defaultLayer = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType).defaultLayer;
  361. AddSceneItem(itemCfg, true, false);
  362. }
  363. }
  364. }
  365. private void UpdateNpc(ItemCfg itemCfg)
  366. {
  367. Transform tf = _sceneObject.transform.Find(NpcResPath);
  368. string resPath = ResPathUtil.GetNpcPicFPath(itemCfg.res);
  369. SceneController.SetSpriteRendererToTransform(tf, resPath);
  370. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  371. tf.localPosition = new Vector2(-spr.bounds.center.x, -spr.bounds.center.y);
  372. SceneController.SetBoxCollider2DToGameObject(tf.gameObject);
  373. AddItemGameObject(tf.parent.gameObject, true);
  374. }
  375. private void UpdateBorder(ItemCfg itemCfg)
  376. {
  377. Transform tf = _sceneObject.transform.Find(BorderResPath);
  378. string resPath = ResPathUtil.GetPhotographFPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
  379. SceneController.SetSpriteRendererToTransform(tf, resPath);
  380. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  381. spr.sortingOrder = 10000;//边框在所有道具的上边
  382. }
  383. private void UpdateEffect()
  384. {
  385. }
  386. private void AddSceneItem(ItemCfg itemCfg, bool isDefaultLayer, bool setLayer)
  387. {
  388. int index = 0;
  389. GameObject parentGameObj;
  390. if (itemCfg.resLayer2 > 0)
  391. {
  392. if (!isDefaultLayer)
  393. {
  394. PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData);
  395. }
  396. index = _equipSceneData[itemCfg.id].Count - 1;
  397. parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 1));
  398. SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, 2, itemCfg.resLayer2);
  399. AddItemGameObject(parentGameObj, setLayer);
  400. }
  401. if (itemCfg.resLayer1 > 0)
  402. {
  403. if (!isDefaultLayer)
  404. {
  405. PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData);
  406. }
  407. index = _equipSceneData[itemCfg.id].Count - 1;
  408. parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 0));
  409. SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, 1, itemCfg.resLayer1);
  410. AddItemGameObject(parentGameObj, setLayer);
  411. }
  412. }
  413. private void AddItemGameObject(GameObject parentGameObj, bool setLayer)
  414. {
  415. _itemGameObjs.Add(parentGameObj);
  416. if (setLayer)
  417. {
  418. int index = _itemGameObjs.Count - 1;
  419. PhotographDataManager.Instance.SetLayer(_itemGameObjs[index], index * 100, "up");
  420. }
  421. _itemGameObjs.Sort((GameObject a, GameObject b) =>
  422. {
  423. int layerA = PhotographDataManager.Instance.GetMinLayer(a);
  424. int layerB = PhotographDataManager.Instance.GetMinLayer(b);
  425. if (layerA < layerB)
  426. {
  427. return -1;
  428. }
  429. else if (layerA > layerB)
  430. {
  431. return 1;
  432. }
  433. return 0;
  434. });
  435. }
  436. private void OnClickBtnBg()
  437. {
  438. _ui.m_ComSelectRes.target.visible = false;
  439. // GuideController.TryGuideOpenPhotographView(null);
  440. }
  441. private void OnClickLoaGuide()
  442. {
  443. _ui.m_loaGuide1.enabled = true;
  444. _ui.m_loaGuide.enabled = false;
  445. _ui.m_ComSelectRes.target.visible = false;
  446. }
  447. private void OnClickLoaGuide1()
  448. {
  449. _ui.m_loaGuide1.enabled = false;
  450. _ui.m_ComSelectRes.target.visible = false;
  451. }
  452. private void OnTouchBtnFlipBegin()//翻转
  453. {
  454. Transform transform = memoryHitGameObj.transform;
  455. if (memoryHitGameObj.name == RoleName)
  456. {
  457. transform.Rotate(Vector3.up, 180, Space.Self);
  458. return;
  459. }
  460. for (int i = 0; i < transform.childCount; i++)
  461. {
  462. transform.GetChild(i).Rotate(Vector3.up, 180, Space.Self);
  463. }
  464. }
  465. private void OnTouchBtnFlipEnd()
  466. {
  467. }
  468. private void OnTouchBtnDeleteBegin()//删除
  469. {
  470. if (memoryHitGameObj.transform.name == RolePath)
  471. {
  472. return;
  473. }
  474. else if (memoryHitGameObj.transform.name == NpcPath)
  475. {
  476. SpriteRenderer spriteRenderer = memoryHitGameObj.transform.GetChild(0).GetComponent<SpriteRenderer>();
  477. if (spriteRenderer != null)
  478. {
  479. GameObject.Destroy(spriteRenderer);
  480. }
  481. }
  482. else
  483. {
  484. GameObject.DestroyImmediate(memoryHitGameObj);
  485. }
  486. _itemGameObjs.Remove(memoryHitGameObj);
  487. _ui.m_comSelectBox.target.visible = false;
  488. }
  489. private void OnTouchBtnDeleteEnd()
  490. {
  491. }
  492. private void SetUIView()
  493. {
  494. _ui.m_ComSelectRes.target.visible = true;
  495. _ui.m_comSelectBox.target.visible = false;
  496. hitGameObj = null;
  497. memoryHitGameObj = null;
  498. }
  499. private void OnClickBtnUp()
  500. {
  501. int index = _itemGameObjs.IndexOf(memoryHitGameObj);
  502. if (index < 0)
  503. {
  504. PromptController.Instance.ShowFloatTextPrompt("未选中任物品");
  505. return;
  506. }
  507. if (index == _itemGameObjs.Count - 1)
  508. {
  509. PromptController.Instance.ShowFloatTextPrompt("已经在最上层了");
  510. return;
  511. }
  512. GameObject gameObject = _itemGameObjs[index];
  513. _itemGameObjs.RemoveAt(index);
  514. _itemGameObjs.Insert((index + 1), gameObject);
  515. PhotographDataManager.Instance.SetLayer(memoryHitGameObj, (index + 1) * 100, "up");
  516. PhotographDataManager.Instance.SetLayer(_itemGameObjs[index], index * 100, "down");
  517. }
  518. private void OnClickBtnDown()
  519. {
  520. int index = _itemGameObjs.IndexOf(memoryHitGameObj);
  521. if (index < 0)
  522. {
  523. PromptController.Instance.ShowFloatTextPrompt("未选中任物品");
  524. return;
  525. }
  526. if (index == 0)
  527. {
  528. PromptController.Instance.ShowFloatTextPrompt("已经在最下层了");
  529. return;
  530. }
  531. GameObject gameObject = _itemGameObjs[index];
  532. _itemGameObjs.RemoveAt(index);
  533. _itemGameObjs.Insert((index - 1), gameObject);
  534. PhotographDataManager.Instance.SetLayer(memoryHitGameObj, (index - 1) * 100, "down");
  535. PhotographDataManager.Instance.SetLayer(_itemGameObjs[index], index * 100, "up");
  536. }
  537. private void OnClickBtnPhotograph()
  538. {
  539. _ui.target.visible = false;
  540. Timers.inst.StartCoroutine(ScreenShotTex());// ();
  541. }
  542. private IEnumerator ScreenShotTex()
  543. {
  544. _ui.target.visible = false;
  545. yield return new WaitForEndOfFrame();
  546. Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
  547. Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);//新建一个Texture2D对象
  548. tex.ReadPixels(rect, 0, 0);//读取像素,屏幕左下角为0点
  549. tex.Apply();//保存像素信息
  550. ViewManager.Show<PhotographSaveView>(tex);
  551. _ui.target.visible = true;
  552. }
  553. private void OnClickBtnBack()
  554. {
  555. this.Hide();
  556. // ViewManager.Show(ViewName.DRESS_UP_VIEW);
  557. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  558. }
  559. protected override void OnHide()
  560. {
  561. base.OnHide();
  562. if (_sceneObject != null)
  563. {
  564. GameObject.Destroy(_sceneObject);
  565. _sceneObject = null;
  566. }
  567. _equipSceneData.Clear();
  568. hitGameObj = null;
  569. memoryHitGameObj = null;
  570. pinchGesture.onAction.Remove(OnPinch);
  571. rotationGesture.onAction.Remove(OnRotate);
  572. pinchGesture = null;
  573. rotationGesture = null;
  574. }
  575. public override void Dispose()
  576. {
  577. if (_scenePrefab != null)
  578. {
  579. GameObject.Destroy(_scenePrefab);
  580. _scenePrefab = null;
  581. }
  582. base.Dispose();
  583. }
  584. protected override void UpdateToCheckGuide(object param)
  585. {
  586. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  587. GuideController.TryGuide(_ui.m_ComSelectRes.m_comBtnTab.m_btn2, ConstGuideId.PHOTOGRAPH, 4, "可以自由添加已有道具");
  588. GuideController.TryGuide(_ui.m_loaGuide, ConstGuideId.PHOTOGRAPH, 5, "点击空白处查看整体效果");
  589. GuideController.TryGuide(_ui.m_loaGuide1, ConstGuideId.PHOTOGRAPH, 6, "双指可控制放大缩小,或点击边框上的按键控制");
  590. GuideController.TryGuide(_ui.m_btnPhotograph, ConstGuideId.PHOTOGRAPH, 7, "点击拍照,可以记录和分享美照啦");
  591. GuideController.TryCompleteGuide(ConstGuideId.PHOTOGRAPH, 7);
  592. }
  593. }
  594. }