Files
2026-02-21 16:45:37 +08:00

109 lines
2.1 KiB
C#

using UnityEngine;
namespace UltimateWater.Internal
{
public class Quads
{
private static Mesh _BipolarXY;
private static Mesh _BipolarXInversedY;
private static Mesh _BipolarXZ;
private static bool _Initialized;
public static Mesh BipolarXY
{
get
{
if (!_Initialized)
{
CreateMeshes();
}
return _BipolarXY;
}
}
public static Mesh BipolarXInversedY
{
get
{
if (!_Initialized)
{
CreateMeshes();
}
return _BipolarXInversedY;
}
}
public static Mesh BipolarXZ
{
get
{
if (!_Initialized)
{
CreateMeshes();
}
return _BipolarXZ;
}
}
private static void CreateMeshes()
{
_BipolarXY = CreateBipolarXY(false);
_BipolarXInversedY = CreateBipolarXY(SystemInfo.graphicsDeviceVersion.Contains("Direct3D"));
_BipolarXZ = CreateBipolarXZ();
_Initialized = true;
}
private static Mesh CreateBipolarXY(bool inversedY)
{
Mesh mesh = new Mesh();
mesh.hideFlags = HideFlags.DontSave;
mesh.vertices = new Vector3[4]
{
new Vector3(-1f, -1f, 0f),
new Vector3(1f, -1f, 0f),
new Vector3(1f, 1f, 0f),
new Vector3(-1f, 1f, 0f)
};
mesh.uv = new Vector2[4]
{
new Vector2(0f, (!inversedY) ? 0f : 1f),
new Vector2(1f, (!inversedY) ? 0f : 1f),
new Vector2(1f, (!inversedY) ? 1f : 0f),
new Vector2(0f, (!inversedY) ? 1f : 0f)
};
Mesh mesh2 = mesh;
mesh2.SetTriangles(new int[6] { 0, 1, 2, 0, 2, 3 }, 0);
mesh2.UploadMeshData(true);
return mesh2;
}
private static Mesh CreateBipolarXZ()
{
Mesh mesh = new Mesh();
mesh.name = "Shoreline Quad Mesh";
mesh.hideFlags = HideFlags.DontSave;
mesh.vertices = new Vector3[4]
{
new Vector3(-1f, 0f, -1f),
new Vector3(-1f, 0f, 1f),
new Vector3(1f, 0f, 1f),
new Vector3(1f, 0f, -1f)
};
mesh.uv = new Vector2[4]
{
new Vector2(0f, 0f),
new Vector2(0f, 1f),
new Vector2(1f, 1f),
new Vector2(1f, 0f)
};
Mesh mesh2 = mesh;
mesh2.SetIndices(new int[4] { 0, 1, 2, 3 }, MeshTopology.Quads, 0);
mesh2.UploadMeshData(true);
return mesh2;
}
}
}