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


C# Transform.GetComponentInChildren方法代码示例

本文整理汇总了C#中UnityEngine.Transform.GetComponentInChildren方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.GetComponentInChildren方法的具体用法?C# Transform.GetComponentInChildren怎么用?C# Transform.GetComponentInChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Transform的用法示例。


在下文中一共展示了Transform.GetComponentInChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindAnimatorRecursive

		// Finds the first Animator/Animation up the hierarchy
		private void FindAnimatorRecursive(Transform t, bool findInChildren) {
			if (isAnimated) return;

			animator = t.GetComponent<Animator>();
			animation = t.GetComponent<Animation>();

			if (isAnimated) return;

			if (animator == null && findInChildren) animator = t.GetComponentInChildren<Animator>();
			if (animation == null && findInChildren) animation = t.GetComponentInChildren<Animation>();

			if (!isAnimated && t.parent != null) FindAnimatorRecursive(t.parent, false);
		}
开发者ID:ChemaLeon,项目名称:RitualCops,代码行数:14,代码来源:SolverManager.cs

示例2: Start

        public void Start()
        {
            // Get the values of the parameters:
            string animatorParameter = GetParameter(0);
            animatorParameterHash = Animator.StringToHash(animatorParameter);
            targetValue = GetParameterAsFloat(1, 1);
            subject = GetSubject(2);
            duration = GetParameterAsFloat(3, 0);
            if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Sequencer: AnimatorFloat({1}, {2}, {3}, {4})", new System.Object[] { DialogueDebug.Prefix, animatorParameter, targetValue, subject, duration }));

            // Check the parameters:
            if (subject == null) {
                if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AnimatorFloat(): subject '{1}' wasn't found.", new System.Object[] { DialogueDebug.Prefix, GetParameter(2) }));
                Stop();
            } else {
                animator = subject.GetComponentInChildren<Animator>();
                if (animator == null) {
                    if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AnimatorFloat(): no Animator found on '{1}'.", new System.Object[] { DialogueDebug.Prefix, subject.name }));
                    Stop();
                } else if (duration < SmoothMoveCutoff) {
                    Stop();
                } else {

                    // Set up the lerp:
                    startTime = DialogueTime.time;
                    endTime = startTime + duration;
                    originalValue = animator.GetFloat(animatorParameterHash);
                }
            }
        }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:30,代码来源:SequencerCommandAnimatorFloat.cs

示例3: Start

        public void Start()
        {
            // Get the values of the parameters:
            layerIndex = GetParameterAsInt(0, 1);
            weight = GetParameterAsFloat(1, 1);
            subject = GetSubject(2);
            duration = GetParameterAsFloat(3, 0);
            if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Sequencer: AnimatorLayer({1}, {2}, {3}, {4})", new System.Object[] { DialogueDebug.Prefix, layerIndex, weight, subject, duration }));

            // Check the parameters:
            if (subject == null) {
                if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AnimatorLayer(): subject '{1}' wasn't found.", new System.Object[] { DialogueDebug.Prefix, GetParameter(2) }));
                Stop();
            } else {
                animator = subject.GetComponentInChildren<Animator>();
                if (animator == null) {
                    if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AnimatorLayer(): no Animator found on '{1}'.", new System.Object[] { DialogueDebug.Prefix, subject.name }));
                    Stop();
                } else if ((layerIndex < 1) || (layerIndex >= animator.layerCount)) {
                    if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AnimatorLayer(): layer index {1} is invalid.", new System.Object[] { DialogueDebug.Prefix, layerIndex }));
                    Stop();
                } else if (duration < SmoothMoveCutoff) {
                    Stop();
                } else {

                    // Set up the lerp:
                    startTime = DialogueTime.time;
                    endTime = startTime + duration;
                    originalWeight = animator.GetLayerWeight(layerIndex);
                }
            }
        }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:32,代码来源:SequencerCommandAnimatorLayer.cs

示例4: Start

        void Start() {
            if ( !Target ) {
                var ship = GameObject.Find( "Ship" );
                if ( ship ) {
                    Target = ship.GetComponentInParent<CelestialBody>();
                }
            }
            _defaultTimeScale = SimulationControl.instance.TimeScale;
            if ( timeScaleButtons.Length == 3 ) {
                timeScaleButtons[0].interactable = false;
            }
            if ( !ShipControl ) {
                ShipControl = Target.GetComponent<ShipController>();
            }
            if ( !FuelSlider ) {
				Debug.Log("SpaceGravity2D.ShipGUI: fuel slider ref is null");
            } else {
                FuelSlider.maxValue = ShipControl.MaxFuel;
                FuelSlider.value = ShipControl.Fuel;
            }
            if ( MarkPrefab ) {
                _markApoapsis = Instantiate( MarkPrefab ) as Transform;
                _markApoapsis.name = "apoapsisMark";
                _markApoapsis.GetComponentInChildren<Text>().text = "A";
                _markPeriapsis = Instantiate( MarkPrefab ) as Transform;
                _markPeriapsis.name = "periapsisMark";
                _markPeriapsis.GetComponentInChildren<Text>().text = "P";
            }

        }
开发者ID:frotein,项目名称:TinyUniverse,代码行数:30,代码来源:ShipHUD.cs

示例5: GetInternalName

 public static string GetInternalName(Transform t)
 {
     OverrideActorName overrideActorName = t.GetComponentInChildren<OverrideActorName>();
     if (overrideActorName == null && t.parent != null) overrideActorName = t.parent.GetComponent<OverrideActorName>();
     if (overrideActorName != null) {
         if (!string.IsNullOrEmpty(overrideActorName.internalName)) return overrideActorName.internalName;
         if (!string.IsNullOrEmpty(overrideActorName.overrideName)) return overrideActorName.overrideName;
     }
     return t.name;
 }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:10,代码来源:OverrideActorName.cs

示例6: Start

 // Use this for initialization
 private void Start()
 {
     //This should be ok for now since there aren't multiple cameras flying around
     //TODO: There are multiple cameras flying around make sure this is alright
     var userCamera = GetComponentInChildren<Camera>();
     userCamera = CameraManager.Instance.GetPlayerCamera();
     cameraRig = userCamera.transform.parent;
     
     playerMesh = transform.FindChild("Character");
     playerAnimator = playerMesh.GetComponentInChildren<Animator>();
     
     rigidBody = GetComponent<Rigidbody>();
 }
开发者ID:harjup,项目名称:WizardBroadcast,代码行数:14,代码来源:UserMovement.cs

示例7: SetAnimatorController

		private void SetAnimatorController(UnityEngine.UI.Image image, Transform speaker, ref Animator animator) {
			if (speaker == null || image == null) return;
			if (animator == null) animator = image.GetComponent<Animator>();
			if (animator == null) animator = image.gameObject.AddComponent<Animator>();
			if (!animatedPortraits.ContainsKey(speaker)) {
				var animatedPortrait = (speaker != null) ? speaker.GetComponentInChildren<AnimatedPortrait>() : null;
				animatedPortraits.Add(speaker, animatedPortrait);
			}
			if (animatedPortraits[speaker] != null) {
				var animatorController = animatedPortraits[speaker].animatorController;
				if (animator.runtimeAnimatorController != animatorController) {
					animator.runtimeAnimatorController = animatorController;
				}
			}

		}
开发者ID:SHEePYTaGGeRNeP,项目名称:DialogGame,代码行数:16,代码来源:UseAnimatedPortraits.cs

示例8: BindTo

 /// <summary>
 /// Parents (target) to this camera, and offsets the camera a size-dependent distance from the target.
 /// </summary>
 public void BindTo(Transform target)
 {
     Debug.Log("CameraController: binding to target " + target.ToString());
     Renderer targetMesh = target.GetComponentInChildren<Renderer>();
     //make the target our parent
     transform.parent = target;
     //if the target has a mesh, we can setup a displacement vector
     if (targetMesh != null)
     {
         Debug.Log("CameraController.BindTo: found mesh " + targetMesh.name);
         //since we want the target on the bottom left side of the screen,
         //we want a displacement vector with positive x, positive y, and negative z
         //Debug.Log ("CameraController.BindTo: mesh bounds = " + targetMesh.bounds.size);
         //calculate a number representing the horiz to vert proportions
         Vector3 boundsSize = targetMesh.bounds.size;
         float meshAspectRatio = boundsSize.x / boundsSize.y;
         Vector3 scaledMeshSize = boundsSize * DisplaceFactor;
         DisplaceVec = Vector3.zero;//targetMesh.bounds.extents * displaceFactor;
         //bounds should always be positive, so we only need to negate the z component
         DisplaceVec.x = scaledMeshSize.x * DisplaceHorizFactor;
         //DisplaceVec.z = scaledMeshSize.z * -DisplaceDepthFactor;//scaledMeshSize.z * -DisplaceDepthFactor;
         //DisplaceVec.z = scaledMeshSize.z * -DisplaceDepthFactor;//scaledMeshSize.z * -DisplaceDepthFactor;
         //the x displacement of the camera should put the camera at a 33 degree angle to give a nice offset to the 3rd person view
         DisplaceVec.z = -Mathf.Abs(DisplaceVec.x / (Mathf.Tan(DisplaceAngle * Mathf.Deg2Rad))) * DisplaceDepthFactor;
         DisplaceVec.y = scaledMeshSize.y * DisplaceVertFactor;//(DisplaceVertFactor / Mathf.Pow(scaledMeshSize.y, 2)); /// 2.0f;// * meshAspectRatio * DisplaceVertFactor;
         //Debug.Log ("CameraController.BindTo: displacement vec = " + DisplaceVec.ToString());
     }
     //otherwise, just place the camera at the target's center
     else
     {
         DisplaceVec = Vector3.zero;
     }
     //setup our new positions - first reset the camera's local position so rotations don't distort the new displacement,
     cam.transform.localPosition = Vector3.zero;
     transform.localPosition = Vector3.zero;
     //then set our rotation and displace the camera by the vector we calculated
     transform.rotation = target.rotation;
     cam.transform.localPosition = DisplaceVec;
 }
开发者ID:eliot2,项目名称:kopykat-ggj14,代码行数:42,代码来源:CameraController.cs

示例9: NewWorldObject

 /// <summary>
 /// Creates a new WorldObject.
 /// </summary>
 /// <returns>The world object.</returns>
 /// <param name="meshTransform">Mesh transform.</param>
 public static WorldObject NewWorldObject(Transform meshTransform)
 {
     WorldObject worldObject = new WorldObject();
     if (meshTransform.GetComponentInChildren<MeshFilter>()) {
         worldObject.transform = meshTransform;
         worldObject.Initialize ();
     } else Debug.Log("Could not find a mesh in "+meshTransform.name+".");
     return worldObject;
 }
开发者ID:PawkaHub,项目名称:Lore-Unity,代码行数:14,代码来源:PlaygroundParticlesC.cs

示例10: CheckIfPlayerIsInvolved

 private void CheckIfPlayerIsInvolved(Transform actor)
 {
     if (actor == null) {
         isPlayerInvolved = false;
     } else if (actor.GetComponentInChildren<Player>() != null) {
         isPlayerInvolved = true;
     } else {
         Actor dbActor = DialogueManager.MasterDatabase.GetActor(OverrideActorName.GetActorName(actor));
         isPlayerInvolved = (dbActor != null) && dbActor.IsPlayer;
     }
 }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:11,代码来源:AdventureCreatorBridge.cs

示例11: Bark

        /// <summary>
        /// Attempts to make a character bark. This is a coroutine; you must start it using
        /// StartCoroutine() or Unity will hang. Shows a line from the named conversation, plays 
        /// the sequence, and sends OnBarkStart/OnBarkEnd messages to the participants.
        /// </summary>
        /// <param name='conversationTitle'>
        /// Title of conversation to pull bark lines from.
        /// </param>
        /// <param name='speaker'>
        /// Speaker performing the bark.
        /// </param>
        /// <param name='listener'>
        /// Listener that the bark is directed to; may be <c>null</c>.
        /// </param>
        /// <param name='barkHistory'>
        /// Bark history used to keep track of the most recent bark so this method can iterate 
        /// through them in a specified order.
        /// </param>
        /// <param name='database'>
        /// The dialogue database to use. If <c>null</c>, uses DialogueManager.MasterDatabase.
        /// </param>
        public static IEnumerator Bark(string conversationTitle, Transform speaker, Transform listener, BarkHistory barkHistory, DialogueDatabase database = null, bool stopAtFirstValid = false)
        {
            if (string.IsNullOrEmpty(conversationTitle) && DialogueDebug.LogWarnings) Debug.Log(string.Format("{0}: Bark (speaker={1}, listener={2}): conversation title is blank", new System.Object[] { DialogueDebug.Prefix, speaker, listener }), speaker);
            if ((speaker == null) && DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' speaker is null", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }));
            if (string.IsNullOrEmpty(conversationTitle) || (speaker == null)) yield break;
            IBarkUI barkUI = speaker.GetComponentInChildren(typeof(IBarkUI)) as IBarkUI;
            if ((barkUI == null) && DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' speaker has no bark UI", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker);
            var firstValid = stopAtFirstValid || ((barkHistory == null) ? false : barkHistory.order == (BarkOrder.FirstValid));
            ConversationModel conversationModel = new ConversationModel(database ?? DialogueManager.MasterDatabase, conversationTitle, speaker, listener, DialogueManager.AllowLuaExceptions, DialogueManager.IsDialogueEntryValid, -1, firstValid);
            ConversationState firstState = conversationModel.FirstState;
            if ((firstState == null) && DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' has no START entry", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker);
            if ((firstState != null) && !firstState.HasAnyResponses && DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' has no valid bark at this time", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker);
            if ((firstState != null) && firstState.HasAnyResponses) {
                try {
                    InformParticipants("OnBarkStart", speaker, listener);
                    Response[] responses = firstState.HasNPCResponse ? firstState.npcResponses : firstState.pcResponses;
                    int index = (barkHistory ?? new BarkHistory(BarkOrder.Random)).GetNextIndex(responses.Length);
                    DialogueEntry barkEntry = responses[index].destinationEntry;
                    if ((barkEntry == null) && DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' bark entry is null", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker);
                    if (barkEntry != null) {
                        ConversationState barkState = conversationModel.GetState(barkEntry, false);
                        if (barkState == null) {
                            if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' can't find a valid dialogue entry", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker);
                            yield break;
                        }
                        if (firstState.HasNPCResponse) {
                            CharacterInfo tempInfo = barkState.subtitle.speakerInfo;
                            barkState.subtitle.speakerInfo = barkState.subtitle.listenerInfo;
                            barkState.subtitle.listenerInfo = tempInfo;
                        }
                        if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}'", new System.Object[] { DialogueDebug.Prefix, speaker, listener, barkState.subtitle.formattedText.text }), speaker);

                        // Show the bark subtitle:
                        if (((barkUI == null) || !(barkUI as MonoBehaviour).enabled) && DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' bark UI is null or disabled", new System.Object[] { DialogueDebug.Prefix, speaker, listener, barkState.subtitle.formattedText.text }), speaker);
                        if ((barkUI != null) && (barkUI as MonoBehaviour).enabled) {
                            barkUI.Bark(barkState.subtitle);
                        }

                        // Run Lua:
                        if (!string.IsNullOrEmpty(barkState.subtitle.dialogueEntry.userScript)) {
                            Lua.Run(barkState.subtitle.dialogueEntry.userScript, DialogueDebug.LogInfo, false);
                        }

                        // Play the sequence:
                        Sequencer sequencer = null;
                        if (!string.IsNullOrEmpty(barkState.subtitle.sequence)) {
                            sequencer = DialogueManager.PlaySequence(barkState.subtitle.sequence, speaker, listener, false, false);
                            sequencer.entrytag = barkState.subtitle.entrytag;
                        }
                        LastSequencer = sequencer;
                        while (((sequencer != null) && sequencer.IsPlaying) || ((barkUI != null) && barkUI.IsPlaying)) {
                            yield return null;
                        }
                        if (sequencer != null) GameObject.Destroy(sequencer);
                    }
                } finally {
                    InformParticipants("OnBarkEnd", speaker, listener);
                }
            }
        }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:81,代码来源:BarkController.cs

示例12: NewSkinnedWorldObject

 /// <summary>
 /// Creates a new SkinnedWorldObject.
 /// </summary>
 /// <returns>The skinned world object.</returns>
 /// <param name="meshTransform">Mesh transform.</param>
 public static SkinnedWorldObject NewSkinnedWorldObject(Transform meshTransform)
 {
     SkinnedWorldObject skinnedWorldObject = new SkinnedWorldObject();
     if (meshTransform.GetComponentInChildren<SkinnedMeshRenderer>()) {
         skinnedWorldObject.transform = meshTransform;
         skinnedWorldObject.Initialize ();
     } else Debug.Log("Could not find a skinned mesh in "+meshTransform.name+".");
     return skinnedWorldObject;
 }
开发者ID:PawkaHub,项目名称:Lore-Unity,代码行数:14,代码来源:PlaygroundParticlesC.cs

示例13: GetPortrait

 private Texture2D GetPortrait(Transform character, Actor actor)
 {
     Texture2D portrait = null;
     if (character != null) {
         OverrideActorName overrideActorName = character.GetComponentInChildren<OverrideActorName>();
         if (overrideActorName != null) portrait = GetPortraitByActorName(overrideActorName.GetOverrideName());
         if (portrait == null) portrait = GetPortraitByActorName(character.name);
     }
     if ((portrait == null) && (actor != null)) {
         portrait = GetPortraitByActorName(actor.Name);
         if (portrait == null) portrait = actor.portrait;
     }
     return portrait;
 }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:14,代码来源:ConversationModel.cs

示例14: BarkCachedLine

 private void BarkCachedLine(Transform speaker, Transform listener)
 {
     if (barkUI == null) barkUI = speaker.GetComponentInChildren(typeof(IBarkUI)) as IBarkUI;
     if (cachedState == null) PopulateCache(speaker, listener);
     BarkNextCachedLine(speaker, listener);
 }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:6,代码来源:BarkStarter.cs

示例15: SetConversationUI

 /// <summary>
 /// Looks for any dialogue UI or display settings overrides on the conversant.
 /// </summary>
 /// <param name='conversant'>
 /// Conversant.
 /// </param>
 private void SetConversationUI(Transform conversant)
 {
     if (conversant != null) {
         OverrideDialogueUI overrideDialogueUI = conversant.GetComponentInChildren<OverrideDialogueUI>();
         OverrideDisplaySettings overrideDisplaySettings = conversant.GetComponentInChildren<OverrideDisplaySettings>();
         if ((overrideDialogueUI != null) && (overrideDialogueUI.ui != null)) {
             isOverrideUIPrefab = Tools.IsPrefab(overrideDialogueUI.ui);
             originalDialogueUI = DialogueUI;
             displaySettings.dialogueUI = overrideDialogueUI.ui;
             currentDialogueUI = null;
         } else if (overrideDisplaySettings != null) {
             if (overrideDisplaySettings.displaySettings.dialogueUI != null) {
                 isOverrideUIPrefab = Tools.IsPrefab(overrideDisplaySettings.displaySettings.dialogueUI);
                 originalDialogueUI = DialogueUI;
                 currentDialogueUI = null;
             }
             originalDisplaySettings = displaySettings;
             displaySettings = overrideDisplaySettings.displaySettings;
         }
         ValidateCurrentDialogueUI();
     }
 }
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:28,代码来源:DialogueSystemController.cs


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