DressUpObjUI.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using FairyGUI;
  2. using System;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class DressUpObjUI
  7. {
  8. public GameObject sceneObject;
  9. public GoWrapper wrapper;
  10. public DressUpObj dressUpObj;
  11. string prefabName;
  12. private Action onShowAction;
  13. public DressUpObjUI(string prefabName = "SceneDressUp", Action onShowAction = null)
  14. {
  15. this.prefabName = prefabName;
  16. this.onShowAction = onShowAction;
  17. dressUpObj = new DressUpObj();
  18. wrapper = new GoWrapper();
  19. }
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. /// <param name="scale"></param>
  24. /// <param name="needSetMask">如果UI界面的组件有遮罩,那么这里也需要设置为true才能生效</param>
  25. /// <param name="showSceneType">是否显示场景道具类型</param>
  26. /// <param name="roleObj"></param>
  27. /// <param name="showBg">是否显示背景</param>
  28. public void ResetSceneObj(int scale = 100, bool needSetMask = false, bool showSceneType = true, GameObject roleObj = null, bool showBg = true)
  29. {
  30. //这里每次都要实例化新的,复用会有bug
  31. sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath(this.prefabName));
  32. sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  33. dressUpObj.setSceneObj(sceneObject, needSetMask, showSceneType, roleObj, showBg, OnShow);
  34. }
  35. public void UpdateWrapper(GGraph holder)
  36. {
  37. holder.SetNativeObject(wrapper);
  38. wrapper.wrapTarget = sceneObject;
  39. }
  40. public void Dispose()
  41. {
  42. onShowAction = null;
  43. if (sceneObject != null)
  44. {
  45. PrefabManager.Instance.Restore(sceneObject);
  46. sceneObject = null;
  47. }
  48. if (dressUpObj != null)
  49. {
  50. dressUpObj.Dispose();
  51. dressUpObj = null;
  52. }
  53. if (wrapper != null)
  54. {
  55. if (wrapper.wrapTarget != null)
  56. {
  57. wrapper.wrapTarget = null;
  58. }
  59. wrapper.Dispose();
  60. wrapper = null;
  61. }
  62. }
  63. private void OnShow()
  64. {
  65. onShowAction?.Invoke();
  66. if (sceneObject == null)
  67. {
  68. return;
  69. }
  70. if(wrapper != null)
  71. {
  72. wrapper.wrapTarget = sceneObject;
  73. //wrapper.CacheRenderers();
  74. }
  75. }
  76. }
  77. }