本文整理汇总了C#中GameObject.InitWithPrefab方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.InitWithPrefab方法的具体用法?C# GameObject.InitWithPrefab怎么用?C# GameObject.InitWithPrefab使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.InitWithPrefab方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestFx
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;
}
示例2: RequestSound
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;
}
示例3: RequestFx
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;
}