UnityParticleSystem特效进步同步的问题

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ParticleSystemTest : MonoBehaviour
{
    public ParticleSystem[] particleSystems;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //处理同类特效 不同时间创建时 需要跟前面得特效进步同步的问题
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            particleSystems[0].gameObject.SetActive(true);       
            particleSystems[0].Simulate(0.1f);
            //API解释https://blog.csdn.net/SmillCool/article/details/127070139
            particleSystems[0].Play();
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            particleSystems[1].gameObject.SetActive(true);
            //特效跟随到特效索引0的进度
            particleSystems[1].Simulate(particleSystems[0].time);
            //从此进度开始一起播放
            particleSystems[1].Play();
        }

        /**
         * 以下是lua代码
            
        --增加需要关心得特效
        function _M:AddItemEffect(effect)
	        if	not self.mCareEffectList then
		        self.mCareEffectList = {effect}
		        self:UpdateReferenceEffect(effect)
	        else
		        table.insert(self.mCareEffectList,effect)
	        end
        end

        --更新参照得特效
        function _M:UpdateReferenceEffect(effect)
	        self.mReferenceEffect = effect
        end

        --- 刷新特效进度
        function _M:RefreshParticeSystemSimulate()
	        if not self.mScrollReward then	return	end
	        if not self.mReferenceEffect then	return	end
	        for i, effect in ipairs(self.mCareEffectList) do
		        effect:SyncSimulateProcess(self.mReferenceEffect)
	        end
        end
         
         */

        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            particleSystems[2].gameObject.SetActive(true);
            particleSystems[2].Simulate(particleSystems[0].time);
            particleSystems[2].Play();
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            particleSystems[3].gameObject.SetActive(true);
            particleSystems[3].Simulate(particleSystems[0].time);
            particleSystems[3].Play();
        }
    }
}

UnityParticleSystem特效进步同步的问题_第1张图片

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Game.UI;
using Game.Framework;
using UnityEngine.UI;
using Youda.Game;

//namespace Youda.Game
//{

public class SimulateEffectMgr :MonoBehaviour
    {

        public EffectBase ReferenceEffectBase;
        public List EffectBasesList = new List();

        public void AddEffectBasesList(EffectBase effectBase)
        {
            EffectBasesList.Add(effectBase);
        }

        public void SetReferenceEffectBase(EffectBase effectBase)
        {
            ReferenceEffectBase = effectBase;
        }


        private void Update()
        {
            if (ReferenceEffectBase)
            {
                //ReferenceEffectBase.SimulateProcessUnscaledDeltaTime();
                foreach (EffectBase item in EffectBasesList)
                {
                    item.SyncAllSimulateProcess(ReferenceEffectBase);
                }
            }
        }
        private void OnDestroy()
        {
            EffectBasesList.Clear();
            ReferenceEffectBase = null;
        }
    }
//}
 public class EffectBase : EntityBase
    {

        //所有粒子系统
        protected ParticleSystem[] ParticleList;

        public void SyncAllSimulateProcess(EffectBase effectBase)
        {
            //必须需要是根节点特效 这样子节点才能 一起进度同步
            for (int index = 0; index < 1; index++)
            {
                if (ParticleList[index].time != effectBase.GetParticleSystem(index).time)
                {
                    ParticleList[index].Simulate(effectBase.GetParticleSystem(index).time);
                    ParticleList[index].Play();
                }
            }
        }



        /// 
        /// 获取索引特效
        /// 
        /// 
        /// 
        public ParticleSystem GetParticleSystem(int index = 0)
        {
            return ParticleList[index];
        }
    }

你可能感兴趣的:(junit,unity,特效同步)