本文整理汇总了C#中GameObject.GetComponentsInChildren方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponentsInChildren方法的具体用法?C# GameObject.GetComponentsInChildren怎么用?C# GameObject.GetComponentsInChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetComponentsInChildren方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshShader
public static void RefreshShader(GameObject obj)
{
List<Renderer> meshrs = new List<Renderer>(obj.GetComponentsInChildren<Renderer>(false));
List<Material> mats = new List<Material>();
//meshrs.Add(obj.GetComponent<Renderer>());
for (int i = 0; i < meshrs.Count; i++)
{
Material[] mat = meshrs[i].sharedMaterials;
if (mat == null) mat = meshrs[i].materials;
if (mat != null)
{
mats.AddRange(mat);
}
}
for (int i = 0; i < mats.Count; i++)
{
Material mat = mats[i];
if (mat != null)
{
string shaderName = mat.shader.name;
Shader newShader = Shader.Find(shaderName);
if (newShader != null)
{
mat.shader = newShader;
}
}
}
}
示例2: RegisterPrefab
internal static void RegisterPrefab(GameObject prefab)
{
NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
if ((bool) ((Object) component))
{
if (LogFilter.logDebug)
Debug.Log((object) ("Registering prefab '" + prefab.name + "' as asset:" + (object) component.assetId));
NetworkScene.s_GuidToPrefab[component.assetId] = prefab;
if (prefab.GetComponentsInChildren<NetworkIdentity>().Length <= 1 || !LogFilter.logWarn)
return;
Debug.LogWarning((object) ("The prefab '" + prefab.name + "' has multiple NetworkIdentity components. There can only be one NetworkIdentity on a prefab, and it must be on the root object."));
}
else
{
if (!LogFilter.logError)
return;
Debug.LogError((object) ("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"));
}
}
示例3: ScaledVersionLoader
// Runtime Constructor, uses CelestialBody
public ScaledVersionLoader(CelestialBody body)
{
// Get the scaled version object
scaledVersion = body.scaledBody;
owner = body;
// Figure out what kind of body we are
if (scaledVersion.GetComponentsInChildren<SunShaderController>(true).Length > 0)
type = BodyType.Star;
else if (owner.atmosphere)
type = BodyType.Atmospheric;
else
type = BodyType.Vacuum;
}