hch
3 天以前 82769d5295e83e53ef79c64638829f56fa94b28b
0312 特效播放优化,描边
4个文件已修改
158 ■■■■ 已修改文件
Main/Component/UI/Core/OutlineEx.cs 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Component/UI/Effect/EffectPlayer.cs 128 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/ResModule/ResManager.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/HeroUI/HeroListWin.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Component/UI/Core/OutlineEx.cs
@@ -34,15 +34,23 @@
    private static List<UIVertex> m_VetexList = new List<UIVertex>();
    // 材质池:Key为"颜色_宽度"格式的字符串,Value为对应的材质; 减少合批问题,又能保持不同的描边;共用材质会同时改变参数
    private static Dictionary<string, Material> m_MaterialPool = new Dictionary<string, Material>();
    private static Shader m_Shader;
    static Shader m_tmpShader;
    private static Shader m_Shader
    {
        get
        {
            if (m_tmpShader == null)
            {
                m_tmpShader = Shader.Find("TSF Shaders/UI/OutlineEx");
            }
            return m_tmpShader;
        }
    }
    protected override void Start()
    {
        base.Start();
        if (m_Shader == null)
        {
            m_Shader = Shader.Find("TSF Shaders/UI/OutlineEx");
        }
        
        // 使用材质池获取或创建材质
        string key = GetMaterialKey(OutlineColor, OutlineWidth);
Main/Component/UI/Effect/EffectPlayer.cs
@@ -13,8 +13,17 @@
    public EffectConfig effectConfig;
    public Action<EffectPlayer> onDestroy;
    public Action onComplete;
    public float speedRate = 1f;
    [Header("是否在显示时播放")]
    public bool isPlayOnEnable = true;
    [Header("是否立即播放spine特效")]
    public bool isPlaySpineImmediately = false;
    [Header("是否循环播放spine特效")]
    public bool isPlaySpineLoop = false;
    [HideInInspector] public Canvas canvas = null;
@@ -31,23 +40,28 @@
    protected List<Renderer> rendererList = new List<Renderer>();
    protected SkeletonGraphic spineComp;
    protected Spine.AnimationState spineAnimationState;
    protected void Start()
    protected void OnEnable()
    {
        ReStart();
        if (isPlayOnEnable)
        {
            Play();
        }
    }
    protected void InitCompnent()
    protected bool InitCompnent()
    {
        if (effectId <= 0)
        {
            effectConfig = null;
            Debug.LogError("EffectPlayer effectId is not set");
#if UNITY_EDITOR
            UnityEditor.Selection.activeGameObject = gameObject;
            UnityEditor.EditorGUIUtility.PingObject(gameObject);
#endif
            return;
            // 根据逻辑需求,动态设置特效的情况
            // Debug.LogError("EffectPlayer effectId is not set");
            // #if UNITY_EDITOR
            //             UnityEditor.Selection.activeGameObject = gameObject;
            //             UnityEditor.EditorGUIUtility.PingObject(gameObject);
            // #endif
            return false;
        }
        effectConfig = EffectConfig.Get(effectId);
@@ -59,7 +73,7 @@
            UnityEditor.Selection.activeGameObject = gameObject;
            UnityEditor.EditorGUIUtility.PingObject(gameObject);
#endif
            return;
            return false;
        }
@@ -68,17 +82,21 @@
        rendererList.Clear();
        spineComp = null;
        //spine是加载文件,需要提前挂载脚本,unity特效是已经做好的预制体待加载后收集组件
        if (effectConfig.isSpine != 0)
        {
            spineComp = gameObject.GetComponentInChildren<SkeletonGraphic>(true);
            spineComp = gameObject.AddMissingComponent<SkeletonGraphic>();
        }
        else
        {
            //  收集组件
            particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
            animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
        }
        rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
        // else
        // {
        //     //  收集组件
        //     particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
        //     animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
        // }
        // rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
        return true;
    }
    public void Stop()
@@ -107,8 +125,16 @@
    {
        if (!isInit)
        {
            if (InitCompnent())
            {
            isInit = true;
            InitCompnent();
            }
            else
            {
                //根据逻辑需求,动态设置特效的情况
                return;
            }
        }
        if (EffectMgr.Instance.IsNotShowBySetting(effectId))
@@ -125,7 +151,41 @@
        //    YYL TODO
        //    在这里考虑用池的话可能走配置好一点 原本的是无论如何都走池 但是实际上有些特效并不需要
        // 加载特效资源
        // 加载spine特效资源
        if (effectConfig.isSpine != 0)
        {
            spineComp.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("UIEffect/" + effectConfig.packageName, effectConfig.fxName + "_SkeletonData");
            spineComp.raycastTarget = false;
            spineComp.Initialize(true);
            spineAnimationState = spineComp.AnimationState;
            spineAnimationState.Complete -= OnSpineAnimationComplete;
            spineAnimationState.Complete += OnSpineAnimationComplete;
            if (isPlaySpineImmediately)
            {
                //UI特效常用方式
                spineComp.enabled = true;
                // 播放第一个动画(作为默认动画)
                var skeletonData = spineComp.Skeleton.Data;
                if (skeletonData.Animations.Count > 0)
                {
                    string defaultAnimationName = skeletonData.Animations.Items[0].Name;
                    spineComp.AnimationState.SetAnimation(0, defaultAnimationName, isPlaySpineLoop);
                }
                else
                {
                    Debug.LogError("Spine 数据中没有找到任何动画!" + effectConfig.id);
                }
            }
            else
            {
                spineComp.enabled = false;
            }
            return;
        }
        //加载unity特效
        var effectPrefab = ResManager.Instance.LoadAsset<GameObject>("UIEffect/" + effectConfig.packageName, effectConfig.fxName);
        if (effectPrefab == null)
        {
@@ -136,6 +196,12 @@
        // 实例化特效
        effectTarget = Instantiate(effectPrefab, transform);
        effectTarget.name = $"Effect_{effectConfig.fxName}";
        //挂载组件后 开始收集
        particleList.AddRange(gameObject.GetComponentsInChildren<ParticleSystem>(true));
        animatorList.AddRange(gameObject.GetComponentsInChildren<Animator>(true));
        rendererList.AddRange(gameObject.GetComponentsInChildren<Renderer>(true));
        //  思考一下在没有挂在节点的时候
        if (null == canvas)
@@ -166,7 +232,29 @@
            onDestroy.Invoke(this);
            onDestroy = null;
        }
        if (spineAnimationState != null)
        {
            spineAnimationState.Complete -= OnSpineAnimationComplete;
    }
    }
    //单次播放完毕就会触发,即使是循环
    protected void OnSpineAnimationComplete(Spine.TrackEntry trackEntry)
    {
        if (!isPlaySpineLoop)
        {
            if (onComplete == null)
            {
                if (effectConfig.isSpine != 0)
                {
                    spineComp.enabled = false;
                }
            }
            onComplete?.Invoke();
        }
    }
    //  创建后的特效会自动隐藏 需要手动调用Play才能播放
    public static EffectPlayer Create(int effectId, Transform parent, bool createNewChild = false)
Main/ResModule/ResManager.cs
@@ -162,13 +162,13 @@
    public string[] LoadConfig(string name)
    {
        string path = string.Empty;
#if UNITY_EDITOR
        if (!AssetSource.isUseAssetBundle)
        {
#if UNITY_EDITOR
            path = ResourcesPath.CONFIG_FODLER + "/" + name + ".txt";
#endif
        }
        else
#endif
        {
            path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.txt");
        }
Main/System/HeroUI/HeroListWin.cs
@@ -56,7 +56,7 @@
    public override void Refresh()
    {
        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Item);
        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Hero);
        if (singlePack == null || singlePack.GetAllItems().Count <= 0)
        {
            heroListEmpty.SetActive(true);
@@ -73,6 +73,8 @@
        {
            attrOnList[i].text = PlayerPropertyConfig.GetFullDescription(new Int2 (PlayerPropertyConfig.baseAttrs[i], 1 ));
        }
        RefreshPakCount(PackType.Hero, 0, 0);
    }
    void OnRefreshCell(ScrollerDataType type, CellView cell)
@@ -96,7 +98,9 @@
    void RefreshPakCount(PackType type, int index, int itemID)
    {
        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Item);
        if (type != PackType.Hero)
            return;
        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Hero);
        if (singlePack == null)
            return;