コード例 #1
0
    void OnGUI()
    {
        switch (Event.current.type)
        {
        case EventType.Repaint:
            tracker.ClearDirty();
            break;
        }

        searchObject = EditorGUILayout.ObjectField("Search Object", searchObject, typeof(Object), true);
        drawSeparator();

        using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition)) {
            if (!!searchObject)
            {
                foreach (var hitGameObject in hitGameObjects)
                {
                    var content = EditorGUIUtility.ObjectContent(hitGameObject, typeof(GameObject));
                    if (GUILayout.Button(content, EditorStyles.label, GUILayout.Height(EditorGUIUtility.singleLineHeight)))
                    {
                        EditorGUIUtility.PingObject(hitGameObject);
                        Selection.activeGameObject = hitGameObject;
                    }
                }
            }

            scrollPosition = scrollViewScope.scrollPosition;
        }
    }
コード例 #2
0
    void OnGUI()
    {
        switch (Event.current.type)
        {
        case EventType.Repaint:
            tracker.ClearDirty();
            break;
        }

        searchObject = EditorGUILayout.ObjectField("Search Object", searchObject, typeof(Object), true);

        replaceReference = EditorGUILayout.ObjectField("Replace Reference", replaceReference, typeof(Object), true);

        if (GUILayout.Button("Replace"))
        {
            var gameObjects = FindObjectsOfType <GameObject>();
            foreach (var gameObject in gameObjects)
            {
                foreach (var component in gameObject.GetComponents <MonoBehaviour>())
                {
                    var serializedObject = new SerializedObject(component);
                    var iterator         = serializedObject.GetIterator();
                    iterator.Next(true);
                    while (iterator.Next(true))
                    {
                        if (iterator.propertyType == SerializedPropertyType.ObjectReference)
                        {
                            if (iterator.objectReferenceValue == searchObject &&
                                iterator.objectReferenceValue != gameObject)
                            {
                                iterator.objectReferenceValue = replaceReference;
                            }
                        }
                    }
                    serializedObject.ApplyModifiedProperties();
                }
            }
        }
        drawSeparator();

        using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition)) {
            if (!!searchObject)
            {
                foreach (var hitGameObject in hitGameObjects)
                {
                    var content = EditorGUIUtility.ObjectContent(hitGameObject, typeof(GameObject));
                    if (GUILayout.Button(content, EditorStyles.label, GUILayout.Height(EditorGUIUtility.singleLineHeight)))
                    {
                        EditorGUIUtility.PingObject(hitGameObject);
                        Selection.activeGameObject = hitGameObject;
                    }
                }
            }

            scrollPosition = scrollViewScope.scrollPosition;
        }
    }