hch
2025-10-17 cb653cf75b17b9bdca0b5b9e6b88edf1ca72e90c
Main/Component/UI/Effect/EffectMgr.cs
@@ -1,35 +1,17 @@
using vnxbqy.UI;
using UnityEngine;
using UnityEngine;
public class EffectMgr : SingletonMonobehaviour<EffectMgr>
public class EffectMgr
{
    public UIEffectBehaviour GetUIEffect(int id, bool _destroy = false)
    {
        var _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect", id.ToString());
        if (_prefab == null)
        {
            return null;
        }
        GameObjectPoolManager.GameObjectPool _pool = GameObjectPoolManager.Instance.RequestPool(_prefab);
        _prefab = _pool.Request();
        var _effect = _prefab.GetComponent<UIEffect>();
        if (_effect != null && _destroy)
        {
            Destroy(_effect);
        }
        var _behaviour = _prefab.AddMissingComponent<UIEffectBehaviour>();
        return _behaviour;
    }
    //玩家是否主动屏蔽了特效
    public bool IsNotShowBySetting(int id)
    public static bool IsNotShowBySetting(int id)
    {
        var config = EffectConfig.Get(id);
        if (config == null)
        {
#if UNITY_EDITOR
            Debug.LogError("特效配置表中没有找到id为" + id + "的特效");
            if (id != 0)
                Debug.LogError("特效配置表中没有找到id为" + id + "的特效");
#endif
            return true;
        }
@@ -40,83 +22,5 @@
        return false;
    }
    public UIEffect PlayUIEffect(int id, int renderQueue, Transform parent, bool loop)
    {
        if (IsNotShowBySetting(id))
            return null;
        UIEffectBehaviour _behaviour = GetUIEffect(id);
        UIEffect uieffect = null;
        if (_behaviour != null)
        {
            _behaviour.SetActive(false);
            _behaviour.transform.SetParent(parent);
            uieffect = _behaviour.AddMissingComponent<UIEffect>();
            uieffect.target = _behaviour;
            SetUIEffect(uieffect, id, renderQueue, loop, Vector3.zero, Vector3.zero);
            uieffect.Active();
        }
        return uieffect;
    }
    public UIEffect PlayUIEffect(int id, int renderQueue, Transform parent, Vector3 _localPos, Vector3 _localRot, bool loop)
    {
        if (IsNotShowBySetting(id))
            return null;
        UIEffectBehaviour _behaviour = GetUIEffect(id);
        UIEffect uieffect = null;
        if (_behaviour != null)
        {
            _behaviour.SetActive(false);
            _behaviour.transform.SetParent(parent);
            uieffect = _behaviour.AddMissingComponent<UIEffect>();
            uieffect.target = _behaviour;
            SetUIEffect(uieffect, id, renderQueue, loop, _localPos, _localRot);
            uieffect.Active();
        }
        return uieffect;
    }
    public UIEffect PlayUIEffect(int id, int renderQueue, Vector3 _localPos, bool loop = false)
    {
        if (IsNotShowBySetting(id))
            return null;
        UIEffectBehaviour _behaviour = GetUIEffect(id);
        UIEffect uieffect = null;
        if (_behaviour != null)
        {
            _behaviour.SetActive(false);
            //  TODO YYL
            // _behaviour.transform.SetParent(WindowCenter.Instance.uiRoot.baseCanvas);
            uieffect = _behaviour.AddMissingComponent<UIEffect>();
            uieffect.target = _behaviour;
            SetUIEffect(uieffect, id, renderQueue, loop, _localPos, Vector3.zero);
            uieffect.Active();
        }
        return uieffect;
    }
    private void SetUIEffect(UIEffect effect, int id, int renderQueue, bool loop, Vector3 _localPos, Vector3 _localRot)
    {
        effect.effect = id;
        effect.renderQueue = renderQueue;
        effect.loop = loop;
        effect.effectPos = _localPos;
        effect.effectRot = _localRot;
    }
    public void RecyleUIEffect(int id, GameObject _effectObj)
    {
        var _prefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect", id.ToString());
        _effectObj.SetActive(false);
        if (_prefab == null)
        {
            return;
        }
        GameObjectPoolManager.GameObjectPool _pool = GameObjectPoolManager.Instance.RequestPool(_prefab);
        if (_pool != null)
        {
            _pool.Release(_effectObj);
        }
    }
}