MD Package Technical & APi Documentation
MDG_TunnelCreator
Namespace: MDPackage.Geometry
Complete tunnel-creator with node-based editor in Unity Engine in editor & at runtime. Apply this script to any gameObject with meshFilter.
Read more here (Online documentation slide)
Public Methods
// Add node on specific position
public void Tunnel_AddNode(Vector3 positionInWorldSpace, bool groupTogetherOnAdd = true)
// Remove last node
public void Tunnel_RemoveLastNode()
// Clear all nodes
public void Tunnel_RemoveAll()
// Refresh current tunnel mesh
public void Tunnel_RefreshNodes()
// Apply changed vertex count and refresh
public void Tunnel_ApplyResolution()
// Group all nodes together in hierarchy
public void Tunnel_GroupAllNodesTogether()
// Ungroup all nodes to 'empty' or to 'some object'
public void Tunnel_UngroupAllNodes(Transform detachToOtherParent = null)
// Update UV sets with specific UV mode
public void Tunnel_UpdateUVsWithUVMode(MDG_TunnelNodeUVData.UVType uvMode)

public static void CreateGeometry()
Public Fields and Properties
[Range(4, 64)] public int tunnelResolution = 16;
public int tunnelResolutionBackup = 0;
public float tunnelRadius = 1.0f;
public float tunnelNodeSize = 0.2f;

public bool tunnelHemi = false;
public bool tunnelHemiVertical = false;
public bool tunnelReverseFaces = false;
public bool tunnelApplyNodeLocalScale = false;

public bool tunnelUpdateEveryFrame = true;
public bool tunnelUseSmartRotation = true;

public bool tunnelUseCustomUVData = false;
public MDG_TunnelNodeUVData.UVType tunnelUVType = MDG_TunnelNodeUVData.UVType.uvZX;

public bool tunnelEnableGizmos = true;

public List<Transform> TunnelCurrentNodes { get; }
Examples
The following paragraphs contain Tunnel Creator used in a practical example. Create a tunnel creator at runtime and add custom tunnel nodes.
using UnityEngine;
using MDPackage.Geometry;

public class SampleScript : MonoBehaviour
{
private MDG_TunnelCreator tunnelCreator;
private Vector3 currentNodePos;

private void Start()
 {
  // Create a new tunnel creator on startup
  tunnelCreator = gameObject.AddComponent<MDG_TunnelCreator>();
  tunnelCreator.transform.position = Vector3.zero;
  // Apply tunnel resolution (required)
  tunnelCreator.Tunnel_ApplyResolution();
 }

private void Update()
 {
  // Create tunnel nodes on the specific direction
  // use WASD to add tunnel nodes
  if (Input.GetKeyDown(KeyCode.W))
   AddNode(Vector3.forward);
  if (Input.GetKeyDown(KeyCode.D))
   AddNode(Vector3.right);
  if (Input.GetKeyDown(KeyCode.S))
   AddNode(Vector3.back);
  if (Input.GetKeyDown(KeyCode.A))
   AddNode(Vector3.left);

  // Local method
  void AddNode(Vector3 pos)
  {
   currentNodePos += pos;
   tunnelCreator.Tunnel_AddNode(currentNodePos);
  }
 }
}