Last active
August 29, 2015 14:22
-
-
Save yasuakiohama/a96b0b1841e5e9bfeffc to your computer and use it in GitHub Desktop.
Find.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Find : MonoBehaviour { | |
void Start () | |
{ | |
FindBytransform (); | |
FindBytransformAll (); | |
FindByGetChild (); | |
FindByGetComponentsInChildren (); | |
Transform t = MyFindChild (this.transform, "A"); | |
if (t) { | |
Debug.Log (t.name); | |
} | |
FindByFindGameObjectsWithTag (); | |
FindByFindObjectsOfType (); | |
FindByGameObjectFind (); | |
FindByTransformFindChild (); | |
FindByTransformFind (); | |
} | |
public void FindBytransform() | |
{ | |
string str = ""; | |
foreach (Transform t in transform) { | |
str += t.name + "\n"; | |
} | |
Debug.Log ("FindBytransform" + "\n" + str); | |
} | |
public void FindByGetChild() | |
{ | |
string str = ""; | |
for (int i = 0; i < transform.childCount; i++) { | |
str += transform.GetChild (i).name + "\n"; | |
} | |
Debug.Log ("FindByGetChild" + "\n" + str); | |
} | |
public void FindByGetComponentsInChildren() | |
{ | |
string str = ""; | |
foreach (Transform t in transform.GetComponentsInChildren<Transform>()) { | |
str += t.name + "\n"; | |
} | |
Debug.Log ("FindByGetComponentsInChildren" + "\n" + str); | |
} | |
public void FindBytransformAll() | |
{ | |
Debug.Log ("FindBytransformAll" + "\n" + RunHierarchieChilds (transform)); | |
} | |
public string RunHierarchieChilds(Transform transform, string parentNames = "") | |
{ | |
parentNames += transform.name; | |
string str = parentNames + "\n"; | |
if (transform.childCount == 0) { | |
return str; | |
} | |
foreach (Transform child in transform) { | |
str += RunHierarchieChilds (child, parentNames + "/"); | |
} | |
return str; | |
} | |
public Transform MyFindChild(Transform transform, string scarch) | |
{ | |
if (scarch == transform.name) { | |
return transform; | |
} | |
Transform scarchChild; | |
foreach (Transform child in transform) { | |
scarchChild = MyFindChild (child, scarch); | |
if (scarchChild) { | |
return scarchChild; | |
} | |
} | |
return null; | |
} | |
public string RunLastChilds(Transform transform) | |
{ | |
if (transform.childCount == 0) { | |
return transform.name + "\n"; | |
} | |
string str = ""; | |
foreach (Transform child in transform) { | |
str += RunLastChilds (child); | |
} | |
return str; | |
} | |
public string RunChilds(Transform transform) | |
{ | |
string str = ""; | |
foreach (Transform child in transform) { | |
str += child.name + "\n" + RunChilds (child); | |
} | |
return str; | |
} | |
public void FindByFindGameObjectsWithTag() | |
{ | |
string str = ""; | |
foreach (GameObject t in GameObject.FindGameObjectsWithTag("Tag")) { | |
str += t.name + "\n"; | |
} | |
Debug.Log ("FindByFindGameObjectsWithTag" + "\n" + str); | |
} | |
public void FindByFindObjectsOfType() | |
{ | |
string str = ""; | |
foreach (Transform t in FindObjectsOfType<Transform>()) { | |
str += t.name + "\n"; | |
} | |
Debug.Log ("FindByFindObjectsOfType" + "\n" + str); | |
} | |
public void FindByGameObjectFind() | |
{ | |
string str = ""; | |
if (GameObject.Find ("Child1")) { | |
str += GameObject.Find ("Child1").name+ "\n"; | |
} | |
if (GameObject.Find ("Child2")) { | |
str += GameObject.Find ("Child2").name+ "\n"; | |
} | |
Debug.Log ("FindByGameObjectFind" + "\n" + str); | |
} | |
public void FindByTransformFindChild() | |
{ | |
string str = ""; | |
if (transform.FindChild ("Child1/Child1_1")) { | |
str += transform.FindChild ("Child1/Child1_1").name+ "\n"; | |
} | |
if (transform.FindChild ("Child2/Child2_1")) { | |
str += transform.FindChild ("Child2/Child2_1").name+ "\n"; | |
} | |
Debug.Log ("FindByTransformFindChild" + "\n" + str); | |
} | |
public void FindByTransformFind() | |
{ | |
string str = ""; | |
if (transform.Find ("Child1/Child1_1")) { | |
str += transform.Find ("Child1/Child1_1").name+ "\n"; | |
} | |
if (transform.Find ("Child2/Child2_1")) { | |
str += transform.Find ("Child2/Child2_1").name+ "\n"; | |
} | |
Debug.Log ("FindByTransformFind" + "\n" + str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment