static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { List <SceneReferenceAsset> allAssets = null; foreach (var path in importedAssets) { if (path.EndsWith(".asset") == false) { continue; } var importedAsset = AssetDatabase.LoadAssetAtPath <SceneReferenceAsset>(path); if (importedAsset == null) { continue; } if (allAssets == null) { allAssets = SceneReferenceAsset.FindAll().ToList(); } if (allAssets.All(asset => asset == importedAsset || asset.path != importedAsset.path)) { continue; } Debug.LogWarning($"{nameof(SceneReferenceAsset)} already exists for '{importedAsset.path}'."); importedAsset.Delete(); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var sceneReferenceAsset = (SceneReferenceAsset)property.objectReferenceValue; Object obj = (sceneReferenceAsset) ? sceneReferenceAsset.FindSceneAsset() : null; var sceneAsset = (SceneAsset)EditorGUI.ObjectField(position, label, obj, typeof(SceneAsset), false); var scenePath = AssetDatabase.GetAssetPath(sceneAsset); if (sceneAsset == null || string.IsNullOrEmpty(scenePath)) { property.objectReferenceValue = null; } else if (sceneReferenceAsset == null || sceneReferenceAsset.path != scenePath) { property.objectReferenceValue = SceneReferenceAsset.FindOrCreate(scenePath); } }
static void MenuItem() { var scenePaths = Selection.objects.Select(AssetDatabase.GetAssetPath).Where(path => path.EndsWith(".unity")); foreach (var scenePath in scenePaths) { var asset = SceneReferenceAsset.FindByScenePath(scenePath); if (asset) { Debug.LogWarning($"{nameof(SceneReferenceAsset)} already exists for '{asset.path}'."); } else { asset = SceneReferenceAsset.CreateByScenePath(scenePath); } Selection.activeObject = asset; } }