돌고래 홈페이지
ID:
PW:


  운영자(2015-08-21 07:22:08, Hit : 426, Vote : 90
 유니티 컴포넌트 참조




https://github.com/uqtimes/ComponentFinder
https://www.assetstore.unity3d.com/en/#!/content/6031

=========================================================================
http://answers.unity3d.com/questions/121423/best-way-to-find-components.html

#1
using UnityEngine;

public static class ExtensionMethods {

public static T FindObjectOfType <T> (this Object unityObject) where T : Object {
     return Object.FindObjectOfType(typeof(T)) as T;
}
public static T[] FindObjectsOfType <T> (this Object unityObject) where T : Object {
     return Object.FindObjectsOfType(typeof(T)) as T[];
}

}


#2
GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType<GameObject>() ;
foreach(object go in allObjects)
    if (go.activeInHierarchy)
       print(thisObject+" is an active object") ;


#3
Transform[] hinges =GameObject.FindObjectsOfType(typeof(Transform)) as Transform[];

#4
GameObject.FindObjectsOfType(typeof(MonoBehaviour)); //returns Object[]
GameObject.FindGameObjectsWithTag("Untagged");  //returns GameObject[]
======================================================================

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace ComponentFinder
{
    public class ComponentFinderWindow : EditorWindow
    {
        string userKeyword = string.Empty;
        Vector2 scrollPosition;
        List<Component> resultComponents = new List<Component>();

        [MenuItem("Window/Component Finder")]
        static void Open()
        {
            ComponentFinderWindow.GetWindow<ComponentFinderWindow>("CompFinder");
        }

        void OnGUI()
        {
            // Check user input
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Keyword: ", GUILayout.Width(58));
            userKeyword = EditorGUILayout.TextField(userKeyword, GUILayout.Width(Screen.width - 70));
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                resultComponents.Clear();
                FindComponent(userKeyword.ToUpper());
            }

            // Show results
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            EditorGUILayout.BeginVertical();
            foreach (var component in resultComponents)
            {
                if (component != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.ObjectField(component, typeof(Component), false);
                    EditorGUILayout.LabelField(component.GetType().ToString());
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }

        GameObject[] GetRootGameObjects()
        {
            return System.Array.FindAll(GameObject.FindObjectsOfType<GameObject>(), (item) => item.transform.parent == null);
        }

        void FindComponent(string keyword)
        {
            foreach (var go in GetRootGameObjects())
            {
                FindComponent(go, keyword);
            }
        }

        void FindComponent(GameObject go, string keyword)
        {
            // Find component
            foreach (var component in go.GetComponents(typeof(Component)))
            {
                var componentName = component.GetType().ToString().ToUpper();
                if (0 < componentName.ToUpper().IndexOf(keyword))
                {
                    resultComponents.Add(component);
                }
            }
            // Find child component
            for (int i = 0, count = go.transform.childCount; i < count; ++i)
            {
                FindComponent(go.transform.GetChild(i).gameObject, keyword);
            }
        }
    }
}

=================================================================

http://androidpot.tistory.com/711

##. GameObject를 찾는 방법
Find  (찾는 것 최상에 것이 찾아진다.) 빠름2
FindWithTag    빠름 1
FindGameObjectWithTag (전부 다찾는것) 빠름3
FindObjectOfType 빠름 4  <== 쓰지 마라 느리다..
FindObjhectsOfType 빠름 5 <== 절대 코드에 적용하지 마라 매우 느리다.




자바기반 서버 ( or C#)
PBR 아트

Copyright 1999-2017 Zeroboard / skin by zero