本文整理汇总了C#中UnityEngine.Transform.GetComponentsInChildren方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.GetComponentsInChildren方法的具体用法?C# Transform.GetComponentsInChildren怎么用?C# Transform.GetComponentsInChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.GetComponentsInChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveRagdollComponents
/// <summary>
/// Removes all the ragdoll components (except Cloth colliders), including compound colliders that are not used by Cloth. Components on the 'target' GameObject will not be touched for they are probably not ragdoll components, but required by a character controller.
/// </summary>
/// <param name="target">Target.</param>
public static void RemoveRagdollComponents(Transform target, int characterControllerLayer)
{
if (target == null) return;
// Get rid of all the ragdoll components on the target
Rigidbody[] rigidbodies = target.GetComponentsInChildren<Rigidbody>();
Cloth[] cloths = target.GetComponentsInChildren<Cloth>();
for (int i = 0; i < rigidbodies.Length; i++) {
if (rigidbodies[i].gameObject != target.gameObject) {
var joint = rigidbodies[i].GetComponent<Joint>();
var collider = rigidbodies[i].GetComponent<Collider>();
if (joint != null) DestroyImmediate(joint);
if (collider != null) {
if (!IsClothCollider(collider, cloths)) DestroyImmediate(collider);
else collider.gameObject.layer = characterControllerLayer;
}
DestroyImmediate(rigidbodies[i]);
}
}
// Get rid of (compound) colliders that are not used by Cloth
Collider[] colliders = target.GetComponentsInChildren<Collider>();
for (int i = 0; i < colliders.Length; i++) {
if (colliders[i].transform != target && !IsClothCollider(colliders[i], cloths)) {
DestroyImmediate(colliders[i]);
}
}
// Get rid of the PuppetMaster
var puppetMaster = target.GetComponent<PuppetMaster>();
if (puppetMaster != null) DestroyImmediate(puppetMaster);
}
示例2: CalculateRelativeRectTransformBounds
public static Bounds CalculateRelativeRectTransformBounds(Transform root, Transform child)
{
RectTransform[] componentsInChildren = child.GetComponentsInChildren<RectTransform>(false);
if (componentsInChildren.Length > 0)
{
Vector3 rhs = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
Vector3 vector2 = new Vector3(float.MinValue, float.MinValue, float.MinValue);
Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
int index = 0;
int length = componentsInChildren.Length;
while (index < length)
{
componentsInChildren[index].GetWorldCorners(s_Corners);
for (int i = 0; i < 4; i++)
{
Vector3 lhs = worldToLocalMatrix.MultiplyPoint3x4(s_Corners[i]);
rhs = Vector3.Min(lhs, rhs);
vector2 = Vector3.Max(lhs, vector2);
}
index++;
}
Bounds bounds = new Bounds(rhs, Vector3.zero);
bounds.Encapsulate(vector2);
return bounds;
}
return new Bounds(Vector3.zero, Vector3.zero);
}
示例3: CalculateRelativeRectTransformBounds
public static Bounds CalculateRelativeRectTransformBounds(Transform root, Transform child)
{
RectTransform[] componentsInChildren = child.GetComponentsInChildren<RectTransform>(false);
if (componentsInChildren.Length > 0)
{
Vector3 vector = new Vector3(3.40282347E+38f, 3.40282347E+38f, 3.40282347E+38f);
Vector3 vector2 = new Vector3(-3.40282347E+38f, -3.40282347E+38f, -3.40282347E+38f);
Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
int i = 0;
int num = componentsInChildren.Length;
while (i < num)
{
componentsInChildren[i].GetWorldCorners(RectTransformUtility.s_Corners);
for (int j = 0; j < 4; j++)
{
Vector3 lhs = worldToLocalMatrix.MultiplyPoint3x4(RectTransformUtility.s_Corners[j]);
vector = Vector3.Min(lhs, vector);
vector2 = Vector3.Max(lhs, vector2);
}
i++;
}
Bounds result = new Bounds(vector, Vector3.zero);
result.Encapsulate(vector2);
return result;
}
return new Bounds(Vector3.zero, Vector3.zero);
}
示例4: PhysicMaterialReplacer
public PhysicMaterialReplacer(Transform anchor, InteractionMaterial material) {
_colliders = anchor.GetComponentsInChildren<Collider>(true);
_originalMaterials = _colliders.Select(c => c.sharedMaterial).ToArray();
switch (material.PhysicMaterialMode) {
case InteractionMaterial.PhysicMaterialModeEnum.NoAction:
_replacementMaterials = null;
break;
case InteractionMaterial.PhysicMaterialModeEnum.DuplicateExisting:
_replacementMaterials = _originalMaterials.Select(m => {
PhysicMaterial newMat;
if (m == null) {
newMat = new PhysicMaterial();
newMat.name = "Grasping Material";
} else {
newMat = Object.Instantiate(m);
newMat.name = m.name + " (Grasping Instance)";
}
newMat.bounciness = 0;
return newMat;
}).ToArray();
break;
case InteractionMaterial.PhysicMaterialModeEnum.Replace:
_replacementMaterials = _originalMaterials.Select(m => material.ReplacementPhysicMaterial).ToArray();
break;
}
}
示例5: SavePose
public static void SavePose(Pose pose, Transform root)
{
List<Bone2D> bones = new List<Bone2D>(50);
root.GetComponentsInChildren<Bone2D>(true,bones);
SerializedObject poseSO = new SerializedObject(pose);
SerializedProperty entriesProp = poseSO.FindProperty("m_PoseEntries");
poseSO.Update();
entriesProp.arraySize = bones.Count;
for (int i = 0; i < bones.Count; i++)
{
Bone2D bone = bones [i];
if(bone)
{
SerializedProperty element = entriesProp.GetArrayElementAtIndex(i);
element.FindPropertyRelative("path").stringValue = BoneUtils.GetBonePath(root,bone);
element.FindPropertyRelative("localPosition").vector3Value = bone.transform.localPosition;
element.FindPropertyRelative("localRotation").quaternionValue = bone.transform.localRotation;
element.FindPropertyRelative("localScale").vector3Value = bone.transform.localScale;
}
}
poseSO.ApplyModifiedProperties();
}
示例6: ContainsChild
/// <summary>
/// Returns true if the transforms contains the child
/// </summary>
public static bool ContainsChild(Transform transform, Transform child) {
if (transform == child) return true;
Transform[] children = transform.GetComponentsInChildren<Transform>() as Transform[];
foreach (Transform c in children) if (c == child) return true;
return false;
}
示例7: MaxBoundsExtent
public static float MaxBoundsExtent(Transform obj, bool includeEffects)
{
// get the maximum bounds extent of object, including all child renderers,
// but excluding particles and trails, for FOV zooming effect.
var renderers = obj.GetComponentsInChildren<Renderer>();
Bounds bounds = new Bounds();
bool initBounds = false;
foreach (Renderer r in renderers)
{
if (!((r is TrailRenderer) || (r is ParticleRenderer) || (r is ParticleSystemRenderer)))
{
if (!initBounds)
{
initBounds = true;
bounds = r.bounds;
}
else
{
bounds.Encapsulate(r.bounds);
}
}
}
float max = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
return max;
}
示例8: OnGUI
private void OnGUI()
{
_removeParent = (Transform)EditorGUILayout.ObjectField("Select object", _removeParent, typeof(Transform), true);
_hideFlags = (HideFlags)EditorGUILayout.EnumPopup("Set hide flag", _hideFlags);
if (GUILayout.Button("Look for hidden objects")) {
if (_removeParent) {
Transform[] childTransforms = _removeParent.GetComponentsInChildren<Transform>();
_deleteList = new List<Transform>(childTransforms.Where(
t => (t.gameObject.hideFlags & _hideFlags) == _hideFlags));
} else {
IEnumerable<GameObject> gos = Resources.FindObjectsOfTypeAll<GameObject>().Where(
go => ((go.hideFlags & _hideFlags) == _hideFlags) && go.transform.parent == null);
_deleteList = new List<Transform>();
foreach (GameObject go in gos) {
_deleteList.Add(go.transform);
}
}
}
if (_deleteList == null || _deleteList.Count <= 0) {
return;
}
GUILayout.BeginHorizontal();
GUILayout.Label("Regex", GUILayout.Width(40f));
_filter = GUILayout.TextField(_filter);
_includePrefabs = EditorGUILayout.Toggle("Include prefabs", _includePrefabs);
GUILayout.EndHorizontal();
Color oldColor = GUI.color;
GUI.color = Color.red;
if (GUILayout.Button("Destroy all")) {
for (int i = 0; i < _deleteList.Count; i++) {
if (ValidItem(_deleteList[i])) {
DestroyImmediate(_deleteList[i].gameObject);
}
}
}
GUI.color = oldColor;
_scrollPos = GUILayout.BeginScrollView(_scrollPos, false, true);
for (int i = 0; i < _deleteList.Count; i++) {
if (!ValidItem(_deleteList[i])) {
continue;
}
GUILayout.BeginHorizontal();
EditorGUILayout.ObjectField("", _deleteList[i], typeof(Transform), true);
GUILayout.Label(PrefabUtility.GetPrefabType(_deleteList[i]).ToString());
if (GUILayout.Button("Destroy")) {
DestroyImmediate(_deleteList[i].gameObject);
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
_deleteList.RemoveAll(t => !t);
}
示例9: Awake
// ================================================================================
// unity methods
// --------------------------------------------------------------------------------
void Awake()
{
_transform = transform;
children = new List<FloatingObject2D>(_transform.GetComponentsInChildren<FloatingObject2D>());
CalculateBounds();
}
示例10: AttachIconsToChildren
static void AttachIconsToChildren (Transform root) {
if (root != null) {
var utilityBones = root.GetComponentsInChildren<SkeletonUtilityBone>();
foreach (var utilBone in utilityBones) {
AttachIcon(utilBone);
}
}
}
示例11: getBounds
public static Bounds getBounds(Transform transform)
{
Bounds bounds = new Bounds(transform.position, Vector3.zero);
Renderer[] renderers = transform.GetComponentsInChildren<Renderer>();
foreach (Renderer renderer in renderers) {
bounds.Encapsulate(renderer.bounds);
}
return bounds;
}
示例12: Start
void Start()
{
DebugPanel = transform.GetChild(0);
arrText = DebugPanel.GetComponentsInChildren<Text>();
FuelBar = transform.GetChild(1).GetChild(0).GetComponent<Image>();
TurboFuelBar = transform.GetChild(1).GetChild(1).GetComponent<Image>();
FuelBarHeigh = FuelBar.rectTransform.sizeDelta.y;
TurboFuelBarHeigh = TurboFuelBar.rectTransform.sizeDelta.y;
DebugPanel.gameObject.SetActive(showDebugDisplay);
}
示例13: ProcessViewsFromRoot
private void ProcessViewsFromRoot(Transform view)
{
MonoBehaviour[] viewScripts = view.GetComponentsInChildren<MonoBehaviour>(false);
foreach (MonoBehaviour viewScript in viewScripts)
{
if (viewScript is IView)
{
ProcessView (viewScript);
}
}
}
示例14: ClearList
// turn off children objects
public void ClearList(Transform root)
{
Transform[] childs = root.GetComponentsInChildren<Transform>();
foreach (Transform child in childs)
{
if (child == root) continue; //don't run clearlist on the root
GuiListItem gli = this.getGuiListItem(child);
gli.disable();
gli.showChildren = false;
}
}
示例15: GetChildren
List<Transform> GetChildren(Transform trans, List<Transform> prevList)
{
List<Transform> newlist;
if (prevList == null)
newlist = new List<Transform>();
else
newlist = prevList;
if (trans.GetComponentsInChildren<Transform>() == null)
newlist.Add(trans);
else
{
foreach (Transform child in trans.GetComponentsInChildren<Transform>())
{
List<Transform> childList = GetChildren(child, newlist);
newlist = childList;
}
}
return newlist;
}