Skip to content

Commit 91e26ed

Browse files
committed
remove deprecated API
1 parent d8bd79b commit 91e26ed

12 files changed

+38
-511
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,6 @@ Thumbs.db
8888
# ====== #
8989
# custom #
9090
# ====== #
91-
Builds/
92-
[Pp]ackages/[Cc]om.unity.asset-store-tools/
91+
/[Pp]ackages/[Cc]om.unity.asset-store-tools/*
92+
/[Aa]ssets/[Gg]enesis Assets/*
93+
/[Aa]ssets/[Gg]enesis Assets.meta

Packages/com.doji.genesis/Editor/DepthSkyboxPrefabUtility.cs

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,17 @@ namespace Genesis.Editor {
99
public static class DepthSkyboxPrefabUtility {
1010

1111
/// <summary>
12-
/// Given an input png file, generates depth and creates a prefab for a DepthSkybox.
12+
/// Given an input image file, generates depth and creates a prefab for a DepthSkybox.
1313
/// </summary>
14-
public static void CreateSkyboxAsset(string pngFilePath) {
15-
string name = Path.GetFileNameWithoutExtension(pngFilePath);
14+
public static void CreateSkyboxAsset(string filePath) {
15+
string name = Path.GetFileNameWithoutExtension(filePath);
1616
string assetPath = Path.Combine(StagingAreaPath, $"{name}");
1717
Directory.CreateDirectory(assetPath);
1818

19-
string pngTargetPath = Path.Combine(assetPath, $"{name}_rgb.png");
20-
Texture2D skybox = ImportImageFile(pngFilePath, pngTargetPath);
19+
string targetPath = Path.Combine(assetPath, $"{name}_rgb{Path.GetExtension(filePath)}");
20+
Texture2D skybox = ImportImageFile(filePath, targetPath);
2121
var range = GenerateDepth(assetPath, name, skybox);
22-
CreateSkyboxPrefab(assetPath, name, range);
23-
}
24-
25-
/// <summary>
26-
/// Downloads skybox from Skybox Lab, generates depth and creates a prefab for a DepthSkybox.
27-
/// </summary>
28-
public static async Task CreateSkyboxAsset(string id, string name) {
29-
string assetPath = Path.Combine(StagingAreaPath, $"{id}");
30-
Directory.CreateDirectory(assetPath);
31-
32-
string imageFile = Path.Combine(assetPath, $"{name}_rgb.png");
33-
Texture2D skybox = await DownloadSkyboxById(imageFile, id);
34-
var range = GenerateDepth(assetPath, name, skybox);
35-
CreateSkyboxPrefab(assetPath, name, range);
22+
CreateSkyboxPrefab(skybox, assetPath, name, range);
3623
}
3724

3825
private static Vector2 GenerateDepth(string assetPath, string name, Texture2D skybox) {
@@ -70,18 +57,15 @@ private static void CreateAsset(Object obj, string path) {
7057
AssetDatabase.CreateAsset(obj, path);
7158
}
7259

73-
public static void CreateSkyboxPrefab(string assetPath, string name, Vector2 range) {
60+
public static void CreateSkyboxPrefab(Texture2D skybox, string assetPath, string name, Vector2 range) {
7461
int progressId = Progress.Start("Creating skybox assets", "Your skybox assets are being created...");
7562

7663
GameObject skyboxPrefab = (GameObject)Resources.Load("Prefabs/DepthSkybox");
7764

7865
GameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(skyboxPrefab);
7966
MeshRenderer renderer = instance.GetComponent<MeshRenderer>();
8067

81-
string skyboxPath = Path.Combine(assetPath, $"{name}_rgb.png");
8268
string depthPath = Path.Combine(assetPath, $"{name}_depth.asset");
83-
84-
Texture2D skybox = (Texture2D)AssetDatabase.LoadMainAssetAtPath(skyboxPath);
8569
Texture2D skyboxDepth = (Texture2D)AssetDatabase.LoadMainAssetAtPath(depthPath);
8670

8771
Material m = new Material(renderer.sharedMaterial);
@@ -109,49 +93,18 @@ public static void CreateSkyboxPrefab(string assetPath, string name, Vector2 ran
10993
Progress.Remove(progressId);
11094
}
11195

112-
/// <summary>
113-
/// Downloads a skybox by its ID and saves it inside the project as a .png file.
114-
/// This method assumes that the generation has already completed and that the
115-
/// skybox is available on the server and returns null otherwise.
116-
/// </summary>
117-
private static async Task<Texture2D> DownloadSkyboxById(string path, string id) {
118-
int progressId = Progress.Start($"Downloading skybox {id}", "Your skybox is being downloaded...");
119-
120-
// download the skybox
121-
Texture2D skybox = await AssetForge.Instance.GetSkyboxById(id);
122-
if (skybox == null) {
123-
Progress.Remove(progressId);
124-
return null;
125-
}
126-
127-
File.WriteAllBytes(path, skybox.EncodeToPNG());
128-
Object.DestroyImmediate(skybox);
129-
130-
AssetDatabase.Refresh();
131-
Texture2D skyboxTextureAsset = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
132-
133-
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(path);
134-
importer.maxTextureSize = 4096;
135-
importer.textureCompression = TextureImporterCompression.CompressedHQ;
136-
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
137-
138-
Progress.Remove(progressId);
139-
140-
return skyboxTextureAsset;
141-
}
142-
143-
private static Texture2D ImportImageFile(string pngFilePath, string pngTargetPath) {
96+
private static Texture2D ImportImageFile(string filePath, string targetPath) {
14497
int progressId = Progress.Start($"Importing image", "Your panorama is being imported...");
14598

146-
File.Copy(pngFilePath, pngTargetPath);
99+
File.Copy(filePath, targetPath);
147100

148101
AssetDatabase.Refresh();
149-
Texture2D skyboxTextureAsset = AssetDatabase.LoadAssetAtPath<Texture2D>(pngTargetPath);
102+
Texture2D skyboxTextureAsset = AssetDatabase.LoadAssetAtPath<Texture2D>(targetPath);
150103

151-
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(pngTargetPath);
104+
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(targetPath);
152105
importer.maxTextureSize = 4096;
153106
importer.textureCompression = TextureImporterCompression.CompressedHQ;
154-
AssetDatabase.ImportAsset(pngTargetPath, ImportAssetOptions.ForceUpdate);
107+
AssetDatabase.ImportAsset(targetPath, ImportAssetOptions.ForceUpdate);
155108

156109
Progress.Remove(progressId);
157110

Packages/com.doji.genesis/Editor/GenesisEditorWindow.cs

Lines changed: 0 additions & 103 deletions
This file was deleted.

Packages/com.doji.genesis/Editor/GenesisEditorWindow.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Packages/com.doji.genesis/Editor/GenesisImportByIDEditorWindow.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using static Genesis.Editor.DepthSkyboxPrefabUtility;
4+
5+
namespace Genesis.Editor {
6+
7+
public class GenesisImportPanoramaEditorWindow : EditorWindow {
8+
9+
[MenuItem("Genesis/Import equirectangular panorama from disk", false, 0)]
10+
public static void ImportViaPath() {
11+
string[] filter = new string[] { "Image files", "png,jpg,jpeg", "All files", "*" };
12+
string path = EditorUtility.OpenFilePanelWithFilters("Select panorama", "", filter);
13+
14+
if (string.IsNullOrEmpty(path)) {
15+
return;
16+
}
17+
18+
CreateSkyboxAsset(path);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)