hch
2025-10-30 dc7922d80c1d133b6261b8af1d521567d2c0a35d
Main/Component/UI/Effect/BattleEffectPlayer.cs
@@ -30,11 +30,53 @@
        }
    }
    private Bone followedBone;
    public bool isBindBone = false;
    public bool isRedCamp = true;
    public EffectConfig effectConfig;
    public float speedRate = 1.5f;
    private float m_Alpha = 1f;
    public float Alpha
    {
        get
        {
            return m_Alpha;
        }
        set
        {
            if (value == m_Alpha)
                return;
            m_Alpha = value;
            OnAlphaChanged();
        }
    }
    private void OnAlphaChanged()
    {
        if (spineComp != null)
        {
            var skeleton = spineComp.Skeleton;
            skeleton.A = Alpha;
            spineComp.LateUpdate();
        }
        for (int i = 0; i < rendererList.Count; i++)
        {
            var renderer = rendererList[i];
            if (renderer != null && renderer.material != null && renderer.material.HasProperty("_Color"))
            {
                Color color = renderer.material.color;
                color.a = Alpha;
                renderer.material.color = color;
            }
        }
    }
    [Header("播放完毕立即回收")]
    public bool isReleaseImmediately = false;  //界面特效一般不需要自我销毁,跟随界面或者父对象销毁就行
@@ -58,8 +100,6 @@
    protected SkeletonAnimation spineComp;
    protected Spine.AnimationState spineAnimationState;
    protected int heroSetedSortingOrder;
    public GameObjectPoolManager.GameObjectPool pool;
    public Action onComplete;
@@ -70,11 +110,13 @@
    protected virtual void OnEnable()
    {
        if (spineComp != null)
        {
            //隐藏,会有静态显示问题
            spineComp.enabled = false;
        }
        // if (spineComp != null)
        // {
        //     //隐藏,会有静态显示问题
        //     spineComp.enabled = false;
        // }
        ApplySortingOrder();
    }
@@ -126,6 +168,8 @@
        {
            rectTrans.localScale *= effectConfig.effectScale;
        }
        spineComp.loop = effectConfig.isLoop != 0;
    }
    protected virtual void Clear()
@@ -159,24 +203,54 @@
        onComplete?.Invoke();
    }
    public void SetSortingOrder(int _heroSetedSortingOrder)
    public Func<bool> funcIsHeroFront;
    public void SetSortingOrder(Func<bool> _isHeroFrontCallback)
    {
        heroSetedSortingOrder = _heroSetedSortingOrder;
        funcIsHeroFront = _isHeroFrontCallback;
        int so = heroSetedSortingOrder;
        ApplySortingOrder();
    }
        if (null != blocker && effectConfig != null)
    public void ApplySortingOrder()
    {
        if (null != blocker && effectConfig != null && funcIsHeroFront != null)
        {
            if (BattleConst.UnactiveHeroSortingOrder == heroSetedSortingOrder)
            {
                so = effectConfig.frontBack == 1 ? BattleConst.UnactiveHeroFrontSortingOrder : BattleConst.UnactiveHeroBackSortingOrder;
            }
            else
            {
                so = effectConfig.frontBack == 1 ? BattleConst.ActiveHeroFrontSortingOrder : BattleConst.ActiveHeroBackSortingOrder;
            }
            bool isEffectFront = effectConfig.frontBack == 1;
            blocker.SetSortingOrder(so);
            bool isHeroFront = funcIsHeroFront();
            int finalSortingOrder = isHeroFront ?
                (isEffectFront ? BattleConst.ActiveHeroActionSortingOrder : BattleConst.ActiveHeroBackSortingOrder) : (isEffectFront ? BattleConst.UnactiveHeroFrontSortingOrder : BattleConst.UnactiveHeroBackSortingOrder);
            blocker.SetSortingOrder(finalSortingOrder);
        }
    }
    public void FollowBoneXY()
    {
        if (followedBone == null || !isBindBone)
        {
            return;
        }
        Vector2 vector2 = Vector2.zero;
        if (effectConfig.effectPos != null && effectConfig.effectPos.Length >= 2)
        {
            vector2 = new Vector2((isRedCamp ? 1f : -1f) * effectConfig.effectPos[0], effectConfig.effectPos[1]);
        }
        if (spineComp != null)
        {
            spineComp.transform.localPosition = new Vector3(followedBone.WorldX + vector2.x, followedBone.WorldY + vector2.y, 0);
        }
        if (effectTarget != null)
        {
            effectTarget.transform.localPosition = new Vector3(followedBone.WorldX + vector2.x, followedBone.WorldY + vector2.y, 0);
        }
    }
@@ -269,6 +343,7 @@
        {
            PlayUnityEffect();
        }
        OnAlphaChanged();
    }
    protected void PlaySpineEffect()
@@ -286,6 +361,8 @@
        spineComp.Initialize(true);
        spineComp.timeScale = speedRate;
        spineComp.skeleton.A = Alpha;
        spineAnimationState = spineComp.state;
        spineAnimationState.Complete -= OnSpineAnimationComplete;
        spineAnimationState.Complete += OnSpineAnimationComplete;
@@ -295,24 +372,11 @@
        blocker.onSortingChanged = OnSortingChanged;
        if (0 != heroSetedSortingOrder)
        {
            if (BattleConst.UnactiveHeroSortingOrder == heroSetedSortingOrder)
            {
                heroSetedSortingOrder = effectConfig.frontBack == 1 ? BattleConst.UnactiveHeroFrontSortingOrder : BattleConst.UnactiveHeroBackSortingOrder;
            }
            else
            {
                heroSetedSortingOrder = effectConfig.frontBack == 1 ? BattleConst.ActiveHeroFrontSortingOrder : BattleConst.ActiveHeroBackSortingOrder;
            }
            blocker.SetSortingOrder(heroSetedSortingOrder);
        }
        ApplySortingOrder();
        spineComp.enabled = true;
        spineComp.timeScale = speedRate;
        spineAnimationState.TimeScale = speedRate;
        Spine.Animation animation = spineAnimationState.Data.SkeletonData.Animations.First();
        spineAnimationState.SetAnimation(0, animation, effectConfig.isLoop != 0);
@@ -496,11 +560,6 @@
            spineComp.timeScale = 0f;
        }
        if (spineAnimationState != null)
        {
            spineAnimationState.TimeScale = 0f;
        }
        // Animator动画
        foreach (var animator in animatorList)
        {
@@ -521,11 +580,6 @@
        if (spineComp != null)
        {
            spineComp.timeScale = speedRate;
        }
        if (spineAnimationState != null)
        {
            spineAnimationState.TimeScale = speedRate;
        }
        // Animator动画
@@ -589,4 +643,31 @@
            animator.speed = speedRate;
        }
    }
    public void BindBone(SkeletonAnimation skeletonAnim, string v)
    {
        Bone bone = skeletonAnim.skeleton.FindBone(v);
        if (null == bone)
        {
             return;
        }
        isBindBone = true;
        followedBone = bone;
        BoneFollower boneFollower = gameObject.AddMissingComponent<BoneFollower>();
        boneFollower.boneName = v;
        boneFollower.skeletonRenderer = skeletonAnim;
        boneFollower.followBoneRotation = false;
        boneFollower.followXYPosition = true;
        boneFollower.followZPosition = false;
        boneFollower.followLocalScale = false;
        boneFollower.followParentWorldScale = false;
        boneFollower.followSkeletonFlip = false;
        boneFollower.Initialize();
        boneFollower.LateUpdate();
    }
}