本文整理汇总了C#中UnityEngine.GameObject.GetComponentsInChildren方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponentsInChildren方法的具体用法?C# GameObject.GetComponentsInChildren怎么用?C# GameObject.GetComponentsInChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.GameObject
的用法示例。
在下文中一共展示了GameObject.GetComponentsInChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearTextsAndSprite
public void ClearTextsAndSprite(GameObject _targ)
{
new OTTween(DarkBG, 1f).Tween("alpha", 0f);
if (_targ.GetComponentsInChildren<OTSprite>() != null)
{
foreach (OTSprite _spr in _targ.GetComponentsInChildren<OTSprite>())
{
_spr.alpha = 0f;
}
}
if (_targ.GetComponentsInChildren<TextUI>() != null)
{
foreach (TextUI _txt in _targ.GetComponentsInChildren<TextUI>())
{
_txt.makeFadeOut();
}
}
if (_targ.GetComponentsInChildren<UIBtn>() != null)
{
foreach (UIBtn _btn in _targ.GetComponentsInChildren<UIBtn>())
{
_btn.reDisable();
}
}
}
示例2: OnPostprocessModel
void OnPostprocessModel(GameObject go)
{
MeshRenderer[] meshComponents = go.GetComponentsInChildren<MeshRenderer>();
SkinnedMeshRenderer[] skinMeshComponents = go.GetComponentsInChildren<SkinnedMeshRenderer>();
bool isAnim = false;
if(meshComponents.Length == 0 && skinMeshComponents.Length == 0)
{
isAnim = true;
}
ModelImporter importer = assetImporter as ModelImporter;
if(isAnim)
{
importer.optimizeMesh = false;
importer.importMaterials = false;
importer.normalImportMode = ModelImporterTangentSpaceMode.None;
importer.tangentImportMode = ModelImporterTangentSpaceMode.None;
importer.splitTangentsAcrossSeams = false;
}
//
importer.importAnimation = isAnim;
go.tag = isAnim ? EAssetType.Anim.ToString() : EAssetType.Model.ToString();
}
示例3: OnMouseDown
void OnMouseDown()
{
if (!GameObject.Find ("Popup(Clone)") && !GameObject.Find ("Map(Clone)") && !GameObject.Find ("EncounterBox(Clone)") && !GameObject.Find ("gradList(Clone)") && !GameObject.Find ("gratzPop(Clone)") && !GameObject.Find ("TutorialBox(Clone)")) {
mainVar.selectedStudent = this.name;
Debug.Log (this);
studentData = this.GetComponent<StudentData> ();
if (mainVar.gameState) {
newPopup = Instantiate (Resources.Load ("Popup"))as GameObject;
newPopup.GetComponentsInChildren<TextMesh> () [1].text = studentData.name;
newPopup.GetComponentsInChildren<TextMesh> () [2].text = studentData.major;
newPopup.GetComponentsInChildren<TextMesh> () [0].text = "'" + studentData.tagline + "'";
// cgpaBar = studentData.CGPA;
// cgpaBar = (cgpaBar - 0) / (12 - 0) * (3 - 0) + 0;
// newPopup.GetComponentsInChildren<Transform> () [10].localScale = new Vector3 (cgpaBar, 3f, 3f);
// newPopup.AddComponent<BoxCollider2D> ();
// newPopup.layer = 5;
// newPopup.GetComponent<BoxCollider2D> ().isTrigger = true;
// newPopup.GetComponent<BoxCollider2D> ().size = new Vector2 (5, 3);
AudioSource[] audioSources = GameObject.Find ("Main Camera").GetComponents<AudioSource> ();
audioSources [1].Play ();
// newPopup.AddComponent<AudioSource>();
// newPopup.GetComponent<AudioSource>().clip = Resources.Load("Audio/blip") as AudioClip;
// newPopup.GetComponent<AudioSource>().Play ();
newPopup.AddComponent<DestoryPopup> ();
mainVar.gameState = false;
}
}
// Debug.Log (this.name);
}
示例4: initialise
public void initialise(ASPPainter painter)
{
_painter = painter;
ScreenMessages.PostScreenMessage("Paint Pointer - RMB or Escape to exit", 5, ScreenMessageStyle.UPPER_CENTER);
if (_pointer == null)
{
GameObject modelObject = GameDatabase.Instance.GetModel(_pointerModel).gameObject;
_pointer = Instantiate(modelObject) as GameObject;
Collider[] colliders = _pointer.GetComponentsInChildren<Collider>(true);
foreach (Collider collider in colliders)
{
Destroy(collider);
}
_meshRenderers = _pointer.GetComponentsInChildren<MeshRenderer>(true);
foreach (MeshRenderer mesh in _meshRenderers)
{
mesh.material = new Material(Shader.Find("Transparent/Diffuse"));
}
_pointer.SetActive(true);
}
GameEvents.onVesselChange.Add(new EventData<Vessel>.OnEvent(this.OnVesselChange));
}
示例5: Start
void Start()
{
if (particle != null)
{
GO = Instantiate(particle) as GameObject;
GO.transform.SetParent(transform, false);
if (autoStart)
{
foreach (ParticleSystem ps in GO.GetComponentsInChildren<ParticleSystem>())
{
ps.loop = true;
ps.playOnAwake = true;
GO.SetActive(false);
GO.SetActive(true);
}
}
else
{
foreach (ParticleSystem ps in GO.GetComponentsInChildren<ParticleSystem>())
{
ps.loop = false;
ps.playOnAwake = false;
GO.SetActive(false);
GO.SetActive(true);
}
}
}
}
示例6: FindMesh1
public Mesh FindMesh1(GameObject go, out GameObject obj)
{
if ( go )
{
MeshFilter[] filters = (MeshFilter[])go.GetComponentsInChildren<MeshFilter>(true);
if ( filters.Length > 0 )
{
if ( filters[0].gameObject != go )
obj = filters[0].gameObject;
else
obj = null;
return filters[0].mesh;
}
SkinnedMeshRenderer[] skins = (SkinnedMeshRenderer[])go.GetComponentsInChildren<SkinnedMeshRenderer>(true);
if ( skins.Length > 0 )
{
if ( skins[0].gameObject != go )
obj = skins[0].gameObject;
else
obj = null;
return skins[0].sharedMesh;
}
}
obj = null;
return null;
}
示例7: EnableRagdoll
/// <summary>
/// Enables the ragdool.
/// </summary>
/// <remarks>
/// The GameObject must have a Collider and a Rigidbody.
/// </remarks>
/// <param name="enable">If set to <c>true</c> enable.</param>
public static void EnableRagdoll(GameObject gameObject, bool enable)
{
var bones = gameObject.GetComponentsInChildren<Rigidbody>();
for (var boneIndex = 0; boneIndex < bones.Length; boneIndex++) {
var bone = bones[boneIndex];
var collider = bone.GetComponent<Collider>();
if (collider != null) {
collider.enabled = enable;
}
bone.isKinematic = !enable;
bone.mass = (enable ? 0.1f : 0.01f);
}
gameObject.GetComponent<Collider>().enabled = !enable;
var rigidbody = gameObject.GetComponent<Rigidbody>();
if (enable) {
rigidbody.useGravity = false;
rigidbody.isKinematic = true;
} else {
rigidbody.mass = 1.0f;
rigidbody.useGravity = true;
rigidbody.isKinematic = false;
}
var animators = gameObject.GetComponentsInChildren<Animator>();
for (var animatorIndex = 0; animatorIndex < animators.Length; animatorIndex++) {
animators[animatorIndex].enabled = !enable;
}
}
示例8: InitializeDialoguePanel
protected override void InitializeDialoguePanel()
{
m_currentState = DialogueTreeStates.RUNNING;
m_dialoguePanel = Instantiate((GameObject)Resources.Load("DialoguePanel", typeof(GameObject)));
Text[] messages = m_dialoguePanel.GetComponentsInChildren<Text>();
for(int i=0; i<messages.Length;i++)
{
if(messages[i].gameObject.name == "Message")
{
messages[i].text = m_singleMessage;
break;
}
}
Button[] buttons = m_dialoguePanel.GetComponentsInChildren<Button>();
for (int i = 0; i < buttons.Length; i++)
{
if (buttons[i].gameObject.name == "ButtonOptionA")
{
buttons[i].onClick.AddListener(() => OnOptionClicked());
}
else if (buttons[i].gameObject.name == "ButtonOptionB")
{
buttons[i].onClick.AddListener(() => OnOptionClicked());
}
}
}
示例9: Awake
void Awake(){
thisObj=gameObject;
thisT=transform;
thisObj.layer=LayerManager.LayerShootObject();
if(autoSearchLineRenderer){
LineRenderer[] lines = thisObj.GetComponentsInChildren<LineRenderer>(true);
for(int i=0; i<lines.Length; i++) lineList.Add(lines[i]);
}
TrailRenderer[] trails = thisObj.GetComponentsInChildren<TrailRenderer>(true);
for(int i=0; i<trails.Length; i++) trailList.Add(trails[i]);
if(type==_ShootObjectType.FPSProjectile){
SphereCollider sphereCol=GetComponent<SphereCollider>();
if(sphereCol==null){
sphereCol=thisObj.AddComponent<SphereCollider>();
sphereCol.radius=0.15f;
}
hitRadius=sphereCol.radius;
}
if(shootEffect!=null) ObjectPoolManager.New(shootEffect);
if(hitEffect!=null) ObjectPoolManager.New(hitEffect);
}
示例10: Start
void Start () {
shadowRoot = (GameObject)Instantiate(gameObject);
if (hideShadow)
shadowRoot.hideFlags = HideFlags.HideInHierarchy;
shadowRoot.transform.parent = transform.root;
shadowTable = new Dictionary<Transform, Transform>();
Destroy(shadowRoot.GetComponent<SkeletonUtilityKinematicShadow>());
shadowRoot.transform.position = transform.position;
shadowRoot.transform.rotation = transform.rotation;
Vector3 scaleRef = transform.TransformPoint(Vector3.right);
float scale = Vector3.Distance(transform.position, scaleRef);
shadowRoot.transform.localScale = Vector3.one;
var shadowJoints = shadowRoot.GetComponentsInChildren<Joint>();
foreach (Joint j in shadowJoints) {
j.connectedAnchor *= scale;
}
var joints = GetComponentsInChildren<Joint>();
foreach (var j in joints)
Destroy(j);
var rbs = GetComponentsInChildren<Rigidbody>();
foreach (var rb in rbs)
Destroy(rb);
var colliders = GetComponentsInChildren<Collider>();
foreach (var c in colliders)
Destroy(c);
//match by bone name
var shadowBones = shadowRoot.GetComponentsInChildren<SkeletonUtilityBone>();
var bones = GetComponentsInChildren<SkeletonUtilityBone>();
//build bone lookup
foreach (var b in bones) {
if (b.gameObject == gameObject)
continue;
foreach (var sb in shadowBones) {
if (sb.rigidbody == null)
continue;
if (sb.boneName == b.boneName) {
shadowTable.Add(sb.transform, b.transform);
break;
}
}
}
foreach (var b in shadowBones)
Destroy(b);
}
示例11: Start
void Start()
{
hinweis = GameObject.Find ("Hinweis");
hinweisText = hinweis.GetComponentsInChildren<Text> ();
hinweisBild = hinweis.GetComponentsInChildren<Image> ();
showHinweis(false, "");
showtime = 0;
}
示例12: SetEnabledForGameObject
private void SetEnabledForGameObject(GameObject go, bool enabled)
{
go.GetComponent<Movement>().enabled = enabled;
go.GetComponent<PlayerController>().enabled = enabled;
go.GetComponent<Rigidbody>().useGravity = enabled;
go.GetComponentsInChildren<MeshRenderer>().SetEnabled(enabled);
go.GetComponentsInChildren<Collider>().SetEnabled(enabled);
}
示例13: InputRegister
// InputManagerSetup
internal static void InputRegister( GameObject gameObject )
{
controllers = gameObject.GetComponentsInChildren<ControllerBase>();
controllersCount = controllers.Length;
buttons = gameObject.GetComponentsInChildren<ButtonBase>();
buttonsCount = buttons.Length;
}
示例14: GridSetUp
private void GridSetUp(GameObject gridObject, GameObject spriteObject)
{
for (int i = 0; i < gridObject.GetComponentsInChildren<Image>().Length; i++) {
if (gridObject.GetComponentsInChildren<Image>()[i].tag == "Sprite") {
gridObject.GetComponentsInChildren<Image>()[i].sprite = spriteObject.GetComponent<Image>().sprite;
}
}
}
示例15: Start
void Start () {
// Duplicate this gameObject as the "shadow" with a different parent.
shadowRoot = Instantiate<GameObject>(this.gameObject);
Destroy(shadowRoot.GetComponent<SkeletonUtilityKinematicShadow>());
// Prepare shadow gameObject's properties.
var shadowRootTransform = shadowRoot.transform;
shadowRootTransform.position = transform.position;
shadowRootTransform.rotation = transform.rotation;
Vector3 scaleRef = transform.TransformPoint(Vector3.right);
float scale = Vector3.Distance(transform.position, scaleRef);
shadowRootTransform.localScale = Vector3.one;
if (!detachedShadow) {
// Do not change to null coalescing operator (??). Unity overloads null checks for UnityEngine.Objects but not the ?? operator.
if (parent == null)
shadowRootTransform.parent = transform.root;
else
shadowRootTransform.parent = parent;
}
if (hideShadow)
shadowRoot.hideFlags = HideFlags.HideInHierarchy;
var shadowJoints = shadowRoot.GetComponentsInChildren<Joint>();
foreach (Joint j in shadowJoints)
j.connectedAnchor *= scale;
// Build list of bone pairs (matches shadow transforms with bone transforms)
var bones = GetComponentsInChildren<SkeletonUtilityBone>();
var shadowBones = shadowRoot.GetComponentsInChildren<SkeletonUtilityBone>();
foreach (var b in bones) {
if (b.gameObject == this.gameObject)
continue;
foreach (var sb in shadowBones) {
if (sb.GetComponent<Rigidbody>() != null && sb.boneName == b.boneName) {
shadowTable.Add(new TransformPair {
dest = b.transform,
src = sb.transform
});
break;
}
}
}
// Destroy conflicting and unneeded components
DestroyComponents(shadowBones);
DestroyComponents(GetComponentsInChildren<Joint>());
DestroyComponents(GetComponentsInChildren<Rigidbody>());
DestroyComponents(GetComponentsInChildren<Collider>());
}