Newer
Older
MaZiFAU
committed
using System;
using System.Linq;
using UnityEngine;
public class PrismGenerator : PlaneGenerator
{
#region InspectorVariables
[Header("Plane values")]
[SerializeField]
private Vector3 _offset;
public Vector3 Offset
{
get => _offset;
set
{
_offset = value;
GenerateShapeForAll();
}
}
MaZiFAU
committed
public bool ExpandBothDirections = false;
#endregion InspectorVariables
#region Implementation
protected override (Vector3[] vertices, int[] triangles) GenerateTopology()
{
(Vector3[] vertices, int[] triangles) plane = CreatePlane(_vertices);
MaZiFAU
committed
Vector3[] normals = CreateMesh(plane).normals;
return CreatePrism(
MaZiFAU
committed
( // Topology for top
plane.vertices
.Zip(normals, (v, n) =>
v + Quaternion.FromToRotation(Vector3.up, n) *
(ExpandBothDirections ? (Offset * 0.5f) : Offset))
.ToArray(),
plane.triangles
),
( // Topology for bottom
ExpandBothDirections
? plane.vertices
.Zip(normals, (v, n) =>
v + Quaternion.FromToRotation(Vector3.up, n) *
-(Offset * 0.5f))
.ToArray()
: plane.vertices,
plane.triangles.Reverse().ToArray()
),