PhotographView.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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. if (GuideDataManager.GetGuideCountCopy(ConstGuideId.PHOTOGRAPH) > 0)
  94. {
  95. _ui.m_loaGuide.enabled = false;
  96. _ui.m_loaGuide1.enabled = false;
  97. }
  98. else
  99. {
  100. _ui.m_loaGuide.enabled = true;
  101. _ui.m_loaGuide1.enabled = false;
  102. }
  103. // CreatTex();
  104. }
  105. /************************************************************UI界面*********************************************************/
  106. private void OnContorllerChanged(EventContext context)
  107. {
  108. int index = _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  109. RefreshList((EnumPhotographType)index);
  110. }
  111. private void RefreshList(EnumPhotographType index)
  112. {
  113. _ui.m_ComSelectRes.m_list.numItems = 0;
  114. _listData = PhotographDataManager.Instance.GetListData(index);
  115. _ui.m_ComSelectRes.m_list.numItems = _listData.Count;
  116. }
  117. private void RenderListItem(int index, GObject obj)
  118. {
  119. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listData[index]);
  120. string resPath = ResPathUtil.GetIconPath(itemCfg);
  121. UI_ListItem item = UI_ListItem.Proxy(obj);
  122. item.target.data = _listData[index];
  123. item.m_loaIcon.url = resPath;
  124. item.m_txtName.text = itemCfg.name;
  125. }
  126. private void OnListItemClick(EventContext context)
  127. {
  128. if (_itemGameObjs.Count >= MAX_COUNT)
  129. {
  130. PromptController.Instance.ShowFloatTextPrompt("最多穿戴" + MAX_COUNT + "件物品");
  131. return;
  132. }
  133. int itemID = (int)((context.data as GObject).data);
  134. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
  135. EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
  136. switch (type)
  137. {
  138. case EnumPhotographType.BG:
  139. UpdateBg(itemCfg);
  140. break;
  141. case EnumPhotographType.BORDER:
  142. if (_listData.IndexOf(itemID) == 0)
  143. {
  144. Transform tf = _sceneObject.transform.Find(BorderResPath);
  145. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  146. if (spr != null)
  147. {
  148. GameObject.Destroy(spr);
  149. }
  150. return;
  151. }
  152. UpdateBorder(itemCfg);
  153. break;
  154. case EnumPhotographType.NPC:
  155. UpdateNpc(itemCfg);
  156. break;
  157. case EnumPhotographType.SCENE:
  158. AddSceneItem(itemCfg, false);
  159. break;
  160. case EnumPhotographType.EFFECT:
  161. break;
  162. }
  163. }
  164. /************************************************************场景*********************************************************/
  165. private void OnTouchUIBegin(EventContext context)
  166. {
  167. context.CaptureTouch();
  168. if (_ui.m_ComSelectRes.target.visible == true) return;//添加道具不监听场景点击
  169. if (Stage.inst.touchCount > 1 && hitGameObj != null || Stage.inst.touchCount == 1 && context.inputEvent.touchId != 0) return;//两根手指&&两指不是同时按下||一根手指但属于中途换指
  170. if (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return;
  171. RaycastHit2D[] hit2Ds = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  172. if (hit2Ds.Length > 0)
  173. {
  174. lastPos = Vector2.zero;
  175. hitGameObj = SceneController.GetFirstHitObj(hit2Ds);
  176. _ui.m_comSelectBox.m_btnDelete.visible = true;
  177. if (hitGameObj.name == "Body")//主角不可删除
  178. {
  179. _ui.m_comSelectBox.m_btnDelete.visible = false;
  180. }
  181. _ui.m_comSelectBox.target.visible = false;
  182. if (hitGameObj.name != BgResName)//背景不可改动层级
  183. {
  184. hitGameObj = hitGameObj.transform.parent.gameObject;
  185. PhotographDataManager.Instance.SetItemLayer(hitGameObj, maxLayer);
  186. maxLayer = PhotographDataManager.Instance.GetMaxLayer(hitGameObj, maxLayer) + 1;
  187. _ui.m_comSelectBox.target.visible = true;
  188. if (!_equipDistance.ContainsKey(hitGameObj))
  189. {
  190. SceneController.SetGameObjectCenter(hitGameObj);
  191. }
  192. }
  193. memoryHitGameObj = hitGameObj;
  194. distance = Input.mousePosition - Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  195. Vector3 localEulerAngles = hitGameObj.transform.localEulerAngles;
  196. float rotation = 0;
  197. if (localEulerAngles.y == 0)
  198. {
  199. rotation = -hitGameObj.transform.localEulerAngles.z;
  200. }
  201. else
  202. {
  203. if (hitGameObj.transform.localEulerAngles.z > 180)
  204. {
  205. rotation = hitGameObj.transform.localEulerAngles.z - 360;
  206. }
  207. else
  208. {
  209. rotation = hitGameObj.transform.localEulerAngles.z;
  210. }
  211. }
  212. _ui.m_comSelectBox.target.rotation = rotation;// localEulerAngles.y != 0 ? hitGameObj.transform.localEulerAngles.z : -hitGameObj.transform.localEulerAngles.z;
  213. Debug.Log("rotation:" + _ui.m_comSelectBox.target.rotation + " " + _ui.m_comSelectBox.target.rotationX + " " + _ui.m_comSelectBox.target.rotationY);
  214. _ui.m_comSelectBox.target.size = SceneController.GetGameObjectSize(hitGameObj);
  215. ControllerSelectBoxPos();
  216. }
  217. }
  218. private void OnTouchUIMove(EventContext context)
  219. {
  220. if (hitGameObj == null) return;//未选中任何物体
  221. if (Stage.inst.touchCount > 1) return; //只监听1根手指
  222. if (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return;
  223. Debug.Log("拖动");
  224. ControllerObjectPos();
  225. ControllerSelectBoxPos();
  226. }
  227. private void OnTouchUIEnd(EventContext context)
  228. {
  229. // if (Stage.inst.touchCount > 1 || context.inputEvent.touchId != 0) return; //只监听1根手指
  230. hitGameObj = null;
  231. }
  232. //选中物体的位置
  233. private void ControllerObjectPos()
  234. {
  235. hitGameObj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition - distance);
  236. if (hitGameObj.name == BgResName)
  237. {
  238. PhotographDataManager.Instance.SetBgPos(hitGameObj, _ui.target.size);
  239. }
  240. }
  241. //选中框的位置
  242. private void ControllerSelectBoxPos()
  243. {
  244. Vector2 objScreenPos = Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
  245. Vector2 localPos = this.viewCom.GlobalToLocal(new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y)));
  246. _ui.m_comSelectBox.target.position = localPos;
  247. }
  248. private void OnTouchBtnSizeBegin(EventContext context)
  249. {
  250. InputEvent inputEvent = (InputEvent)context.data;
  251. Vector2 pt0 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
  252. Vector2 screenPos = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.m_btnSize.LocalToGlobal(Vector2.zero));
  253. Vector2 pt1 = new Vector2(screenPos.x, screenPos.y);
  254. Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
  255. lastDistance = Vector2.Distance(pt0, pt2);
  256. if (!_equipDistance.ContainsKey(memoryHitGameObj))
  257. {
  258. float distance = Vector2.Distance(pt1, pt2) / memoryHitGameObj.transform.localScale.x;
  259. Debug.Log("distance:" + distance + " pt1:" + pt1 + " pt2:" + pt2);
  260. _equipDistance.Add(memoryHitGameObj, distance);
  261. }
  262. }
  263. private void OnTouchBtnSizeMove(EventContext context)
  264. {
  265. if (memoryHitGameObj == null) return;
  266. InputEvent inputEvent = (InputEvent)context.data;
  267. Vector2 pt1 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
  268. Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
  269. Vector2 curPos = pt1 - pt2;
  270. float angle = Vector3.Angle(lastPos, curPos); //求出两向量之间的夹角
  271. Vector3 normal = Vector3.Cross(lastPos, curPos);//叉乘求出法线向量
  272. angle *= Mathf.Sign(Vector3.Dot(normal, Vector3.forward)); //Mathf.Sign()求符号,Vector3.Dot()求方向,求法线向量与物体上方向向量点乘,结果为1或-1,修正旋转方向
  273. lastPos = curPos;
  274. ControllerRotate(angle, memoryHitGameObj);
  275. float dist = Vector2.Distance(pt1, pt2);
  276. float ss = dist / lastDistance;
  277. Debug.Log("dist:" + dist + " lastDistance:" + lastDistance + " ss:" + ss);
  278. float newValue = Mathf.Clamp(ss * memoryHitGameObj.transform.localScale.x, 0.1f, 2);
  279. ControllerScale(newValue, memoryHitGameObj);
  280. if (newValue <= 0.1f) return;
  281. Debug.Log("ss:" + ss + " newValue:" + newValue);
  282. lastDistance = dist;
  283. Debug.Log("newValue:" + newValue);
  284. }
  285. private void OnTouchBtnSizeEnd(EventContext context)
  286. {
  287. lastPos = Vector2.zero;
  288. }
  289. //双指缩放
  290. private void OnPinch(EventContext context)
  291. {
  292. if (hitGameObj == null) return;
  293. if (hitGameObj.name == BgResName) return;//背景不可以缩放、旋转
  294. GTween.Kill(hitGameObj);
  295. PinchGesture gesture = (PinchGesture)context.sender;
  296. float newValue = Mathf.Clamp(hitGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
  297. Debug.Log("双指缩放:" + newValue);
  298. ControllerScale(newValue, hitGameObj);
  299. }
  300. //双指旋转
  301. private void OnRotate(EventContext context)
  302. {
  303. Debug.Log("双指旋转hitGameObj:" + hitGameObj);
  304. if (hitGameObj == null) return;
  305. Debug.Log("双指旋转name:" + hitGameObj.name);
  306. if (hitGameObj.name == BgResName) return;//背景不可以缩放、旋转
  307. // isTwoTouchPoint = true;
  308. GTween.Kill(hitGameObj.transform);
  309. RotationGesture gesture = (RotationGesture)context.sender;
  310. Debug.Log("双指旋转:" + gesture.delta);
  311. ControllerRotate(gesture.delta, hitGameObj);
  312. }
  313. private void ControllerScale(float value, GameObject gameObject)
  314. {
  315. if (value > MaxScale || value < MinScale) return;
  316. gameObject.transform.localScale = new Vector3(value, value, 1);
  317. Vector2 size = SceneController.GetGameObjectSize(gameObject);
  318. _ui.m_comSelectBox.target.size = size;
  319. // _ui.m_comSelectBox.target.SetSize(size.x, size.y);
  320. }
  321. private void ControllerRotate(float value, GameObject gameObject)
  322. {
  323. gameObject.transform.Rotate(Vector3.forward, -value, Space.World);
  324. _ui.m_comSelectBox.target.rotation += value;
  325. }
  326. private void UpdateBg(ItemCfg itemCfg)
  327. {
  328. Transform tf = _sceneObject.transform.Find(BgResPath);
  329. string resPath = ResPathUtil.GetDressUpPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
  330. SceneController.SetSpriteRendererToTransform(tf, resPath);
  331. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  332. spr.sortingOrder = ItemTypeCfgArray.Instance.GetCfg(ConstDressUpItemType.BEI_JING).defaultLayer;
  333. SceneController.SetBoxCollider2DToGameObject(tf.gameObject);
  334. }
  335. //主角
  336. private void UpdateBody()
  337. {
  338. GameObject bodyParent = _sceneObject.transform.Find(RolePath).gameObject;
  339. SceneController.UpdatePhotographBody(PhotographDataManager.Instance._equipRoleData.ToArray(), _sceneObject, bodyParent);
  340. _itemGameObjs.Add(bodyParent);
  341. maxLayer = PhotographDataManager.Instance.GetMaxLayer(bodyParent, maxLayer) + 1;
  342. }
  343. //添加初始场景道具
  344. private void UpdateScene()
  345. {
  346. ICollection keys = _equipSceneData.Keys;
  347. foreach (int key in keys)
  348. {
  349. for (int i = 0; i < _equipSceneData[key].Count; i++)
  350. {
  351. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(key);
  352. int defaultLayer = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType).defaultLayer;
  353. AddSceneItem(itemCfg, true);
  354. }
  355. }
  356. }
  357. private void UpdateNpc(ItemCfg itemCfg)
  358. {
  359. maxLayer++;
  360. Transform tf = _sceneObject.transform.Find(NpcResPath);
  361. string resPath = ResPathUtil.GetNpcPicFPath(itemCfg.res);
  362. SceneController.SetSpriteRendererToTransform(tf, resPath);
  363. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  364. spr.sortingOrder = maxLayer;
  365. tf.localPosition = new Vector2(-spr.bounds.center.x, -spr.bounds.center.y);
  366. SceneController.SetBoxCollider2DToGameObject(tf.gameObject);
  367. _itemGameObjs.Add(tf.parent.gameObject);
  368. }
  369. private void UpdateBorder(ItemCfg itemCfg)
  370. {
  371. Transform tf = _sceneObject.transform.Find(BorderResPath);
  372. string resPath = ResPathUtil.GetPhotographFPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
  373. SceneController.SetSpriteRendererToTransform(tf, resPath);
  374. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  375. spr.sortingOrder = 10000;//边框在所有道具的上边
  376. }
  377. private void UpdateEffect()
  378. {
  379. }
  380. private void AddSceneItem(ItemCfg itemCfg, bool isDefaultLayer)
  381. {
  382. int index = 0;
  383. GameObject parentGameObj;
  384. if (itemCfg.resLayer2 > 0)
  385. {
  386. if (!isDefaultLayer)
  387. {
  388. PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData);
  389. }
  390. index = _equipSceneData[itemCfg.id].Count - 1;
  391. parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 1));
  392. SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, 2, itemCfg.resLayer2);
  393. maxLayer = PhotographDataManager.Instance.GetMaxLayer(parentGameObj, maxLayer) + 1;
  394. _itemGameObjs.Add(parentGameObj);
  395. if (!isDefaultLayer)
  396. {
  397. PhotographDataManager.Instance.SetItemLayer(parentGameObj, maxLayer);
  398. }
  399. }
  400. if (itemCfg.resLayer1 > 0)
  401. {
  402. if (!isDefaultLayer)
  403. {
  404. PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData);
  405. }
  406. index = _equipSceneData[itemCfg.id].Count - 1;
  407. parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 0));
  408. SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, 1, itemCfg.resLayer1);
  409. maxLayer = PhotographDataManager.Instance.GetMaxLayer(parentGameObj, maxLayer) + 1;
  410. _itemGameObjs.Add(parentGameObj);
  411. if (!isDefaultLayer)
  412. {
  413. PhotographDataManager.Instance.SetItemLayer(parentGameObj, maxLayer);
  414. }
  415. }
  416. }
  417. private void OnClickBtnBg()
  418. {
  419. _ui.m_ComSelectRes.target.visible = false;
  420. // GuideController.TryGuideOpenPhotographView(null);
  421. }
  422. private void OnClickLoaGuide()
  423. {
  424. _ui.m_loaGuide1.enabled = true;
  425. _ui.m_loaGuide.enabled = false;
  426. _ui.m_ComSelectRes.target.visible = false;
  427. }
  428. private void OnClickLoaGuide1()
  429. {
  430. _ui.m_loaGuide1.enabled = false;
  431. _ui.m_ComSelectRes.target.visible = false;
  432. }
  433. private void OnTouchBtnFlipBegin()//翻转
  434. {
  435. Transform transform = memoryHitGameObj.transform;
  436. if (memoryHitGameObj.name == RoleName)
  437. {
  438. transform.Rotate(Vector3.up, 180, Space.Self);
  439. return;
  440. }
  441. for (int i = 0; i < transform.childCount; i++)
  442. {
  443. transform.GetChild(i).Rotate(Vector3.up, 180, Space.Self);
  444. }
  445. }
  446. private void OnTouchBtnFlipEnd()
  447. {
  448. }
  449. private void OnTouchBtnDeleteBegin()//删除
  450. {
  451. if (memoryHitGameObj.transform.name == RolePath)
  452. {
  453. return;
  454. }
  455. else if (memoryHitGameObj.transform.name == NpcPath)
  456. {
  457. SpriteRenderer spriteRenderer = memoryHitGameObj.transform.GetChild(0).GetComponent<SpriteRenderer>();
  458. if (spriteRenderer != null)
  459. {
  460. GameObject.Destroy(spriteRenderer);
  461. }
  462. }
  463. else
  464. {
  465. GameObject.DestroyImmediate(memoryHitGameObj);
  466. }
  467. _itemGameObjs.Remove(memoryHitGameObj);
  468. _ui.m_comSelectBox.target.visible = false;
  469. }
  470. private void OnTouchBtnDeleteEnd()
  471. {
  472. }
  473. private void SetUIView()
  474. {
  475. _ui.m_ComSelectRes.target.visible = true;
  476. _ui.m_comSelectBox.target.visible = false;
  477. hitGameObj = null;
  478. memoryHitGameObj = null;
  479. }
  480. private void OnClickBtnUp()
  481. {
  482. }
  483. private void OnClickBtnDown()
  484. {
  485. }
  486. private void OnClickBtnPhotograph()
  487. {
  488. _ui.target.visible = false;
  489. Timers.inst.StartCoroutine(ScreenShotTex());// ();
  490. }
  491. private IEnumerator ScreenShotTex()
  492. {
  493. _ui.target.visible = false;
  494. yield return new WaitForEndOfFrame();
  495. Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
  496. Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);//新建一个Texture2D对象
  497. tex.ReadPixels(rect, 0, 0);//读取像素,屏幕左下角为0点
  498. tex.Apply();//保存像素信息
  499. ViewManager.Show<PhotographSaveView>(tex);
  500. _ui.target.visible = true;
  501. }
  502. private void OnClickBtnBack()
  503. {
  504. this.Hide();
  505. // ViewManager.Show(ViewName.DRESS_UP_VIEW);
  506. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  507. }
  508. protected override void OnHide()
  509. {
  510. base.OnHide();
  511. if (_sceneObject != null)
  512. {
  513. GameObject.Destroy(_sceneObject);
  514. _sceneObject = null;
  515. }
  516. _equipSceneData.Clear();
  517. hitGameObj = null;
  518. memoryHitGameObj = null;
  519. pinchGesture.onAction.Remove(OnPinch);
  520. rotationGesture.onAction.Remove(OnRotate);
  521. pinchGesture = null;
  522. rotationGesture = null;
  523. }
  524. public override void Dispose()
  525. {
  526. if (_scenePrefab != null)
  527. {
  528. GameObject.Destroy(_scenePrefab);
  529. _scenePrefab = null;
  530. }
  531. base.Dispose();
  532. }
  533. protected override void UpdateToCheckGuide(object param)
  534. {
  535. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  536. GuideController.TryGuide(_ui.m_ComSelectRes.m_comBtnTab.m_btn2, ConstGuideId.PHOTOGRAPH, 4, "可以自由添加已有道具");
  537. GuideController.TryGuide(_ui.m_loaGuide, ConstGuideId.PHOTOGRAPH, 5, "点击空白处查看整体效果");
  538. GuideController.TryGuide(_ui.m_loaGuide1, ConstGuideId.PHOTOGRAPH, 6, "双指可控制放大缩小,或点击边框上的按键控制");
  539. GuideController.TryGuide(_ui.m_btnPhotograph, ConstGuideId.PHOTOGRAPH, 7, "点击拍照,可以记录和分享美照啦");
  540. GuideController.TryCompleteGuide(ConstGuideId.PHOTOGRAPH, 7);
  541. }
  542. }
  543. }