Children#
Transform / Children
Can Read
Cannot Write
Description#
The collection of Game Objects that hang from the Transform of another one
Parameters#
| Name | Description |
|---|---|
| Game Object | The Game Object whose children are collected |
| Recursive | Whether the children of each child are also collected |
| Include Inactive | Whether Game Objects that are not active are also collected |
Code#
using System;
using System.Collections.Generic;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Children")]
[Category("Transform/Children")]
[Description("The collection of Game Objects that hang from the Transform of another one")]
[Image(typeof(IconHanger), ColorTheme.Type.Lime, typeof(BadgeList))]
[Parameter("Game Object", "The Game Object whose children are collected")]
[Parameter("Recursive", "Whether the children of each child are also collected")]
[Parameter("Include Inactive", "Whether Game Objects that are not active are also collected")]
[Keywords("Transform", "Hierarchy", "Parent", "Descendants", "Sons", "Nested")]
[Serializable]
public class TypeCollectionGameObjectsTransformChildren : TypeCollectionGameObjects
{
// EXPOSED MEMBERS: -----------------------------------------------------------------------
[SerializeField] private GetGameObject m_GameObject = new GetGameObject();
[SerializeField] private GetBool m_Recursive = new GetBool(false);
[SerializeField] private GetBool m_IncludeInactive = new GetBool(true);
// PUBLIC METHODS: ------------------------------------------------------------------------
public override void Get(Args args, List<GameObject> values)
{
values.Clear();
Transform transform = this.m_GameObject.Get<Transform>(args);
if (transform == null) return;
Collect(transform, values, this.m_Recursive.Get(args), this.m_IncludeInactive.Get(args));
}
public override string ToString()
{
return $"{this.m_GameObject} Children";
}
// PRIVATE METHODS: -----------------------------------------------------------------------
private static void Collect(Transform parent, List<GameObject> values, bool recursive, bool includeInactive)
{
int childCount = parent.childCount;
for (int i = 0; i < childCount; ++i)
{
Transform child = parent.GetChild(i);
if (!includeInactive && !child.gameObject.activeInHierarchy) continue;
values.Add(child.gameObject);
if (recursive) Collect(child, values, true, includeInactive);
}
}
// PROTECTED METHODS: ---------------------------------------------------------------------
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}