예제 #1
0
        public static void ProcessTilemap(Object inspectedUnityObject, Tilemap target, EntryAddSettings addSettings)
        {
            var tilesCount = target.GetUsedTilesCount();

            if (tilesCount == 0)
            {
                return;
            }

            var usedTiles = new TileBase[tilesCount];

            target.GetUsedTilesNonAlloc(usedTiles);

            foreach (var usedTile in usedTiles)
            {
                ReferenceEntryFinder.TryAddEntryToMatchedConjunctions(inspectedUnityObject, usedTile.GetInstanceID(), addSettings);

                var tile = usedTile as Tile;
                if (tile == null)
                {
                    continue;
                }

                if (tile.sprite != null)
                {
                    ReferenceEntryFinder.TryAddEntryToMatchedConjunctions(inspectedUnityObject, tile.sprite.GetInstanceID(),
                                                                          addSettings);
                }
            }
        }
예제 #2
0
        public static void ProcessObject(Location currentLocation, Object inspectedUnityObject, Object target, EntryAddSettings addSettings)
        {
            var onlyVisibleProperties = currentLocation != Location.ScriptAsset;
            var componentTraverseInfo = new SerializedObjectTraverseInfo(target, onlyVisibleProperties);

            string lastScriptPropertyName = null;

            CSTraverseTools.TraverseObjectProperties(componentTraverseInfo, (info, sp) =>
            {
                if (currentLocation == Location.ScriptAsset)
                {
                    if (sp.isArray)
                    {
                        if (sp.type == "string")
                        {
                            if (sp.propertyPath.IndexOf("m_DefaultReferences.Array.data[", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                if (sp.stringValue != null)
                                {
                                    lastScriptPropertyName = sp.stringValue;

                                    // skipping first pair item of the m_DefaultReferences array item
                                    sp.Next(false);
                                }
                            }
                        }
                    }
                }

                if (sp.propertyType == SerializedPropertyType.ObjectReference && sp.objectReferenceValue != null)
                {
                    string propertyName;

                    if (lastScriptPropertyName != null)
                    {
                        propertyName           = lastScriptPropertyName;
                        lastScriptPropertyName = string.Empty;
                    }
                    else
                    {
                        propertyName = sp.propertyPath;
                    }

                    /*if (string.Equals(propertyName, "m_Script", StringComparison.OrdinalIgnoreCase))
                     * {
                     *      propertyName = "Script source";
                     * }*/

                    addSettings.propertyPath = propertyName;

                    ReferenceEntryFinder.TryAddEntryToMatchedConjunctions(inspectedUnityObject, sp.objectReferenceInstanceIDValue, addSettings);

                    /* material instance handling */

                    var material = sp.objectReferenceValue as Material;
                    if (material == null)
                    {
                        return;
                    }

                    if (currentLocation == Location.PrefabAssetGameObject)
                    {
                        if (AssetDatabase.GetAssetPath(material) != AssetDatabase.GetAssetPath(target))
                        {
                            return;
                        }
                        if (AssetDatabase.IsSubAsset(material))
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (AssetDatabase.Contains(material))
                        {
                            return;
                        }
                    }

                    addSettings.prefix = "[Material Instance]";
                    addSettings.suffix = "(Main Texture)";

                    var mainTextureInstanceId = material.mainTexture != null ? material.mainTexture.GetInstanceID() : 0;
                    ReferenceEntryFinder.TryAddEntryToMatchedConjunctions(inspectedUnityObject, mainTextureInstanceId, addSettings);

                    addSettings.suffix = "(Shader)";

                    var shaderInstanceId = material.shader != null ? material.shader.GetInstanceID() : 0;
                    ReferenceEntryFinder.TryAddEntryToMatchedConjunctions(inspectedUnityObject, shaderInstanceId, addSettings);

                    var materialSo = new SerializedObject(material);

                    var texEnvs = materialSo.FindProperty("m_SavedProperties.m_TexEnvs.Array");
                    if (texEnvs != null)
                    {
                        for (var k = 0; k < texEnvs.arraySize; k++)
                        {
                            var arrayItem = texEnvs.GetArrayElementAtIndex(k);
                            var fieldName = arrayItem.displayName;
                            if (fieldName == "_MainTex")
                            {
                                continue;
                            }

                            var textureProperty = arrayItem.FindPropertyRelative("second.m_Texture");
                            if (textureProperty != null)
                            {
                                if (textureProperty.propertyType == SerializedPropertyType.ObjectReference)
                                {
                                    addSettings.suffix = " (" + fieldName + ")";
                                    ReferenceEntryFinder.TryAddEntryToMatchedConjunctions(inspectedUnityObject, textureProperty.objectReferenceInstanceIDValue, addSettings);
                                }
                            }
                            else
                            {
                                Debug.LogError(Maintainer.ConstructError("Can't get second.m_Texture from texEnvs at " + inspectedUnityObject.name));
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError(Maintainer.ConstructError("Can't get m_SavedProperties.m_TexEnvs.Array from material instance at " + inspectedUnityObject.name));
                    }
                }

                lastScriptPropertyName = null;
            });
        }