EffectUI.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using FairyGUI;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class EffectUI
  7. {
  8. private GameObject _gameObject;
  9. private GoWrapper _wrapper;
  10. public bool Released;
  11. public void Reset(GGraph holder, string uiName, string resName, float scale = 100,
  12. EffectUIType effectUIType = EffectUIType.UI, Action onComplete = null)
  13. {
  14. if (!Released) Release();
  15. Released = false;
  16. string resPath;
  17. switch (effectUIType)
  18. {
  19. case EffectUIType.Card:
  20. resPath = ResPathUtil.GetCardAnimationPath(resName);
  21. break;
  22. default:
  23. resPath = ResPathUtil.GetViewEffectPath(uiName, resName);
  24. break;
  25. }
  26. PrefabManager.Instance.SpawnAsync(resPath, (go) =>
  27. {
  28. if (go == null)
  29. {
  30. onComplete?.Invoke(); // 即使失败也通知
  31. return;
  32. }
  33. _gameObject = go;
  34. _gameObject.transform.localScale = new Vector3(scale, scale, scale);
  35. _wrapper = new GoWrapper(_gameObject);
  36. holder.SetNativeObject(_wrapper);
  37. var obj = _gameObject.GetComponent<BoxCollider2D>();
  38. if (obj != null)
  39. {
  40. CardDataManager.CardResInitWidth = (int)(obj.size.x * 100);
  41. CardDataManager.CardResInitHight = (int)(obj.size.y * 100);
  42. holder.x = CardDataManager.CardResInitWidth / 2 - obj.offset.x * 100;
  43. holder.y = CardDataManager.CardResInitHight / 2 - obj.offset.y * 100;
  44. }
  45. onComplete?.Invoke();
  46. });
  47. }
  48. public void Release()
  49. {
  50. Released = true;
  51. if (_gameObject != null)
  52. {
  53. PrefabManager.Instance.Restore(_gameObject);
  54. //GameObject.DestroyImmediate(_gameObject);
  55. _gameObject = null;
  56. }
  57. if (_wrapper != null)
  58. {
  59. if (_wrapper.wrapTarget != null)
  60. {
  61. _wrapper.wrapTarget = null;
  62. }
  63. _wrapper.Dispose();
  64. _wrapper = null;
  65. }
  66. }
  67. public GameObject GetObj()
  68. {
  69. return _gameObject;
  70. }
  71. }
  72. }