新增动态水物理插件

This commit is contained in:
Bob.Song
2026-02-27 17:44:21 +08:00
parent a6e061d9ce
commit 60744d113d
2218 changed files with 698551 additions and 189 deletions

View File

@@ -0,0 +1,78 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ 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 NWH.Common.Input;
using NWH.Common.Vehicles;
using NWH.DWP2.ShipController;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
#endregion
namespace NWH.DWP2.DemoContent
{
public class GUIHandler : MonoBehaviour
{
public Image anchorImage;
public bool reset;
public Text rudderText;
public Text speedText;
private AdvancedShipController activeShip;
private void Update()
{
bool toggleGUI = InputProvider
.CombinedInput<SceneInputProviderBase>(i => i.ToggleGUI());
if (toggleGUI)
{
Canvas canvas = GetComponent<Canvas>();
if (canvas != null)
{
canvas.enabled = !canvas.enabled;
}
}
activeShip = Vehicle.ActiveVehicle as AdvancedShipController;
if (activeShip != null)
{
float speed = activeShip.SpeedKnots;
speedText.text = "SPEED: " + $"{speed:0.0}" + "kts";
if (activeShip.rudders.Count > 0)
{
float rudderAngle = activeShip.rudders[0].Angle;
rudderText.text = "RUDDER: " + $"{rudderAngle:0.0}" + "°";
}
if (activeShip.Anchor != null)
{
if (activeShip.Anchor.Dropped)
{
anchorImage.gameObject.SetActive(true);
}
else
{
anchorImage.gameObject.SetActive(false);
}
}
}
}
public void ResetScene()
{
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene(scene.name);
}
}
}

View File

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

View File

@@ -0,0 +1,179 @@
// ╔════════════════════════════════════════════════════════════════╗
// ║ 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 NWH.DWP2.WaterObjects;
using UnityEngine;
#if UNITY_EDITOR
using NWH.NUI;
using UnityEditor;
#endif
#endregion
namespace NWH.DWP2.Tests
{
public class WaterObjectTest : MonoBehaviour
{
public GameObject prefab;
private GameObject _instance;
public void Instantiate(Vector3 position)
{
_instance = Instantiate(prefab);
_instance.transform.position = position;
}
public void Activate()
{
_instance.SetActive(true);
}
public void Deactivate()
{
_instance.SetActive(false);
}
public void EnableWaterObject()
{
WaterObject wo = GetComponentInChildren<WaterObject>();
if (wo != null)
{
wo.enabled = true;
}
}
public void DisableWaterObject()
{
WaterObject wo = GetComponentInChildren<WaterObject>();
if (wo != null)
{
wo.enabled = false;
}
}
public void Destroy()
{
Destroy(_instance);
}
public void Teleport(Vector3 distance)
{
_instance.transform.position += distance;
}
public void Rotate(Vector3 eulerAngles)
{
_instance.transform.Rotate(eulerAngles, Space.Self);
}
public void ToggleIsKinematic()
{
Rigidbody rb = _instance.GetComponentInChildren<Rigidbody>();
rb.isKinematic = !rb.isKinematic;
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(WaterObjectTest))]
[CanEditMultipleObjects]
public class WaterObjectTestEditor : NUIEditor
{
private WaterObjectTest _wot;
public override bool OnInspectorNUI()
{
if (!base.OnInspectorNUI())
{
return false;
}
_wot = (WaterObjectTest)target;
drawer.Field("prefab");
if (drawer.Button("Instantiate"))
{
_wot.Instantiate(Vector3.zero);
}
if (drawer.Button("Activate"))
{
_wot.Activate();
}
if (drawer.Button("Deactivate"))
{
_wot.Deactivate();
}
if (drawer.Button("Destroy"))
{
_wot.Destroy();
}
if (drawer.Button("Teleport Forward"))
{
_wot.Teleport(Vector3.forward);
}
if (drawer.Button("Teleport Up"))
{
_wot.Teleport(Vector3.up);
}
if (drawer.Button("Teleport Down"))
{
_wot.Teleport(Vector3.down);
}
if (drawer.Button("Rotate Left"))
{
_wot.Rotate(new Vector3(0, -90, 0));
}
if (drawer.Button("Rotate Right"))
{
_wot.Rotate(new Vector3(0, 90, 0));
}
if (drawer.Button("Instantiate & Synchronize"))
{
_wot.Instantiate(Vector3.zero);
}
if (drawer.Button("Instantiate & Synchronize & Teleport"))
{
_wot.Instantiate(Vector3.zero);
_wot.DisableWaterObject();
_wot.EnableWaterObject();
}
if (drawer.Button("Toggle IsKinematic"))
{
_wot.ToggleIsKinematic();
}
drawer.EndEditor(this);
return true;
}
}
#endif
}

View File

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