补齐备份工程打开依赖
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f31dc67949f82694bbbba2e4ed6662d7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
#pragma warning disable 162
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
/*------------------------------------------------------------------------
|
||||
スクリプトインポート時チェック
|
||||
古いバージョンのファイルがまだある場合にダイアログとWarningを表示
|
||||
※他でスクリプトエラーが発生していると呼ばれないので注意
|
||||
-------------------------------------------------------------------------*/
|
||||
public class CheckConflict {
|
||||
|
||||
// ファイルのGUID ※TexGenフォルダ内のファイルであること
|
||||
static readonly string GUID = "3a4975b64748c9a4db8c082b2e1877eb";
|
||||
static readonly string OLD_FILE_NAME = "IconPause.png"; // v2には無い
|
||||
static bool conflicting {
|
||||
get {
|
||||
var path = AssetDatabase.GUIDToAssetPath (GUID);
|
||||
// ※削除した後、実際に無くてもパスが返ってくるので注意 File.Exists必須
|
||||
return !string.IsNullOrEmpty (path) && path.EndsWith (OLD_FILE_NAME) && File.Exists (path);
|
||||
}
|
||||
}
|
||||
static readonly double INTERVAL = 30d;
|
||||
static double s_NestTime;
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
static private void initializeOnLoad () {
|
||||
EditorApplication.delayCall += delayFunc;
|
||||
}
|
||||
|
||||
static void delayFunc () {
|
||||
EditorApplication.update -= editorUpdate;
|
||||
if (conflicting) {
|
||||
EditorApplication.update += editorUpdate;
|
||||
showDialog ();
|
||||
}
|
||||
}
|
||||
|
||||
static void editorUpdate () {
|
||||
if (EditorApplication.timeSinceStartup > s_NestTime) {
|
||||
if (conflicting) {
|
||||
showError ();
|
||||
s_NestTime = EditorApplication.timeSinceStartup + INTERVAL;
|
||||
} else {
|
||||
EditorApplication.update -= editorUpdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if WCE_DEVELOPMENT
|
||||
[MenuItem ("WCM/TestDialog/CheckConflict")]
|
||||
static void test () { showDialog (); showError (); }
|
||||
#endif
|
||||
|
||||
static string title = $"Conflicting Error ({Constant.ASSET_NAME})";
|
||||
static string body = $"Conflicting error with older version.\nPlease re-import after delete the folder.\n\n1, Delete the \"Assets/{Constant.ASSET_FOLDER_NAME}\" folder.\n\n2, Re-import this asset again.\n\n[{Constant.ASSET_NAME}]";
|
||||
static void showDialog () {
|
||||
EditorUtility.DisplayDialog ($"Conflicting Error ({Constant.ASSET_NAME})", body, "OK");
|
||||
}
|
||||
static void showError () {
|
||||
Debug.LogError ($"{title} {body.Replace("\n", " ")}\n\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03231be3beb7fa54bae3130503848057
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.Text.RegularExpressions;
|
||||
#endif
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
public class Constant {
|
||||
public const string URL_MANUAL = "https://hacoapp.com/asset/wce/v2/ManualPDF.pdf";
|
||||
public const string ASSET_NAME = "WaterCausticsEffect for URP";
|
||||
public const string ASSET_FOLDER_NAME = "WaterCausticsModules";
|
||||
public const string EFFECT_FOLDER_NAME = "WaterCausticsEffect";
|
||||
public const string ASE_PACKAGE_NAME = "ForAmplifyShaderEditor.unitypackage";
|
||||
public const string REQUIRE_UNITY_VER = "2020.3 or later";
|
||||
public const string REQUIRE_URP_VER = "10.4 or later";
|
||||
public const string SHADER_NAME_HEADER = "Hidden/WaterCausticsModules/";
|
||||
public const string URL_HOW_TO_ADD_FEATURE = "https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@14.0/manual/urp-renderer-feature-how-to-add.html";
|
||||
public const string README_MENU_ITEM_PATH = "Window/WaterCausticsModules/Readme";
|
||||
public const int WCE_VERSION_INT = 20001;
|
||||
public const string WCE_VERSION_STR = "2.0.1";
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static public bool CheckPackageName (string packageName) {
|
||||
// OK : "Water Caustics Effect for URP"
|
||||
// OK : "Water Caustics Effect for URP V2"
|
||||
// OK : "WaterCausticsEffect for URP"
|
||||
// OK : "WaterCausticsEffectForURP"
|
||||
// OK : "WaterCausticsEffectForURP_V2"
|
||||
// OK : "Water Caustics Modules"
|
||||
// OK : "Water Caustics Module"
|
||||
// OK : "PackageWaterCausticsModules_v2"
|
||||
// OK : "WaterCausticsTexGen"
|
||||
// NO : "WaterEffect"
|
||||
packageName = packageName.ToLower ();
|
||||
if (new Regex (".*water ?caustics ?effect ?for ?urp.*").IsMatch (packageName))
|
||||
return true;
|
||||
if (new Regex (".*water ?caustics ?modules?.*").IsMatch (packageName))
|
||||
return true;
|
||||
if (new Regex (".*water ?caustics ?(tex|texture) ?gen?.*").IsMatch (packageName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b3cf681b8dff4740b11e2f3bef2383b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32a93edaee788e44d88724c553bfce84
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 261 B |
@@ -0,0 +1,144 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00f635a8489e49047bc7e1e9a86437ae
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 1
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 0
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: iPhone
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Windows Store Apps
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 188 B |
@@ -0,0 +1,144 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84b574295abb91649b9f9a4dd8d7d14b
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 1
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 0
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: iPhone
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Windows Store Apps
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
Shader "Hidden/WaterCausticsModules/Icon" {
|
||||
Properties {
|
||||
_MainTex ("Texture", 2D) = "Black" { }
|
||||
}
|
||||
SubShader {
|
||||
LOD 100
|
||||
Pass {
|
||||
Tags { "RenderType" = "Transparent" }
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata {
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert(appdata v) {
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target {
|
||||
fixed4 col;
|
||||
col.rgb = 1;
|
||||
col.a = tex2D(_MainTex, i.uv).r;
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4badb18dc89fef40ae07e8a56416ae5
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 231 B |
@@ -0,0 +1,144 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef50b6a95a84a124f98087051f675cde
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 1
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 0
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: iPhone
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: 63
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Windows Store Apps
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
/*------------------------------------------------------------------------
|
||||
アセット上書きアップデート防止
|
||||
このアセットがインポートされようとした際、古いバージョンを削除するようダイアログ表示
|
||||
-------------------------------------------------------------------------*/
|
||||
public class PreventOverwriteAsset {
|
||||
[InitializeOnLoadMethod]
|
||||
static private void registerCallback () {
|
||||
AssetDatabase.importPackageStarted -= importStarted;
|
||||
AssetDatabase.importPackageStarted += importStarted;
|
||||
}
|
||||
|
||||
static void importStarted (string packageName) {
|
||||
var str = packageName.ToLower ();
|
||||
if (!str.Contains ("patch") && !str.Contains ("fix") && Constant.CheckPackageName (str)) {
|
||||
// フォルダ削除後もこのスクリプトがしばらく残っていてダイアログが表示されてしまうのでFile.Existsでチェック
|
||||
if (findAsset<TexGenModuleRef> (out var asset, out var path) && File.Exists (path)) {
|
||||
if (asset.assetFolder && asset.assetFolder.name == Constant.ASSET_FOLDER_NAME) {
|
||||
// アセットルートPathが取得出来た場合
|
||||
var folderPath = AssetDatabase.GetAssetPath (asset.assetFolder);
|
||||
showDialog (folderPath);
|
||||
} else {
|
||||
// アセットルートPathが取得出来ない場合
|
||||
showDialog ($"Assets/{Constant.ASSET_FOLDER_NAME}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if WCE_DEVELOPMENT
|
||||
[MenuItem ("WCM/TestDialog/PreventOverwrite")]
|
||||
static void dialogTest2 () {
|
||||
if (findAsset<TexGenModuleRef> (out var asset, out var path) && asset.assetFolder) {
|
||||
var folderPath = AssetDatabase.GetAssetPath (asset.assetFolder);
|
||||
showDialog (folderPath);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void showDialog (string folderPath) {
|
||||
string str0 = "Please delete old version before update.";
|
||||
string str1 = $"If this package is a different version,\nthe older version must be removed first to avoid conflicts.\n\n1, Cancel in the Import window appearing after this.\n\n2, Delete the \"{folderPath}\" folder.\n\n3, Import this asset again.\n\n\n({Constant.ASSET_NAME})";
|
||||
EditorUtility.DisplayDialog (str0, str1, "OK", "It's not different version.");
|
||||
}
|
||||
|
||||
static private bool findAsset<T> (out T asset, out string path) where T : Object {
|
||||
asset = null;
|
||||
path = null;
|
||||
var guids = AssetDatabase.FindAssets ($"t:{typeof (T).ToString()}", new [] { "Assets" }); // "t:MH.WaterCausticsModules.TexGenModuleRef"
|
||||
if (guids.Length == 0) return false;
|
||||
path = AssetDatabase.GUIDToAssetPath (guids [0]);
|
||||
asset = AssetDatabase.LoadAssetAtPath<T> (path);
|
||||
return asset != null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6d53284efe324f4abf18af23f2a010c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,361 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR && UNITY_2020_3_OR_NEWER
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
internal class PreviewWindow : EditorWindow {
|
||||
// --------------------------------------------------------------- Static
|
||||
internal static void OpenWindow (WaterCausticsTexGenerator target) {
|
||||
var win = GetWindow<PreviewWindow> (true);
|
||||
PreviewWindowStore.instance.window = win;
|
||||
win.setTarget (target);
|
||||
}
|
||||
|
||||
internal static void SetTargetIfShowing (WaterCausticsTexGenerator target) {
|
||||
var win = PreviewWindowStore.instance.window;
|
||||
if (win != null)
|
||||
win.setTarget (target);
|
||||
}
|
||||
|
||||
internal static void RemoveTarget (WaterCausticsTexGenerator target) {
|
||||
var win = PreviewWindowStore.instance.window;
|
||||
if (win != null && win._target == target)
|
||||
win.setTarget (null);
|
||||
}
|
||||
|
||||
internal static bool IsShowing () {
|
||||
return EditorWindow.HasOpenInstances<PreviewWindow> ();
|
||||
}
|
||||
|
||||
internal static void InspectorChanged (WaterCausticsTexGenerator target) {
|
||||
var win = PreviewWindowStore.instance.window;
|
||||
if (win != null && win._target == target)
|
||||
win.inspectorChanged ();
|
||||
}
|
||||
|
||||
internal static void CloseWindow () {
|
||||
var win = PreviewWindowStore.instance.window;
|
||||
if (win != null)
|
||||
win.Close ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
// --------------------------------------------------------------- SerializeField
|
||||
[SerializeField] private Texture m_iconUnlock;
|
||||
[SerializeField] private Texture m_iconLock;
|
||||
[SerializeField] private Texture m_iconMenu;
|
||||
[SerializeField] private Shader m_shaderIcon;
|
||||
|
||||
private WaterCausticsTexGenerator _target, _subTarget;
|
||||
private RenderTexture _rt;
|
||||
private double _lastTime;
|
||||
|
||||
private bool __locked;
|
||||
private bool isLocked {
|
||||
get => __locked;
|
||||
set {
|
||||
__locked = value;
|
||||
if (value == false)
|
||||
setTarget (_subTarget);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- Event
|
||||
private void OnEnable () { }
|
||||
|
||||
private void OnDisable () {
|
||||
releaseTarget ();
|
||||
releaseTmpRT ();
|
||||
}
|
||||
|
||||
private void OnDestroy () {
|
||||
releaseTarget ();
|
||||
releaseTmpRT ();
|
||||
destroy (ref __matIcon);
|
||||
}
|
||||
|
||||
private void destroy<T> (ref T o) where T : Object {
|
||||
if (o == null) return;
|
||||
if (Application.isPlaying)
|
||||
Destroy (o);
|
||||
else
|
||||
DestroyImmediate (o);
|
||||
o = null;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- Target
|
||||
private void releaseTarget () {
|
||||
if (_target != null) _target.FinishPreview ();
|
||||
_target = null;
|
||||
}
|
||||
private void setTarget (WaterCausticsTexGenerator target) {
|
||||
if (isLocked) {
|
||||
_subTarget = target;
|
||||
return;
|
||||
}
|
||||
if (_target != target)
|
||||
releaseTarget ();
|
||||
_target = _subTarget = target;
|
||||
_lastTime = EditorApplication.timeSinceStartup;
|
||||
setTitle ();
|
||||
previewUpdate ();
|
||||
}
|
||||
|
||||
private void setTitle () {
|
||||
string tarName = (_target != null) ? _target.name : "No Generator";
|
||||
this.titleContent = new GUIContent (tarName);
|
||||
}
|
||||
|
||||
private void inspectorChanged () {
|
||||
previewUpdate ();
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------- RenderTexture
|
||||
private void releaseTmpRT () {
|
||||
if (_rt) RenderTexture.ReleaseTemporary (_rt);
|
||||
_rt = null;
|
||||
}
|
||||
|
||||
private void getTmpRT (RenderTexture rt) {
|
||||
if (rt) _rt = RenderTexture.GetTemporary (rt.descriptor);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------- Material
|
||||
private Material __matIcon;
|
||||
private Material matIcon () {
|
||||
if (__matIcon == null) {
|
||||
if (m_shaderIcon == null) {
|
||||
Debug.LogError ("Shader is null. " + this);
|
||||
Close ();
|
||||
} else {
|
||||
__matIcon = new Material (m_shaderIcon);
|
||||
__matIcon.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
}
|
||||
return __matIcon;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------- OnGUI
|
||||
|
||||
private bool isLockable => (_target != null);
|
||||
private Rect getIconRect (float x, float y, float iconW = 20f) {
|
||||
var iconHalf = iconW * 0.5f;
|
||||
return new Rect (position.width - x - iconHalf, y - iconHalf, iconW, iconW);
|
||||
}
|
||||
|
||||
private bool clickCheck (Vector2 mousePos, float x, float y, float r) {
|
||||
return (mousePos - new Vector2 (position.width - x, y)).sqrMagnitude < r * r;
|
||||
}
|
||||
|
||||
void OnGUI () {
|
||||
// Draw Contents
|
||||
var winW = position.width;
|
||||
|
||||
if (_rt != null) {
|
||||
EditorGUI.DrawPreviewTexture (new Rect (0, 0, winW, winW), _rt, null, ScaleMode.StretchToFill, 0);
|
||||
} else if (_target != null) {
|
||||
GUILayout.Space (position.size.y / 2 - 10);
|
||||
EditorGUILayout.LabelField ("No Output Render Texture", StyleConstant.alertPinkCenter);
|
||||
} else {
|
||||
isLocked = false;
|
||||
GUILayout.Space (position.size.y / 2 - 10);
|
||||
EditorGUILayout.LabelField ("No Generator Selected", StyleConstant.alertCenter);
|
||||
}
|
||||
|
||||
EditorGUI.DrawPreviewTexture (getIconRect (10f, 10f), m_iconMenu, matIcon (), ScaleMode.StretchToFill, 0f, -1f);
|
||||
if (isLockable)
|
||||
EditorGUI.DrawPreviewTexture (getIconRect (30f, 10f), isLocked ? m_iconLock : m_iconUnlock, matIcon (), ScaleMode.StretchToFill, 0f, -1f);
|
||||
|
||||
|
||||
// Support Click
|
||||
if (Event.current != null && Event.current.type == EventType.MouseDown && Event.current.button == 0) {
|
||||
var mousePos = Event.current.mousePosition;
|
||||
if (clickCheck (mousePos, x : 10f, y : 10f, r : 10f))
|
||||
openContext ();
|
||||
else if (isLockable && clickCheck (mousePos, x : 30f, y : 10f, r : 10f))
|
||||
toggleLock ();
|
||||
}
|
||||
|
||||
// ContextMenu
|
||||
Event evt = Event.current;
|
||||
if (evt.type == EventType.ContextClick) {
|
||||
openContext ();
|
||||
evt.Use ();
|
||||
}
|
||||
}
|
||||
|
||||
private void openContext () {
|
||||
GenericMenu menu = new GenericMenu ();
|
||||
var winW = position.width;
|
||||
if (isLockable) {
|
||||
menu.AddItem (new GUIContent ("Lock", "Unlocked when entered into play mode."), isLocked, (o) => toggleLock (), null);
|
||||
menu.AddSeparator ("");
|
||||
}
|
||||
string curSize = $"Window Size ({winW.ToString ("F0")}x{winW.ToString ("F0")})/";
|
||||
if (_rt && _rt.width == _rt.height) {
|
||||
string rtW = _rt.width.ToString ("F0");
|
||||
menu.AddItem (new GUIContent ($"{curSize}Fit Texture {rtW}x{rtW}"), winW == _rt.width, specifyWindowSize, (float) _rt.width);
|
||||
menu.AddSeparator (curSize);
|
||||
}
|
||||
menu.AddItem (new GUIContent ($"{curSize}128x128"), winW == 128f, specifyWindowSize, 128f);
|
||||
menu.AddItem (new GUIContent ($"{curSize}256x256"), winW == 256f, specifyWindowSize, 256f);
|
||||
menu.AddItem (new GUIContent ($"{curSize}512x512"), winW == 512f, specifyWindowSize, 512f);
|
||||
menu.AddItem (new GUIContent ($"{curSize}1024x1024"), winW == 1024f, specifyWindowSize, 1024f);
|
||||
|
||||
if (_target != null) {
|
||||
menu.AddSeparator ("");
|
||||
menu.AddItem (new GUIContent ("Select Generator : " + _target.name), false, (o) => pingAndSelect (_target, true), null);
|
||||
if (_target.renderTexture != null) {
|
||||
bool isLocking = isLockable && isLocked;
|
||||
string action = isLocking ? "Select" : "Ping";
|
||||
menu.AddItem (new GUIContent (action + " Texture : " + _target.renderTexture.name), false, (o) => pingAndSelect (_target.renderTexture, isLocking), null);
|
||||
if (_rt != null) {
|
||||
menu.AddSeparator ("");
|
||||
menu.AddItem (new GUIContent ("Save PNG 8bit", "Save PNG 8bit"), false, savePng, null);
|
||||
menu.AddItem (new GUIContent ("Save EXR 32bit", "Save EXR 32bit"), false, saveEXR, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
menu.AddSeparator ("");
|
||||
menu.AddItem (new GUIContent ("Close"), false, (o) => Close (), null);
|
||||
|
||||
menu.ShowAsContext ();
|
||||
}
|
||||
|
||||
|
||||
private string _preSaveImagePath;
|
||||
private void savePng (object o) {
|
||||
saveImage (isEXR: false);
|
||||
}
|
||||
private void saveEXR (object o) {
|
||||
saveImage (isEXR: true);
|
||||
}
|
||||
private void saveImage (bool isEXR) {
|
||||
if (_target == null || _target.renderTexture == null || _rt == null) return;
|
||||
string defaultPath = string.IsNullOrEmpty (_preSaveImagePath) ? Application.dataPath : Path.GetDirectoryName (_preSaveImagePath);
|
||||
string defaultName = string.IsNullOrEmpty (_preSaveImagePath) ? "WaterCausticsTexture" : Path.GetFileNameWithoutExtension (_preSaveImagePath);
|
||||
string path = EditorUtility.SaveFilePanel (isEXR ? "Save EXR Image" : "Save PNG Image", defaultPath, defaultName, isEXR ? "exr" : "png");
|
||||
if (string.IsNullOrEmpty (path)) return;
|
||||
_preSaveImagePath = path;
|
||||
|
||||
Texture2D tex = new Texture2D (_rt.width, _rt.height, TextureFormat.RGBAFloat, false);
|
||||
var tmp = RenderTexture.active;
|
||||
RenderTexture.active = _rt;
|
||||
tex.ReadPixels (new Rect (0, 0, _rt.width, _rt.height), 0, 0);
|
||||
var pixels = tex.GetPixels ();
|
||||
for (int i = 0; i < pixels.Length; i++) {
|
||||
if (!isEXR && PlayerSettings.colorSpace == ColorSpace.Linear) {
|
||||
pixels [i].r = Mathf.Pow (pixels [i].r, 1f / 2.2f);
|
||||
pixels [i].g = Mathf.Pow (pixels [i].g, 1f / 2.2f);
|
||||
pixels [i].b = Mathf.Pow (pixels [i].b, 1f / 2.2f);
|
||||
} else if (isEXR && PlayerSettings.colorSpace == ColorSpace.Gamma) {
|
||||
pixels [i].r = Mathf.Pow (pixels [i].r, 2.2f);
|
||||
pixels [i].g = Mathf.Pow (pixels [i].g, 2.2f);
|
||||
pixels [i].b = Mathf.Pow (pixels [i].b, 2.2f);
|
||||
}
|
||||
pixels [i].a = 1f;
|
||||
}
|
||||
tex.SetPixels (pixels);
|
||||
tex.Apply ();
|
||||
RenderTexture.active = tmp;
|
||||
|
||||
byte [] bytes = isEXR ? tex.EncodeToEXR (Texture2D.EXRFlags.CompressZIP) : tex.EncodeToPNG ();
|
||||
destroy (ref tex);
|
||||
File.WriteAllBytes (path, bytes);
|
||||
AssetDatabase.Refresh ();
|
||||
}
|
||||
|
||||
|
||||
private void pingAndSelect (Object obj, bool isSelect) {
|
||||
EditorGUIUtility.PingObject (obj);
|
||||
if (isSelect)
|
||||
Selection.activeObject = obj;
|
||||
}
|
||||
|
||||
private void toggleLock () {
|
||||
isLocked = !isLocked;
|
||||
Repaint ();
|
||||
}
|
||||
|
||||
private void specifyWindowSize (object w) {
|
||||
var pos = position;
|
||||
pos.size = new Vector2 ((float) w, (float) w);
|
||||
position = pos;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- Update
|
||||
|
||||
private void setWindowSize () {
|
||||
var pos = position;
|
||||
if (pos.width != pos.height) {
|
||||
pos.size = new Vector2 (pos.width, pos.width);
|
||||
position = pos;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update () {
|
||||
if (!UnityEditorInternal.InternalEditorUtility.isApplicationActive) return;
|
||||
if (PreviewWindowStore.instance.window != this) Close ();
|
||||
setWindowSize ();
|
||||
previewUpdate ();
|
||||
}
|
||||
|
||||
private void previewUpdate () {
|
||||
var curTime = EditorApplication.timeSinceStartup;
|
||||
var deltaTime = curTime - _lastTime;
|
||||
_lastTime = curTime;
|
||||
bool usablePreview = (_target != null && _target.renderTexture != null);
|
||||
if (usablePreview) {
|
||||
releaseTmpRT ();
|
||||
getTmpRT (_target.renderTexture);
|
||||
if (deltaTime > 0.15) deltaTime = 0;
|
||||
_target.Preview ((float) deltaTime, _rt);
|
||||
} else {
|
||||
releaseTmpRT ();
|
||||
}
|
||||
Repaint ();
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------- Style
|
||||
|
||||
private static class StyleConstant {
|
||||
internal static GUIStyle alertCenter;
|
||||
internal static GUIStyle alertPink;
|
||||
internal static GUIStyle alertPinkCenter;
|
||||
static StyleConstant () {
|
||||
alertPink = new GUIStyle ("Label");
|
||||
alertPink.normal.textColor = new Color (1f, 0.3f, 0.6f, 1f);
|
||||
|
||||
alertPinkCenter = new GUIStyle (alertPink);
|
||||
alertPinkCenter.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
alertCenter = new GUIStyle ("Label");
|
||||
alertCenter.alignment = TextAnchor.MiddleCenter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------- Singleton
|
||||
internal class PreviewWindowStore : ScriptableSingleton<PreviewWindowStore> {
|
||||
internal PreviewWindow window;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a62b3cb9074a074a8c2d2e124f9e663
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_ViewDataDictionary: {instanceID: 0}
|
||||
- m_iconUnlock: {fileID: 2800000, guid: ef50b6a95a84a124f98087051f675cde, type: 3}
|
||||
- m_iconLock: {fileID: 2800000, guid: 00f635a8489e49047bc7e1e9a86437ae, type: 3}
|
||||
- m_iconPause: {fileID: 2800000, guid: 3a4975b64748c9a4db8c082b2e1877eb, type: 3}
|
||||
- m_iconResume: {fileID: 2800000, guid: d7a7047de193e4647b9c83dec83d813c, type: 3}
|
||||
- m_iconMenu: {fileID: 2800000, guid: 84b574295abb91649b9f9a4dd8d7d14b, type: 3}
|
||||
- m_shaderIcon: {fileID: 4800000, guid: f4badb18dc89fef40ae07e8a56416ae5, type: 3}
|
||||
- m_shaderImg: {fileID: 4800000, guid: fbe4f8dba6701284b9405ecf1901c10d, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0182e4a02e4c40c469a3f6ef1bc2a1e8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
/*------------------------------------------------------------------------
|
||||
Readme
|
||||
※クラス名がReadmeだと他の名前空間のReadmeでもアイコンが変わってしまうので注意
|
||||
-------------------------------------------------------------------------*/
|
||||
public class WCMReadme : ScriptableObject {
|
||||
// ------------------------------------ ScriptableObject
|
||||
public Texture2D icon;
|
||||
public string title;
|
||||
public Section [] sections;
|
||||
|
||||
[System.Serializable]
|
||||
public class Section {
|
||||
public string heading, text, linkText, linkDesc, url;
|
||||
public Object obj;
|
||||
}
|
||||
|
||||
// ------------------------------------ AssetDatabase Callback
|
||||
// このアセットがインポートされた場合にReadmeを選択
|
||||
[InitializeOnLoadMethod]
|
||||
static private void registerCallback () {
|
||||
AssetDatabase.importPackageCompleted -= importCompleted;
|
||||
AssetDatabase.importPackageCompleted += importCompleted;
|
||||
}
|
||||
|
||||
static void importCompleted (string packageName) {
|
||||
if (Constant.CheckPackageName (packageName))
|
||||
EditorApplication.delayCall += selectReadme;
|
||||
}
|
||||
|
||||
// TODO ウィンドウ化
|
||||
[MenuItem (Constant.README_MENU_ITEM_PATH)]
|
||||
static void selectReadme () {
|
||||
if (findAsset<WCMReadme> (out var asset, out var path)) {
|
||||
showInspectorWindow ();
|
||||
EditorGUIUtility.PingObject (asset);
|
||||
Selection.activeObject = asset;
|
||||
}
|
||||
}
|
||||
|
||||
private static void showInspectorWindow () {
|
||||
var windowType = typeof (Editor).Assembly.GetType ("UnityEditor.InspectorWindow");
|
||||
EditorWindow.GetWindow (windowType);
|
||||
}
|
||||
|
||||
static private bool findAsset<T> (out T asset, out string path) where T : Object {
|
||||
asset = null;
|
||||
path = null;
|
||||
var guids = AssetDatabase.FindAssets ($"t:{typeof (T).ToString()}", new [] { "Assets" });
|
||||
if (guids.Length == 0) return false;
|
||||
path = AssetDatabase.GUIDToAssetPath (guids [0]);
|
||||
asset = AssetDatabase.LoadAssetAtPath<T> (path);
|
||||
return asset != null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7014fb6ed4db25e49a7ce277160913ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- icon: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: d9814e54a4057294780a501cf65720c3, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,146 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
|
||||
[CustomEditor (typeof (WCMReadme))]
|
||||
public class WCMReadmeEditor : Editor {
|
||||
private bool isDark => EditorGUIUtility.isProSkin;
|
||||
private GUIStyle _baseStyle, _titleStyle, _textStyle, _headerStyle, _linkUrlStyle, _linkObjStyle, _warningStyle;
|
||||
void prepStyle () {
|
||||
if (_baseStyle != null) return;
|
||||
_baseStyle = new GUIStyle (EditorStyles.label);
|
||||
_baseStyle.wordWrap = true;
|
||||
_baseStyle.fontSize = 13;
|
||||
_baseStyle.richText = true;
|
||||
|
||||
_titleStyle = new GUIStyle (_baseStyle);
|
||||
_titleStyle.fontStyle = FontStyle.Bold;
|
||||
_titleStyle.fontSize = 18;
|
||||
|
||||
_textStyle = new GUIStyle (_baseStyle);
|
||||
_textStyle.fontSize = 14;
|
||||
|
||||
_headerStyle = new GUIStyle (_baseStyle);
|
||||
_headerStyle.fontStyle = FontStyle.Bold;
|
||||
_headerStyle.fontSize = 16;
|
||||
|
||||
_linkUrlStyle = new GUIStyle (_baseStyle);
|
||||
_linkUrlStyle.wordWrap = false;
|
||||
_linkUrlStyle.normal.textColor = isDark ? new Color (0f, 0.8f, 1f, 1f) : new Color (0f, 0.4f, 0.8f, 1f);
|
||||
_linkUrlStyle.hover.textColor = _linkUrlStyle.normal.textColor + Color.white * (isDark ? 0.3f : 0.2f);
|
||||
_linkUrlStyle.stretchWidth = false;
|
||||
|
||||
_linkObjStyle = new GUIStyle (_linkUrlStyle);
|
||||
_linkObjStyle.normal.textColor = isDark ? new Color (0f, 0.85f, 0.4f, 1f) : new Color (0f, 0.5f, 0.2f, 1f);
|
||||
_linkObjStyle.hover.textColor = _linkObjStyle.normal.textColor + Color.white * (isDark ? 0.3f : 0.2f);
|
||||
|
||||
_warningStyle = new GUIStyle (_baseStyle);
|
||||
_warningStyle.normal.textColor = isDark ? Color.white : new Color (0.8f, 0.1f, 0f, 1f);
|
||||
_warningStyle.normal.background = Texture2D.whiteTexture;
|
||||
}
|
||||
|
||||
protected override void OnHeaderGUI () {
|
||||
var icon = (target as WCMReadme).icon;
|
||||
if (icon == null) return;
|
||||
float iconW = EditorGUIUtility.currentViewWidth;
|
||||
float iconH = Mathf.Min (iconW * icon.height / icon.width, 150f);
|
||||
iconW = iconH * icon.width / icon.height;
|
||||
Rect rect = GUILayoutUtility.GetRect (iconW, iconH);
|
||||
rect.width -= 1f;
|
||||
GUI.DrawTexture (rect, icon, ScaleMode.ScaleAndCrop);
|
||||
}
|
||||
|
||||
|
||||
#if !UNITY_2020_3_OR_NEWER //|| WCE_DEVELOPMENT
|
||||
private readonly bool UNITY_VER_OK = false;
|
||||
#else
|
||||
private readonly bool UNITY_VER_OK = true;
|
||||
#endif
|
||||
|
||||
#if !WCM_URP_10 //|| WCE_DEVELOPMENT
|
||||
private readonly bool URP_OK = false;
|
||||
#else
|
||||
private readonly bool URP_OK = true;
|
||||
#endif
|
||||
|
||||
public override void OnInspectorGUI () {
|
||||
prepStyle ();
|
||||
|
||||
var tar = target as WCMReadme;
|
||||
GUILayout.Space (6);
|
||||
GUILayout.Label (tar.title, _titleStyle);
|
||||
GUILayout.Space (2);
|
||||
GUILayout.Label (Constant.WCE_VERSION_STR, _baseStyle);
|
||||
GUILayout.Space (4);
|
||||
|
||||
if (!UNITY_VER_OK) {
|
||||
GUILayout.Space (2);
|
||||
labelWarning ($"This asset is not compatible with current Unity version {Application.unityVersion}. Unity {Constant.REQUIRE_UNITY_VER} is required.");
|
||||
GUILayout.Space (6);
|
||||
}
|
||||
|
||||
if (!URP_OK) {
|
||||
GUILayout.Space (2);
|
||||
GUILayout.Label ($"This asset contains two modules TexGenerator and Effect. The Effect module is available for import in environments using UniversalRP {Constant.REQUIRE_URP_VER}. TexGenerator works with all render pipelines. The generated texture could be used in Light Cookie, Decal, Projector, and Materials.", _textStyle);
|
||||
GUILayout.Space (6);
|
||||
}
|
||||
|
||||
GUILayout.Space (2);
|
||||
|
||||
foreach (var section in tar.sections) {
|
||||
bool used = false;
|
||||
if (hasStr (section.heading)) {
|
||||
GUILayout.Space (12);
|
||||
GUILayout.Label (section.heading, _headerStyle);
|
||||
used = true;
|
||||
}
|
||||
if (hasStr (section.text)) {
|
||||
GUILayout.Space (2);
|
||||
GUILayout.Label (section.text, _baseStyle);
|
||||
used = true;
|
||||
}
|
||||
if (hasStr (section.linkText) && (hasStr (section.url) || section.obj != null)) {
|
||||
GUILayout.Space (2);
|
||||
bool isObj = (section.obj != null);
|
||||
used = true;
|
||||
if (labelLink (new GUIContent (section.linkText, hasStr (section.linkDesc) ? section.linkDesc : section.url), isObj)) {
|
||||
if (isObj) {
|
||||
AssetDatabase.OpenAsset (section.obj);
|
||||
} else {
|
||||
Application.OpenURL (section.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (used) GUILayout.Space (4);
|
||||
}
|
||||
GUILayout.Space (80);
|
||||
}
|
||||
|
||||
private bool hasStr (string str) => !string.IsNullOrEmpty (str);
|
||||
|
||||
void labelWarning (string text) {
|
||||
Color tmp = GUI.backgroundColor;
|
||||
GUI.backgroundColor = isDark ? new Color (1f, 0.3f, 0.6f, 0.4f) : new Color (1f, 0.3f, 0.6f, 0.5f);
|
||||
GUILayout.Label (text, _warningStyle);
|
||||
GUI.backgroundColor = tmp;
|
||||
}
|
||||
|
||||
private bool labelLink (GUIContent label, bool isObj = false, params GUILayoutOption [] options) {
|
||||
GUIStyle style = isObj ? _linkObjStyle : _linkUrlStyle;
|
||||
var rect = GUILayoutUtility.GetRect (label, style, options);
|
||||
Handles.BeginGUI ();
|
||||
Handles.color = style.normal.textColor;
|
||||
Handles.DrawLine (new Vector3 (rect.xMin, rect.yMax), new Vector3 (rect.xMax, rect.yMax));
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI ();
|
||||
EditorGUIUtility.AddCursorRect (rect, MouseCursor.Link);
|
||||
return GUI.Button (rect, label, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec73cd83e04473b4b8bfea0e73a586fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
@@ -0,0 +1,144 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9814e54a4057294780a501cf65720c3
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 1
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: iPhone
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Windows Store Apps
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 5e97eb03825dee720800000000000000
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
@@ -0,0 +1,144 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df4ebd6140d53224396c4acf7d948291
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 0
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: iPhone
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Windows Store Apps
|
||||
maxTextureSize: 8192
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f4dc12126bc22543afc6fdad86a286b, type: 3}
|
||||
m_Name: TexGenModuleRef
|
||||
m_EditorClassIdentifier:
|
||||
m_assetFolder: {fileID: 102900000, guid: fd4ab3b30e03a184483ced099b43ec19, type: 3}
|
||||
m_texGenModule: {fileID: 102900000, guid: 05cc36a4b7f8df24499d7e13464045a6, type: 3}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8049e24e9bb6d27469ea2050d91944cb
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
#if WCE_DEVELOPMENT
|
||||
[CreateAssetMenu]
|
||||
#endif
|
||||
public class TexGenModuleRef : ScriptableObject {
|
||||
// WaterCausticsModulesフォルダ
|
||||
[SerializeField] private Object m_assetFolder;
|
||||
internal Object assetFolder => m_assetFolder;
|
||||
|
||||
// WaterCausticsTexGeneratorフォルダ
|
||||
[SerializeField] private Object m_texGenModule;
|
||||
internal Object texGenModule => m_texGenModule;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f4dc12126bc22543afc6fdad86a286b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR && (!UNITY_2020_3_OR_NEWER || WCE_DEVELOPMENT)
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
#pragma warning disable 162
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
/*------------------------------------------------------------------------
|
||||
このアセットがインポートされた際、Unityのバージョンが低い場合にダイアログとWarningを表示
|
||||
-------------------------------------------------------------------------*/
|
||||
public class VersionCheck {
|
||||
#if WCE_DEVELOPMENT
|
||||
[MenuItem ("WCM/TestDialog/VersionCheck")]
|
||||
static void dialogTest () => showDialog ();
|
||||
static private readonly bool isDeveloping = true;
|
||||
#else
|
||||
static private readonly bool isDeveloping = false;
|
||||
#endif
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
static private void registerCallback () {
|
||||
AssetDatabase.importPackageCompleted -= importCompleted;
|
||||
AssetDatabase.importPackageCompleted += importCompleted;
|
||||
}
|
||||
|
||||
static void importCompleted (string packageName) {
|
||||
if (isDeveloping) return;
|
||||
if (Constant.CheckPackageName (packageName))
|
||||
showDialog ();
|
||||
}
|
||||
|
||||
static void showDialog () {
|
||||
string str0 = $"Requires Unity {Constant.REQUIRE_UNITY_VER}";
|
||||
string str1 = $"This asset is not compatible with current Unity version.\n\nCurrent : {Application.unityVersion} \nRequire : {Constant.REQUIRE_UNITY_VER}\n\n\n({Constant.ASSET_NAME})";
|
||||
EditorUtility.DisplayDialog (str0, str1, "OK");
|
||||
Debug.LogWarning ($"{str1.Replace("\n", " ")}\n\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 457ec14637a5af748b3988768371cc74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,865 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MH.WaterCausticsModules.TexGen {
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor (typeof (WaterCausticsTexGenerator))]
|
||||
public class WaterCausticsTexGeneratorEditor : Editor {
|
||||
#if UNITY_2020_3_OR_NEWER //&& !WCE_DEVELOPMENT
|
||||
private SerializedProperty m_generateInEditMode;
|
||||
private SerializedProperty m_animateInEditMode;
|
||||
private SerializedProperty m_pause;
|
||||
private SerializedProperty m_density;
|
||||
private SerializedProperty m_height;
|
||||
private SerializedProperty m_speed;
|
||||
private SerializedProperty m_flow;
|
||||
private SerializedProperty m_flowDirection;
|
||||
private SerializedProperty m_waves;
|
||||
private SerializedProperty m_calcResolution;
|
||||
private SerializedProperty m_renderTexture;
|
||||
private SerializedProperty m_FillGap;
|
||||
private SerializedProperty m_lightRay;
|
||||
private SerializedProperty m_lightTransform;
|
||||
private SerializedProperty m_lightVector;
|
||||
private SerializedProperty m_lightDirection;
|
||||
private SerializedProperty m_lightIncidentAngle;
|
||||
private SerializedProperty m_style;
|
||||
private SerializedProperty m_refractedRay;
|
||||
private SerializedProperty m_brightness;
|
||||
private SerializedProperty m_gamma;
|
||||
private SerializedProperty m_clamp;
|
||||
private SerializedProperty m_refractionIndex;
|
||||
private SerializedProperty m_useChromaticAberration;
|
||||
private SerializedProperty m_chromaticAberration;
|
||||
private SerializedProperty m_usePostProcessing;
|
||||
private SerializedProperty m_useBlur;
|
||||
private SerializedProperty m_blurIterations;
|
||||
private SerializedProperty m_blurSpread;
|
||||
private SerializedProperty m_msaa;
|
||||
private SerializedProperty m_blurDirectional;
|
||||
private SerializedProperty m_blurDirection;
|
||||
private SerializedProperty m_colorShift;
|
||||
private SerializedProperty m_colorShiftDir;
|
||||
private SerializedProperty m_useSyncDirection;
|
||||
private SerializedProperty m_postContrast;
|
||||
private SerializedProperty m_postBrightness;
|
||||
private SerializedProperty m_computeShader;
|
||||
private SerializedProperty m_shader;
|
||||
|
||||
private void prepProperties () {
|
||||
if (m_generateInEditMode != null) return;
|
||||
m_generateInEditMode = serializedObject.FindProperty ("m_generateInEditMode");
|
||||
m_animateInEditMode = serializedObject.FindProperty ("m_animateInEditMode");
|
||||
m_pause = serializedObject.FindProperty ("m_pause");
|
||||
m_density = serializedObject.FindProperty ("m_density");
|
||||
m_height = serializedObject.FindProperty ("m_height");
|
||||
m_speed = serializedObject.FindProperty ("m_speed");
|
||||
m_flow = serializedObject.FindProperty ("m_flow");
|
||||
m_flowDirection = serializedObject.FindProperty ("m_flowDirection");
|
||||
m_waves = serializedObject.FindProperty ("m_waves");
|
||||
m_calcResolution = serializedObject.FindProperty ("m_calcResolution");
|
||||
m_renderTexture = serializedObject.FindProperty ("m_renderTexture");
|
||||
m_FillGap = serializedObject.FindProperty ("m_FillGap");
|
||||
m_lightRay = serializedObject.FindProperty ("m_lightRay");
|
||||
m_lightTransform = serializedObject.FindProperty ("m_lightTransform");
|
||||
m_lightVector = serializedObject.FindProperty ("m_lightVector");
|
||||
m_lightDirection = serializedObject.FindProperty ("m_lightDirection");
|
||||
m_lightIncidentAngle = serializedObject.FindProperty ("m_lightIncidentAngle");
|
||||
m_style = serializedObject.FindProperty ("m_style");
|
||||
m_refractedRay = serializedObject.FindProperty ("m_refractedRay");
|
||||
m_brightness = serializedObject.FindProperty ("m_brightness");
|
||||
m_gamma = serializedObject.FindProperty ("m_gamma");
|
||||
m_clamp = serializedObject.FindProperty ("m_clamp");
|
||||
m_refractionIndex = serializedObject.FindProperty ("m_refractionIndex");
|
||||
m_useChromaticAberration = serializedObject.FindProperty ("m_useChromaticAberration");
|
||||
m_chromaticAberration = serializedObject.FindProperty ("m_chromaticAberration");
|
||||
m_usePostProcessing = serializedObject.FindProperty ("m_usePostProcessing");
|
||||
m_useBlur = serializedObject.FindProperty ("m_useBlur");
|
||||
m_blurIterations = serializedObject.FindProperty ("m_blurIterations");
|
||||
m_blurSpread = serializedObject.FindProperty ("m_blurSpread");
|
||||
m_msaa = serializedObject.FindProperty ("m_msaa");
|
||||
m_blurDirectional = serializedObject.FindProperty ("m_blurDirectional");
|
||||
m_blurDirection = serializedObject.FindProperty ("m_blurDirection");
|
||||
m_colorShift = serializedObject.FindProperty ("m_colorShift");
|
||||
m_colorShiftDir = serializedObject.FindProperty ("m_colorShiftDir");
|
||||
m_useSyncDirection = serializedObject.FindProperty ("m_useSyncDirection");
|
||||
m_postContrast = serializedObject.FindProperty ("m_postContrast");
|
||||
m_postBrightness = serializedObject.FindProperty ("m_postBrightness");
|
||||
m_computeShader = serializedObject.FindProperty ("m_computeShader");
|
||||
m_shader = serializedObject.FindProperty ("m_shader");
|
||||
}
|
||||
|
||||
static readonly GUIContent [] _litRayTypeEnumGC = {
|
||||
new GUIContent ("Direction"),
|
||||
new GUIContent ("Vector"),
|
||||
new GUIContent ("Transform"),
|
||||
new GUIContent ("Sun"),
|
||||
new GUIContent ("Auto"),
|
||||
};
|
||||
|
||||
static readonly int [] _litDirTypeEnumOrder = { 4, 0, 1, 2, 3, };
|
||||
|
||||
static readonly string [] _resEnumStr = {
|
||||
"64 x 64",
|
||||
"96 x 96",
|
||||
"128 x 128",
|
||||
"160 x 160",
|
||||
"256 x 256",
|
||||
"320 x 320",
|
||||
"512 x 512",
|
||||
};
|
||||
|
||||
static readonly string [] _msaaEnumStr = { "None", "2x", "4x", "8x" };
|
||||
|
||||
private enum EnumMSAA {
|
||||
NoMSAA = 1,
|
||||
MSAA2x = 2,
|
||||
MSAA4x = 4,
|
||||
MSAA8x = 8
|
||||
}
|
||||
|
||||
private readonly string _animInEditModeDesc = "Animate the wave even in edit mode, and force update scene and game view.\n\nTo use it, AdvancedSettings / In EditMode / Generate needs to be On.";
|
||||
|
||||
// -----------------------------------------------------------
|
||||
private void OnEnable () {
|
||||
foreach (var tar in targets.OfType<WaterCausticsTexGenerator> ()) {
|
||||
tar.VersionCheck ();
|
||||
tar.CheckRenderTex ();
|
||||
}
|
||||
PreviewWindow.SetTargetIfShowing (target as WaterCausticsTexGenerator);
|
||||
}
|
||||
|
||||
private void OnDisable () {
|
||||
PreviewWindow.RemoveTarget (target as WaterCausticsTexGenerator);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI () {
|
||||
prepProperties ();
|
||||
prepWaveList ();
|
||||
serializedObject.Update ();
|
||||
using (var check = new EditorGUI.ChangeCheckScope ()) {
|
||||
drawProperties ();
|
||||
serializedObject.ApplyModifiedProperties ();
|
||||
if (check.changed)
|
||||
PreviewWindow.InspectorChanged (target as WaterCausticsTexGenerator);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- Draw
|
||||
readonly Color colorPinkBar = new Color (1f, 0.3f, 0.6f, 0.3f);
|
||||
readonly Color colorPinkContent = new Color (1f, 0.3f, 0.6f, 1f);
|
||||
readonly Color colorGreenButton = new Color (0.0f, 1f, 0.66f, 1f);
|
||||
readonly float SPACE_SUB_TOP_5 = 5f;
|
||||
readonly float SPACE_SUB_BTM_12 = 12f;
|
||||
readonly float SPACE_MAIN_TOP_7 = 7f;
|
||||
readonly float SPACE_MAIN_BTM_5 = 5f;
|
||||
|
||||
private void setLabelAreaWidth (float labelWidthMin, float valWidthMin) {
|
||||
if (EditorGUIUtility.labelWidth < labelWidthMin)
|
||||
EditorGUIUtility.labelWidth = labelWidthMin;
|
||||
if (EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth < valWidthMin)
|
||||
EditorGUIUtility.labelWidth = EditorGUIUtility.currentViewWidth - valWidthMin;
|
||||
}
|
||||
|
||||
private void drawProperties () {
|
||||
storeIndentWidth ();
|
||||
EditorGUIUtility.labelWidth += 6;
|
||||
EditorGUI.indentLevel++;
|
||||
setLabelAreaWidth (labelWidthMin: 145f, valWidthMin: 170f);
|
||||
|
||||
bool useTextureWarning = (m_renderTexture.objectReferenceValue == null && isGameObjectOnScene () && !serializedObject.isEditingMultipleObjects);
|
||||
// ---------------------------------------------------------------------------------- Calculation
|
||||
bool expandCalc = expandMainGroup (m_calcResolution, true, "Calculation", isPink : useTextureWarning);
|
||||
// --------- Preview Window Button
|
||||
if (!expandCalc) {
|
||||
var rect = GUILayoutUtility.GetLastRect ();
|
||||
float width = 150f;
|
||||
rect.x += rect.width - width;
|
||||
rect.width = width;
|
||||
rect.y += 1f;
|
||||
if (PreviewWindow.IsShowing ()) {
|
||||
if (GUI.Button (rect, "Close Preview", EditorStyles.miniButton)) {
|
||||
PreviewWindow.CloseWindow ();
|
||||
}
|
||||
} else {
|
||||
bool useBtn = !serializedObject.isEditingMultipleObjects && !useTextureWarning;
|
||||
using (new DisableScope (useBtn)) {
|
||||
using (new ColorScope (useBtn?colorGreenButton : GUI.color))
|
||||
if (GUI.Button (rect, "Open Preview", EditorStyles.miniButton)) {
|
||||
PreviewWindow.OpenWindow (target as WaterCausticsTexGenerator);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EditorGUILayout.Space (SPACE_MAIN_TOP_7);
|
||||
// --------- RenderTexture
|
||||
using (new ColorScope (useTextureWarning ? colorPinkContent : GUI.color)) {
|
||||
EditorGUILayout.PropertyField (m_renderTexture, new GUIContent ("Render Texture", "Output destination RenderTexture."));
|
||||
if (!m_renderTexture.hasMultipleDifferentValues) {
|
||||
if (useTextureWarning) {
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
GUILayout.FlexibleSpace ();
|
||||
var descBtn = new GUIContent ("Create RenderTexture", "Create a new RenderTexture asset. It will be created in the same folder as the scene file.");
|
||||
if (GUILayout.Button (descBtn, EditorStyles.miniButton, GUILayout.Width (150))) {
|
||||
m_renderTexture.objectReferenceValue = WaterCausticsTexGeneratorMenuItem.CreateRTAsset ();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
} else {
|
||||
if (m_renderTexture.objectReferenceValue != null) {
|
||||
var rt = m_renderTexture.objectReferenceValue as RenderTexture;
|
||||
string mipmapStr = rt.useMipMap ? "MipMapOn" : "MipMapOff";
|
||||
string str = $"{rt.width}x{rt.height} / {rt.graphicsFormat} / {(EnumMSAA)rt.antiAliasing} / {mipmapStr}";
|
||||
EditorGUILayout.HelpBox (str, MessageType.None);
|
||||
if (rt.antiAliasing > 1 && rt.useMipMap) {
|
||||
EditorGUILayout.Space (1);
|
||||
str = "MipMap is not applied because RenderTexture's Anti-aliasing (MSAA) is On. To use MipMap and MSAA together, turn off MSAA of RenderTexture and use MSAA in PostProcessing of this component.";
|
||||
EditorGUILayout.HelpBox (str, MessageType.Warning);
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
GUILayout.FlexibleSpace ();
|
||||
if (GUILayout.Button (new GUIContent ("Fix", "Turn off MSAA of RenderTexture and use MSAA in PostProcessing of this component."), EditorStyles.miniButton, GUILayout.Width (150))) {
|
||||
Undo.RecordObject (rt, "Turn off MSAA of RenderTexture and use MSAA in PostProcessing of this component.");
|
||||
EditorUtility.SetDirty (rt);
|
||||
int tmp = rt.antiAliasing;
|
||||
if (rt.IsCreated ()) {
|
||||
bool isActive = (RenderTexture.active == rt);
|
||||
if (isActive) RenderTexture.active = null;
|
||||
rt.Release ();
|
||||
rt.antiAliasing = 1;
|
||||
rt.Create ();
|
||||
if (isActive) RenderTexture.active = rt;
|
||||
} else {
|
||||
rt.antiAliasing = 1;
|
||||
}
|
||||
m_usePostProcessing.boolValue = true;
|
||||
m_msaa.intValue = Mathf.Max (tmp, m_msaa.intValue);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
EditorGUILayout.Space (4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space (1);
|
||||
popup (m_calcResolution, _resEnumStr, "Calc Resolution", "Resolution used for internal calculations.");
|
||||
EditorGUILayout.PropertyField (m_FillGap, new GUIContent ("Fill Gap", "If the edges of the output image are not drawn, increase the value. Make it as small as possible to reduce the load."));
|
||||
using (new DisableScope (m_generateInEditMode.boolValue)) {
|
||||
EditorGUILayout.PropertyField (m_animateInEditMode, new GUIContent ("Animate In EditMode", _animInEditModeDesc));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------- Preview Window Button
|
||||
EditorGUILayout.Space (5);
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
GUILayout.FlexibleSpace ();
|
||||
if (PreviewWindow.IsShowing ()) {
|
||||
if (GUILayout.Button ("Close Preview", EditorStyles.miniButton, GUILayout.Width (150))) {
|
||||
PreviewWindow.CloseWindow ();
|
||||
}
|
||||
} else {
|
||||
bool useBtn = !serializedObject.isEditingMultipleObjects && !useTextureWarning;
|
||||
using (new DisableScope (useBtn)) {
|
||||
using (new ColorScope (useBtn?colorGreenButton : GUI.color))
|
||||
if (GUILayout.Button ("Open Preview", EditorStyles.miniButton, GUILayout.Width (150))) {
|
||||
PreviewWindow.OpenWindow (target as WaterCausticsTexGenerator);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
|
||||
EditorGUILayout.Space (SPACE_SUB_BTM_12 - SPACE_MAIN_BTM_5);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space (SPACE_MAIN_BTM_5);
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------- Parameters
|
||||
if (expandMainGroup (m_density, true, "Parameters")) {
|
||||
EditorGUILayout.Space (SPACE_MAIN_TOP_7);
|
||||
// ----------------------------------------- Wave
|
||||
if (expandSubGroup (m_pause, true, "Wave")) {
|
||||
EditorGUILayout.Space (SPACE_SUB_TOP_5);
|
||||
EditorGUILayout.PropertyField (m_pause, new GUIContent ("Pause", "Suspend the overall waves."));
|
||||
EditorGUILayout.PropertyField (m_density, new GUIContent ("Density", "Adjust the overall density."));
|
||||
EditorGUILayout.PropertyField (m_height, new GUIContent ("Height", "Adjust the overall height."));
|
||||
|
||||
using (new DisableScope (!m_pause.boolValue)) {
|
||||
EditorGUILayout.PropertyField (m_speed, new GUIContent ("Speed", "Adjust the overall speed."));
|
||||
}
|
||||
EditorGUILayout.Space (1);
|
||||
using (new DisableScope (!m_pause.boolValue)) {
|
||||
EditorGUILayout.PropertyField (m_flow, new GUIContent ("Flow", "Adjust the overall flow."));
|
||||
if (m_flow.floatValue != 0f) {
|
||||
using (new IndentScope (-2f, 0f, 2)) {
|
||||
EditorGUILayout.PropertyField (m_flowDirection, new GUIContent ("Direction", "Adjust the overall direction of flow."));
|
||||
drawDirMark (m_flowDirection, !m_pause.boolValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space (8);
|
||||
drawLine ();
|
||||
EditorGUILayout.Space (8);
|
||||
if (isExpand (m_waves, false, new GUIContent ("Waves", $"Wave settings. Supports up to {WaterCausticsTexGenerator.WAVE_MAX_CNT}."))) {
|
||||
EditorGUILayout.Space (3);
|
||||
drawWaveList ();
|
||||
} else {
|
||||
EditorGUILayout.Space (5);
|
||||
}
|
||||
EditorGUILayout.Space (SPACE_SUB_BTM_12);
|
||||
}
|
||||
// ----------------------------------------- Refraction
|
||||
if (expandSubGroup (m_refractionIndex, true, "Refraction")) {
|
||||
EditorGUILayout.Space (SPACE_SUB_TOP_5);
|
||||
|
||||
EditorGUILayout.PropertyField (m_style, new GUIContent ("Style", "How to calculate light focusing."));
|
||||
EditorGUILayout.PropertyField (m_refractionIndex, new GUIContent ("Refraction Index", "Index of refraction."));
|
||||
|
||||
EditorGUILayout.Space (1);
|
||||
if (isExpand (m_lightRay, false, new GUIContent ("Details"))) {
|
||||
EditorGUILayout.PropertyField (m_useChromaticAberration, new GUIContent ("Chromatic Aberration", "Simulate more realistic chromatic aberrations. \nAmount of calculation increases. For mobile devices, consider using color shift.\n\nRequires RenderTexture having RGB channels."));
|
||||
if (m_useChromaticAberration.boolValue) {
|
||||
using (new IndentScope (-2, 2)) {
|
||||
EditorGUILayout.PropertyField (m_chromaticAberration, new GUIContent ("Intensity", "Shifts the refractive index in the RGB channels."));
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space (1);
|
||||
orderedPopup (m_lightRay, _litRayTypeEnumGC, _litDirTypeEnumOrder, "Light Ray", "Direction of the ray from the Light.");
|
||||
using (new IndentScope (0, 1)) {
|
||||
switch ((LightRay) m_lightRay.enumValueIndex) {
|
||||
case LightRay.Vector:
|
||||
EditorGUILayout.PropertyField (m_lightVector, new GUIContent ("Direction", "Specify the direction of light rays as a vector. It will be normalized."));
|
||||
break;
|
||||
case LightRay.Transform:
|
||||
EditorGUILayout.PropertyField (m_lightTransform, new GUIContent ("Transform", "Transforms the light to be referenced."));
|
||||
break;
|
||||
case LightRay.LitSettingSun:
|
||||
EditorGUILayout.LabelField ("Use the sun setting in the Light Settings window.", new GUIStyle ("HelpBox"));
|
||||
break;
|
||||
case LightRay.Auto:
|
||||
EditorGUILayout.LabelField ("Use the shader's global variable \"_LightDirection\".", new GUIStyle ("HelpBox"));
|
||||
break;
|
||||
case LightRay.Direction:
|
||||
default:
|
||||
EditorGUILayout.PropertyField (m_lightIncidentAngle, new GUIContent ("Incident Angle", "Angle of incidence of light rays."));
|
||||
if (m_lightIncidentAngle.floatValue > 0f) {
|
||||
drawSyncDirProp (m_lightDirection, true, new GUIContent ("Direction", "Direction of light rays. \n\nChain mark is On, the Light Ray, Directional Blur, and Color Shift directions are synchronized."));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space (1);
|
||||
EditorGUILayout.PropertyField (m_refractedRay, new GUIContent ("Refracted Ray", "Normalize the rays after refraction or extend them until they hit the bottom."));
|
||||
}
|
||||
EditorGUILayout.Space (SPACE_SUB_BTM_12);
|
||||
}
|
||||
// ----------------------------------------- Adjustment
|
||||
if (expandSubGroup (m_brightness, true, "Adjustment")) {
|
||||
EditorGUILayout.Space (SPACE_SUB_TOP_5);
|
||||
EditorGUILayout.PropertyField (m_gamma, new GUIContent ("Gamma", "Adjusts the contrast."));
|
||||
EditorGUILayout.PropertyField (m_brightness, new GUIContent ("Brightness", "Adjust the brightness."));
|
||||
EditorGUILayout.PropertyField (m_clamp, new GUIContent ("Clamp", "Limit the brightness to this value."));
|
||||
}
|
||||
EditorGUILayout.Space (SPACE_SUB_BTM_12 - SPACE_MAIN_BTM_5);
|
||||
}
|
||||
EditorGUILayout.Space (SPACE_MAIN_BTM_5);
|
||||
// ---------------------------------------------------------------------------------- Post Processing
|
||||
if (expandMainGroup (m_usePostProcessing, true, "Post Processing")) {
|
||||
EditorGUILayout.Space (SPACE_MAIN_TOP_7);
|
||||
|
||||
EditorGUILayout.PropertyField (m_usePostProcessing, new GUIContent ("Post Processing", "Apply the post processing effect. \nWhen post-processing is used, it is first drawn to a temporary RenderTexture, then post-processed, and output to a destination RenderTexture."));
|
||||
using (new DisableScope (m_usePostProcessing.boolValue)) {
|
||||
EditorGUILayout.Space (1);
|
||||
popup (m_msaa, _msaaEnumStr, "MSAA", "Multi-Sampling Anti-Alias. \nWhen post-processing is used, it is first drawn to a temporary RenderTexture, then post-processed, and output to a destination RenderTexture. This setting is MSAA for that first drawing. \n\nIf using Post Processing, MSAA of the RenderTexture for output is not used and will be disabled on the actual device.");
|
||||
EditorGUILayout.Space (1);
|
||||
EditorGUILayout.PropertyField (m_useBlur, new GUIContent ("Blur", "Use blur or not."));
|
||||
if (isExpandMarkOnly (m_useBlur, true)) {
|
||||
using (new IndentScope (-2f, 1f)) {
|
||||
using (new DisableScope (m_useBlur.boolValue)) {
|
||||
EditorGUILayout.PropertyField (m_blurIterations, new GUIContent ("Blur Iteration", "Number of iterations."));
|
||||
EditorGUILayout.PropertyField (m_blurSpread, new GUIContent ("Spread", "Amount of spread."));
|
||||
using (new DisableScope (m_blurIterations.intValue > 1 || m_blurSpread.floatValue > 0f)) {
|
||||
EditorGUILayout.PropertyField (m_blurDirectional, new GUIContent ("Directional", "Give directionality to the blur."));
|
||||
if (m_blurDirectional.floatValue > 0f) {
|
||||
bool isActive = m_usePostProcessing.boolValue && m_useBlur.boolValue && (m_blurIterations.intValue > 1 || m_blurSpread.floatValue > 0f);
|
||||
drawSyncDirProp (m_blurDirection, isActive, new GUIContent ("Direction", "Blur direction.\n\nChain mark is On, the Light Ray, Directional Blur, and Color Shift directions are synchronized."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space (1);
|
||||
EditorGUILayout.PropertyField (m_colorShift, new GUIContent ("Color Shift", "Amount of color shift.\n\nRequires RenderTexture having RGB channels."));
|
||||
if (m_colorShift.floatValue > 0f) {
|
||||
drawSyncDirProp (m_colorShiftDir, m_usePostProcessing.boolValue, new GUIContent ("Direction", "Color Shift direction.\n\nChain mark is On, the Light Ray, Directional Blur, and Color Shift directions are synchronized."));
|
||||
}
|
||||
EditorGUILayout.Space (1);
|
||||
EditorGUILayout.PropertyField (m_postContrast, new GUIContent ("Contrast", "Contrast adjustment."));
|
||||
EditorGUILayout.PropertyField (m_postBrightness, new GUIContent ("Brightness", "Brightness adjustment in post-processing."));
|
||||
}
|
||||
EditorGUILayout.Space (SPACE_SUB_BTM_12 - SPACE_MAIN_BTM_5);
|
||||
}
|
||||
EditorGUILayout.Space (SPACE_MAIN_BTM_5);
|
||||
// ---------------------------------------------------------------------------------- Advanced Settings
|
||||
if (expandMainGroup (m_computeShader, false, "Advanced Settings")) {
|
||||
EditorGUILayout.Space (SPACE_MAIN_TOP_7);
|
||||
if (expandSubGroup (m_generateInEditMode, true, "In EditMode")) {
|
||||
EditorGUILayout.Space (SPACE_SUB_TOP_5);
|
||||
EditorGUILayout.PropertyField (m_generateInEditMode, new GUIContent ("Generate", "Whether to generate while in edit mode."));
|
||||
using (new DisableScope (m_generateInEditMode.boolValue)) {
|
||||
EditorGUILayout.PropertyField (m_animateInEditMode, new GUIContent ("Animate", _animInEditModeDesc));
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space (SPACE_SUB_BTM_12);
|
||||
EditorGUILayout.Space (SPACE_MAIN_BTM_5);
|
||||
EditorGUILayout.Space (SPACE_MAIN_BTM_5);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Wave List
|
||||
private ReorderableList _waveList;
|
||||
private float lineH = EditorGUIUtility.singleLineHeight + 2;
|
||||
private void prepWaveList () {
|
||||
if (_waveList != null) return;
|
||||
_waveList = new ReorderableList (serializedObject, m_waves, true, false, true, true);
|
||||
_waveList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
|
||||
rect.x += 12f;
|
||||
rect.width -= 12f;
|
||||
rect.y += 2f;
|
||||
using (new AdjustLabelSpaceWidthScope (-48f)) {
|
||||
rect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
var element = m_waves.GetArrayElementAtIndex (index);
|
||||
element.isExpanded = EditorGUI.Foldout (rect, element.isExpanded, new GUIContent ($" ", ""));
|
||||
var m_active = element.FindPropertyRelative ("m_active");
|
||||
EditorGUI.PropertyField (rect, m_active, new GUIContent ($"Wave [{index}]", "Enables/Disables this wave."));
|
||||
if (element.isExpanded) {
|
||||
var m_density = element.FindPropertyRelative ("m_density");
|
||||
var m_height = element.FindPropertyRelative ("m_height");
|
||||
var m_fluctuation = element.FindPropertyRelative ("m_fluctuation");
|
||||
var m_flow = element.FindPropertyRelative ("m_flow");
|
||||
var m_direction = element.FindPropertyRelative ("m_direction");
|
||||
var indent2 = 10f;
|
||||
using (new AdjustLabelSpaceWidthScope (-indent2)) {
|
||||
rect.x += indent2;
|
||||
rect.width -= indent2;
|
||||
rect.y += 2;
|
||||
using (new DisableScope (m_active.boolValue)) {
|
||||
rect.y += lineH;
|
||||
EditorGUI.PropertyField (rect, m_density, new GUIContent ($"Density", "Density of this wave."));
|
||||
rect.y += lineH;
|
||||
EditorGUI.PropertyField (rect, m_height, new GUIContent ($"Height", "Height of this wave."));
|
||||
}
|
||||
bool isEnable = m_active.boolValue && !m_pause.boolValue && !this.m_pause.boolValue;
|
||||
using (new DisableScope (isEnable)) {
|
||||
rect.y += lineH;
|
||||
EditorGUI.PropertyField (rect, m_fluctuation, new GUIContent ($"Fluctuation", "Fluctuation of this wave."));
|
||||
rect.y += lineH + 2;
|
||||
EditorGUI.PropertyField (rect, m_flow, new GUIContent ($"Flow", "Amount of flow."));
|
||||
bool showFlowDir = (m_flow.floatValue != 0f || m_flow.hasMultipleDifferentValues);
|
||||
if (showFlowDir) {
|
||||
rect.y += lineH;
|
||||
rect.x += _indentWidth;
|
||||
rect.width -= _indentWidth;
|
||||
drawDirMark (rect, m_direction, isEnable);
|
||||
rect.x += _indentWidth;
|
||||
rect.width -= _indentWidth;
|
||||
using (new AdjustLabelSpaceWidthScope (-_indentWidth * 2f)) {
|
||||
EditorGUI.PropertyField (rect, m_direction, new GUIContent ($"Direction", "Flow Direction. \n\n -90:Up \n180:Left 0:Right \n 90:Down"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
_waveList.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
|
||||
ReorderableList.defaultBehaviours.DrawElementBackground (rect, index, isActive && isFocused, isFocused, true);
|
||||
};
|
||||
_waveList.elementHeightCallback = (int index) => {
|
||||
var element = m_waves.GetArrayElementAtIndex (index);
|
||||
var height = EditorGUI.GetPropertyHeight (m_waves.GetArrayElementAtIndex (index)) + 4f;
|
||||
if (element.isExpanded) height += -lineH + 10;
|
||||
var m_flow = element.FindPropertyRelative ("m_flow");
|
||||
bool showFlowDir = (m_flow.floatValue != 0f || m_flow.hasMultipleDifferentValues);
|
||||
if (!showFlowDir) height += -lineH;
|
||||
return height;
|
||||
};
|
||||
}
|
||||
|
||||
private void drawWaveList () {
|
||||
var rect = GUILayoutUtility.GetRect (0f, _waveList.GetHeight ());
|
||||
rect = EditorGUI.IndentedRect (rect);
|
||||
_waveList.displayAdd = _waveList.count < WaterCausticsTexGenerator.WAVE_MAX_CNT;
|
||||
_waveList.displayRemove = _waveList.count > 1;
|
||||
_waveList.DoList (rect);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Parts
|
||||
private float _indentWidth;
|
||||
private void storeIndentWidth () {
|
||||
if (_indentWidth != 0f) return;
|
||||
var x0 = EditorGUI.IndentedRect (Rect.zero).x;
|
||||
EditorGUI.indentLevel++;
|
||||
_indentWidth = EditorGUI.IndentedRect (Rect.zero).x - x0;
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
static private Vector3 [] syncIconPts = {
|
||||
new Vector3 (-0.18f, -0.135f),
|
||||
new Vector3 (-0.29f, -0.135f),
|
||||
new Vector3 (-0.332426f, -0.117426f),
|
||||
new Vector3 (-0.35f, -0.075f),
|
||||
new Vector3 (-0.35f, 0.075f),
|
||||
new Vector3 (-0.332426f, 0.117426f),
|
||||
new Vector3 (-0.29f, 0.135f),
|
||||
new Vector3 (0.02f, 0.135f),
|
||||
new Vector3 (0.0624264f, 0.117426f),
|
||||
new Vector3 (0.08f, 0.075f),
|
||||
new Vector3 (0.08f, -0.01f),
|
||||
};
|
||||
static private Vector3 [] asyncIconPts = {
|
||||
new Vector3 (-0.07f, -0.135f),
|
||||
new Vector3 (-0.29f, -0.135f),
|
||||
new Vector3 (-0.332426f, -0.117426f),
|
||||
new Vector3 (-0.35f, -0.075f),
|
||||
new Vector3 (-0.35f, 0.075f),
|
||||
new Vector3 (-0.332426f, 0.117426f),
|
||||
new Vector3 (-0.29f, 0.135f),
|
||||
new Vector3 (-0.07f, 0.135f),
|
||||
};
|
||||
|
||||
private void drawSyncDirProp (SerializedProperty prop, bool isActive, GUIContent label) {
|
||||
using (new IndentScope (-2f, 0f, 2)) {
|
||||
// ----- Sync Icon
|
||||
{
|
||||
var rect = GUILayoutUtility.GetRect (0, 0);
|
||||
rect.height = lineH;
|
||||
rect.x += EditorGUIUtility.labelWidth - 15f;
|
||||
rect.y += 2f;
|
||||
rect.width = 15f;
|
||||
bool clicked = isActive && Event.current != null && Event.current.type == EventType.MouseDown && Event.current.button == 0 && rect.Contains (Event.current.mousePosition);
|
||||
if (clicked) {
|
||||
bool newVal = m_useSyncDirection.hasMultipleDifferentValues ? true : !m_useSyncDirection.boolValue;
|
||||
m_useSyncDirection.boolValue = newVal;
|
||||
if (newVal) m_lightDirection.floatValue = m_blurDirection.floatValue = m_colorShiftDir.floatValue = prop.floatValue;
|
||||
}
|
||||
GUI.BeginClip (rect, new Vector2 (rect.width * 0.5f, rect.height * 0.5f), Vector2.zero, false);
|
||||
if (!m_useSyncDirection.hasMultipleDifferentValues) {
|
||||
float alpha = (isActive? 0.8f : 0.4f) * (m_useSyncDirection.boolValue? 1f : 0.4f);
|
||||
drawSyncIcon (m_useSyncDirection.boolValue, 15f, 0f, alpha);
|
||||
} else {
|
||||
float alpha = (isActive? 0.8f : 0.4f) * 0.7f;
|
||||
drawSyncIcon (true, 15f, -2f, alpha);
|
||||
alpha *= 0.6f;
|
||||
drawSyncIcon (false, 15f, 2f, alpha);
|
||||
}
|
||||
GUI.EndClip ();
|
||||
void drawSyncIcon (bool sync, float size, float shiftX, float alpha) {
|
||||
var pts = sync? syncIconPts : asyncIconPts;
|
||||
var tmpMatrix = Handles.matrix;
|
||||
Handles.color = colorMulAlpha (EditorStyles.label.normal.textColor, alpha);
|
||||
Handles.matrix = tmpMatrix * Matrix4x4.TRS (Vector3.right * shiftX, Quaternion.Euler (0f, 0f, -45f), Vector3.one * size);
|
||||
Handles.DrawAAPolyLine (Texture2D.whiteTexture, 1.1f, pts);
|
||||
Handles.matrix *= Matrix4x4.Rotate (Quaternion.Euler (0f, 0f, 180f));
|
||||
Handles.DrawAAPolyLine (Texture2D.whiteTexture, 1.1f, pts);
|
||||
Handles.matrix = tmpMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
// ----- DirMark & Slider
|
||||
using (var check = new EditorGUI.ChangeCheckScope ()) {
|
||||
EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;
|
||||
float newDir = EditorGUILayout.Slider (label, prop.floatValue, -180f, 180f);
|
||||
drawDirMark (prop, isActive);
|
||||
if (check.changed) {
|
||||
for (int i = 0; i < serializedObject.targetObjects.Length; i++) {
|
||||
var so = new SerializedObject (serializedObject.targetObjects [i]);
|
||||
var useSyncProp = so.FindProperty (m_useSyncDirection.name);
|
||||
if (useSyncProp.boolValue) {
|
||||
so.FindProperty (m_lightDirection.name).floatValue = newDir;
|
||||
so.FindProperty (m_blurDirection.name).floatValue = newDir;
|
||||
so.FindProperty (m_colorShiftDir.name).floatValue = newDir;
|
||||
} else {
|
||||
so.FindProperty (prop.name).floatValue = newDir;
|
||||
}
|
||||
so.ApplyModifiedProperties ();
|
||||
}
|
||||
serializedObject.SetIsDifferentCacheDirty ();
|
||||
}
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static private Color colorMulAlpha (Color c, float mulAlpha) => new Color (c.r, c.g, c.b, c.a * mulAlpha);
|
||||
|
||||
private void drawDirMark (SerializedProperty prop, bool isActive = true) {
|
||||
EditorGUI.indentLevel--;
|
||||
var rect = EditorGUI.IndentedRect (GUILayoutUtility.GetLastRect ());
|
||||
drawDirMark (rect, prop, isActive);
|
||||
EditorGUI.indentLevel++;
|
||||
}
|
||||
private void drawDirMark (Rect rect, SerializedProperty prop, bool isActive = true) {
|
||||
rect.width = EditorGUIUtility.labelWidth;
|
||||
Vector2 origin = new Vector2 (CIRCLE_R + 1, rect.height * 0.5f);
|
||||
float dir = prop.floatValue;
|
||||
Handles.color = colorMulAlpha (EditorStyles.label.normal.textColor, isActive ? 0.8f : 0.4f);
|
||||
var tmpMatrix = Handles.matrix;
|
||||
GUI.BeginClip (rect, origin, Vector2.zero, false);
|
||||
Handles.matrix = tmpMatrix * Matrix4x4.Scale (Vector3.one * CIRCLE_R);
|
||||
Handles.DrawAAPolyLine (Texture2D.whiteTexture, 1, circlePts);
|
||||
if (!prop.hasMultipleDifferentValues) {
|
||||
Handles.matrix = tmpMatrix * Matrix4x4.Rotate (Quaternion.Euler (0f, 0f, dir)) * Matrix4x4.Scale (Vector3.one * (CIRCLE_R - 0.5f));
|
||||
Handles.DrawAAConvexPolygon (arrowAry);
|
||||
}
|
||||
Handles.matrix = tmpMatrix;
|
||||
GUI.EndClip ();
|
||||
}
|
||||
|
||||
static private Vector2 dirToVec (float dir) => new Vector2 (Mathf.Sin (dir * Mathf.Deg2Rad), -Mathf.Cos (dir * Mathf.Deg2Rad));
|
||||
const float CIRCLE_R = 5f;
|
||||
static readonly private Vector3 [] arrowAry = {
|
||||
dirToVec (0),
|
||||
dirToVec (150f),
|
||||
dirToVec (170f),
|
||||
dirToVec (-170f),
|
||||
dirToVec (-150f),
|
||||
};
|
||||
static readonly private Vector3 [] circlePts = {
|
||||
new Vector3 (-1f, 0f),
|
||||
new Vector3 (-0.87f, -0.5f),
|
||||
new Vector3 (-0.5f, -0.87f),
|
||||
new Vector3 (0f, -1f),
|
||||
new Vector3 (0.5f, -0.87f),
|
||||
new Vector3 (0.87f, -0.5f),
|
||||
new Vector3 (1f, 0f),
|
||||
new Vector3 (0.87f, 0.5f),
|
||||
new Vector3 (0.5f, 0.87f),
|
||||
new Vector3 (0f, 1f),
|
||||
new Vector3 (-0.5f, 0.87f),
|
||||
new Vector3 (-0.87f, 0.5f),
|
||||
new Vector3 (-1f, 0f),
|
||||
};
|
||||
|
||||
bool isGameObjectOnScene () {
|
||||
return (target as Component).gameObject.scene.IsValid ();
|
||||
}
|
||||
|
||||
private void drawRectMain (bool isPink = false) {
|
||||
Color color = isPink ? colorPinkBar : new Color (0f, 0f, 0f, 0.2f);
|
||||
Rect rect = GUILayoutUtility.GetRect (0, 0);
|
||||
rect.height = lineH;
|
||||
rect.x -= _indentWidth + 4;
|
||||
rect.width += _indentWidth + 8;
|
||||
EditorGUI.DrawRect (rect, color);
|
||||
}
|
||||
|
||||
private bool expandMainGroup (SerializedProperty prop, bool defOpen, string label, bool isPink = false) {
|
||||
EditorGUI.indentLevel--;
|
||||
drawRectMain (isPink);
|
||||
bool expand = isExpand (prop, true, new GUIContent (label));
|
||||
EditorGUI.indentLevel++;
|
||||
return expand;
|
||||
}
|
||||
|
||||
|
||||
private bool expandSubGroup (SerializedProperty prop, bool defOpen, string label, bool isPink = false) {
|
||||
Color color = isPink ? colorPinkBar : colorMulAlpha (EditorStyles.label.normal.textColor, 0.1f);
|
||||
GUILayout.Label (" ");
|
||||
Rect rect = GUILayoutUtility.GetLastRect ();
|
||||
rect.y += 1f;
|
||||
rect.x += 3f;
|
||||
rect.width -= 3f;
|
||||
Rect rect2 = rect;
|
||||
rect2.x -= 14f;
|
||||
rect2.width += 15f;
|
||||
EditorGUI.DrawRect (rect2, color);
|
||||
GUI.Label (rect, label);
|
||||
if (prop == null) {
|
||||
return true;
|
||||
} else {
|
||||
rect.x -= 14;
|
||||
prop.isExpanded = EditorGUI.Foldout (rect, prop.isExpanded != defOpen, " ") != defOpen;
|
||||
return prop.isExpanded != defOpen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void popup (SerializedProperty prop, string [] enumStr, string text, string tooltip) {
|
||||
using (var check = new EditorGUI.ChangeCheckScope ()) {
|
||||
EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;
|
||||
var newVal = EditorGUILayout.Popup (new GUIContent (text, tooltip), prop.enumValueIndex, enumStr);
|
||||
if (check.changed)
|
||||
prop.enumValueIndex = newVal;
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void orderedPopup (SerializedProperty prop, GUIContent [] enumStr, int [] intAry, string text, string tooltip) {
|
||||
using (var check = new EditorGUI.ChangeCheckScope ()) {
|
||||
EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;
|
||||
var newVal = EditorGUILayout.IntPopup (new GUIContent (text, tooltip), prop.enumValueIndex, enumStr, intAry);
|
||||
if (check.changed)
|
||||
prop.enumValueIndex = newVal;
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isExpand (SerializedProperty prop, bool defOpen, GUIContent label) {
|
||||
prop.isExpanded = EditorGUILayout.Foldout (prop.isExpanded != defOpen, label) != defOpen;
|
||||
return prop.isExpanded != defOpen;
|
||||
}
|
||||
|
||||
private bool isExpandMarkOnly (SerializedProperty prop, bool defOpen, float adjustX = 0f, float adjustY = 0f) {
|
||||
var rect = GUILayoutUtility.GetLastRect ();
|
||||
prop.isExpanded = EditorGUI.Foldout (rect, prop.isExpanded != defOpen, " ") != defOpen;
|
||||
return prop.isExpanded != defOpen;
|
||||
}
|
||||
|
||||
private void drawLine () {
|
||||
Rect r = GUILayoutUtility.GetRect (0, 0);
|
||||
Color col = colorMulAlpha (EditorStyles.label.normal.textColor, 0.09f);
|
||||
EditorGUI.DrawRect (new Rect (r.x + 14f, r.y, r.width - 14f, 1f), col);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- Scope
|
||||
|
||||
private class AdjustLabelSpaceWidthScope : GUI.Scope {
|
||||
private readonly float _store;
|
||||
internal AdjustLabelSpaceWidthScope (float adjust) {
|
||||
_store = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth += adjust;
|
||||
}
|
||||
protected override void CloseScope () {
|
||||
EditorGUIUtility.labelWidth = _store;
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelAndIndentScope : GUI.Scope {
|
||||
private float _spaceBtm;
|
||||
internal LabelAndIndentScope (string label, float spaceTop = 0f, float spaceMid = 2f, float spaceBtm = 0f) {
|
||||
_spaceBtm = spaceBtm;
|
||||
EditorGUILayout.Space (spaceTop);
|
||||
EditorGUILayout.LabelField (label);
|
||||
EditorGUILayout.Space (spaceMid);
|
||||
EditorGUI.indentLevel++;
|
||||
}
|
||||
protected override void CloseScope () {
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.Space (_spaceBtm);
|
||||
}
|
||||
}
|
||||
|
||||
private class IndentScope : GUI.Scope {
|
||||
private float _spaceBtm;
|
||||
private int _indent;
|
||||
internal IndentScope (float spaceTop = 0f, float spaceBtm = 0f, int indent = 1) {
|
||||
_spaceBtm = spaceBtm;
|
||||
_indent = indent;
|
||||
EditorGUILayout.Space (spaceTop);
|
||||
EditorGUI.indentLevel += indent;
|
||||
}
|
||||
protected override void CloseScope () {
|
||||
EditorGUI.indentLevel -= _indent;
|
||||
EditorGUILayout.Space (_spaceBtm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class DisableScope : GUI.Scope {
|
||||
private readonly bool _tmp;
|
||||
internal DisableScope (bool isActive = false) {
|
||||
_tmp = isActive;
|
||||
if (!_tmp) EditorGUI.BeginDisabledGroup (true);
|
||||
}
|
||||
protected override void CloseScope () {
|
||||
if (!_tmp) EditorGUI.EndDisabledGroup ();
|
||||
}
|
||||
}
|
||||
|
||||
private class ColorScope : GUI.Scope {
|
||||
private readonly Color _tmp;
|
||||
internal ColorScope (Color color) {
|
||||
_tmp = GUI.color;
|
||||
GUI.color = color;
|
||||
}
|
||||
protected override void CloseScope () {
|
||||
GUI.color = _tmp;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
// ----------------------------------------------------------- 以下 UNITY 2030.3より下用
|
||||
public override void OnInspectorGUI () {
|
||||
onInspectorGUI_UnityVersionLow ();
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool isDark => EditorGUIUtility.isProSkin;
|
||||
private GUIStyle _textStyle, _linkUrlStyle, _warningStyle;
|
||||
private void onInspectorGUI_UnityVersionLow () {
|
||||
if (_textStyle == null) {
|
||||
_textStyle = new GUIStyle (EditorStyles.label);
|
||||
_textStyle.wordWrap = true;
|
||||
_textStyle.fontSize = 14;
|
||||
|
||||
_linkUrlStyle = new GUIStyle (_textStyle);
|
||||
_linkUrlStyle.wordWrap = false;
|
||||
_linkUrlStyle.normal.textColor = isDark ? new Color (0f, 0.8f, 1f, 1f) : new Color (0f, 0.4f, 0.8f, 1f);
|
||||
_linkUrlStyle.hover.textColor = _linkUrlStyle.normal.textColor + Color.white * (isDark ? 0.3f : 0.2f);
|
||||
_linkUrlStyle.stretchWidth = false;
|
||||
|
||||
_warningStyle = new GUIStyle (_textStyle);
|
||||
_warningStyle.normal.textColor = isDark ? Color.white : new Color (0.8f, 0.1f, 0f, 1f);
|
||||
_warningStyle.normal.background = Texture2D.whiteTexture;
|
||||
}
|
||||
|
||||
EditorGUILayout.Space (50);
|
||||
labelWarning ($"This asset is not compatible with current Unity version {Application.unityVersion}. Unity {Constant.REQUIRE_UNITY_VER} is required.");
|
||||
EditorGUILayout.Space (10);
|
||||
GUILayout.Label ($"Current : Unity {Application.unityVersion}", _textStyle);
|
||||
GUILayout.Label ($"Require : Unity {Constant.REQUIRE_UNITY_VER}", _textStyle);
|
||||
|
||||
EditorGUILayout.Space (10);
|
||||
var url = Constant.URL_MANUAL;
|
||||
if (labelLink (new GUIContent ("Open Asset Manual", url)))
|
||||
Application.OpenURL (url);
|
||||
EditorGUILayout.Space (50);
|
||||
}
|
||||
|
||||
void labelWarning (string text) {
|
||||
Color tmp = GUI.backgroundColor;
|
||||
GUI.backgroundColor = isDark ? new Color (1f, 0.3f, 0.6f, 0.4f) : new Color (1f, 0.3f, 0.6f, 0.5f);
|
||||
GUILayout.Label (text, _warningStyle);
|
||||
GUI.backgroundColor = tmp;
|
||||
}
|
||||
|
||||
private bool labelLink (GUIContent label, params GUILayoutOption [] options) {
|
||||
GUIStyle style = _linkUrlStyle;
|
||||
var rect = GUILayoutUtility.GetRect (label, style, options);
|
||||
Handles.BeginGUI ();
|
||||
Handles.color = style.normal.textColor;
|
||||
Handles.DrawLine (new Vector3 (rect.xMin, rect.yMax), new Vector3 (rect.xMax, rect.yMax));
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI ();
|
||||
EditorGUIUtility.AddCursorRect (rect, MouseCursor.Link);
|
||||
return GUI.Button (rect, label, style);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e989360942cc2642a0a28a6e3e49419
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
#if UNITY_EDITOR && UNITY_2020_3_OR_NEWER
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
public class WaterCausticsTexGeneratorMenuItem {
|
||||
[MenuItem ("GameObject/WaterCausticsModules/TexGen (with RenderTexture Asset)", false, 1)]
|
||||
static public WaterCausticsTexGenerator CreateTexGeneratorWithRT () {
|
||||
var texGen = createGameObject ();
|
||||
texGen.renderTexture = CreateRTAsset ();
|
||||
Selection.activeObject = texGen.gameObject;
|
||||
return texGen;
|
||||
}
|
||||
|
||||
[MenuItem ("GameObject/WaterCausticsModules/TexGen", false, 2)]
|
||||
static public void CreateTexGeneratorGO () {
|
||||
createGameObject ();
|
||||
}
|
||||
|
||||
static private WaterCausticsTexGenerator createGameObject () {
|
||||
var go = new GameObject ("WaterCausticsTexGen");
|
||||
Undo.RegisterCreatedObjectUndo (go, "Create WaterCausticsTexGen");
|
||||
var tra = go.transform;
|
||||
if (Selection.activeGameObject != null) {
|
||||
var baseTra = Selection.activeGameObject.transform;
|
||||
tra.parent = baseTra.parent;
|
||||
tra.SetSiblingIndex (baseTra.GetSiblingIndex () + 1);
|
||||
}
|
||||
tra.localPosition = Vector3.zero;
|
||||
tra.localRotation = Quaternion.identity;
|
||||
tra.localScale = Vector3.one;
|
||||
Selection.activeObject = go;
|
||||
return go.AddComponent<WaterCausticsTexGenerator> ();
|
||||
}
|
||||
|
||||
static public RenderTexture CreateRTAsset () {
|
||||
var rtName = "WaterCausticsRT";
|
||||
var scene = SceneManager.GetActiveScene ();
|
||||
var path = scene.path;
|
||||
if (string.IsNullOrEmpty (path))
|
||||
path = $"Assets/{rtName}";
|
||||
else
|
||||
path = $"{Path.GetDirectoryName (path).Replace ("\\", "/")}/{scene.name}_{rtName}";
|
||||
int idx = 1;
|
||||
var savePath = $"{path}.renderTexture";
|
||||
while (File.Exists (savePath))
|
||||
savePath = $"{path}{++idx}.renderTexture";
|
||||
RenderTextureDescriptor desc = new RenderTextureDescriptor (512, 512, RenderTextureFormat.ARGBHalf, 0);
|
||||
desc.autoGenerateMips = false;
|
||||
desc.msaaSamples = 1;
|
||||
desc.useMipMap = true;
|
||||
desc.autoGenerateMips = true;
|
||||
RenderTexture rt = new RenderTexture (desc);
|
||||
rt.anisoLevel = 4;
|
||||
rt.wrapMode = TextureWrapMode.Repeat;
|
||||
rt.Create ();
|
||||
AssetDatabase.CreateAsset (rt, savePath);
|
||||
AssetDatabase.SaveAssets ();
|
||||
EditorGUIUtility.PingObject (rt);
|
||||
Debug.Log ("A new RenderTexture was created at the following location.\n\"" + savePath + "\"\n");
|
||||
return rt;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afa42b0dae9c61c4c8e85022abbe43bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,936 @@
|
||||
// WaterCausticsModules
|
||||
// Copyright (c) 2021 Masataka Hakozaki
|
||||
|
||||
using System.Collections.Generic;
|
||||
using MH.WaterCausticsModules.TexGen;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MH.WaterCausticsModules {
|
||||
namespace TexGen {
|
||||
// ----------------------------------------------------------- Enum
|
||||
public enum Style { StyleA, StyleB, StyleC, }
|
||||
public enum RefractedRay { Normalize, Extend, }
|
||||
public enum MSAASamples { None = 1, MSAA2x = 2, MSAA4x = 4, MSAA8x = 8 }
|
||||
public enum LightRay { Vector = 0, Transform, LitSettingSun, Auto, Direction, }
|
||||
public enum CalcRes { x64 = 64, x96 = 96, x128 = 128, x160 = 160, x256 = 256, x320 = 320, x512 = 512, }
|
||||
}
|
||||
|
||||
[ExecuteAlways]
|
||||
[HelpURL (Constant.URL_MANUAL)]
|
||||
[AddComponentMenu ("WaterCausticsModules/WaterCausticsTexGenerator")]
|
||||
public class WaterCausticsTexGenerator : MonoBehaviour {
|
||||
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
// ----------------------------------------------------------- Constant
|
||||
private const int THREAD_SIZE = 16;
|
||||
internal const int WAVE_MAX_CNT = 4;
|
||||
readonly private string [] _lcStyleStr = { "STYLE_A", "STYLE_B", "STYLE_C", };
|
||||
readonly private float [] _lcStyleBright = { 1f, 1.3f, 1.3f };
|
||||
readonly private float [] _lcStyleGamma = { 1f, 1.25f, 1.02f };
|
||||
|
||||
// ----------------------------------------------------------- SerializeField
|
||||
[SerializeField] private bool m_generateInEditMode = true;
|
||||
[SerializeField] private bool m_animateInEditMode = true;
|
||||
[SerializeField] private bool m_pause;
|
||||
[SerializeField, Range (0.1f, 3f)] private float m_density = 1f;
|
||||
[SerializeField, Range (0f, 4f)] private float m_height = 1f;
|
||||
[SerializeField, Range (0f, 4f)] private float m_speed = 1f;
|
||||
[SerializeField, Range (0f, 1.5f)] private float m_flow = 0f;
|
||||
[SerializeField, Range (-180f, 180f)] private float m_flowDirection = 0f;
|
||||
[SerializeField] private List<Wave> m_waves = new List<Wave> () {
|
||||
new Wave (7.3f, 0.55f, 0.85f, 0.11f, 100f),
|
||||
new Wave (3.7f, 0.4f, 0.55f, 0.2f, -60f)
|
||||
};
|
||||
[SerializeField] private CalcRes m_calcResolution = CalcRes.x160;
|
||||
[SerializeField] private RenderTexture m_renderTexture;
|
||||
[FormerlySerializedAs ("m_FillGapAmount")] [SerializeField, Range (0f, 0.5f)] private float m_FillGap = 0.08f;
|
||||
[FormerlySerializedAs ("m_lightDirectionType")] [SerializeField] private LightRay m_lightRay = LightRay.Direction;
|
||||
[SerializeField] private Transform m_lightTransform;
|
||||
[FormerlySerializedAs ("m_lightDir")] [SerializeField] private Vector3 m_lightVector = Vector3.down;
|
||||
[SerializeField, Range (-180f, 180f)] private float m_lightDirection = 0f;
|
||||
[SerializeField, Range (0f, 90f)] private float m_lightIncidentAngle = 0f;
|
||||
[FormerlySerializedAs ("m_lightCondensingStyle")] [SerializeField] private int m_version = Constant.WCE_VERSION_INT;
|
||||
[SerializeField] private Style m_style = Style.StyleA;
|
||||
[FormerlySerializedAs ("m_rayStyle")] [SerializeField] private RefractedRay m_refractedRay = RefractedRay.Normalize;
|
||||
[SerializeField, Range (0f, 3f)] private float m_brightness = 1f;
|
||||
[SerializeField, Range (0.0001f, 2f)] private float m_gamma = 1f;
|
||||
[SerializeField, Range (0f, 3f)] private float m_clamp = 1f;
|
||||
[Range (1f, 3f), SerializeField] private float m_refractionIndex = 1.33f;
|
||||
[SerializeField] private bool m_useChromaticAberration = false;
|
||||
[Range (0f, 0.3f), SerializeField] private float m_chromaticAberration = 0.005f;
|
||||
[SerializeField] private bool m_usePostProcessing = true;
|
||||
[SerializeField] private bool m_useBlur = true;
|
||||
[SerializeField, Range (1, 20)] private int m_blurIterations = 1;
|
||||
[SerializeField, Range (0f, 1f)] private float m_blurSpread = 0.5f;
|
||||
[SerializeField] private MSAASamples m_msaa = MSAASamples.MSAA8x;
|
||||
[SerializeField, Range (0f, 1f)] private float m_blurDirectional = 0f;
|
||||
[SerializeField, Range (-180f, 180f)] private float m_blurDirection = 0f;
|
||||
[SerializeField, Range (0f, 3f)] private float m_colorShift = 0f;
|
||||
[SerializeField, Range (-180f, 180f)] private float m_colorShiftDir = 0f;
|
||||
[SerializeField] private bool m_useSyncDirection = true;
|
||||
[SerializeField, Range (0f, 2f)] private float m_postBrightness = 1f;
|
||||
[SerializeField, Range (0.0001f, 2f)] private float m_postContrast = 1f;
|
||||
[SerializeField] private ComputeShader m_computeShader;
|
||||
[SerializeField] private Shader m_shader;
|
||||
#if WCE_DEVELOPMENT
|
||||
[SerializeField] private bool m_useSpecifiedTime;
|
||||
[SerializeField] private float m_specifiedTime;
|
||||
[SerializeField, Range (0f, 1f)] private float m_specifiedTimeMultiplier = 0.05f;
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------- private property
|
||||
private bool useChromAbe => (m_useChromaticAberration && m_chromaticAberration > 0f);
|
||||
private int bufSize3or1 => useChromAbe? 3 : 1;
|
||||
|
||||
// ----------------------------------------------------------- Public property
|
||||
public bool generateInEditMode {
|
||||
get => m_generateInEditMode;
|
||||
set => m_generateInEditMode = value;
|
||||
}
|
||||
public bool animateInEditMode {
|
||||
get => m_animateInEditMode;
|
||||
set => m_animateInEditMode = value;
|
||||
}
|
||||
public bool pause {
|
||||
get => m_pause;
|
||||
set => m_pause = value;
|
||||
}
|
||||
public float density {
|
||||
get => m_density;
|
||||
set => m_density = Mathf.Clamp (value, 0.1f, 4f);
|
||||
}
|
||||
public float height {
|
||||
get => m_height;
|
||||
set => m_height = Mathf.Max (value, 0f);
|
||||
}
|
||||
public float speed {
|
||||
get => m_speed;
|
||||
set => m_speed = Mathf.Max (value, 0f);
|
||||
}
|
||||
public float flow {
|
||||
get => m_flow;
|
||||
set => m_flow = value;
|
||||
}
|
||||
public float flowDirection {
|
||||
get => m_flowDirection;
|
||||
set => m_flowDirection = wrapAngle180 (value);
|
||||
}
|
||||
public List<Wave> waves {
|
||||
get => m_waves;
|
||||
}
|
||||
public CalcRes calculateResolution {
|
||||
get => m_calcResolution;
|
||||
set => m_calcResolution = value;
|
||||
}
|
||||
public RenderTexture renderTexture {
|
||||
get => m_renderTexture;
|
||||
set => m_renderTexture = value;
|
||||
}
|
||||
public float fillGapAmount {
|
||||
get => m_FillGap;
|
||||
set => m_FillGap = Mathf.Clamp (value, 0f, 0.5f);
|
||||
}
|
||||
public LightRay lightRayType {
|
||||
get => m_lightRay;
|
||||
set => m_lightRay = value;
|
||||
}
|
||||
public Transform lightTransform {
|
||||
get => m_lightTransform;
|
||||
set => m_lightTransform = value;
|
||||
}
|
||||
public Vector3 lightVector {
|
||||
get => m_lightVector;
|
||||
set => m_lightVector = value;
|
||||
}
|
||||
public float lightDirection {
|
||||
get => m_lightDirection;
|
||||
set => syncDir (ref m_lightDirection, value);
|
||||
}
|
||||
public float lightIncidentAngle {
|
||||
get => m_lightIncidentAngle;
|
||||
set => m_lightIncidentAngle = Mathf.Clamp (value, 0f, 90f);
|
||||
}
|
||||
public Style style {
|
||||
get => m_style;
|
||||
set => m_style = value;
|
||||
}
|
||||
public RefractedRay refractedRayProcessing {
|
||||
get => m_refractedRay;
|
||||
set => m_refractedRay = value;
|
||||
}
|
||||
public float brightness {
|
||||
get => m_brightness;
|
||||
set => m_brightness = Mathf.Max (value, 0f);
|
||||
}
|
||||
public float gamma {
|
||||
get => m_gamma;
|
||||
set => m_gamma = Mathf.Max (value, 0.0001f);
|
||||
}
|
||||
public float clamp {
|
||||
get => m_clamp;
|
||||
set => m_clamp = Mathf.Max (value, 0f);
|
||||
}
|
||||
public float refractionIndex {
|
||||
get => m_refractionIndex;
|
||||
set => m_refractionIndex = Mathf.Clamp (value, 1f, 3f);
|
||||
}
|
||||
public bool useChromaticAberration {
|
||||
get => m_useChromaticAberration;
|
||||
set => m_useChromaticAberration = value;
|
||||
}
|
||||
public float chromaticAberration {
|
||||
get => m_chromaticAberration;
|
||||
set => m_chromaticAberration = Mathf.Clamp (value, 0f, 0.5f);
|
||||
}
|
||||
public bool usePostProcessing {
|
||||
get => m_usePostProcessing;
|
||||
set => m_usePostProcessing = value;
|
||||
}
|
||||
public bool useBlur {
|
||||
get => m_useBlur;
|
||||
set => m_useBlur = value;
|
||||
}
|
||||
public int blurIterations {
|
||||
get => m_blurIterations;
|
||||
set => m_blurIterations = Mathf.Clamp (value, 1, 10);
|
||||
}
|
||||
public float blurSpread {
|
||||
get => m_blurSpread;
|
||||
set => m_blurSpread = Mathf.Clamp (value, 0f, 1f);
|
||||
}
|
||||
public MSAASamples msaa {
|
||||
get => m_msaa;
|
||||
set => m_msaa = value;
|
||||
}
|
||||
public float blurDirectional {
|
||||
get => m_blurDirectional;
|
||||
set => m_blurDirectional = Mathf.Clamp (value, 0f, 1f);
|
||||
}
|
||||
public float blurDirection {
|
||||
get => m_blurDirection;
|
||||
set => syncDir (ref m_blurDirection, value);
|
||||
}
|
||||
public float colorShift {
|
||||
get => m_colorShift;
|
||||
set => m_colorShift = Mathf.Max (value, 0f);
|
||||
}
|
||||
public float colorShiftDirection {
|
||||
get => m_colorShiftDir;
|
||||
set => syncDir (ref m_colorShiftDir, value);
|
||||
}
|
||||
|
||||
public bool useSyncDirection {
|
||||
get => m_useSyncDirection;
|
||||
set {
|
||||
m_useSyncDirection = value;
|
||||
if (value) m_blurDirection = m_colorShiftDir = m_lightDirection;
|
||||
}
|
||||
}
|
||||
public float postContrast {
|
||||
get => m_postContrast;
|
||||
set => m_postContrast = Mathf.Max (value, 0.0001f);
|
||||
}
|
||||
public float postBrightness {
|
||||
get => m_postBrightness;
|
||||
set => m_postBrightness = Mathf.Max (value, 0f);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- Tools
|
||||
private void syncDir (ref float prop, float dir) {
|
||||
if (m_useSyncDirection)
|
||||
m_lightDirection = m_blurDirection = m_colorShiftDir = wrapAngle180 (dir);
|
||||
else
|
||||
prop = wrapAngle180 (dir);
|
||||
}
|
||||
static private float round2Dec (float val) => (float) (System.Math.Round (val * 100f) * 0.01); // 小数点2位で丸め
|
||||
static private float round2Dec5 (float val) => (float) (System.Math.Round (val * 20f) * 0.05); // 小数点2位を0か5で丸め
|
||||
static private float wrapAngle180 (float angle) => Mathf.Repeat (angle + 180f, 360f) - 180f;
|
||||
static private Vector2 dirToVec (float dir) => new Vector2 (Mathf.Sin (dir * Mathf.Deg2Rad), Mathf.Cos (-dir * Mathf.Deg2Rad));
|
||||
static private float vecToDir (Vector2 v) => round2Dec5 (wrapAngle180 (Mathf.Atan2 (v.x, v.y) * Mathf.Rad2Deg));
|
||||
|
||||
// ----------------------------------------------------------- MenuItem
|
||||
#if UNITY_EDITOR
|
||||
[ContextMenu ("Apply Overall Wave Adjustment To Each Waves")]
|
||||
private void ApplyOverallWaveAdjustment () {
|
||||
Undo.RecordObject (this, "WCEffect Version Update");
|
||||
EditorUtility.SetDirty (this);
|
||||
foreach (var wave in m_waves) {
|
||||
wave.density = round2Dec5 (wave.density * m_density);
|
||||
wave.height = round2Dec5 (wave.height * m_height);
|
||||
wave.fluctuation = round2Dec5 (wave.fluctuation * m_speed);
|
||||
wave.flow = round2Dec (wave.flow / m_density * m_speed);
|
||||
}
|
||||
m_density = 1f;
|
||||
m_height = 1f;
|
||||
m_speed = 1f;
|
||||
}
|
||||
|
||||
[ContextMenu ("Open Asset Manual")]
|
||||
private void OpenManualURL () {
|
||||
Application.OpenURL (Constant.URL_MANUAL);
|
||||
}
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------- Init
|
||||
private void Reset () { }
|
||||
|
||||
internal void VersionCheck () {
|
||||
#if UNITY_EDITOR
|
||||
if (m_version < Constant.WCE_VERSION_INT) EditorUtility.SetDirty (this);
|
||||
#endif
|
||||
const int VER_20000 = 20000;
|
||||
if (m_version < VER_20000) {
|
||||
// -- Ver1.2.2以前に作成されている場合、データをv2用にアップデート
|
||||
m_style = (Style) m_version; // m_version は元 m_lightCondensingStyle
|
||||
if (m_lightRay == LightRay.Vector && m_lightVector == Vector3.down) {
|
||||
m_lightRay = LightRay.Direction;
|
||||
m_lightIncidentAngle = 0f;
|
||||
}
|
||||
foreach (var w in m_waves)
|
||||
w.renewFlowData (m_density);
|
||||
m_usePostProcessing = false;
|
||||
m_version = VER_20000; // ※最後に設定
|
||||
}
|
||||
if (m_version < Constant.WCE_VERSION_INT)
|
||||
m_version = Constant.WCE_VERSION_INT;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal void CheckRenderTex () {
|
||||
var rt = m_renderTexture;
|
||||
if (rt && rt.depth != 0) {
|
||||
if (rt.IsCreated ()) {
|
||||
bool isActive = (RenderTexture.active == rt);
|
||||
if (isActive) RenderTexture.active = null;
|
||||
rt.Release ();
|
||||
rt.depth = 0;
|
||||
rt.anisoLevel = 4;
|
||||
rt.Create ();
|
||||
if (isActive) RenderTexture.active = rt;
|
||||
} else {
|
||||
rt.depth = 0;
|
||||
rt.anisoLevel = 4;
|
||||
}
|
||||
EditorUtility.SetDirty (rt);
|
||||
Debug.Log ($"DepthBuffer of RenderTexture ({rt.name}) in use in WaterCausticsTexGenerator has been removed as it is not used.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
private void Awake () {
|
||||
VersionCheck ();
|
||||
storeSystemMaxMSAA ();
|
||||
}
|
||||
|
||||
private void OnEnable () {
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.update -= constantUpdate;
|
||||
UnityEditor.EditorApplication.update += constantUpdate;
|
||||
CheckRenderTex ();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnDisable () {
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.update -= constantUpdate;
|
||||
#endif
|
||||
if (!Application.isPlaying)
|
||||
destroyAllBuffers ();
|
||||
}
|
||||
|
||||
void OnDestroy () {
|
||||
destroyAllBuffers ();
|
||||
}
|
||||
|
||||
private void destroyAllBuffers () {
|
||||
releaseGraphicsBuffers ();
|
||||
destroy (ref __mesh);
|
||||
destroy (ref __mat);
|
||||
destroy (ref __computeShader);
|
||||
}
|
||||
|
||||
private void destroy<T> (ref T o) where T : Object {
|
||||
if (o == null) return;
|
||||
if (Application.isPlaying)
|
||||
Destroy (o);
|
||||
else
|
||||
DestroyImmediate (o);
|
||||
o = null;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- PropertyToID
|
||||
private class pID {
|
||||
readonly internal static int _WaveCnt = Shader.PropertyToID ("_WaveCnt");
|
||||
readonly internal static int _WaveData = Shader.PropertyToID ("_WaveData");
|
||||
readonly internal static int _WaveUVShift = Shader.PropertyToID ("_WaveUVShift");
|
||||
readonly internal static int _WaveNoiseDir = Shader.PropertyToID ("_WaveNoiseDir");
|
||||
readonly internal static int _CalcResUI = Shader.PropertyToID ("_CalcResUI");
|
||||
readonly internal static int _CalcTexel = Shader.PropertyToID ("_CalcTexel");
|
||||
readonly internal static int _CalcTexelInv = Shader.PropertyToID ("_CalcTexelInv");
|
||||
readonly internal static int _LightDir = Shader.PropertyToID ("_LightDir");
|
||||
readonly internal static int _Eta = Shader.PropertyToID ("_Eta");
|
||||
readonly internal static int _Brightness = Shader.PropertyToID ("_Brightness");
|
||||
readonly internal static int _Gamma = Shader.PropertyToID ("_Gamma");
|
||||
readonly internal static int _Clamp = Shader.PropertyToID ("_Clamp");
|
||||
readonly internal static int _IdxStride = Shader.PropertyToID ("_IdxStride");
|
||||
readonly internal static int _DrawOffset = Shader.PropertyToID ("_DrawOffset");
|
||||
readonly internal static int _BufNoiseRW = Shader.PropertyToID ("_BufNoiseRW");
|
||||
readonly internal static int _BufNoise = Shader.PropertyToID ("_BufNoise");
|
||||
readonly internal static int _BufRefractRW = Shader.PropertyToID ("_BufRefractRW");
|
||||
readonly internal static int _BufRefract = Shader.PropertyToID ("_BufRefract");
|
||||
readonly internal static int _LightDirection = Shader.PropertyToID ("_LightDirection");
|
||||
readonly internal static int _Offset = Shader.PropertyToID ("_Offset");
|
||||
readonly internal static int _OffsetColor = Shader.PropertyToID ("_OffsetColor");
|
||||
readonly internal static int _SSLinearTex = Shader.PropertyToID ("_SSLinearTex");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- ComputeShader
|
||||
private ComputeShader __computeShader;
|
||||
private ComputeShader getComputeShader () {
|
||||
if (__computeShader != null)
|
||||
return __computeShader;
|
||||
|
||||
if (m_computeShader == null) {
|
||||
Debug.LogError ("Compute Shader is null. " + this);
|
||||
return null;
|
||||
} else {
|
||||
__computeShader = (ComputeShader) Instantiate (m_computeShader);
|
||||
kID.setKernelID (__computeShader);
|
||||
return __computeShader;
|
||||
}
|
||||
}
|
||||
|
||||
private class kID {
|
||||
internal static int NoiseCS;
|
||||
internal static int RefractCS;
|
||||
internal static int ColorCS;
|
||||
internal static void setKernelID (ComputeShader cs) {
|
||||
NoiseCS = cs.FindKernel ("NoiseCS");
|
||||
RefractCS = cs.FindKernel ("RefractCS");
|
||||
ColorCS = cs.FindKernel ("ColorCS");
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- Material
|
||||
private Material __mat;
|
||||
private Material getMat () {
|
||||
if (__mat != null) return __mat;
|
||||
if (m_shader == null) {
|
||||
Debug.LogError ("Shader is null. " + this);
|
||||
return null;
|
||||
} else {
|
||||
__mat = new Material (m_shader);
|
||||
__mat.hideFlags = HideFlags.HideAndDontSave;
|
||||
return __mat;
|
||||
}
|
||||
}
|
||||
|
||||
private void setMaterialKeyword (Material mat, bool isEnable, string keyword) {
|
||||
if (isEnable)
|
||||
mat.EnableKeyword (keyword);
|
||||
else
|
||||
mat.DisableKeyword (keyword);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- Mesh
|
||||
private Mesh __mesh;
|
||||
private int _meshVertsCnt;
|
||||
private int calcVerticesCnt (int res) {
|
||||
int wholeWidth = (int) res + (int) ((float) res * m_FillGap) * 2;
|
||||
return (wholeWidth + 1) * (wholeWidth + 1) * bufSize3or1;
|
||||
}
|
||||
private Mesh getMesh () {
|
||||
if (!__mesh || _meshVertsCnt != calcVerticesCnt ((int) m_calcResolution))
|
||||
setupMesh ();
|
||||
return __mesh;
|
||||
}
|
||||
|
||||
private void setupMesh () {
|
||||
int width = (int) m_calcResolution;
|
||||
float widthF = (float) width;
|
||||
int bufArea = width * width;
|
||||
float cellSz = 1f / widthF;
|
||||
int over = (int) (widthF * m_FillGap);
|
||||
int wholeWidth = width + over * 2;
|
||||
int bufSz3or1 = bufSize3or1;
|
||||
int verticesCnt = (wholeWidth + 1) * (wholeWidth + 1) * bufSz3or1;
|
||||
Vector3 [] vertices = new Vector3 [verticesCnt];
|
||||
for (int vi = 0, i = 0; i < bufSz3or1; i++) {
|
||||
for (int y = 0; y <= wholeWidth; y++) {
|
||||
for (int x = 0; x <= wholeWidth; x++, vi++) {
|
||||
int pX = x - over;
|
||||
int pY = y - over;
|
||||
float vX = (float) pX * cellSz;
|
||||
float vY = (float) pY * cellSz;
|
||||
int idx = ((pY + width * 10) % width) * width + ((pX + width * 10) % width);
|
||||
float vZ = (float) (i * bufArea + idx) + 0.1f;
|
||||
vertices [vi] = new Vector3 (vX * 2f - 1f, vY * 2f - 1f, vZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
int [] triangles = new int [wholeWidth * wholeWidth * 6 * bufSz3or1];
|
||||
for (int ti = 0, vi = 0, i = 0; i < bufSz3or1; i++, vi += wholeWidth + 1) {
|
||||
for (int y = 0; y < wholeWidth; y++, vi++) {
|
||||
for (int x = 0; x < wholeWidth; x++, ti += 6, vi++) {
|
||||
triangles [ti] = vi;
|
||||
triangles [ti + 2] = triangles [ti + 3] = vi + 1;
|
||||
triangles [ti + 1] = triangles [ti + 4] = vi + wholeWidth + 1;
|
||||
triangles [ti + 5] = vi + wholeWidth + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (__mesh == null)
|
||||
__mesh = new Mesh ();
|
||||
__mesh.Clear ();
|
||||
__mesh.indexFormat = (verticesCnt >= 65536) ? IndexFormat.UInt32 : IndexFormat.UInt16;
|
||||
__mesh.vertices = vertices;
|
||||
__mesh.triangles = triangles;
|
||||
__mesh.name = "WaterCausticsTexGen";
|
||||
_meshVertsCnt = verticesCnt;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- GraphicsBuffer
|
||||
private GraphicsBuffer _bufNoise;
|
||||
private GraphicsBuffer _bufRefract;
|
||||
void prepGraphicsBuffers () {
|
||||
int res = (int) m_calcResolution;
|
||||
int resSq = res * res;
|
||||
checkAndRemakeCBuffer (ref _bufNoise, resSq, 1);
|
||||
checkAndRemakeCBuffer (ref _bufRefract, resSq * bufSize3or1, 5);
|
||||
}
|
||||
|
||||
private void checkAndRemakeCBuffer (ref GraphicsBuffer buf, int count, int stride) {
|
||||
if (buf == null || buf.count != count) {
|
||||
if (buf != null) buf.Release ();
|
||||
buf = new GraphicsBuffer (GraphicsBuffer.Target.Structured, count, sizeof (float) * stride);
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseGraphicsBuffers () {
|
||||
release (ref _bufNoise);
|
||||
release (ref _bufRefract);
|
||||
}
|
||||
|
||||
private void release (ref GraphicsBuffer cb) {
|
||||
if (cb == null) return;
|
||||
cb.Release ();
|
||||
cb = null;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- Preview
|
||||
#if UNITY_EDITOR
|
||||
private bool _isPreviewTarget;
|
||||
internal void Preview (float deltaTime, RenderTexture rt) {
|
||||
_isPreviewTarget = true;
|
||||
if (isActiveAndEnabled && isDrawer (this))
|
||||
Graphics.Blit (m_renderTexture, rt);
|
||||
else {
|
||||
generate (deltaTime, rt);
|
||||
}
|
||||
}
|
||||
|
||||
internal void FinishPreview () {
|
||||
_isPreviewTarget = false;
|
||||
if (!isActiveAndEnabled)
|
||||
destroyAllBuffers ();
|
||||
}
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------- Update
|
||||
static private Dictionary<RenderTexture, WaterCausticsTexGenerator> s_drawer = new Dictionary<RenderTexture, WaterCausticsTexGenerator> ();
|
||||
static private bool isDrawer (WaterCausticsTexGenerator texGen) {
|
||||
var rt = texGen.m_renderTexture;
|
||||
return (rt != null && s_drawer.ContainsKey (rt) && s_drawer [rt] == texGen);
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private bool needAnimInEditMode => ((m_animateInEditMode && m_generateInEditMode) || _isPreviewTarget);
|
||||
private void constantUpdate () {
|
||||
if (!UnityEditorInternal.InternalEditorUtility.isApplicationActive) return;
|
||||
if (Application.isPlaying) return;
|
||||
if (needAnimInEditMode) {
|
||||
EditorApplication.QueuePlayerLoopUpdate ();
|
||||
// UnityEditorInternal.InternalEditorUtility.RepaintAllViews ();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void Update () {
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying && !m_generateInEditMode && !_isPreviewTarget) return;
|
||||
#endif
|
||||
if (m_renderTexture)
|
||||
s_drawer [m_renderTexture] = this;
|
||||
}
|
||||
|
||||
|
||||
private void LateUpdate () {
|
||||
if (!isDrawer (this)) return;
|
||||
#if UNITY_EDITOR
|
||||
float deltaTime = (Application.isPlaying || needAnimInEditMode) ? Time.deltaTime : 0f;
|
||||
generate (deltaTime, m_renderTexture);
|
||||
#else
|
||||
generate (Time.deltaTime, m_renderTexture);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
private void generate (float deltaTime, RenderTexture rt) {
|
||||
if (rt == null) return;
|
||||
|
||||
// Prepare
|
||||
prepGraphicsBuffers ();
|
||||
|
||||
// Set data for compute shader
|
||||
setConstantBuffer (deltaTime);
|
||||
|
||||
// Compute shader
|
||||
calcComputeShader ();
|
||||
|
||||
// Draw mesh
|
||||
if (m_usePostProcessing) {
|
||||
var baseRT = getPPTmpRT (rt, useMSAA : true);
|
||||
drawMesh (baseRT);
|
||||
postProcessing (baseRT, rt);
|
||||
} else {
|
||||
drawMesh (rt);
|
||||
}
|
||||
|
||||
// MipMap
|
||||
if (rt.useMipMap && rt.antiAliasing == 1 && !rt.autoGenerateMips)
|
||||
rt.GenerateMips ();
|
||||
}
|
||||
|
||||
|
||||
Vector3 refract (Vector3 I, float eta) {
|
||||
float dot = -I.z;
|
||||
float k = 1f - eta * eta * (1f - dot * dot);
|
||||
return (k < 0f) ? Vector3.zero : eta * I + Vector3.forward * (eta * dot + Mathf.Sqrt (k));
|
||||
}
|
||||
|
||||
|
||||
private Vector4 [] _tmpDataAry = new Vector4 [WAVE_MAX_CNT];
|
||||
private Vector4 [] _tmpUVAry = new Vector4 [WAVE_MAX_CNT];
|
||||
private Vector4 [] _tmpDirAry = new Vector4 [WAVE_MAX_CNT];
|
||||
|
||||
|
||||
private float getDecimal (float v) {
|
||||
return v - Mathf.Floor (v);
|
||||
}
|
||||
|
||||
const float NOISE_RADIUS = 100f;
|
||||
const float NOISE_CIRCUMFERENCE_INV = 1f / (NOISE_RADIUS * 2f * Mathf.PI);
|
||||
|
||||
private void setConstantBuffer (float delteTime) {
|
||||
var cs = getComputeShader ();
|
||||
if (cs == null) return;
|
||||
|
||||
// Waves
|
||||
int waveIdx = 0;
|
||||
float delta = delteTime * m_speed * (m_pause? 0f : 1f);
|
||||
#if WCE_DEVELOPMENT
|
||||
if (m_useSpecifiedTime) {
|
||||
foreach (Wave w in m_waves)
|
||||
w.pos = Vector3.zero;
|
||||
delta = m_specifiedTime * m_specifiedTimeMultiplier;
|
||||
}
|
||||
#endif
|
||||
Vector2 overallFlow = dirToVec (m_flowDirection) * m_flow * delta;
|
||||
for (int i = 0; i < m_waves.Count; i++) {
|
||||
Wave w = m_waves [i];
|
||||
if (!w.active) continue;
|
||||
Vector2 flowV = dirToVec (w.direction) * w.flow * delta / m_density + overallFlow;
|
||||
w.pos.x = getDecimal (w.pos.x - flowV.x);
|
||||
w.pos.y = getDecimal (w.pos.y - flowV.y);
|
||||
w.pos.z = getDecimal (w.pos.z + w.fluctuation * NOISE_CIRCUMFERENCE_INV * delta);
|
||||
float rad = w.pos.z * Mathf.PI * 2f;
|
||||
float cos = Mathf.Cos (rad);
|
||||
float sin = Mathf.Sin (rad);
|
||||
_tmpDirAry [waveIdx] = new Vector2 (cos, sin);
|
||||
_tmpUVAry [waveIdx] = new Vector2 (w.pos.x, w.pos.y);
|
||||
_tmpDataAry [waveIdx] = w.getData (m_density, m_height, i);
|
||||
if (++waveIdx >= WAVE_MAX_CNT) break;
|
||||
}
|
||||
cs.SetInt (pID._WaveCnt, waveIdx);
|
||||
cs.SetVectorArray (pID._WaveData, _tmpDataAry);
|
||||
cs.SetVectorArray (pID._WaveUVShift, _tmpUVAry);
|
||||
cs.SetVectorArray (pID._WaveNoiseDir, _tmpDirAry);
|
||||
|
||||
// Resolution
|
||||
int calcRes = (int) m_calcResolution;
|
||||
float texel = 1f / (float) calcRes;
|
||||
cs.SetFloat (pID._CalcTexel, texel);
|
||||
cs.SetFloat (pID._CalcTexelInv, (float) calcRes);
|
||||
cs.SetInt (pID._CalcResUI, calcRes);
|
||||
cs.SetInt (pID._IdxStride, calcRes * calcRes);
|
||||
|
||||
// light Direction
|
||||
Vector3 litDir;
|
||||
switch (m_lightRay) {
|
||||
case LightRay.Vector:
|
||||
litDir = (m_lightVector != Vector3.zero) ? m_lightVector.normalized : Vector3.down;
|
||||
break;
|
||||
case LightRay.Transform:
|
||||
litDir = (m_lightTransform != null) ? m_lightTransform.forward : Vector3.down;
|
||||
break;
|
||||
case LightRay.LitSettingSun:
|
||||
litDir = (RenderSettings.sun != null) ? RenderSettings.sun.transform.forward : Vector3.down;
|
||||
break;
|
||||
case LightRay.Auto:
|
||||
litDir = -Shader.GetGlobalVector (pID._LightDirection);
|
||||
break;
|
||||
case LightRay.Direction:
|
||||
default:
|
||||
if (m_lightIncidentAngle == 0f) {
|
||||
litDir = Vector3.down;
|
||||
} else {
|
||||
Vector2 dirV = dirToVec (m_lightDirection);
|
||||
litDir = Vector3.Slerp (Vector3.down, new Vector3 (dirV.x, 0f, dirV.y), m_lightIncidentAngle / 90f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (litDir.y >= 0f) {
|
||||
litDir.y = -0.01f;
|
||||
litDir = litDir.normalized;
|
||||
}
|
||||
litDir = new Vector3 (litDir.x, litDir.z, -litDir.y);
|
||||
cs.SetVector (pID._LightDir, litDir);
|
||||
|
||||
// Brightness
|
||||
cs.SetFloat (pID._Brightness, m_brightness * _lcStyleBright [(int) m_style] * 0.1f);
|
||||
cs.SetFloat (pID._Gamma, m_gamma * _lcStyleGamma [(int) m_style]);
|
||||
cs.SetFloat (pID._Clamp, m_clamp);
|
||||
|
||||
// Refraction index
|
||||
float eta = 1f / m_refractionIndex;
|
||||
float chrAb = 1f + m_chromaticAberration;
|
||||
Vector3 refractIdx = new Vector3 (eta * chrAb, eta, eta / chrAb);
|
||||
cs.SetVector (pID._Eta, refractIdx);
|
||||
|
||||
// Offset drawing position
|
||||
Vector3 refractG = refract (litDir, eta);
|
||||
if (m_refractedRay == RefractedRay.Normalize) {
|
||||
cs.DisableKeyword ("EXTEND_RAY");
|
||||
cs.SetVector (pID._DrawOffset, -(Vector2) refractG);
|
||||
} else {
|
||||
cs.EnableKeyword ("EXTEND_RAY");
|
||||
cs.SetVector (pID._DrawOffset, -(Vector2) refractG / refractG.z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void calcComputeShader () {
|
||||
var cs = getComputeShader ();
|
||||
if (cs == null) return;
|
||||
|
||||
cs.EnableKeyword (_lcStyleStr [(int) m_style]);
|
||||
|
||||
int kernel;
|
||||
int sc = (int) m_calcResolution / THREAD_SIZE;
|
||||
int shift = useChromAbe ? 1 : 0;
|
||||
|
||||
cs.SetBuffer (kID.NoiseCS, pID._BufNoiseRW, _bufNoise);
|
||||
cs.Dispatch (kID.NoiseCS, sc, sc, 1);
|
||||
|
||||
kernel = kID.RefractCS + shift;
|
||||
cs.SetBuffer (kernel, pID._BufNoise, _bufNoise);
|
||||
cs.SetBuffer (kernel, pID._BufRefractRW, _bufRefract);
|
||||
cs.Dispatch (kernel, sc, sc, 1);
|
||||
|
||||
kernel = kID.ColorCS + shift;
|
||||
cs.SetBuffer (kernel, pID._BufRefractRW, _bufRefract);
|
||||
cs.Dispatch (kernel, sc, sc, 1);
|
||||
|
||||
// // ---- for Debug
|
||||
// cs.SetBuffer (kID.ColorCS + 2, pID._BufNoise, _bufNoise);
|
||||
// cs.SetBuffer (kID.ColorCS + 2, pID._BufRefractRW, _bufRefract);
|
||||
// cs.Dispatch (kID.ColorCS + 2, sc, sc, 1);
|
||||
// // ----
|
||||
|
||||
// Keywords
|
||||
cs.DisableKeyword (_lcStyleStr [(int) m_style]);
|
||||
}
|
||||
|
||||
|
||||
private void drawMesh (RenderTexture rt) {
|
||||
var mat = getMat ();
|
||||
if (mat == null) return;
|
||||
|
||||
var temp = RenderTexture.active;
|
||||
RenderTexture.active = rt;
|
||||
rt.DiscardContents ();
|
||||
GL.Clear (false, true, Color.clear);
|
||||
setMaterialKeyword (mat, useChromAbe, "_USE_RGB");
|
||||
mat.SetBuffer (pID._BufRefract, _bufRefract);
|
||||
mat.SetPass (0);
|
||||
Graphics.DrawMeshNow (getMesh (), Matrix4x4.identity);
|
||||
RenderTexture.active = temp;
|
||||
|
||||
rt.IncrementUpdateCount ();
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------- PostProcessing
|
||||
private int _sysMaxMSAA = 8;
|
||||
private void storeSystemMaxMSAA () {
|
||||
var desc = new RenderTextureDescriptor (128, 128);
|
||||
desc.msaaSamples = 8;
|
||||
_sysMaxMSAA = SystemInfo.GetRenderTextureSupportedMSAASampleCount (desc);
|
||||
}
|
||||
|
||||
private RenderTexture getPPTmpRT (RenderTexture rt, bool useMSAA) {
|
||||
var desc = new RenderTextureDescriptor (rt.width, rt.height, rt.graphicsFormat, 0); // rt.formatだとSNORMテクスチャでエラー
|
||||
desc.useDynamicScale = rt.useDynamicScale;
|
||||
desc.msaaSamples = useMSAA ? Mathf.Min ((int) m_msaa, _sysMaxMSAA) : 1;
|
||||
return RenderTexture.GetTemporary (desc);
|
||||
}
|
||||
|
||||
private void postProcessing (RenderTexture src, RenderTexture dst) {
|
||||
#if !UNITY_EDITOR // GLES3でアーティファクトが発生するので対応
|
||||
if (dst.antiAliasing > 1) {
|
||||
dst.Release ();
|
||||
dst.antiAliasing = 1;
|
||||
}
|
||||
#endif
|
||||
Vector4 offsetBaseV;
|
||||
int iteration = m_useBlur ? m_blurIterations : 1;
|
||||
float spread = m_useBlur ? m_blurSpread : 0f;
|
||||
bool useBlur = m_useBlur && (iteration > 1 || spread > 0f);
|
||||
if (useBlur && m_blurDirectional > 0f) {
|
||||
var rot = Quaternion.Euler (0f, 0f, m_blurDirection - 90f);
|
||||
var rotInv = Quaternion.Inverse (rot);
|
||||
Vector2 offA = rot * Vector2.one;
|
||||
Vector2 offB = rot * new Vector2 (1f, -1f);
|
||||
float oblateness = 1f - m_blurDirectional;
|
||||
offA.y *= oblateness;
|
||||
offB.y *= oblateness;
|
||||
offA = rotInv * offA;
|
||||
offB = rotInv * offB;
|
||||
offsetBaseV = new Vector4 (offA.x, offA.y, offB.x, offB.y);
|
||||
} else {
|
||||
offsetBaseV = new Vector4 (1f, 1f, 1f, -1f);
|
||||
}
|
||||
|
||||
var mat = getMat ();
|
||||
setMaterialKeyword (mat, useChromAbe, "_USE_RGB");
|
||||
mat.SetVector (pID._OffsetColor, Vector2.zero);
|
||||
float colShift = 1f;
|
||||
bool useColAdjust = (m_postContrast != 1f || m_postBrightness != 1f || QualitySettings.activeColorSpace != ColorSpace.Linear);
|
||||
setMaterialKeyword (mat, false, "_BRIGHTNESS_ADJ");
|
||||
|
||||
var temp = RenderTexture.active;
|
||||
RenderTexture.active = dst; // ← エディタでGLES3使用時 DstがMSAA使用の場合必須
|
||||
RenderTexture buf = src;
|
||||
|
||||
void sampling (RenderTexture src, RenderTexture dst, Vector4 offV, bool useColorShift = false) {
|
||||
bool canDiv (float v) { return 0.5f - Mathf.Abs (v - Mathf.Floor (v) - 0.5f) <= 0.001f; }
|
||||
src.filterMode = (!useColorShift && canDiv (offV.x) && canDiv (offV.y) && canDiv (offV.z) && canDiv (offV.w)) ? FilterMode.Point : FilterMode.Bilinear;
|
||||
src.wrapMode = TextureWrapMode.Repeat;
|
||||
mat.SetVector (pID._Offset, offV);
|
||||
Graphics.Blit (src, dst, mat, 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Mathf.Max (1, iteration); i++) {
|
||||
bool isLast = (i == iteration - 1);
|
||||
RenderTexture buf2 = isLast ? dst : getPPTmpRT (dst, useMSAA : false);
|
||||
float off = (iteration == 1) ? spread : 0.5f + i * spread;
|
||||
colShift += off * 0.25f;
|
||||
setMaterialKeyword (mat, off != 0f, "_SAMPLE4");
|
||||
if (isLast && useColAdjust) {
|
||||
setMaterialKeyword (mat, true, "_BRIGHTNESS_ADJ");
|
||||
mat.SetFloat (pID._Gamma, m_postContrast * (QualitySettings.activeColorSpace == ColorSpace.Gamma ? 1f / 2.2f : 1f));
|
||||
mat.SetFloat (pID._Brightness, m_postBrightness * m_postContrast);
|
||||
}
|
||||
if (isLast && m_colorShift > 0f) {
|
||||
Vector2 offCol = dirToVec (m_colorShiftDir) * (m_colorShift * colShift);
|
||||
setMaterialKeyword (mat, true, "_USE_RGB");
|
||||
mat.SetVector (pID._OffsetColor, offCol * 0.01f);
|
||||
sampling (buf, buf2, offsetBaseV * off, true);
|
||||
} else {
|
||||
sampling (buf, buf2, offsetBaseV * off);
|
||||
}
|
||||
RenderTexture.ReleaseTemporary (buf);
|
||||
buf = buf2;
|
||||
}
|
||||
|
||||
dst.IncrementUpdateCount ();
|
||||
RenderTexture.active = temp;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Wave class
|
||||
[System.Serializable]
|
||||
public class Wave {
|
||||
[SerializeField, FormerlySerializedAs ("Active")] private bool m_active = true;
|
||||
[SerializeField, Range (1f, 20f)] private float m_density = 3f;
|
||||
[SerializeField, Range (0f, 1f)] private float m_height = 0.5f;
|
||||
[SerializeField, Range (0f, 4f)] private float m_fluctuation = 0.6f;
|
||||
[SerializeField, Range (0f, 1.5f)] private float m_flow;
|
||||
[SerializeField, Range (-180f, 180f)] private float m_direction;
|
||||
[SerializeField, HideInInspector] private bool Pause; // Legacy
|
||||
[SerializeField, HideInInspector] private float m_flowU; // Legacy
|
||||
[SerializeField, HideInInspector] private float m_flowV; // Legacy
|
||||
|
||||
public bool active {
|
||||
get => m_active;
|
||||
set => m_active = value;
|
||||
}
|
||||
public float density {
|
||||
get => m_density;
|
||||
set => m_density = Mathf.Clamp (value, 1f, 20f);
|
||||
}
|
||||
public float height {
|
||||
get => m_height;
|
||||
set => m_height = Mathf.Clamp (value, 0f, 1f);
|
||||
}
|
||||
public float fluctuation {
|
||||
get => m_fluctuation;
|
||||
set => m_fluctuation = Mathf.Clamp (value, 0f, 4f);
|
||||
}
|
||||
public float flow {
|
||||
get => m_flow;
|
||||
set => m_flow = value;
|
||||
}
|
||||
public float direction {
|
||||
get => m_direction;
|
||||
set => m_direction = wrapAngle180 (value);
|
||||
}
|
||||
|
||||
[System.NonSerialized] internal Vector3 pos;
|
||||
|
||||
public Wave (float density, float height, float fluct, float flow, float dir) {
|
||||
m_density = density;
|
||||
m_height = height;
|
||||
m_fluctuation = fluct;
|
||||
m_flow = flow;
|
||||
m_direction = dir;
|
||||
}
|
||||
|
||||
internal Vector3 getData (float adjustDensity, float adjustHeight, int idx) {
|
||||
float d = m_density * adjustDensity;
|
||||
return new Vector3 (d, m_height * adjustHeight / (d * d) * 0.5f, idx);
|
||||
}
|
||||
|
||||
internal void renewFlowData (float scale) {
|
||||
Vector2 v = new Vector2 (m_flowU, m_flowV) * scale / m_density;
|
||||
float dir = Mathf.Atan2 (-v.y, v.x) * Mathf.Rad2Deg;
|
||||
m_flow = round2Dec (v.magnitude);
|
||||
m_direction = vecToDir (v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
#endif // End of UNITY_2020_3_OR_NEWER
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce6f32962bedf3d4aa7f27136ff042df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_renderTexture: {instanceID: 0}
|
||||
- m_lightTransform: {instanceID: 0}
|
||||
- m_computeShader: {fileID: 7200000, guid: cf24bd9d2b71b65458b930c520b46e99, type: 3}
|
||||
- m_shader: {fileID: 4800000, guid: e031a2e28107901449265842632577a4, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user