当前位置: 首页>>代码示例>>C#>>正文


C# Transform.GetComponentsInChildren方法代码示例

本文整理汇总了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);
        }
开发者ID:cupsster,项目名称:ExtremeBusiness,代码行数:39,代码来源:PuppetMasterSetup.cs

示例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);
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:27,代码来源:RectTransformUtility.cs

示例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);
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:27,代码来源:RectTransformUtility.cs

示例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;
      }
    }
开发者ID:WilliamRADFunk,项目名称:vedic,代码行数:27,代码来源:PhysicMaterialReplacer.cs

示例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();
		}
开发者ID:Kundara,项目名称:project1,代码行数:28,代码来源:PoseUtils.cs

示例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;
		}
开发者ID:paulkelly,项目名称:GGJ2016,代码行数:10,代码来源:Hierarchy.cs

示例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;
        }
开发者ID:oatssss,项目名称:McGill-Once-McGill-Twice,代码行数:27,代码来源:TargetFieldOfView.cs

示例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);
        }
开发者ID:petereichinger,项目名称:unity-helpers,代码行数:59,代码来源:RemoveHiddenObjectsTool.cs

示例9: Awake

		// ================================================================================
		//  unity methods
		// --------------------------------------------------------------------------------

		void Awake()
		{
			_transform = transform;

			children = new List<FloatingObject2D>(_transform.GetComponentsInChildren<FloatingObject2D>());

			CalculateBounds();
		}
开发者ID:paveltimofeev,项目名称:GameJamFramework,代码行数:12,代码来源:FloatingObjectsController.cs

示例10: AttachIconsToChildren

		static void AttachIconsToChildren (Transform root) {
			if (root != null) {
				var utilityBones = root.GetComponentsInChildren<SkeletonUtilityBone>();
				foreach (var utilBone in utilityBones) {
					AttachIcon(utilBone);
				}
			}
		}
开发者ID:X-Ray-Jin,项目名称:spine-runtimes,代码行数:8,代码来源:SkeletonUtilityInspector.cs

示例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;
 }
开发者ID:CreateAppAdmin,项目名称:SteamVR_Unity_Toolkit,代码行数:9,代码来源:Utilities.cs

示例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);
        }
开发者ID:brunobittarello,项目名称:ProjectBoosters,代码行数:12,代码来源:UIDebugger.cs

示例13: ProcessViewsFromRoot

		private void ProcessViewsFromRoot(Transform view)
		{
			MonoBehaviour[] viewScripts = view.GetComponentsInChildren<MonoBehaviour>(false);

			foreach (MonoBehaviour viewScript in viewScripts)
			{
				if (viewScript is IView)
				{
					ProcessView (viewScript);
				}
			}
		}
开发者ID:mikecann,项目名称:robotlegs-sharp-framework,代码行数:12,代码来源:UnityStageCrawler.cs

示例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;
            }
        }
开发者ID:rlawther,项目名称:AmnesiaMuseumUnity,代码行数:13,代码来源:DebugDropDownList.cs

示例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;
        }
开发者ID:cyberimp,项目名称:Dark-Invaders,代码行数:21,代码来源:TransformUtilty.cs


注:本文中的UnityEngine.Transform.GetComponentsInChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。