PhotographView.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using FairyGUI;
  2. using System;
  3. using UI.DressUp;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. namespace GFGGame
  7. {
  8. public class PhotographView : BaseView
  9. {
  10. private UI_PhotographUI _ui;
  11. private GameObject _scenePrefab;
  12. private GameObject _sceneObject;
  13. private DressUpObjDataCache equipDataCache;
  14. protected override void OnInit()
  15. {
  16. base.OnInit();
  17. packageName = UI_PhotographUI.PACKAGE_NAME;
  18. _ui = UI_PhotographUI.Create();
  19. viewCom = _ui.target;
  20. isfullScreen = true;
  21. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  22. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("ScenePhotograph"));
  23. }
  24. protected override void OnShown()
  25. {
  26. base.OnShown();
  27. // Debug.Log("Length:" + EquipDataCache.cacher.equipDatas.Length);
  28. // Debug.Log("bgId:" + EquipDataCache.cacher.bgId);
  29. // Debug.Log("suitId:" + EquipDataCache.cacher.suitId);
  30. if (_sceneObject == null)
  31. {
  32. _sceneObject = GameObject.Instantiate(_scenePrefab);
  33. // _sceneObject.sortingOrder = 1000;
  34. EquipDataCache.cacher.setSceneObj(_sceneObject);
  35. }
  36. equipDataCache = EquipDataCache.cacher;
  37. UpdateBg();
  38. UpdateBody();
  39. Timers.inst.Add(0.001f, 0, OnClickListener);
  40. }
  41. private void OnClickListener(object param)
  42. {
  43. // Debug.Log("点击鼠标:" + Input.GetMouseButtonDown(0));
  44. if (Input.GetMouseButtonDown(0))
  45. {
  46. if (Stage.isTouchOnUI) //点在了UI上
  47. {
  48. Debug.Log("点击UI");
  49. }
  50. else //没有点在UI上
  51. {
  52. Debug.Log("点击场景");
  53. }
  54. //从摄像机发出到点击坐标的射线
  55. RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  56. Vector2 pos = Input.mousePosition;
  57. // Debug.Log("pos:" + pos);
  58. if (hit.collider != null)
  59. {
  60. //划出射线,只有在scene视图中才能看到
  61. // Debug.DrawLine(ray.origin, hitInfo.point, Color.red);
  62. GameObject gameObj = hit.collider.gameObject;
  63. Debug.Log("click object name is :" + gameObj.name);
  64. //当射线碰撞目标为boot类型的物品,执行拾取操作
  65. if (gameObj.tag == "boot")
  66. {
  67. Debug.Log("pickup!");
  68. }
  69. }
  70. }
  71. }
  72. //背景
  73. private void UpdateBg()
  74. {
  75. Transform tf = _sceneObject.transform.Find("Bg");
  76. SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
  77. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(equipDataCache.bgId);
  78. var resPath = ResPathUtil.GetDressUpPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
  79. Sprite sp = GFGAsset.Load<Sprite>(resPath);
  80. DressUpUtil.AddAssetReleaser(tf.gameObject, resPath);
  81. spr.sprite = sp;
  82. int[] bgId = { equipDataCache.bgId };
  83. GameObject obj = _sceneObject.transform.Find("Bg").gameObject;
  84. SceneController.UpdateRole(bgId, _sceneObject, false, null, false, obj);
  85. SetObjSize(obj.transform.GetChild(0).gameObject);
  86. }
  87. private void SetObjSize(GameObject obj)
  88. {
  89. obj.AddComponent<BoxCollider2D>();
  90. }
  91. //主角
  92. private void UpdateBody()
  93. {
  94. // CustomSuitData suitSavedData = CustomSuitDataManager.GetCurrentSuitList();
  95. int[] equipDatas = equipDataCache.equipDatas;
  96. SceneController.UpdateRole(equipDatas, _sceneObject, false, null, false);
  97. if (equipDataCache.IsSuitPic && equipDataCache.suitId > 0)
  98. {
  99. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(equipDataCache.suitId);
  100. DressUpUtil.UpdateBody(suitCfg.picRes, _sceneObject);
  101. }
  102. }
  103. //合照NPC
  104. private void UpdateNpc()
  105. {
  106. }
  107. //场景道具
  108. private void UpdateScene()
  109. {
  110. }
  111. //边框
  112. private void UpdateBorder()
  113. {
  114. }
  115. //滤镜效果
  116. private void UpdateEffect()
  117. {
  118. }
  119. private void OnClickBtnBack()
  120. {
  121. this.Hide();
  122. // ViewManager.Show(ViewName.DRESS_UP_VIEW);
  123. EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
  124. }
  125. protected override void OnHide()
  126. {
  127. base.OnHide();
  128. if (_sceneObject != null)
  129. {
  130. GameObject.Destroy(_sceneObject);
  131. _sceneObject = null;
  132. }
  133. equipDataCache = null;
  134. }
  135. public override void Dispose()
  136. {
  137. if (_scenePrefab != null)
  138. {
  139. GameObject.Destroy(_scenePrefab);
  140. _scenePrefab = null;
  141. }
  142. base.Dispose();
  143. }
  144. }
  145. }