Example #1
0
        private static void ProcessScriptableObjectAsset(string path)
        {
            var mainAsset = AssetDatabase.LoadMainAssetAtPath(path);

            if (mainAsset == null)
            {
                return;
            }

            EntryFinder.currentLocation = Location.ScriptableObjectAsset;

            var addSettings = new EntryAddSettings();

            EntryFinder.TraverseObjectProperties(mainAsset, mainAsset, addSettings);
        }
Example #2
0
		private static void OnGameObjectComponentTraverse(ObjectTraverseInfo traverseInfo, Component component, int orderIndex)
		{
			if (component == null) return;

			var target = traverseInfo.current;
			var componentName = CSComponentTools.GetComponentName(component);
			if (CSObjectTools.IsHiddenInInspector(component))
			{
				orderIndex = -1;
			}

			var addSettings = new EntryAddSettings
			{
				componentName = componentName,
				componentIndex = orderIndex,
				componentInstanceId = component.GetInstanceID(),
			};

			TraverseObjectProperties(target, component, addSettings);
		}
        private static void ProcessScriptableObjectAsset()
        {
            var path      = assetConjunctions.asset.Path;
            var mainAsset = AssetDatabase.LoadMainAssetAtPath(path);

            if (mainAsset == null)
            {
                return;
            }

            currentObjectCache = null;
            currentLocation    = Location.ScriptableObjectAsset;

            var addSettings = new EntryAddSettings
            {
                componentIndex = -1,
            };

            TraverseObjectProperties(mainAsset, mainAsset, addSettings);
        }
        private static bool OnGameObjectTraverse(ObjectTraverseInfo traverseInfo)
        {
            var target = traverseInfo.current;

            currentObjectCache = null;

            //Debug.Log("OnGameObjectTraverse " + target);

            if (traverseInfo.inPrefabInstance)
            {
                //Debug.Log("traverseInfo.dirtyComponents " + traverseInfo.dirtyComponents);
                var prefabAssetSource = CSPrefabTools.GetAssetSource(target);
                if (prefabAssetSource != null)
                {
                    var instanceId = prefabAssetSource.GetInstanceID();
                    TryAddEntryToMatchedConjunctions(target, instanceId, null);

                    if (traverseInfo.dirtyComponents == null)
                    {
                        traverseInfo.skipCurrentTree = true;
                        return(true);
                    }
                }
            }

            var thumbnail = AssetPreview.GetMiniThumbnail(target);

            if (thumbnail != null && (thumbnail.hideFlags & HideFlags.HideAndDontSave) == 0)
            {
                var addSettings = new EntryAddSettings
                {
                    prefix = "[Object Icon]",
                };
                TryAddEntryToMatchedConjunctions(target, thumbnail.GetInstanceID(), addSettings);
            }

            CSTraverseTools.TraverseGameObjectComponents(traverseInfo, OnGameObjectComponentTraverse);

            return(true);
        }
Example #5
0
		public static bool OnGameObjectTraverse(ObjectTraverseInfo traverseInfo)
		{
			var target = traverseInfo.current;

			//Debug.Log("OnGameObjectTraverse " + target);

			if (traverseInfo.inPrefabInstance)
			{
				var prefabAssetSource = CSPrefabTools.GetAssetSource(target);
				if (prefabAssetSource != null)
				{
					var instanceId = prefabAssetSource.GetInstanceID();
					currentProcessReferenceCallback(target, instanceId, null);

					if (traverseInfo.dirtyComponents == null)
					{
						traverseInfo.skipCurrentTree = true;
						return true;
					}
				}
			}

			var thumbnail = AssetPreview.GetMiniThumbnail(target);
			if (thumbnail != null && (thumbnail.hideFlags & HideFlags.HideAndDontSave) == 0)
			{
				var addSettings = new EntryAddSettings
				{
					prefix = "[Object Icon]",
				};
				currentProcessReferenceCallback(target, thumbnail.GetInstanceID(), addSettings);
			}

			CSTraverseTools.TraverseGameObjectComponents(traverseInfo, OnGameObjectComponentTraverse);

			return true;
		}
        private static void OnGameObjectComponentTraverse(ObjectTraverseInfo traverseInfo, Component component, int orderIndex)
        {
            if (component == null)
            {
                return;
            }

            var target        = traverseInfo.current;
            var componentName = component.GetType().Name;

            if ((component.hideFlags & HideFlags.HideInInspector) != 0)
            {
                componentName += " (HideInInspector)";
                orderIndex     = -1;
            }

            var addSettings = new EntryAddSettings
            {
                componentName  = componentName,
                componentIndex = orderIndex,
            };

            TraverseObjectProperties(target, component, addSettings);
        }
Example #7
0
        private static void ProcessPrefab(string path)
        {
            var assetObject = AssetDatabase.LoadMainAssetAtPath(path);

            if (assetObject == null)
            {
                return;
            }

            var prefabRootGameObject = assetObject as GameObject;

            if (prefabRootGameObject == null)
            {
                return;
            }

            bool prefabOpened;
            var  stageRoot = TryGetPrefabRootFromStage(path, assetObject, out prefabOpened);

            if (stageRoot != null)
            {
                prefabRootGameObject = stageRoot;
            }

            EntryFinder.currentLocation = Location.PrefabAssetGameObject;
            CSTraverseTools.TraversePrefabGameObjects(prefabRootGameObject, true, false, EntryFinder.OnGameObjectTraverse);

            // specific cases handling for main asset -----------------------------------------------------

            /*var importSettings = AssetImporter.GetAtPath(path) as ModelImporter;
             * if (importSettings == null) return;
             *
             * var settings = new EntryAddSettings { suffix = "| Model Importer: RIG > Source" };
             * TryAddEntryToMatchedConjunctions(assetConjunctions.conjunctions, prefabRootGameObject, importSettings.sourceAvatar, settings);
             *
             * for (var i = 0; i < importSettings.clipAnimations.Length; i++)
             * {
             *      var clipAnimation = importSettings.clipAnimations[i];
             *      settings.suffix = "| Model Importer: Animations [" + clipAnimation.name + "] > Mask";
             *      TryAddEntryToMatchedConjunctions(assetConjunctions.conjunctions, prefabRootGameObject, clipAnimation.maskSource, settings);
             * }*/

            var allObjectsInPrefab = AssetDatabase.LoadAllAssetsAtPath(path);

            foreach (var objectOnPrefab in allObjectsInPrefab)
            {
                if (objectOnPrefab == null)
                {
                    continue;
                }
                if (objectOnPrefab is GameObject || objectOnPrefab is Component)
                {
                    continue;
                }

                EntryFinder.currentLocation = Location.PrefabAssetObject;

                var addSettings = new EntryAddSettings();

                EntryFinder.TraverseObjectProperties(objectOnPrefab, objectOnPrefab, addSettings);

                /*if (AssetDatabase.IsMainAsset(objectOnPrefab))
                 * {
                 *
                 * }
                 * else*/
                {
                    // specific cases handling ------------------------------------------------------------------------

                    /*if (objectOnPrefab is BillboardAsset)
                     * {
                     *      var billboardAsset = objectOnPrefab as BillboardAsset;
                     *      var settings = new EntryAddSettings { suffix = "| BillboardAsset: Material" };
                     *      TryAddEntryToMatchedConjunctions(assetConjunctions.conjunctions, billboardAsset, billboardAsset.material, settings);
                     * }
                     * else if (objectOnPrefab is TreeData)
                     * {
                     *      CachedObjectData objectInAssetCachedData = null;
                     *      InspectComponent(assetConjunctions.conjunctions, objectOnPrefab, objectOnPrefab, -1, true, ref objectInAssetCachedData);
                     * }*/
                }
            }

            if (prefabOpened)
            {
                StageUtility.GoBackToPreviousStage();
            }
        }
Example #8
0
        public static ReferencingEntryData CreateNewReferenceEntry(Location currentLocation, Object lookAt, GameObject lookAtGameObject, EntryAddSettings settings)
        {
            var lookAtInstanceId = lookAt.GetInstanceID();
            CachedObjectData cachedObject;

            if (CachedObjects.ContainsKey(lookAtInstanceId))
            {
                cachedObject = CachedObjects[lookAtInstanceId];
            }
            else
            {
                cachedObject = new CachedObjectData
                {
                    objectId         = CSObjectTools.GetUniqueObjectId(lookAt),
                    objectInstanceId = lookAt.GetInstanceID(),
                };

                if (currentLocation == Location.SceneGameObject || currentLocation == Location.PrefabAssetGameObject)
                {
                    if (lookAtGameObject != null)
                    {
                        var transform = lookAtGameObject.transform;
                        cachedObject.transformPath = CSEditorTools.GetFullTransformPath(transform);
                    }
                    else
                    {
                        cachedObject.transformPath = lookAt.name;
                    }
                }
                else if (currentLocation == Location.PrefabAssetObject)
                {
                    cachedObject.transformPath = lookAt.name;
                }
                else
                {
                    cachedObject.transformPath = string.Empty;
                }

                CachedObjects.Add(lookAtInstanceId, cachedObject);
            }

            var newEntry = new ReferencingEntryData
            {
                location         = currentLocation,
                objectId         = cachedObject.objectId,
                objectInstanceId = cachedObject.objectInstanceId,
                transformPath    = cachedObject.transformPath
            };

            if (settings != null)
            {
                newEntry.componentName       = settings.componentName;
                newEntry.componentId         = settings.componentIndex;
                newEntry.componentInstanceId = settings.componentInstanceId;
                newEntry.prefixLabel         = settings.prefix;
                newEntry.suffixLabel         = settings.suffix;
                newEntry.propertyPath        = settings.propertyPath;
            }

            return(newEntry);
        }
Example #9
0
        public static void ProcessObject(Location currentLocation, Object inspectedUnityObject, Object target, EntryAddSettings addSettings, ProcessObjectReferenceHandler processReferenceCallback)
        {
            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;

                    processReferenceCallback(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 = 0;
                    if (material.HasProperty(MainTextureShaderProperty))
                    {
                        var mainTexture       = material.mainTexture;
                        mainTextureInstanceId = mainTexture != null ? mainTexture.GetInstanceID() : 0;
                    }

                    processReferenceCallback(inspectedUnityObject, mainTextureInstanceId, addSettings);

                    addSettings.suffix = "(Shader)";

                    var shaderInstanceId = material.shader != null ? material.shader.GetInstanceID() : 0;
                    processReferenceCallback(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 == MainTexturePropertyName)
                            {
                                continue;
                            }

                            var textureProperty = arrayItem.FindPropertyRelative("second.m_Texture");
                            if (textureProperty != null)
                            {
                                if (textureProperty.propertyType == SerializedPropertyType.ObjectReference)
                                {
                                    addSettings.suffix = " (" + fieldName + ")";
                                    processReferenceCallback(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;
            });
        }
Example #10
0
        public static void TraverseObjectProperties(Object inspectedUnityObject, Object target, EntryAddSettings addSettings)
        {
            if (target is Tilemap)
            {
                ManualComponentProcessor.ProcessTilemap(inspectedUnityObject, (Tilemap)target, addSettings, currentProcessReferenceCallback);
                return;
            }

            GenericObjectProcessor.ProcessObject(currentLocation, inspectedUnityObject, target, addSettings, currentProcessReferenceCallback);
        }
Example #11
0
        public static void ProcessTilemap(Object inspectedUnityObject, Tilemap target, EntryAddSettings addSettings, ProcessObjectReferenceHandler processReferenceCallback)
        {
            var tilesCount = target.GetUsedTilesCount();

            if (tilesCount == 0)
            {
                return;
            }

            var usedTiles = new TileBase[tilesCount];

            target.GetUsedTilesNonAlloc(usedTiles);

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

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

                if (tile.sprite != null)
                {
                    processReferenceCallback(inspectedUnityObject, tile.sprite.GetInstanceID(), addSettings);
                }
            }
        }
Example #12
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);
                }
            }
        }
        internal static void TryAddEntryToMatchedConjunctions(Object lookAt, int lookForInstanceId, EntryAddSettings settings)
        {
            var lookAtGameObject = lookAt as GameObject;

            for (var i = 0; i < assetConjunctions.conjunctions.Count; i++)
            {
                var conjunction            = assetConjunctions.conjunctions[i];
                var referencedAssetObjects = conjunction.referencedAsset.GetAllAssetObjects();

                var match = false;
                for (var j = 0; j < referencedAssetObjects.Length; j++)
                {
                    if (referencedAssetObjects[j] != lookForInstanceId)
                    {
                        continue;
                    }

                    match = true;
                    break;
                }

                if (!match)
                {
                    continue;
                }

                if (currentObjectCache == null)
                {
                    currentObjectCache          = new CachedObjectData();
                    currentObjectCache.objectId = CSObjectTools.GetUniqueObjectId(lookAt);

                    if (currentLocation == Location.SceneGameObject || currentLocation == Location.PrefabAssetGameObject)
                    {
                        if (lookAtGameObject != null)
                        {
                            var transform = lookAtGameObject.transform;
                            currentObjectCache.transformPath = CSEditorTools.GetFullTransformPath(transform);
                        }
                        else
                        {
                            currentObjectCache.transformPath = lookAt.name;
                        }
                    }
                    else if (currentLocation == Location.PrefabAssetObject)
                    {
                        currentObjectCache.transformPath = lookAt.name;
                    }
                    else
                    {
                        currentObjectCache.transformPath = string.Empty;
                    }
                }

                var newEntry = new ReferencingEntryData
                {
                    location      = currentLocation,
                    objectId      = currentObjectCache.objectId,
                    transformPath = currentObjectCache.transformPath
                };

                if (settings != null)
                {
                    newEntry.componentName = settings.componentName;
                    newEntry.componentId   = settings.componentIndex;
                    newEntry.prefixLabel   = settings.prefix;
                    newEntry.suffixLabel   = settings.suffix;
                    newEntry.propertyPath  = settings.propertyPath;
                }

                conjunction.referencedAtInfo.AddNewEntry(newEntry);
            }
        }
        private static void TraverseObjectProperties(Object inspectedUnityObject, Object target, EntryAddSettings addSettings)
        {
#if UNITY_2018_2_OR_NEWER
            if (target is Tilemap)
            {
                ManualComponentProcessor.ProcessTilemap(inspectedUnityObject, (Tilemap)target, addSettings);
                return;
            }
#endif
            GenericObjectProcessor.ProcessObject(currentLocation, inspectedUnityObject, target, addSettings);
        }