private static void CheckLightMapSettings(TreeConjunction conjunction, int candidateInstanceId) { lightmapSettings = lightmapSettings ? lightmapSettings : CSSettingsTools.GetInSceneLightmapSettings(); if (lightmapSettings == null) { return; } lightmapSettingsSo = lightmapSettingsSo ?? new SerializedObject(lightmapSettings); lightmapParametersField = lightmapParametersField ?? lightmapSettingsSo.FindProperty( "m_LightmapEditorSettings.m_LightmapParameters"); if (lightmapParametersField != null && lightmapParametersField.propertyType == SerializedPropertyType.ObjectReference) { if (lightmapParametersField.objectReferenceInstanceIDValue == candidateInstanceId) { var entry = new ReferencingEntryData { location = Location.SceneLightingSettings, prefixLabel = "Lighting settings (Scene tab > Lightmapping Settings > Lightmap Parameters)" }; conjunction.referencedAtInfo.AddNewEntry(entry); } } else { Debug.LogError( Maintainer.ConstructError( "Can't find m_LightmapParameters at the LightmapSettings!")); } }
private static void CheckRenderSettingsTexture(TreeConjunction conjunction, int candidateInstanceId) { renderSettings = renderSettings ? renderSettings : CSSettingsTools.GetInSceneRenderSettings(); if (renderSettings == null) { return; } renderSettingsSo = renderSettingsSo ?? new SerializedObject(renderSettings); renderHaloField = renderHaloField ?? renderSettingsSo.FindProperty("m_HaloTexture"); if (renderHaloField != null && renderHaloField.propertyType == SerializedPropertyType.ObjectReference) { if (renderHaloField.objectReferenceInstanceIDValue == candidateInstanceId) { var entry = new ReferencingEntryData { location = Location.SceneLightingSettings, prefixLabel = "Lighting settings (Scene tab > Other Settings > Halo Texture)" }; conjunction.referencedAtInfo.AddNewEntry(entry); } } else { Debug.LogError(Maintainer.ConstructError("Can't find m_HaloTexture at the RenderSettings!")); } renderSpotField = renderSpotField ?? renderSettingsSo.FindProperty("m_SpotCookie"); if (renderSpotField != null && renderSpotField.propertyType == SerializedPropertyType.ObjectReference) { if (renderSpotField.objectReferenceInstanceIDValue == candidateInstanceId) { var entry = new ReferencingEntryData { location = Location.SceneLightingSettings, prefixLabel = "Lighting settings (Scene tab > Other Settings > Spot Cookie)" }; conjunction.referencedAtInfo.AddNewEntry(entry); } } else { Debug.LogError(Maintainer.ConstructError("Can't find m_SpotCookie at the RenderSettings!")); } /*var iterator = renderSettingsSo.GetIterator(); * while (iterator.Next(true)) * { * if (iterator.propertyType == SerializedPropertyType.ObjectReference) * { * Debug.Log(iterator.propertyPath + " [" + iterator.objectReferenceValue + "]"); * } * }*/ }
private static void CheckSun(TreeConjunction conjunction, int candidateInstanceId) { if (RenderSettings.sun == null || RenderSettings.sun.GetInstanceID() != candidateInstanceId) { return; } var entry = new ReferencingEntryData { location = Location.SceneLightingSettings, prefixLabel = "Lighting settings (Scene tab > Environment > Sun Source)" }; conjunction.referencedAtInfo.AddNewEntry(entry); }
private static void CheckLightingDataAsset(TreeConjunction conjunction, int candidateInstanceId) { if (Lightmapping.lightingDataAsset == null || Lightmapping.lightingDataAsset.GetInstanceID() != candidateInstanceId) { return; } var entry = new ReferencingEntryData { location = Location.SceneLightingSettings, prefixLabel = "Lighting settings (Global maps tab)" }; conjunction.referencedAtInfo.AddNewEntry(entry); }
private static void CheckLightingCubemap(TreeConjunction conjunction, int candidateInstanceId) { if (RenderSettings.customReflection == null || RenderSettings.customReflection.GetInstanceID() != candidateInstanceId) { return; } var entry = new ReferencingEntryData { location = Location.SceneLightingSettings }; if (RenderSettings.defaultReflectionMode == DefaultReflectionMode.Custom) { entry.prefixLabel = "Lighting settings (Scene tab > Environment > Cubemap)"; } else { entry.prefixLabel = "Lighting settings (Scene tab > Environment > Cubemap), set Reflections > Source > Custom to see"; } conjunction.referencedAtInfo.AddNewEntry(entry); }
private static void CheckNavMesh(TreeConjunction conjunction, int candidateInstanceId) { navMeshSettingsSo = navMeshSettingsSo ?? new SerializedObject(UnityEditor.AI.NavMeshBuilder.navMeshSettingsObject); navMeshDataField = navMeshDataField ?? navMeshSettingsSo.FindProperty("m_NavMeshData"); if (navMeshDataField != null && navMeshDataField.propertyType == SerializedPropertyType.ObjectReference) { if (navMeshDataField.objectReferenceInstanceIDValue == candidateInstanceId) { var entry = new ReferencingEntryData { location = Location.SceneNavigationSettings, prefixLabel = "Navigation settings of scene" }; conjunction.referencedAtInfo.AddNewEntry(entry); } } else { Debug.LogError( Maintainer.ConstructError("Can't find m_NavMeshData at the navMeshSettingsObject!")); } }
private static void SetReferencingEntries(List <TreeConjunction> conjunctions) { foreach (var conjunction in conjunctions) { var referencedAtInfo = conjunction.referencedAtInfo; if (referencedAtInfo.entries == null || referencedAtInfo.entries.Length == 0) { var newEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "No exact reference place found." }; var referencedAtAssetInfo = referencedAtInfo as ReferencedAtAssetInfo; if (referencedAtAssetInfo != null && referencedAtAssetInfo.assetInfo.Type == CSReflectionTools.sceneAssetType) { var sceneSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to remove all missing prefabs/scripts (if any) and re-save scene, it may cleanup junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, sceneSpecificEntry }; } else if (referencedAtAssetInfo != null && referencedAtAssetInfo.assetInfo.Type == CSReflectionTools.gameObjectType) { var prefabSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to re-Apply prefab explicitly, this may clean up junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, prefabSpecificEntry }; } else { referencedAtInfo.entries = new[] { newEntry }; } if (ReferencesFinder.debugMode) { if (conjunction.referencedAsset != null) { Debug.LogWarning(Maintainer.ConstructWarning( "Couldn't determine where exactly this asset is referenced: " + conjunction.referencedAsset.Path, ReferencesFinder.ModuleName)); } } } foreach (var targetTreeElement in conjunction.treeElements) { targetTreeElement.referencingEntries = referencedAtInfo.entries; } } }
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); }
private void SelectRow(ReferencingEntryData reference) { treePanel.SelectRow(reference.objectId, reference.componentId); }
private static void ShowItem(ReferencesTreeViewItem <T> item, ReferencingEntryData referencingEntry = null) { var assetPath = item.data.assetPath; if (referencingEntry != null) { if (referencingEntry.location == Location.SceneLightingSettings || referencingEntry.location == Location.SceneNavigationSettings) { var sceneOpenResult = CSSceneTools.OpenSceneWithSavePrompt(assetPath); if (!sceneOpenResult.success) { Debug.LogError(Maintainer.ConstructError("Can't open scene " + assetPath)); MaintainerWindow.ShowNotification("Can't show it properly"); return; } } switch (referencingEntry.location) { case Location.ScriptAsset: case Location.ScriptableObjectAsset: if (!CSSelectionTools.RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetObject: if (!CSSelectionTools.RevealAndSelectSubAsset(assetPath, referencingEntry.transformPath, referencingEntry.objectId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetGameObject: case Location.SceneGameObject: if (!CSSelectionTools.RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneLightingSettings: if (!CSMenuTools.ShowSceneSettingsLighting()) { Debug.LogError(Maintainer.ConstructError("Can't open Lighting settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneNavigationSettings: if (!CSMenuTools.ShowSceneSettingsNavigation()) { Debug.LogError(Maintainer.ConstructError("Can't open Navigation settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.NotFound: case Location.Invisible: break; case Location.TileMap: if (!CSSelectionTools.RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } // TODO: open tilemap editor window? break; default: throw new ArgumentOutOfRangeException(); } } else { if (item.data.assetSettingsKind == AssetSettingsKind.NotSettings) { if (!CSSelectionTools.RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } } else { if (!CSEditorTools.RevealInSettings(item.data.assetSettingsKind, assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } } } }
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); } }
public static bool FillReferenceEntries() { var canceled = false; var count = ReferencesFinder.ConjunctionInfoList.Count; var updateStep = Math.Max(count / MaintainerSettings.UpdateProgressStep, 1); for (var i = 0; i < count; i++) { if ((i < 10 || i % updateStep == 0) && EditorUtility.DisplayCancelableProgressBar( string.Format(ReferencesFinder.ProgressCaption, 2, ReferencesFinder.PhasesCount), string.Format(ReferencesFinder.ProgressText, "Filling reference details", i + 1, count), (float)i / count)) { canceled = true; break; } assetConjunctions = ReferencesFinder.ConjunctionInfoList[i]; var type = assetConjunctions.asset.Type; if (type == CSReflectionTools.gameObjectType) { ProcessPrefab(); } else if (type == CSReflectionTools.sceneAssetType) { ProcessScene(); } else if (type == CSReflectionTools.monoScriptType) { ProcessScriptAsset(); } else if (type != null && (type.BaseType == CSReflectionTools.scriptableObjectType || type == CSReflectionTools.monoBehaviourType)) { ProcessScriptableObjectAsset(); } foreach (var conjunction in assetConjunctions.conjunctions) { var referencedAtInfo = conjunction.referencedAtInfo; if (referencedAtInfo.entries == null || referencedAtInfo.entries.Length == 0) { var newEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "No exact reference place found." }; if (referencedAtInfo.assetInfo.Type == CSReflectionTools.sceneAssetType) { var sceneSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to remove all missing prefabs/scripts (if any) and re-save scene, it may cleanup junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, sceneSpecificEntry }; } else if (referencedAtInfo.assetInfo.Type == CSReflectionTools.gameObjectType) { var prefabSpecificEntry = new ReferencingEntryData { location = Location.NotFound, prefixLabel = "Please try to re-Apply prefab explicitly, this may clean up junky dependencies." }; referencedAtInfo.entries = new[] { newEntry, prefabSpecificEntry }; } else { referencedAtInfo.entries = new[] { newEntry }; } if (ReferencesFinder.debugMode) { Debug.LogWarning(Maintainer.ConstructWarning("Couldn't determine where exactly this asset is referenced: " + conjunction.referencedAsset.Path, ReferencesFinder.ModuleName)); } } foreach (var targetTreeElement in conjunction.treeElements) { targetTreeElement.referencingEntries = referencedAtInfo.entries; } } } return(canceled); }
public static void RevealAndSelectReferencingEntry(string assetPath, ReferencingEntryData referencingEntry) { if (!string.IsNullOrEmpty(assetPath) && (referencingEntry.location == Location.SceneLightingSettings || referencingEntry.location == Location.SceneNavigationSettings)) { var sceneOpenResult = CSSceneTools.OpenSceneWithSavePrompt(assetPath); if (!sceneOpenResult.success) { Debug.LogError(Maintainer.ConstructError("Can't open scene " + assetPath)); MaintainerWindow.ShowNotification("Can't show it properly"); return; } } switch (referencingEntry.location) { case Location.ScriptAsset: case Location.ScriptableObjectAsset: if (!RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetObject: if (!RevealAndSelectSubAsset(assetPath, referencingEntry.transformPath, referencingEntry.objectId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetGameObject: case Location.SceneGameObject: if (!RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneLightingSettings: if (!CSMenuTools.ShowSceneSettingsLighting()) { Debug.LogError(Maintainer.ConstructError("Can't open Lighting settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneNavigationSettings: if (!CSMenuTools.ShowSceneSettingsNavigation()) { Debug.LogError(Maintainer.ConstructError("Can't open Navigation settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.NotFound: case Location.Invisible: break; case Location.TileMap: if (!RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } // TODO: open tile map editor window? break; default: throw new ArgumentOutOfRangeException(); } }