예제 #1
0
        public void TriggerEffect(Vector2 positionOfTrigger, ParticleEffectType effectType, float scale)
        {
            //    if (!_particleEffects.ContainsKey(effectType))
            //    {
            //        ConsoleManager.WriteLine("Error: effect type " + effectType.ToString() + " not found in particle effects container. Be sure to add it in the ParticleEffectManager constructior.", ConsoleMessageType.Error);
            //    }

            //    switch (effectType)
            //    {
            //        case ParticleEffectType.GlowEffect:
            //            for (int i = 0; i < _particleEffects[ParticleEffectType.GlowEffect].Count; i++)
            //            {
            //                ParticleEmitter glowEmitter = _particleEffects[ParticleEffectType.GlowEffect][i];
            //                glowEmitter.ReleaseScale = scale;
            //                _particleEffects[ParticleEffectType.GlowEffect][i] = glowEmitter;
            //            }
            //            _particleEffects[ParticleEffectType.GlowEffect].Trigger(positionOfTrigger);
            //            break;
            //        default:
            //            {
            //                _particleEffects[effectType].Trigger(positionOfTrigger);
            //                break;
            //            }
            //    }
        }
    //粒子特效演出(多載2/2) ※額外參數
    //[input] type = 特效種類 , pos = 位置, isWorld = true:世界座標/false:本地座標
    public void OneShotEffect(ParticleEffectType type, Vector2 pos, bool isWorld, object param)
    {
        GameObject go = ExtractFromPool(type); //從物件池中取得物件

        if (isWorld)
        {
            go.transform.position = pos;          //指定特效發生位置
        }
        else
        {
            go.transform.localPosition = pos;  //指定特效發生位置
        }
        //尋找粒子特效物件是否有額外行為
        foreach (IExtensibleParticle i in go.GetComponentsInChildren <IExtensibleParticle>())
        {
            i.Initialize(param);
        }

        foreach (ParticleSystemRenderer renderer in go.GetComponentsInChildren <ParticleSystemRenderer>()) //設定顯示層級
        {
            renderer.sortingOrder = parentRect.GetComponentInParent <Canvas>().sortingOrder;
        }

        go.GetComponent <ParticleSystem>().Play(); //執行特效
    }
예제 #3
0
    public void StopEffect(ParticleEffectType effectType)
    {
        var effectGO = _particleEffects.SingleOrDefault(x => x.GetComponent <ParticleEffect>().EffectType == effectType);
        var effect   = effectGO.GetComponent <ParticleSystem>();

        effect.Stop();
    }
예제 #4
0
 public ParticleEffect AddEffect(ParticleEffectType type, Func<ParticleEffect, Location> start, Func<ParticleEffect, Location> end,
     Func<ParticleEffect, float> fdata, float ttl, Location color, Location color2, bool fades, Texture texture, float salpha = 1)
 {
     ParticleEffect pe = new ParticleEffect(TheClient) { Type = type, Start = start, End = end, FData = fdata, TTL = ttl, O_TTL = ttl, Color = color, Color2 = color2, Alpha = salpha, Fades = fades, texture = texture };
     ActiveEffects.Add(pe);
     return pe;
 }
예제 #5
0
    public void CreateAndPlayEffect(ParticleEffectType effectType, GameObject parent)
    {
        var go     = InstantiateEffectPrefab(effectType);
        var effect = go.GetComponent <ParticleSystem>();

        AttachParticleToGameObject(go, parent);
        effect.Play();
    }
예제 #6
0
    public void CreateAndPlayEffect(ParticleEffectType effectType)
    {
        var go     = InstantiateEffectPrefab(effectType);
        var effect = go.GetComponent <ParticleSystem>();

        effect.Play();
        GameObject.Destroy(go, effect.main.duration);
    }
예제 #7
0
        public void SetPoolSize(ParticleEffectType type, int poolSize)
        {
            if (m_prefabs.ContainsKey(type))
            {
                throw new System.ArgumentException(string.Format("type {0} is not registered", type));
            }

            m_pools[type].SetPoolSize(poolSize);
        }
예제 #8
0
        public ParticleEffect Acquire(ParticleEffectType type)
        {
            if (!m_pools.ContainsKey(type))
            {
                return(null);
            }

            return(m_pools[type].Acquire());
        }
예제 #9
0
 public LaserWaveProjectileStats()
 {
     Lifetime       = 4000;
     BaseSpeed      = 5;
     Texture        = TextureManager.Laser;
     DrawEffectType = ParticleEffectType.LaserWaveEffect;
     DrawPeriod     = 40;
     ProjectileType = ProjectileTypes.LaserWave;
     ZeroFraction   = .25f;
 }
 /// <summary>
 /// Remove the given particle-effect type from the maanger.
 /// </summary>
 /// <param name="effectType">The enumeration to be cleared against.</param>
 public void UnregisterParticleEffect(ParticleEffectType effectType)
 {
     if (particleEffectCache.ContainsKey(effectType) == true)
     {
         for (int i = 0; i < particleEffectCache[effectType].Count; ++i)
         {
             activeParticleEffects.Remove(particleEffectCache[effectType][i]);
         }
         particleEffectCache.Remove(effectType);
     }
 }
예제 #11
0
        public ParticleEffect AddEffect(ParticleEffectType type, Func <ParticleEffect, Location> start, Func <ParticleEffect, Location> end,
                                        Func <ParticleEffect, float> fdata, float ttl, Location color, Location color2, bool fades, Texture texture, float salpha = 1)
        {
            ParticleEffect pe = new ParticleEffect(TheClient)
            {
                Type = type, Start = start, End = end, FData = fdata, TTL = ttl, O_TTL = ttl, Color = color, Color2 = color2, Alpha = salpha, Fades = fades, texture = texture
            };

            ActiveEffects.Add(pe);
            return(pe);
        }
        /// <summary>
        /// Spawn a new particle effect at a the position of a given gameplay object
        /// </summary>
        /// <param name="effectType">The effect in question.</param>
        /// <param name="actor">The gameplay object.</param>
        /// <returns>The new particle effect.</returns>
        public ParticleEffect SpawnEffect(ParticleEffectType effectType,
                                          GameplayObject gameplayObject)
        {
            // safety-check the parameter
            if (gameplayObject == null)
            {
                throw new ArgumentNullException("gameplayObject");
            }

            return(SpawnEffect(effectType, gameplayObject.Position, gameplayObject));
        }
예제 #13
0
    public void PlayEffect(ParticleEffectType effectType, bool onLoop = false, float?startSpeed = null)
    {
        var effectGO = _particleEffects.SingleOrDefault(x => x.GetComponent <ParticleEffect>().EffectType == effectType);
        var effect   = effectGO.GetComponent <ParticleSystem>();

        var main = effect.main; //I dont understand why I have to do this.

        main.loop = onLoop;     // but I can't just call effect.main.loop, because it's stupid

        if (startSpeed.HasValue)
        {
            main.startSpeed = startSpeed.Value;
        }

        effect.Play();
    }
 /// <summary>
 /// Register a new type of particle effect with the manager.
 /// </summary>
 /// <param name="effectType">The enumeration associated with this type.</param>
 /// <param name="filename">The path to the XML file to be deserialized.</param>
 /// <param name="initialCount">How many of these to pre-create.</param>
 public void RegisterParticleEffect(ParticleEffectType effectType,
     string filename, int initialCount)
 {
     if (!particleEffectCache.ContainsKey(effectType))
     {
         ParticleEffect particleEffect = ParticleEffect.Load(filename);
         particleEffect.Initialize(contentManager);
         particleEffect.Stop(true);
         particleEffectCache.Add(effectType, new List<ParticleEffect>());
         particleEffectCache[effectType].Add(particleEffect);
         for (int i = 1; i < initialCount; i++)
         {
             ParticleEffect cloneEffect = particleEffect.Clone();
             cloneEffect.Initialize(contentManager);
             cloneEffect.Stop(true);
             particleEffectCache[effectType].Add(cloneEffect);
         }
     }
 }
 /// <summary>
 /// Register a new type of particle effect with the manager.
 /// </summary>
 /// <param name="effectType">The enumeration associated with this type.</param>
 /// <param name="filename">The path to the XML file to be deserialized.</param>
 /// <param name="initialCount">How many of these to pre-create.</param>
 public void RegisterParticleEffect(ParticleEffectType effectType,
                                    string filename, int initialCount)
 {
     if (!particleEffectCache.ContainsKey(effectType))
     {
         string         filepath       = Path.Combine(contentManager.RootDirectory, filename);
         ParticleEffect particleEffect = ParticleEffect.Load(filepath);
         particleEffect.Initialize(contentManager);
         particleEffect.Stop(true);
         particleEffectCache.Add(effectType, new List <ParticleEffect>());
         particleEffectCache[effectType].Add(particleEffect);
         for (int i = 1; i < initialCount; i++)
         {
             ParticleEffect cloneEffect = particleEffect.Clone();
             cloneEffect.Initialize(contentManager);
             cloneEffect.Stop(true);
             particleEffectCache[effectType].Add(cloneEffect);
         }
     }
 }
        /// <summary>
        /// Spawn a new particle effect at a given location and gameplay object
        /// </summary>
        /// <param name="effectType">The effect in question.</param>
        /// <param name="position">The position of the effect.</param>
        /// <param name="actor">The gameplay object.</param>
        /// <returns>The new particle effect.</returns>
        public ParticleEffect SpawnEffect(ParticleEffectType effectType,
                                          Vector2 position, GameplayObject gameplayObject)
        {
            ParticleEffect particleEffect = null;

            if (particleEffectCache.ContainsKey(effectType) == true)
            {
                List <ParticleEffect> availableSystems = particleEffectCache[effectType];

                for (int i = 0; i < availableSystems.Count; ++i)
                {
                    if (availableSystems[i].Active == false)
                    {
                        particleEffect = availableSystems[i];
                        break;
                    }
                }

                if (particleEffect == null)
                {
                    particleEffect = availableSystems[0].Clone();
                    particleEffect.Initialize(contentManager);
                    availableSystems.Add(particleEffect);
                }
            }

            if (particleEffect != null)
            {
                particleEffect.Reset();
                particleEffect.GameplayObject = gameplayObject;
                particleEffect.Position       = position;
                activeParticleEffects.Add(particleEffect);
            }

            return(particleEffect);
        }
        /// <summary>
        /// Spawn a new particle effect at a the position of a given gameplay object
        /// </summary>
        /// <param name="effectType">The effect in question.</param>
        /// <param name="actor">The gameplay object.</param>
        /// <returns>The new particle effect.</returns>
        public ParticleEffect SpawnEffect(ParticleEffectType effectType,
            GameplayObject gameplayObject)
        {
            // safety-check the parameter
            if (gameplayObject == null)
            {
                throw new ArgumentNullException("gameplayObject");
            }

            return SpawnEffect(effectType, gameplayObject.Position, gameplayObject);
        }
    //從物件池中抽取物件
    private GameObject ExtractFromPool(ParticleEffectType effectType)
    {
        if (dic_effectTypeIndex == null)
        {
            dic_effectTypeIndex = new Dictionary <ParticleEffectType, int>(); //建立字典
        }
        if (!dic_effectTypeIndex.ContainsKey(effectType))                     //若指定的粒子特效尚未存在物件池
        {
            int _index = particleEffectPool.Count;                            //註冊一個索引值給預備建立的特效種類
            dic_effectTypeIndex.Add(effectType, _index);                      //建立字典儲存 ParticleEffectType ⇔ 索引值

            particleEffectPool.Add(new List <GameObject>());                  //拓寬物件池, 用以儲存新的特效種類物件池
        }

        GameObject go = null;

        System.Func <GameObject> CreateNew = () =>
        {
            GameObject _go = Instantiate(dic_effectPrefab[effectType], parentRect); //建立新物件
            _go.name += "_" + (particleEffectPool[dic_effectTypeIndex[effectType]].Count + 1).ToString();

            return(_go);
        };

        if (particleEffectPool[dic_effectTypeIndex[effectType]].Count == 0) //若物件池中沒有任何物件
        {
            go = CreateNew();
            particleEffectPool[dic_effectTypeIndex[effectType]].Add(go); //追加至物件池
        }
        else //若物件中存在物件
        {
            int index = -1; //物件池陣列索引
            for (int i = 0; i < particleEffectPool[dic_effectTypeIndex[effectType]].Count; i++)
            {
                if (particleEffectPool[dic_effectTypeIndex[effectType]][i] == null) //物件池中存在遺失物件時, 創造新物件替換之
                {
                    particleEffectPool[dic_effectTypeIndex[effectType]][i] = CreateNew();
                    index = i;
                    break;
                }

                if (!particleEffectPool[dic_effectTypeIndex[effectType]][i].GetComponent <ParticleSystem>().isPlaying) //若物件池中有找到未激活(!isPlaying)物件, 則設定其物件所在索引
                {
                    index = i;
                    break;
                }
            }

            if (index < 0) //若物件池中的物件都在激活狀態, 則創立新物件
            {
                go = CreateNew();
                particleEffectPool[dic_effectTypeIndex[effectType]].Add(go); //追加至物件池
            }
            else
            {
                go = particleEffectPool[dic_effectTypeIndex[effectType]][index];  //若物件池中有物件處於未激活(!isPlaying), 則設定回傳該物件
            }
        }

        return(go);
    }
예제 #19
0
    private GameObject InstantiateEffectPrefab(ParticleEffectType effectType)
    {
        var effect = _particleEffects.SingleOrDefault(x => x.GetComponent <ParticleEffect>().EffectType == effectType);

        return(GameObject.Instantiate(effect));
    }
 //粒子特效演出(多載1/2) ※一般特效撥放
 //[input] type = 特效種類 , pos = 位置, isWorld = true:世界座標/false:本地座標
 public void OneShotEffect(ParticleEffectType type, Vector2 pos, bool isWorld)
 {
     OneShotEffect(type, pos, isWorld, null);
 }
 /// <summary>
 /// Spawn a new particle effect at a given location
 /// </summary>
 /// <param name="effectType">The effect in question.</param>
 /// <param name="position">The position of the effect.</param>
 /// <returns>The new particle effect.</returns>
 public ParticleEffect SpawnEffect(ParticleEffectType effectType,
                                   Vector2 position)
 {
     return(SpawnEffect(effectType, position, null));
 }
 /// <summary>
 /// Remove the given particle-effect type from the maanger.
 /// </summary>
 /// <param name="effectType">The enumeration to be cleared against.</param>
 public void UnregisterParticleEffect(ParticleEffectType effectType)
 {
     if (particleEffectCache.ContainsKey(effectType) == true)
     {
         for (int i = 0; i < particleEffectCache[effectType].Count; ++i)
         {
             activeParticleEffects.Remove(particleEffectCache[effectType][i]);
         }
         particleEffectCache.Remove(effectType);
     }
 }
        /// <summary>
        /// Spawn a new particle effect at a given location and gameplay object
        /// </summary>
        /// <param name="effectType">The effect in question.</param>
        /// <param name="position">The position of the effect.</param>
        /// <param name="actor">The gameplay object.</param>
        /// <returns>The new particle effect.</returns>
        public ParticleEffect SpawnEffect(ParticleEffectType effectType,
            Vector2 position, GameplayObject gameplayObject)
        {
            ParticleEffect particleEffect = null;

            if (particleEffectCache.ContainsKey(effectType) == true)
            {
                List<ParticleEffect> availableSystems = particleEffectCache[effectType];

                for (int i = 0; i < availableSystems.Count; ++i)
                {
                    if (availableSystems[i].Active == false)
                    {
                        particleEffect = availableSystems[i];
                        break;
                    }
                }

                if (particleEffect == null)
                {
                    particleEffect = availableSystems[0].Clone();
                    particleEffect.Initialize(contentManager);
                    availableSystems.Add(particleEffect);
                }
            }

            if (particleEffect != null)
            {
                particleEffect.Reset();
                particleEffect.GameplayObject = gameplayObject;
                particleEffect.Position = position;
                activeParticleEffects.Add(particleEffect);
            }

            return particleEffect;
        }
 /// <summary>
 /// Spawn a new particle effect at a given location
 /// </summary>
 /// <param name="effectType">The effect in question.</param>
 /// <param name="position">The position of the effect.</param>
 /// <returns>The new particle effect.</returns>
 public ParticleEffect SpawnEffect(ParticleEffectType effectType,
     Vector2 position)
 {
     return SpawnEffect(effectType, position, null);
 }
예제 #25
0
 public ParticleEffect GetPrefab(ParticleEffectType type)
 {
     return(m_prefabs[type]);
 }