新增动态水物理插件
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47e130a1389a2cf44836f953bed44f68
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 469ef791be8cd0e489f452ff8107a634
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "NWH.DWP2.Integration.StylizedWater3",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:75ecb28acc33857438e533566abcb3be",
|
||||
"GUID:4fd586483f5d4a24491f09604d74752b",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:c76e28da8ce572043b1fb2da95817e18"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 320feda49cc531a43ae8a582349b617c
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,163 @@
|
||||
// ╔════════════════════════════════════════════════════════════════╗
|
||||
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
|
||||
// ║ Licensed under Unity Asset Store Terms of Service: ║
|
||||
// ║ https://unity.com/legal/as-terms ║
|
||||
// ║ Use permitted only in compliance with the License. ║
|
||||
// ║ Distributed "AS IS", without warranty of any kind. ║
|
||||
// ╚════════════════════════════════════════════════════════════════╝
|
||||
|
||||
#region
|
||||
|
||||
using StylizedWater3;
|
||||
using UnityEngine;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NWH.DWP2.WaterData
|
||||
{
|
||||
// Requires assembly reference to SW3 asmdef, as well as unity.matehmatics asmdef
|
||||
public class StylizedWater3WaterDataProvider : WaterDataProvider
|
||||
{
|
||||
public WaveProfile waveProfile;
|
||||
|
||||
[Tooltip("Reference to the Stylized Water 3 water surface object to query heights from.")]
|
||||
public StylizedWater3.WaterObject stylizedWater3Surface;
|
||||
|
||||
private HeightQuerySystem.Interface heightInterface;
|
||||
private HeightQuerySystem.Sampler heightSampler;
|
||||
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
// Auto-find StylizedWater3 surface
|
||||
if (stylizedWater3Surface == null)
|
||||
{
|
||||
stylizedWater3Surface = FindAnyObjectByType<StylizedWater3.WaterObject>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
if (stylizedWater3Surface is null)
|
||||
{
|
||||
Debug.LogError($"Stylized Water 3 surface not assigned. " +
|
||||
$"Please assign a reference to the SW3 water surface in the inspector.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (waveProfile is null)
|
||||
{
|
||||
Debug.LogError($"{typeof(WaveProfile)} not set. {GetType()} needs to have a set {typeof(WaveProfile)}");
|
||||
return;
|
||||
}
|
||||
|
||||
heightSampler = new HeightQuerySystem.Sampler();
|
||||
heightSampler.SetSampleCount(4);
|
||||
|
||||
heightInterface = new HeightQuerySystem.Interface();
|
||||
heightInterface.method = HeightQuerySystem.Interface.Method.CPU;
|
||||
heightInterface.waterObject = stylizedWater3Surface;
|
||||
heightInterface.waveProfile = waveProfile;
|
||||
heightInterface.autoFind = false;
|
||||
}
|
||||
|
||||
|
||||
public override bool SupportsWaterFlowQueries()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override bool SupportsWaterHeightQueries()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override bool SupportsWaterNormalQueries()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override void GetWaterHeights(WaterObjects.WaterObject waterObject, ref Vector3[] points,
|
||||
ref float[] waterHeights)
|
||||
{
|
||||
if (heightInterface.HasMissingReferences())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
heightSampler.SetSampleCount(points.Length, true);
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
heightSampler.SetSamplePosition(i, points[i]);
|
||||
}
|
||||
|
||||
Gerstner.ComputeHeight(heightSampler, heightInterface);
|
||||
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
waterHeights[i] = heightSampler.heightValues[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
heightSampler.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
namespace NWH.DWP2.WaterData
|
||||
{
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor(typeof(StylizedWater3WaterDataProvider))]
|
||||
[CanEditMultipleObjects]
|
||||
public class StylizedWater3WaterDataProviderEditor : WaterDataProviderEditor
|
||||
{
|
||||
protected override void DrawStatus(WaterDataProvider provider)
|
||||
{
|
||||
var sw3Provider = (StylizedWater3WaterDataProvider)provider;
|
||||
|
||||
drawer.BeginSubsection("Status");
|
||||
if (sw3Provider.stylizedWater3Surface != null)
|
||||
{
|
||||
drawer.Info($"SW3 Water Surface: {sw3Provider.stylizedWater3Surface.name}");
|
||||
drawer.Info($"Water base height: {sw3Provider.stylizedWater3Surface.transform.position.y:F2}m");
|
||||
}
|
||||
else
|
||||
{
|
||||
drawer.Info("Stylized Water 3 surface not assigned.", MessageType.Error);
|
||||
}
|
||||
|
||||
if (sw3Provider.waveProfile != null)
|
||||
{
|
||||
drawer.Info($"Wave Profile: {sw3Provider.waveProfile.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
drawer.Info("Wave Profile not assigned.", MessageType.Error);
|
||||
}
|
||||
drawer.EndSubsection();
|
||||
}
|
||||
|
||||
protected override void DrawSettings(WaterDataProvider provider)
|
||||
{
|
||||
drawer.BeginSubsection("Settings");
|
||||
drawer.Field("stylizedWater3Surface");
|
||||
drawer.Field("waveProfile");
|
||||
drawer.EndSubsection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aaf99cc42f33a9f4b935b61ff8e67d6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user