Пример #1
0
    public void Load(SfxFile effectFile, bool once = false, bool preload = false)
    {
        loop = !once;
        file = effectFile.strfile;
        var effectList = effectFile.effectList;

        playedTime = 0.0f;
        //必须看一下信息,才知道创建什么大小的预设,主要是网格可能大小不一样
        SortedDictionary <int, SFXUnit> dic = new SortedDictionary <int, SFXUnit>();

        for (int i = 0; i < effectList.Count; i++)
        {
            GameObject objSfx = null;
            SFXUnit    sfx    = null;
            if (effectList[i].EffectType == "AUDIO")
            {
                audioList.Add(effectList[i]);
            }
            else if (effectList[i].EffectType == "BILLBOARD")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
                //sfx.Init(effectList[i], this, i);
            }
            else if (effectList[i].EffectType == "BOX")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
                //sfx.Init(effectList[i], this, i);
            }
            else if (effectList[i].EffectType == "PLANE")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
                //sfx.Init(effectList[i], this, i);
            }
            else if (effectList[i].EffectType == "DONUT")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
                //sfx.Init(effectList[i], this, i);
            }
            else if (effectList[i].EffectType == "MODEL")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
                //sfx.Init(effectList[i], this, i);
            }
            else if (effectList[i].EffectType == "SPHERE")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
                //sfx.Init(effectList[i], this, i);
            }
            else if (effectList[i].EffectType == "PARTICLE")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
                //sfx.Init(effectList[i], this, i);
            }
            else if (effectList[i].EffectType == "CYLINDER")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();
            }
            else if (effectList[i].EffectType == "DRAG")
            {
                objSfx = Instantiate(SfxUnit);
                sfx    = objSfx.GetComponent <SFXUnit>();

                //sfx.Init(effectList[i], this, i);
            }
            else
            {
                Debug.LogError("can not recognize");
            }

            if (sfx != null)
            {
                dic.Add(i, sfx);
                //特效可以非角色发出.
                if (owner != null)
                {
                    owner.AddAttackSFX(sfx);//因为这个特效可以做攻击
                }
                sfx.name = effectList[i].EffectName;
            }
        }

        //第一次先创建,再初始化,否则先初始化的,如果要挂到后初始化的上面,会找不到对象
        foreach (var each in dic)
        {
            if (each.Value != null)
            {
                played.Add(each.Value);
            }
        }

        //分2次循环,第一次让前面的可以找到后面的,第二次都开始初始化,就可以互相引用了
        foreach (var each in dic)
        {
            if (each.Value != null)
            {
                each.Value.Init(effectList[each.Key], this, each.Key, 0, preload);
            }
        }
        if (audioList.Count != 0)
        {
            audioUpdate = true;
        }
    }