hch
8 天以前 303f5970d2bef26905c9d6d471cd13f41bc722a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections;
using System.Collections.Generic;
using Spine.Unity;
using UnityEngine;
using Spine;
using UnityEngine.UI;
using Cysharp.Threading.Tasks;
 
//UI特效播放器,spine特效直接加载无需提前做预制体
//UI特效大部分情况不会改变特效,无需销毁
public class UIEffectPlayer : EffectPlayer
{
 
    
    //spine里的第几个动画
    public void Play(int index, bool showLog = true)
    {
        playSpineAnimIndex = index;
        PlayAsync(showLog).Forget();
    }
 
    //配置动画组数组索引
    public void PlayByArrIndex(int index, bool showLog = true)
    {
        var config = EffectConfig.Get(effectId);
        playSpineAnimIndex = config.animIndex[index];
        PlayAsync(showLog).Forget();
    }
 
 
    //  创建后的特效会自动隐藏 需要手动调用Play才能播放
    public static UIEffectPlayer CreateEffect(int effectId, Transform parent, bool createNewChild = false)
    {
        UIEffectPlayer effectPlayer = null;
 
        if (createNewChild)
        {
            GameObject newGo = new GameObject("EffectPlayer_" + effectId);
            newGo.transform.SetParent(parent, false);
            effectPlayer = newGo.AddComponent<UIEffectPlayer>();
        }
        else
        {
            effectPlayer = parent.AddMissingComponent<UIEffectPlayer>();
            effectPlayer.effectId = effectId;
        }
        effectPlayer.SetActive(true);
        return effectPlayer;
    }
 
 
}