update libs
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetStoreTools.Previews.Utility
|
||||
{
|
||||
internal static class GraphicsUtility
|
||||
{
|
||||
public static Texture2D GetTextureFromCamera(Camera camera, int desiredWidth, int desiredHeight, int desiredDepth)
|
||||
{
|
||||
var texture = new Texture2D(desiredWidth, desiredHeight);
|
||||
var originalRenderTexture = RenderTexture.active;
|
||||
var renderTexture = RenderTexture.GetTemporary(desiredWidth, desiredHeight, desiredDepth);
|
||||
var cameraInitiallyEnabled = camera.enabled;
|
||||
|
||||
try
|
||||
{
|
||||
if (cameraInitiallyEnabled)
|
||||
camera.enabled = false;
|
||||
|
||||
camera.targetTexture = renderTexture;
|
||||
camera.Render();
|
||||
|
||||
RenderTexture.active = renderTexture;
|
||||
texture.ReadPixels(new Rect(0, 0, texture.width, texture.height), 0, 0);
|
||||
texture.Apply();
|
||||
}
|
||||
finally
|
||||
{
|
||||
camera.targetTexture = null;
|
||||
RenderTexture.active = originalRenderTexture;
|
||||
RenderTexture.ReleaseTemporary(renderTexture);
|
||||
camera.enabled = cameraInitiallyEnabled;
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Texture2D ResizeTexture(Texture2D source, int desiredWidth, int desiredHeight)
|
||||
{
|
||||
var texture = new Texture2D(desiredWidth, desiredHeight);
|
||||
var originalRenderTexture = RenderTexture.active;
|
||||
var renderTexture = RenderTexture.GetTemporary(desiredWidth, desiredHeight, 32);
|
||||
|
||||
try
|
||||
{
|
||||
RenderTexture.active = renderTexture;
|
||||
Graphics.Blit(source, renderTexture);
|
||||
|
||||
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
|
||||
texture.Apply();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RenderTexture.active = originalRenderTexture;
|
||||
RenderTexture.ReleaseTemporary(renderTexture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Texture2D ResizeTextureNormalMap(Texture2D source, int desiredWidth, int desiredHeight)
|
||||
{
|
||||
var texture = new Texture2D(desiredWidth, desiredHeight);
|
||||
var originalRenderTexture = RenderTexture.active;
|
||||
var renderTexture = RenderTexture.GetTemporary(desiredWidth, desiredHeight, 32, RenderTextureFormat.Default, RenderTextureReadWrite.Linear);
|
||||
|
||||
try
|
||||
{
|
||||
RenderTexture.active = renderTexture;
|
||||
Graphics.Blit(source, renderTexture);
|
||||
|
||||
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
|
||||
|
||||
for (int i = 0; i < texture.width; i++)
|
||||
{
|
||||
for (int j = 0; j < texture.height; j++)
|
||||
{
|
||||
var color = texture.GetPixel(i, j);
|
||||
color.b = color.r;
|
||||
color.r = color.a;
|
||||
color.a = 1;
|
||||
texture.SetPixel(i, j, color);
|
||||
}
|
||||
}
|
||||
|
||||
texture.Apply();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RenderTexture.active = originalRenderTexture;
|
||||
RenderTexture.ReleaseTemporary(renderTexture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0a4fc8f266b4dd41a59693dd581e232
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Utility/GraphicsUtility.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,72 @@
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetStoreTools.Previews.Utility
|
||||
{
|
||||
internal static class PreviewConvertUtility
|
||||
{
|
||||
public static string ConvertFilename(Object asset, FileNameFormat format)
|
||||
{
|
||||
string fileName = string.Empty;
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case FileNameFormat.Guid:
|
||||
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(asset, out var guid, out long _);
|
||||
fileName = guid;
|
||||
break;
|
||||
case FileNameFormat.FullAssetPath:
|
||||
var assetPath = AssetDatabase.GetAssetPath(asset);
|
||||
|
||||
if (assetPath.StartsWith("Assets/"))
|
||||
fileName = assetPath.Substring("Assets/".Length);
|
||||
else if (assetPath.StartsWith("Packages/"))
|
||||
fileName = assetPath.Substring("Packages/".Length);
|
||||
|
||||
fileName = fileName.Replace("/", "_");
|
||||
break;
|
||||
case FileNameFormat.AssetName:
|
||||
fileName = asset.name;
|
||||
break;
|
||||
default:
|
||||
throw new System.Exception("Undefined format");
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public static string ConvertExtension(PreviewFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PreviewFormat.JPG:
|
||||
return "jpg";
|
||||
case PreviewFormat.PNG:
|
||||
return "png";
|
||||
default:
|
||||
throw new System.Exception("Undefined format");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConvertFilenameWithExtension(Object asset, FileNameFormat nameFormat, PreviewFormat imageFormat)
|
||||
{
|
||||
var filename = ConvertFilename(asset, nameFormat);
|
||||
var extension = ConvertExtension(imageFormat);
|
||||
return $"{filename}.{extension}";
|
||||
}
|
||||
|
||||
public static byte[] ConvertTexture(Texture2D texture, PreviewFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PreviewFormat.JPG:
|
||||
return texture.EncodeToJPG();
|
||||
case PreviewFormat.PNG:
|
||||
return texture.EncodeToPNG();
|
||||
default:
|
||||
throw new System.Exception("Undefined format");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 700eaf82299628d44853599774664bea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Utility/PreviewConvertUtility.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
#if AST_URP_AVAILABLE
|
||||
using UnityEngine.Rendering.Universal;
|
||||
#endif
|
||||
#if AST_HDRP_AVAILABLE
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
#endif
|
||||
|
||||
namespace AssetStoreTools.Previews.Utility
|
||||
{
|
||||
internal static class PreviewSceneUtility
|
||||
{
|
||||
private const string PreviewSceneName = "Preview Generation In Progress";
|
||||
private static readonly Color BackgroundColor = new Color(82f / 255, 82f / 255, 82f / 255);
|
||||
private static readonly Color BackgroundColorHDRP = new Color(38f / 255, 38f / 255, 38f / 255);
|
||||
|
||||
public static async Task OpenPreviewSceneForCurrentPipeline()
|
||||
{
|
||||
// Wait for an Editor frame to avoid recursive player loop internal errors
|
||||
await WaitForEditorUpdate();
|
||||
|
||||
switch (RenderPipelineUtility.GetCurrentPipeline())
|
||||
{
|
||||
case RenderPipeline.BiRP:
|
||||
await OpenPreviewSceneBiRP();
|
||||
break;
|
||||
#if AST_URP_AVAILABLE
|
||||
case RenderPipeline.URP:
|
||||
await OpenPreviewSceneURP();
|
||||
break;
|
||||
#endif
|
||||
#if AST_HDRP_AVAILABLE
|
||||
case RenderPipeline.HDRP:
|
||||
await OpenPreviewSceneHDRP();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
throw new NotImplementedException("Undefined Render Pipeline");
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task WaitForEditorUpdate()
|
||||
{
|
||||
var updateCalled = false;
|
||||
var delayCalled = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
EditorApplication.update -= Update;
|
||||
updateCalled = true;
|
||||
}
|
||||
|
||||
EditorApplication.update += Update;
|
||||
while (!updateCalled)
|
||||
await Task.Delay(10);
|
||||
|
||||
void DelayCall()
|
||||
{
|
||||
EditorApplication.delayCall -= DelayCall;
|
||||
delayCalled = true;
|
||||
}
|
||||
|
||||
EditorApplication.delayCall += DelayCall;
|
||||
while (!delayCalled)
|
||||
await Task.Delay(10);
|
||||
}
|
||||
|
||||
public static async Task OpenPreviewSceneBiRP()
|
||||
{
|
||||
OpenNewScene();
|
||||
|
||||
CreateSceneCamera();
|
||||
CreateSceneLighting();
|
||||
|
||||
await WaitForLighting();
|
||||
}
|
||||
|
||||
private static void OpenNewScene()
|
||||
{
|
||||
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
|
||||
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
||||
scene.name = PreviewSceneName;
|
||||
}
|
||||
|
||||
private static Camera CreateSceneCamera()
|
||||
{
|
||||
var cameraGO = new GameObject() { name = "Camera" };
|
||||
var camera = cameraGO.AddComponent<Camera>();
|
||||
camera.enabled = false;
|
||||
camera.tag = "MainCamera";
|
||||
|
||||
camera.nearClipPlane = 0.01f;
|
||||
camera.farClipPlane = 100000;
|
||||
camera.clearFlags = CameraClearFlags.SolidColor;
|
||||
camera.backgroundColor = BackgroundColor;
|
||||
|
||||
return camera;
|
||||
}
|
||||
|
||||
private static Light CreateSceneLighting()
|
||||
{
|
||||
var lightGO = new GameObject() { name = "Lights" };
|
||||
lightGO.transform.rotation = Quaternion.Euler(45, 225, 0);
|
||||
var light = lightGO.AddComponent<Light>();
|
||||
light.intensity = 0.75f;
|
||||
light.type = LightType.Directional;
|
||||
light.shadows = LightShadows.None;
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
private static async Task WaitForLighting()
|
||||
{
|
||||
while (!DynamicGI.isConverged)
|
||||
await Task.Delay(100);
|
||||
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
#if AST_URP_AVAILABLE
|
||||
public static async Task OpenPreviewSceneURP()
|
||||
{
|
||||
OpenNewScene();
|
||||
|
||||
var camera = CreateSceneCamera();
|
||||
camera.gameObject.AddComponent<UniversalAdditionalCameraData>();
|
||||
|
||||
var lighting = CreateSceneLighting();
|
||||
lighting.intensity = 0.5f;
|
||||
lighting.gameObject.AddComponent<UniversalAdditionalLightData>();
|
||||
|
||||
await WaitForLighting();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if AST_HDRP_AVAILABLE
|
||||
public static async Task OpenPreviewSceneHDRP()
|
||||
{
|
||||
OpenNewScene();
|
||||
|
||||
var camera = CreateSceneCamera();
|
||||
var cameraData = camera.gameObject.AddComponent<HDAdditionalCameraData>();
|
||||
cameraData.clearColorMode = HDAdditionalCameraData.ClearColorMode.Color;
|
||||
cameraData.backgroundColorHDR = BackgroundColorHDRP;
|
||||
|
||||
var light = CreateSceneLighting();
|
||||
var lightData = light.gameObject.AddComponent<HDAdditionalLightData>();
|
||||
lightData.SetIntensity(5000, LightUnit.Lux);
|
||||
|
||||
CreateHDRPVolumeProfile();
|
||||
|
||||
await WaitForLighting();
|
||||
}
|
||||
|
||||
private static Volume CreateHDRPVolumeProfile()
|
||||
{
|
||||
var volumeGO = new GameObject() { name = "Volume" };
|
||||
var volume = volumeGO.gameObject.AddComponent<Volume>();
|
||||
|
||||
var profile = VolumeProfile.CreateInstance<VolumeProfile>();
|
||||
volume.profile = profile;
|
||||
volume.isGlobal = true;
|
||||
|
||||
var exposure = profile.Add<Exposure>();
|
||||
exposure.active = true;
|
||||
|
||||
exposure.mode.overrideState = true;
|
||||
exposure.mode.value = ExposureMode.Fixed;
|
||||
|
||||
exposure.fixedExposure.overrideState = true;
|
||||
exposure.fixedExposure.value = 11;
|
||||
|
||||
var fog = profile.Add<Fog>();
|
||||
fog.active = true;
|
||||
|
||||
fog.enabled.overrideState = true;
|
||||
fog.enabled.value = false;
|
||||
|
||||
#if AST_HDRP_AVAILABLE_V12
|
||||
var volumetricClouds = profile.Add<VolumetricClouds>();
|
||||
volumetricClouds.active = true;
|
||||
|
||||
volumetricClouds.enable.overrideState = true;
|
||||
volumetricClouds.enable.value = false;
|
||||
#endif
|
||||
|
||||
return volume;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63fa5650920e7914dae6fe76badac249
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Utility/PreviewSceneUtility.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace AssetStoreTools.Previews.Utility
|
||||
{
|
||||
internal enum RenderPipeline
|
||||
{
|
||||
Unknown = 0,
|
||||
BiRP = 1,
|
||||
URP = 2,
|
||||
HDRP = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c43c7ce2b9090ab49bb8944bc6bdb3c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Utility/RenderPipeline.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,32 @@
|
||||
using UnityEngine.Rendering;
|
||||
#if AST_URP_AVAILABLE
|
||||
using UnityEngine.Rendering.Universal;
|
||||
#endif
|
||||
#if AST_HDRP_AVAILABLE
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
#endif
|
||||
|
||||
namespace AssetStoreTools.Previews.Utility
|
||||
{
|
||||
internal static class RenderPipelineUtility
|
||||
{
|
||||
public static RenderPipeline GetCurrentPipeline()
|
||||
{
|
||||
var currentPipelineAsset = GraphicsSettings.currentRenderPipeline;
|
||||
if (currentPipelineAsset == null)
|
||||
return RenderPipeline.BiRP;
|
||||
|
||||
#if AST_URP_AVAILABLE
|
||||
if (currentPipelineAsset is UniversalRenderPipelineAsset)
|
||||
return RenderPipeline.URP;
|
||||
#endif
|
||||
|
||||
#if AST_HDRP_AVAILABLE
|
||||
if (currentPipelineAsset is HDRenderPipelineAsset)
|
||||
return RenderPipeline.HDRP;
|
||||
#endif
|
||||
|
||||
return RenderPipeline.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e42bdf53cd8b51429b10a6742ec5272
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Utility/RenderPipelineUtility.cs
|
||||
uploadId: 724584
|
||||
Reference in New Issue
Block a user