本文整理汇总了C#中UnityEngine.GetComponentsInChildren方法的典型用法代码示例。如果您正苦于以下问题:C# UnityEngine.GetComponentsInChildren方法的具体用法?C# UnityEngine.GetComponentsInChildren怎么用?C# UnityEngine.GetComponentsInChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine
的用法示例。
在下文中一共展示了UnityEngine.GetComponentsInChildren方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindChild
public static GameObject FindChild(UnityEngine.GameObject root, string name)
{
/*
if (root == null)
return null;
Transform tran = root.transform.Find(name);
if (tran)
return tran.gameObject;
Transform[] children = rootGameObject.transform.GetComponents<Transform>();
UnityEngine.GameObject obj = null;
for (int i = 0; i < children.Length; i++)
{
obj = FindChild(children[i].gameObject, name);
if (obj != null)
break;
}*/
Transform child = root.transform.Find(name);
if (child)
return child.gameObject;
Transform[] trans = root.GetComponentsInChildren<Transform>();
foreach(var tran in trans)
{
if (tran.name == name)
return tran.gameObject;
}
return null;
}
示例2: HandleCustomProperties
public void HandleCustomProperties(UnityEngine.GameObject gameObject,
IDictionary<string, string> props)
{
// Simply add a component to our GameObject
if (props.ContainsKey ("PrefabPath")) {
string path = props["PrefabPath"];
UnityEngine.Object spawn =
AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
if (spawn != null)
{
GameObject spawnInstance =
(GameObject)GameObject.Instantiate(spawn);
spawnInstance.name = spawn.name;
// Use the position of the game object we're attached to
spawnInstance.transform.parent = gameObject.transform;
spawnInstance.transform.localPosition = Vector3.zero;
gameObject.transform.localScale = Vector3.one * 100;
}
}
if (props.ContainsKey ("Platform")) {
gameObject.GetComponent<Collider2D>().usedByEffector = true;
gameObject.AddComponent<PlatformEffector2D>().surfaceArc = 170f;
}
if(props.ContainsKey("ColliderMaterial"))
{
foreach(Collider2D collider in gameObject.GetComponentsInChildren<Collider2D>())
{
string path = props["ColliderMaterial"];
collider.sharedMaterial = (PhysicsMaterial2D)AssetDatabase.LoadAssetAtPath(path, typeof(PhysicsMaterial2D));
}
}
}
示例3: Update_EDITOR
private void Update_EDITOR(UnityEngine.UI.Windows.WindowLayout _target) {
foreach (var element in _target.elements) element.Update_EDITOR();
#region COMPONENTS
_target.canvas = _target.GetComponentsInChildren<Canvas>(true)[0];
var raycasters = _target.GetComponentsInChildren<UnityEngine.EventSystems.BaseRaycaster>(true);
if (raycasters != null && raycasters.Length > 0) _target.raycaster = raycasters[0];
#endregion
_target.initialized = (_target.canvas != null);
#region SETUP
if (_target.initialized == true) {
WindowSystem.ApplyToSettings(_target.canvas);
// Raycaster
if ((_target.raycaster as GraphicRaycaster) != null) {
(_target.raycaster as GraphicRaycaster).GetType().GetField("m_BlockingMask", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue((_target.raycaster as GraphicRaycaster), (LayerMask)(1 << _target.gameObject.layer));
}
}
#endregion
}
示例4: Setup_EDITOR
private void Setup_EDITOR(UnityEngine.UI.Windows.WindowLayout _target) {
var elements = _target.GetComponentsInChildren<WindowLayoutElement>(true);
_target.elements = _target.elements.Where((e) => e != null).ToList();
foreach (var e in elements) {
if (_target.elements.Contains(e) == false) {
// New elements will be added
e.tag = LayoutTag.None;
}
}
var usedTags = new List<LayoutTag>();
_target.elements = _target.elements.Where((e) => elements.Contains(e)).ToList();
foreach (var element in elements) {
if (usedTags.Contains(element.tag) == true) {
element.Reset();
} else {
if (element.tag != LayoutTag.None) usedTags.Add(element.tag);
}
if (_target.elements.Contains(element) == true) {
continue;
}
if (element.tag == LayoutTag.None) {
// Element not installed
_target.elements.Add(element);
this.isDirty = true;
}
}
// Update
foreach (var element in _target.elements) {
if (element.tag == LayoutTag.None) element.tag = this.GetTag(usedTags);
}
}
示例5: HandleSkinnedMeshRendererInfo
// SkinnedMeshRenderer
private void HandleSkinnedMeshRendererInfo(UnityEngine.GameObject go, ref int vertices, ref int skinnedMeshTriangles, ref int meshCount)
{
Component[] skinnedMeshes = go.GetComponentsInChildren(typeof(SkinnedMeshRenderer));
for (int skinnedMeshIndex = 0; skinnedMeshIndex < skinnedMeshes.Length; skinnedMeshIndex++)
{
SkinnedMeshRenderer skinnedMeshRenderer = (SkinnedMeshRenderer)skinnedMeshes[skinnedMeshIndex];
vertices += skinnedMeshRenderer.sharedMesh.vertexCount;
skinnedMeshTriangles += skinnedMeshRenderer.sharedMesh.triangles.Length / 3;
meshCount++;
}
}
示例6: HandleMeshFilterInfo
// MeshFilter
private void HandleMeshFilterInfo(UnityEngine.GameObject go, ref int vertices, ref int meshTriangles, ref int meshCount)
{
Component[] meshFilters = go.GetComponentsInChildren(typeof(MeshFilter));
for (int meshFiltersIndex = 0; meshFiltersIndex < meshFilters.Length; meshFiltersIndex++)
{
MeshFilter meshFilter = (MeshFilter)meshFilters[meshFiltersIndex];
vertices += meshFilter.sharedMesh.vertexCount;
meshTriangles += meshFilter.sharedMesh.triangles.Length / 3;
meshCount++;
}
}