Example #1
0
    /// <summary>
    /// 从缓存池里获取相应的特效
    /// </summary>
    /// <param name="name">特效名称</param>
    /// <returns></returns>
    public PSPool Find(string name)
    {
        name = name.ToLower().Replace("(clone)", "");
        PSPool psPool = null;

        for (int i = 0; i < _pools.Length; ++i)
        {
            if (_pools[i] != null)
            {
                if (_pools[i].TryGetValue(name, out psPool))
                {
                    break;
                }
            }
        }
        return(psPool);
    }
Example #2
0
    /// <summary>
    /// 回收特效
    /// </summary>
    /// <param name="ps"></param>
    public void Recycle(ParticleSystem ps)
    {
        if (ps == null)
        {
            EB.Debug.LogError("为什么是空的特效?回收呢");
            return;
        }
        PSPool psPool = Find(ps.name);

        if (psPool != null)
        {
            psPool.MoveToRecyle(ps, true);
        }
        else
        {
            Register(ps.gameObject, 0, Persistence.Temp);
        }
    }
Example #3
0
 /// <summary>
 /// 注册特效缓存
 /// </summary>
 /// <param name="psobject">将要缓存的对象</param>
 /// <param name="count">实例化次数</param>
 /// <param name="ePersistence">缓存类型</param>
 public void Register(GameObject psobject, int count, Persistence ePersistence)
 {
     if (psobject == null)
     {
         EB.Debug.LogPSPoolAsset("<color=#ff0000>为什么注册特效的对象是空的呢?</color>");
         return;
     }
     //
     if (_pools[(int)ePersistence] != null)
     {
         string name = psobject.name.ToLower().Replace("(clone)", "");
         PSPool pool = Find(name);
         if (pool == null)
         {
             _pools[(int)ePersistence][name] = new PSPool(psobject, count, ePersistence);
         }
     }
 }
Example #4
0
    /// <summary>
    /// 使用指定特效
    /// </summary>
    /// <param name="name">特效名称</param>
    /// <returns></returns>
    private ParticleSystem Use(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            return(null);
        }

        PSPool psPool = Find(name);

        if (psPool != null)
        {
            ParticleSystem ps = psPool.Use();
            if (ps != null)
            {
                //让他下面所有的对象都打开
                ps.name = name;
                var animators = ps.GetComponentsInChildren <Animator>(true);
                for (var i = 0; i < animators.Length; i++)
                {
                    animators[i].gameObject.CustomSetActive(true);
                }
                ps.transform.localPosition = Vector3.zero;
                ParticleSystem[] sys = ps.GetComponentsInChildren <ParticleSystem>();
                for (int i = 0; i < sys.Length; i++)
                {
                    if (sys[i] != null)
                    {
                        var main = sys[i].main;
                        main.scalingMode = ParticleSystemScalingMode.Hierarchy;
                    }
                }
            }
            return(ps);
        }

        return(null);
    }