using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class TestRes : MonoBehaviour {
public GameObject go;
// Use this for initialization
void Start () {
GameObject target = GameObject.Instantiate(go) as GameObject;
List<Transform> findTest = new List<Transform>();
string[] findNames = new string[]
{ "Directional light","GameObject (3)","GameObject (4)"};
FindChild(target.transform, new List<string>(findNames), ref findTest);
for (int i = 0; i < findTest.Count; i++)
{
if (findTest[i].name.Equals(findNames[0]))
{
Light li = findTest[i].GetComponent<Light>();
if (li != null)
{
li.color = Color.black;
Debug.Log(li.color);
}
}
else
{
Debug.Log(findTest[i].name);
}
}
}
void FindChild(Transform go,List<string> findName, ref List<Transform> trf)
{
if (trf.Count == findName.Count)
{
return;
}
if (findName.Contains(go.name))
{
trf.Add(go);
}
if (go.childCount != 0)
{
for (int i = 0; i < go.childCount; i++)
{
FindChild(go.GetChild(i), findName, ref trf);
}
}
}
}
网友评论