Esempio n. 1
0
        private static bool TryFindAssetReferencesAsGameObject(Object unityObject, HashSet <Object> searchedAsset,
                                                               ReferenceDictionary dictionary)
        {
            var gameObject = unityObject as GameObject;

            if (gameObject == null)
            {
                return(false);
            }

            dictionary.AddReference(gameObject);

            var prefabStatus = PrefabUtility.GetPrefabInstanceStatus(gameObject);

            if (prefabStatus == PrefabInstanceStatus.Connected)
            {
                var prefabRoot = PrefabUtility.GetNearestPrefabInstanceRoot(gameObject);
                if (prefabRoot == gameObject)
                {
                    var prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject);
                    var prefab     = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);
                    dictionary.AddReference(gameObject, prefab);
                    FindAssetReferencesRecursive(prefab, searchedAsset, dictionary);
                }
            }

            foreach (var component in gameObject.GetComponents <Component>())
            {
                FindAssetReferencesRecursive(component, searchedAsset, dictionary);
            }

            return(true);
        }
Esempio n. 2
0
        private static void FindSerializedObjectReferenceRecursive(Object unityObject, HashSet <Object> searchedAsset, ReferenceDictionary dictionary)
        {
            var serializedObject = new SerializedObject(unityObject);

            var iterator = serializedObject.GetIterator();

            while (iterator.NextVisible(true))
            {
                var property = iterator;
                if (property.propertyType != SerializedPropertyType.ObjectReference)
                {
                    continue;
                }

                var referredAsset = property.objectReferenceValue;
                if (referredAsset == null)
                {
                    continue;
                }

                dictionary.AddReference(unityObject, referredAsset);

                FindAssetReferencesRecursive(referredAsset, searchedAsset, dictionary);
            }
        }
Esempio n. 3
0
        private UnityObjectReferenceChain(IEnumerable <Object> objects)
        {
            var hashSet    = new HashSet <Object>();
            var dictionary = new ReferenceDictionary();

            foreach (var @object in objects)
            {
                dictionary.AddReference(@object);
                FindAssetReferencesRecursive(@object, hashSet, dictionary);
            }

            Result = dictionary.CreateReadonlyDictionary();
        }
Esempio n. 4
0
        private static void FindMaterialReferenceRecursive(Material material, ReferenceDictionary dictionary)
        {
            if (material.shader == null)
            {
                return;
            }

            //設定中のシェーダーに存在するプロパティの取得
            var count         = ShaderUtil.GetPropertyCount(material.shader);
            var propertyNames = new string[count];

            for (int i = 0; i < count; i++)
            {
                string propName = ShaderUtil.GetPropertyName(material.shader, i);
                propertyNames[i] = propName;
            }

            var serializedObject = new SerializedObject(material);
            var texturesProperty = serializedObject.FindProperty("m_SavedProperties.m_TexEnvs");

            for (int i = 0; i < texturesProperty.arraySize; i++)
            {
                var textureContainerProperty = texturesProperty.GetArrayElementAtIndex(i);
                var textureName = textureContainerProperty.FindPropertyRelative("first").stringValue;
                // シェーダーに存在するテクスチャ指定プロパティ以外は無視
                if (!propertyNames.Contains(textureName))
                {
                    continue;
                }

                var texture = textureContainerProperty.FindPropertyRelative("second.m_Texture").objectReferenceValue;
                if (texture == null)
                {
                    continue;
                }

                dictionary.AddReference(material, texture);
            }
        }