Add water system package
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace WaterSystem
|
||||
{
|
||||
[CustomEditor(typeof(BuoyantObject))]
|
||||
public class BuoyantObjectEditor : Editor
|
||||
{
|
||||
private BuoyantObject obj;
|
||||
private bool _heightsDebugBool;
|
||||
private bool _generalSettingsBool;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
obj = serializedObject.targetObject as BuoyantObject;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
_generalSettingsBool = EditorGUILayout.BeginFoldoutHeaderGroup(_generalSettingsBool, "General Settings");
|
||||
if (_generalSettingsBool)
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
_heightsDebugBool = EditorGUILayout.BeginFoldoutHeaderGroup(_heightsDebugBool, "Height Debug Values");
|
||||
if (_heightsDebugBool)
|
||||
{
|
||||
if (obj.Heights != null)
|
||||
{
|
||||
for (var i = 0; i < obj.Heights.Length; i++)
|
||||
{
|
||||
var h = obj.Heights[i];
|
||||
EditorGUILayout.LabelField($"{i})Wave(heights):", $"X:{h.x:00.00} Y:{h.y:00.00} Z:{h.z:00.00}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("Height debug info only available in playmode.", MessageType.Info);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8763206c9fce6479698aa739878ca7c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace WaterSystem
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(PlanarReflections.PlanarReflectionSettings))]
|
||||
public class PlanarSettingsDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
// Don't make child fields be indented
|
||||
var indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
// Rects
|
||||
Rect resMultiRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
|
||||
Rect offsetRect = new Rect(position.x, resMultiRect.yMax + EditorGUIUtility.standardVerticalSpacing, position.width, EditorGUIUtility.singleLineHeight);
|
||||
Rect layerMaskRect = new Rect(position.x, offsetRect.yMax + EditorGUIUtility.standardVerticalSpacing, position.width, EditorGUIUtility.singleLineHeight);
|
||||
Rect shadowRect = new Rect(position.x, layerMaskRect.yMax + EditorGUIUtility.standardVerticalSpacing, position.width * 0.5f, EditorGUIUtility.singleLineHeight);
|
||||
Rect maxLODRect = new Rect(position.x + position.width * 0.5f, layerMaskRect.yMax + EditorGUIUtility.standardVerticalSpacing, position.width * 0.5f, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
var resMulti = property.FindPropertyRelative("m_ResolutionMultiplier");
|
||||
EditorGUI.PropertyField(resMultiRect, resMulti);
|
||||
position.y += EditorGUIUtility.singleLineHeight;
|
||||
var offset = property.FindPropertyRelative("m_ClipPlaneOffset");
|
||||
EditorGUI.Slider(offsetRect, offset, -0.500f, 0.500f);
|
||||
var layerMask = property.FindPropertyRelative("m_ReflectLayers");
|
||||
EditorGUI.PropertyField(layerMaskRect, layerMask);
|
||||
var shadows = property.FindPropertyRelative("m_Shadows");
|
||||
EditorGUI.PropertyField(shadowRect, shadows);
|
||||
|
||||
// Set indent back to what it was
|
||||
EditorGUI.indentLevel = indent;
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 4f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0bc0b238a7fa4c69938228f2c8d657e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using WaterSystem.Data;
|
||||
|
||||
namespace WaterSystem
|
||||
{
|
||||
[CustomEditor(typeof(Water))]
|
||||
public class WaterEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
Water w = (Water)target;
|
||||
|
||||
var waterSettingsData = serializedObject.FindProperty("settingsData");
|
||||
EditorGUILayout.PropertyField(waterSettingsData, true);
|
||||
if(waterSettingsData.objectReferenceValue != null)
|
||||
{
|
||||
CreateEditor((WaterSettingsData)waterSettingsData.objectReferenceValue).OnInspectorGUI();
|
||||
}
|
||||
|
||||
var waterSurfaceData = serializedObject.FindProperty("surfaceData");
|
||||
EditorGUILayout.PropertyField(waterSurfaceData, true);
|
||||
if(waterSurfaceData.objectReferenceValue != null)
|
||||
{
|
||||
CreateEditor((WaterSurfaceData)waterSurfaceData.objectReferenceValue).OnInspectorGUI();
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if(GUI.changed)
|
||||
{
|
||||
w.Init();
|
||||
}
|
||||
}
|
||||
|
||||
void OnSceneGUI()
|
||||
{
|
||||
/* Water w = target as Water;
|
||||
Camera cam = SceneView.currentDrawingSceneView.camera;
|
||||
var waveDebug = serializedObject.FindProperty("_debugMode");
|
||||
if (cam && waveDebug.intValue != 0)
|
||||
{
|
||||
Vector3 pos = Vector3.zero;
|
||||
float dist = 10f;
|
||||
if (waveDebug.intValue == 2)
|
||||
{
|
||||
Plane p = new Plane(Vector3.zero, Vector3.forward, Vector3.right);
|
||||
|
||||
Ray r = Camera.current.ViewportPointToRay(new Vector2(0.25f, 0.25f));
|
||||
if (p.Raycast(r, out dist))
|
||||
{
|
||||
pos = Camera.current.ViewportToWorldPoint(new Vector3(0.25f, 0.25f, dist));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = w._waves.Length - 1; i >= 0; i--)
|
||||
{
|
||||
Wave wave = w._waves[i];
|
||||
Random.InitState(i);
|
||||
Color c = Color.HSVToRGB(Random.Range(0f, 1f), 1f, 1f);
|
||||
c.a = Mathf.Clamp01(0.01f * dist - 0.1f) * 0.5f;
|
||||
Handles.color = c;
|
||||
pos.y = wave.amplitude;
|
||||
DrawWaveGizmo(pos, wave.direction, wave.amplitude, wave.wavelength);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void DrawWaveGizmo(Vector3 pos, float angle, float size, float length)
|
||||
{
|
||||
Handles.DrawSolidDisc(pos, Vector3.up, length / 2f);
|
||||
Handles.ArrowHandleCap(0, pos, Quaternion.AngleAxis(angle, Vector3.up), -length / 1.75f, EventType.Repaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7760ef1f46dfd455cae527e7f91824d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
|
||||
namespace WaterSystem.Data
|
||||
{
|
||||
[CustomEditor(typeof(WaterSettingsData))]
|
||||
public class WaterSettingsDataEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var geomType = serializedObject.FindProperty("waterGeomType");
|
||||
EditorGUILayout.PropertyField(geomType);
|
||||
|
||||
var refType = serializedObject.FindProperty("refType");
|
||||
refType.enumValueIndex = GUILayout.Toolbar(refType.enumValueIndex, refType.enumDisplayNames);
|
||||
|
||||
switch(refType.enumValueIndex)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
// cubemap
|
||||
var cube = serializedObject.FindProperty("cubemapRefType");
|
||||
EditorGUILayout.PropertyField(cube, new GUIContent("Cubemap Texture"));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
// probe
|
||||
EditorGUILayout.HelpBox("Reflection Probe setting has no options, it automatically uses the nearest reflection probe to the main camera", MessageType.Info);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
// planar
|
||||
var planarSettings = serializedObject.FindProperty("planarSettings");
|
||||
EditorGUILayout.PropertyField(planarSettings, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0935a4ad227524d3cae739e174b846b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,361 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
|
||||
namespace WaterSystem.Data
|
||||
{
|
||||
[CustomEditor(typeof(WaterSurfaceData))]
|
||||
public class WaterSurfaceDataEditor : Editor
|
||||
{
|
||||
[SerializeField]
|
||||
ReorderableList waveList;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
var init = serializedObject.FindProperty("_init");
|
||||
if(init?.boolValue == false)
|
||||
Setup();
|
||||
|
||||
var standardHeight = EditorGUIUtility.singleLineHeight;
|
||||
var standardLine = standardHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
//Reorderable list stuff////////////////////////////////////////////////
|
||||
waveList = new ReorderableList(serializedObject, serializedObject.FindProperty("_waves"), true, true, true, true);
|
||||
|
||||
//Single entry GUI
|
||||
waveList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
|
||||
{
|
||||
var element = waveList.serializedProperty.GetArrayElementAtIndex(index);
|
||||
rect.y += 2;
|
||||
|
||||
// Swell height
|
||||
var preWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = rect.width * 0.2f;
|
||||
Rect ampRect = new Rect(rect.x, rect.y + standardLine, rect.width * 0.5f, standardHeight);
|
||||
var waveAmp = element.FindPropertyRelative("amplitude");
|
||||
waveAmp.floatValue = EditorGUI.Slider(ampRect, "Swell Height", waveAmp.floatValue, 0.1f, 30f);
|
||||
// Wavelength
|
||||
Rect lengthRect = new Rect(rect.x + ampRect.width, rect.y + standardLine, rect.width * 0.5f, standardHeight);
|
||||
var waveLen = element.FindPropertyRelative("wavelength");
|
||||
waveLen.floatValue = EditorGUI.Slider(lengthRect, "Wavelength", waveLen.floatValue, 1.0f, 200f);
|
||||
EditorGUIUtility.labelWidth = preWidth;
|
||||
// Directional controls
|
||||
Rect dirToggleRect = new Rect(rect.x, rect.y + 2 + standardLine * 2, rect.width * 0.5f, standardHeight);
|
||||
Rect omniToggleRect = new Rect(rect.x + rect.width * 0.5f, dirToggleRect.y, rect.width * 0.5f, standardHeight);
|
||||
Rect containerRect = new Rect(rect.x, dirToggleRect.y + 1, rect.width, standardLine * 3.2f);
|
||||
// Direction/origin
|
||||
var waveType = element.FindPropertyRelative("onmiDir");
|
||||
var wTypeBool = (int)waveType.floatValue == 1 ? true : false;
|
||||
GUI.Box(containerRect, "", EditorStyles.helpBox );
|
||||
wTypeBool = !GUI.Toggle(dirToggleRect, !wTypeBool, "Directional", EditorStyles.miniButtonLeft);
|
||||
wTypeBool = GUI.Toggle(omniToggleRect, wTypeBool, "Omni-directional", EditorStyles.miniButtonRight);
|
||||
waveType.floatValue = wTypeBool ? 1 : 0;
|
||||
|
||||
Rect dirRect = new Rect(rect.x + 4, dirToggleRect.y + standardLine, rect.width - 8, standardHeight);
|
||||
Rect buttonRect = new Rect(rect.x + 4, dirRect.y + standardLine + 2, rect.width - 8, standardHeight);
|
||||
// Directional
|
||||
if(!wTypeBool)
|
||||
{
|
||||
var waveDir = element.FindPropertyRelative("direction");
|
||||
waveDir.floatValue = EditorGUI.Slider(dirRect, "Facing Direction", waveDir.floatValue, -180.0f, 180.0f);
|
||||
if(GUI.Button(buttonRect, "Align with Scene Camera"))
|
||||
waveDir.floatValue = CameraRelativeDirection();
|
||||
}
|
||||
else
|
||||
{// Omni-Directional
|
||||
EditorGUIUtility.wideMode = true;
|
||||
//var perWidth = EditorGUIUtility.labelWidth;
|
||||
//EditorGUIUtility.labelWidth = 20f;
|
||||
var waveOrig = element.FindPropertyRelative("origin");
|
||||
waveOrig.vector2Value = EditorGUI.Vector2Field(dirRect, "Point of Origin", waveOrig.vector2Value);
|
||||
if(GUI.Button(buttonRect, "Project Origin from Scene Camera"))
|
||||
waveOrig.vector2Value = CameraRelativeOrigin(waveOrig.vector2Value);
|
||||
//EditorGUIUtility.labelWidth = perWidth;
|
||||
}
|
||||
};
|
||||
|
||||
// Check can remove to make sure at least one wave remains
|
||||
waveList.onCanRemoveCallback = (ReorderableList l) =>
|
||||
{
|
||||
return l.count > 1;
|
||||
};
|
||||
|
||||
// Check on remove to give a warning incase removing by accident
|
||||
waveList.onRemoveCallback = (ReorderableList l) =>
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete the wave?", "Yes", "No"))
|
||||
{
|
||||
ReorderableList.defaultBehaviours.DoRemoveButton(l);
|
||||
}
|
||||
};
|
||||
// When adding, check if under 10, if so add a new random wave
|
||||
waveList.onAddCallback = (ReorderableList l) =>
|
||||
{
|
||||
var index = l.serializedProperty.arraySize;
|
||||
if (index < 10)
|
||||
{
|
||||
l.serializedProperty.arraySize++;
|
||||
l.index = index;
|
||||
var element = l.serializedProperty.GetArrayElementAtIndex(index);
|
||||
element.FindPropertyRelative("amplitude").floatValue = Random.Range(0.25f, 1.5f);
|
||||
element.FindPropertyRelative("direction").floatValue = Random.Range(-180f, 180f);
|
||||
element.FindPropertyRelative("wavelength").floatValue = Random.Range(2f, 8f);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("Warning!", "You have reached the limit of 10 waves for this Water.", "Close");
|
||||
}
|
||||
};
|
||||
//Draw header
|
||||
waveList.drawHeaderCallback = (Rect rect) =>
|
||||
{
|
||||
EditorGUI.LabelField(rect, "Wave List");
|
||||
};
|
||||
//Do height of list entry
|
||||
waveList.elementHeightCallback = (index) =>
|
||||
{
|
||||
var elementHeight = standardLine * 6f;
|
||||
return elementHeight;
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.LabelField("Visual Settings", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel += 1;
|
||||
// Max visibility - slider 3-300
|
||||
var maxDepth = serializedObject.FindProperty("_waterMaxVisibility");
|
||||
EditorGUILayout.Slider(maxDepth, 3, 300, new GUIContent("Maximum Visibility", maxDepthTT));
|
||||
// Colouring settings
|
||||
DoSmallHeader("Coloring Controls");
|
||||
// Absorbstion Ramp
|
||||
var absorpRamp = serializedObject.FindProperty("_absorptionRamp");
|
||||
EditorGUILayout.PropertyField(absorpRamp, new GUIContent("Absorption Color", absorpRampTT), true, null);
|
||||
// Scatter Ramp
|
||||
var scatterRamp = serializedObject.FindProperty("_scatterRamp");
|
||||
EditorGUILayout.PropertyField(scatterRamp, new GUIContent("Scattering Color", scatterRampTT), true, null);
|
||||
// Foam Ramps
|
||||
DoSmallHeader("Surface Foam");
|
||||
var foamSettings = serializedObject.FindProperty("_foamSettings");
|
||||
var foamType = foamSettings.FindPropertyRelative("foamType");
|
||||
foamType.intValue = GUILayout.Toolbar(foamType.intValue, foamTypeOptions);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
switch (foamType.intValue)
|
||||
{
|
||||
case 0: //// Auto ////
|
||||
{
|
||||
EditorGUILayout.HelpBox("Automatic will distribute the foam suitable for an average swell", MessageType.Info);
|
||||
}
|
||||
break;
|
||||
case 1: //// Simple ////
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
DoInlineLabel("Foam Profile", foamCurveTT, 50f);
|
||||
var basicFoam = foamSettings.FindPropertyRelative("basicFoam");
|
||||
basicFoam.animationCurveValue = EditorGUILayout.CurveField(basicFoam.animationCurveValue, Color.white, new Rect(Vector2.zero, Vector2.one));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
break;
|
||||
case 2: //// Simple ////
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
DoInlineLabel("Foam Profiles", foam3curvesTT, 50f);
|
||||
var liteFoam = foamSettings.FindPropertyRelative("liteFoam");
|
||||
liteFoam.animationCurveValue = EditorGUILayout.CurveField(liteFoam.animationCurveValue, new Color(0.5f, 0.75f, 1f, 1f), new Rect(Vector2.zero, Vector2.one));
|
||||
var mediumFoam = foamSettings.FindPropertyRelative("mediumFoam");
|
||||
mediumFoam.animationCurveValue = EditorGUILayout.CurveField(mediumFoam.animationCurveValue, new Color(0f, 0.5f, 1f, 1f), new Rect(Vector2.zero, Vector2.one));
|
||||
var denseFoam = foamSettings.FindPropertyRelative("denseFoam");
|
||||
denseFoam.animationCurveValue = EditorGUILayout.CurveField(denseFoam.animationCurveValue, Color.blue, new Rect(Vector2.zero, Vector2.one));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel -= 1;
|
||||
EditorGUILayout.LabelField("Wave Settings", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel += 1;
|
||||
// Wave type - Automatic / Customized
|
||||
//wavesType = EditorGUILayout.Popup("System Type", wavesType, wavesTypeOptions);
|
||||
// Toolbar labels here
|
||||
|
||||
var customWaves = serializedObject.FindProperty("_customWaves");
|
||||
var intVal = customWaves.boolValue ? 1 : 0;
|
||||
intVal = GUILayout.Toolbar(intVal, wavesTypeOptions);
|
||||
customWaves.boolValue = intVal == 1 ? true : false;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
switch(customWaves.boolValue ? 1 : 0)
|
||||
{
|
||||
case 0: //// Automatic ////
|
||||
{
|
||||
var basicSettings = serializedObject.FindProperty("_basicWaveSettings");
|
||||
// Wave count (display warning of on mobile platform and over 6) dropdown 1 > 10
|
||||
var autoCount = basicSettings.FindPropertyRelative("numWaves");
|
||||
EditorGUILayout.IntSlider(autoCount, 1, 10, new GUIContent("Wave Count", waveCountTT), null);
|
||||
// Average Wave height - slider 0.05 - 30
|
||||
var avgHeight = basicSettings.FindPropertyRelative("amplitude");
|
||||
EditorGUILayout.Slider(avgHeight, 0.1f, 30.0f, new GUIContent("Avg Swell Height", avgHeightTT), null);
|
||||
// Average Wavelength - slider 1 - 200
|
||||
var avgWavelength = basicSettings.FindPropertyRelative("wavelength");
|
||||
EditorGUILayout.Slider(avgWavelength, 1.0f, 200.0f, new GUIContent("Avg Wavelength", avgWavelengthTT), null);
|
||||
// Wind direction - slider -180-180
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var windDir = basicSettings.FindPropertyRelative("direction");
|
||||
EditorGUILayout.Slider(windDir, -180.0f, 180.0f, new GUIContent("Wind Direction", windDirTT), null);
|
||||
if(GUILayout.Button(new GUIContent("Align to scene camera", alignButtonTT)))
|
||||
windDir.floatValue = CameraRelativeDirection();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
// [override] - random otherwise(on creation/override check)
|
||||
// Random seed - int input
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var randSeed = serializedObject.FindProperty("randomSeed");
|
||||
randSeed.intValue = EditorGUILayout.IntField(new GUIContent("Random Seed", randSeedTT), randSeed.intValue);
|
||||
if (GUILayout.Button("Randomize Waves"))
|
||||
{
|
||||
randSeed.intValue = System.DateTime.Now.Millisecond * 100 - System.DateTime.Now.Millisecond;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
break;
|
||||
case 1: //// Customized ////
|
||||
{
|
||||
EditorGUI.indentLevel -= 1;
|
||||
// Re-orderable list with wave details
|
||||
waveList.DoLayoutList();
|
||||
/// Type - Directional / Omi-directional
|
||||
//// Amplitude - slider 0.05 - 30
|
||||
//// Wavelength - slider 1 - 200
|
||||
////// Direction(facing) - slider -180-180 && face scene camera direction(if scene view)
|
||||
// OR
|
||||
////// Origin(point of origin) - Vector input && origin at camera aim
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(this);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
void DoSmallHeader(string header)
|
||||
{
|
||||
EditorGUI.indentLevel -= 1;
|
||||
EditorGUILayout.LabelField(header, EditorStyles.miniBoldLabel);
|
||||
EditorGUI.indentLevel += 1;
|
||||
}
|
||||
|
||||
void DoInlineLabel(string label, string tooltip, float width)
|
||||
{
|
||||
var preWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = width;
|
||||
EditorGUILayout.LabelField(new GUIContent(label, tooltip));
|
||||
EditorGUIUtility.labelWidth = preWidth;
|
||||
}
|
||||
|
||||
void Setup()
|
||||
{
|
||||
WaterSurfaceData wsd = (WaterSurfaceData)target;
|
||||
wsd._init = true;
|
||||
wsd._absorptionRamp = DefaultAbsorptionGrad();
|
||||
wsd._scatterRamp = DefaultScatterGrad();
|
||||
EditorUtility.SetDirty(wsd);
|
||||
}
|
||||
|
||||
Gradient DefaultAbsorptionGrad() // Preset for absorption
|
||||
{
|
||||
Gradient g = new Gradient();
|
||||
GradientColorKey[] gck = new GradientColorKey[5];
|
||||
GradientAlphaKey[] gak = new GradientAlphaKey[1];
|
||||
gak[0].alpha = 1;
|
||||
gak[0].time = 0;
|
||||
gck[0].color = Color.white;
|
||||
gck[0].time = 0f;
|
||||
gck[1].color = new Color(0.22f, 0.87f, 0.87f);
|
||||
gck[1].time = 0.082f;
|
||||
gck[2].color = new Color(0f, 0.47f, 0.49f);
|
||||
gck[2].time = 0.318f;
|
||||
gck[3].color = new Color(0f, 0.275f, 0.44f);
|
||||
gck[3].time = 0.665f;
|
||||
gck[4].color = Color.black;
|
||||
gck[4].time = 1f;
|
||||
g.SetKeys(gck, gak);
|
||||
return g;
|
||||
}
|
||||
|
||||
Gradient DefaultScatterGrad() // Preset for scattering
|
||||
{
|
||||
Gradient g = new Gradient();
|
||||
GradientColorKey[] gck = new GradientColorKey[4];
|
||||
GradientAlphaKey[] gak = new GradientAlphaKey[1];
|
||||
gak[0].alpha = 1;
|
||||
gak[0].time = 0;
|
||||
gck[0].color = Color.black;
|
||||
gck[0].time = 0f;
|
||||
gck[1].color = new Color(0.08f, 0.41f, 0.34f);
|
||||
gck[1].time = 0.15f;
|
||||
gck[2].color = new Color(0.13f, 0.55f, 0.45f);
|
||||
gck[2].time = 0.42f;
|
||||
gck[3].color = new Color(0.21f, 0.62f, 0.6f);
|
||||
gck[3].time = 1f;
|
||||
g.SetKeys(gck, gak);
|
||||
return g;
|
||||
}
|
||||
|
||||
float CameraRelativeDirection()
|
||||
{
|
||||
float degrees = 0;
|
||||
|
||||
Vector3 camFwd = UnityEditor.SceneView.lastActiveSceneView.camera.transform.forward;
|
||||
camFwd.y = 0f;
|
||||
camFwd.Normalize();
|
||||
float dot = Vector3.Dot(-Vector3.forward, camFwd);
|
||||
degrees = Mathf.LerpUnclamped(90.0f, 180.0f, dot);
|
||||
if(camFwd.x < 0)
|
||||
degrees *= -1f;
|
||||
|
||||
return Mathf.RoundToInt(degrees * 1000) / 1000;
|
||||
}
|
||||
|
||||
Vector2 CameraRelativeOrigin(Vector2 original)
|
||||
{
|
||||
Camera sceneCam = UnityEditor.SceneView.lastActiveSceneView.camera;
|
||||
|
||||
float angle = 90f - Vector3.Angle(sceneCam.transform.forward, Vector3.down);
|
||||
if (angle > 0.1f)
|
||||
{
|
||||
Vector3 intersect = Vector2.zero;
|
||||
float hypot = (sceneCam.transform.position.y) * (1 / Mathf.Sin(Mathf.Deg2Rad * angle));
|
||||
Vector3 fwd = sceneCam.transform.forward * hypot;
|
||||
intersect = fwd + sceneCam.transform.position;
|
||||
return new Vector2(intersect.x, intersect.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
||||
static string[] wavesTypeOptions = new string[] { "Automatic", "Customized" };
|
||||
|
||||
static string[] foamTypeOptions = new string[3] { "Automatic", "Simple Curve", "Density Curves" };
|
||||
|
||||
|
||||
////TOOLTIPS////
|
||||
private string maxDepthTT = "This controls the max depth of the waters transparency/visiblility, the absorption and scattering gradients map to this depth. Units:Meters";
|
||||
private string absorpRampTT = "This gradient controls the color of the water as it gets deeper, darkening the surfaces under the water as they get deeper.";
|
||||
private string scatterRampTT = "This gradient controls the 'scattering' of the water from shallow to deep, lighting the water as there becomes more of it.";
|
||||
private string waveCountTT = "Number of waves the automatic setup creates, if aiming for mobile set to 6 or less";
|
||||
private string avgHeightTT = "The average height of the waves. Units:Meters";
|
||||
private string avgWavelengthTT = "The average wavelength of the waves. Units:Meters";
|
||||
private string windDirTT = "The general wind direction, this is in degrees from Z+";
|
||||
private string alignButtonTT = "This aligns the wave direction to the current scene view camera facing direction";
|
||||
private string foamCurveTT = "This curve control the foam propagation. X is wave height and Y is foam opacity";
|
||||
private string foam3curvesTT = "These three curves control the Lite, Medium and Dense foam propagation. X is wave height and Y is foam opacity";
|
||||
private string randSeedTT = "This seed controls the automatic wave generation";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1016bd3ba0af54af184326cd470c1bb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "WaterSystem.Editor",
|
||||
"references": [
|
||||
"GUID:eee6090a63a1e48e6857869e0cbe74dc",
|
||||
"GUID:b75d3cd3037d383a8d1e2f9a26d73d8a",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ccf8aeedcc0c4661aacb3c94f093356
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user