补齐备份工程打开依赖

This commit is contained in:
JSD\13999
2026-05-26 17:55:41 +08:00
parent e81881ad78
commit 43b4650ee3
433 changed files with 49783 additions and 3 deletions

View File

@@ -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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03231be3beb7fa54bae3130503848057
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9b3cf681b8dff4740b11e2f3bef2383b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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
}
}
}

View File

@@ -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

View File

@@ -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:

View File

@@ -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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6d53284efe324f4abf18af23f2a010c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -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:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0182e4a02e4c40c469a3f6ef1bc2a1e8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8049e24e9bb6d27469ea2050d91944cb
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f4dc12126bc22543afc6fdad86a286b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 457ec14637a5af748b3988768371cc74
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9e989360942cc2642a0a28a6e3e49419
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: afa42b0dae9c61c4c8e85022abbe43bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: