Exemple #1
0
	public FxOne RequestFx(string name, int priority)  //值越大,优先级越低
    {
		if (m_fxs.Count > m_maxFxones)
		{
			int maxPriorityMax = -1; //正在播放的最低的优先级
			int realCount = 0;
			for (int i = 0; i < m_fxs.Count; ++i)
			{
				FxOne fx1 = m_fxs[i];
				if (fx1.Stable == true)
					continue;
				if (fx1.priority > maxPriorityMax)
					maxPriorityMax = fx1.priority;
				++realCount;
			}
			if(realCount > m_maxFxones)
			{
				if (priority > maxPriorityMax)
				{
					string str = string.Format("can't play fx:{0} due to too lower priority", name);
					Debug.Log(str);
					return null;
				}

				for(int i=0;i<m_fxs.Count;++i)
				{
					FxOne fx1 = m_fxs[i];
                    if (fx1 == null)
                    {
                        m_fxs.Remove(fx1);
                        break;
                    }
					if (fx1.Stable == false && fx1.priority >= priority)
					{
						m_fxs.Remove(fx1);
                        if(fx1 != null)
						    fx1.Stop();
						break;
					}
				}
			}
		}

        FxCache fxcache = null;
        if (m_fxCaches.TryGetValue(name, out fxcache) == false)
        {
			fxcache = new GameObject(name).AddComponent<FxCache>();
			fxcache.transform.parent = m_fxAssets;
			m_fxCaches[name] = fxcache;
			fxcache.transform.position = Vector3.zero;
			fxcache.transform.localScale = Vector3.one;
			fxcache.transform.rotation = Quaternion.identity;
            fxcache.InitWithPrefab(name);
			fxcache.gameObject.SetActive(false);
        }
		FxOne fxone = GetFxOneFromCache();
		fxone.priority = priority;
		if (fxcache.Touch(fxone) == false)
		{
			GiveBack(fxone);
			return null;
		}

		return fxone;
    }
Exemple #2
0
	public SoundOne RequestSound(string name,string soundType,int priority) //值越大,优先级越低
	{
		SoundType st = GetSoundType(soundType);

		//得到总共的active的数量
		Transform soundTypeTrans = st.transform;
		int childcount = soundTypeTrans.childCount;
		List<SoundOne> activeList = new List<SoundOne>();
		int maxPriorityMax = -1;
		SoundOne lowerestSoundOne = null;
		for (int i = 0; i < childcount; ++i)
		{
			Transform ctrans = soundTypeTrans.GetChild(i);
			SoundOne one = ctrans.GetComponent<SoundOne>();
			if (one.IsPlaying)
			{
				activeList.Add(one);
				if (one.audio.priority > maxPriorityMax)
				{
					maxPriorityMax = one.audio.priority;
					lowerestSoundOne = one;
				}
			}
		}

		if (activeList.Count >= st.m_maxCount) //will remove ...
		{
			if (priority >= maxPriorityMax) //要播放的优先级不高于现有的最低优先级
			{
				//string str = string.Format("can't play sound:{0} due to too lower priority",name);
				//Debug.Log(str);
				return null;
			}
			lowerestSoundOne.Stop(1);
		}

		SoundClip soundcache = null;
		if (m_SoundClips.TryGetValue(name, out soundcache) == false)
		{
			//float v = st.m_volume;
			soundcache = new GameObject(name).AddComponent<SoundClip>();
			soundcache.transform.parent = m_clips;
			m_SoundClips[name] = soundcache;
			soundcache.InitWithPrefab(name);
			soundcache.gameObject.SetActive(false);
		}

		SoundOne soundone = GetAudioSourceFromCache();
		soundone.mute = st.m_mute;
		soundone.audio.priority = priority;
		soundone.m_type = soundType;
		soundone.transform.parent = st.transform;

		if (soundcache.Touch(soundone) == false)
		{
			GiveBack(soundone);
			return null;
		}
			
		return soundone;
	}
Exemple #3
0
	public FxOne RequestFx(string name, int priority)
    {
		if (m_fxs.Count > m_maxFxones)
		{
			int realCount = 0;
			for (int i = 0; i < m_fxs.Count; ++i)
			{
				FxOne fx1 = m_fxs[i];
				if (fx1.Stable == true)
					continue;
				++realCount;
			}
			if(realCount > m_maxFxones)
			{
				for(int i=0;i<m_fxs.Count;++i)
				{
					FxOne fx1 = m_fxs[i];
					if (fx1.Stable == false && fx1.priority <= priority)
					{
						m_fxs.Remove(fx1);
						fx1.Stop();
						break;
					}
				}
			}
		}

        FxCache fxcache = null;
        if (m_fxCaches.TryGetValue(name, out fxcache) == false)
        {
			fxcache = new GameObject(name).AddComponent<FxCache>();
			fxcache.transform.parent = m_fxAssets;
			m_fxCaches[name] = fxcache;
			fxcache.transform.position = Vector3.zero;
			fxcache.transform.localScale = Vector3.one;
			fxcache.transform.rotation = Quaternion.identity;
            fxcache.InitWithPrefab(name);
			fxcache.gameObject.SetActive(false);
        }
		FxOne fxone = GetFxOneFromCache();
		fxone.priority = priority;
		if (fxcache.Touch(fxone) == false)
		{
			GiveBack(fxone);
			return null;
		}

		return fxone;
    }