PhotographView.cs 25 KB

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