Loading files
using UnityEngine;
using System.IO;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Leap.Unity.MeshGen {
public class MeshGeneratorAsset : ScriptableObject {
[SerializeField]
private MeshGenerator _meshGenerator = default;
/// <summary>
/// The name given to the Mesh object this generator handles. This name is reassigned
/// every OnValidate.
/// </summary>
public string generatedMeshName = "Generated Mesh";
[SerializeField]
private Mesh _mesh;
/// <summary>
/// The mesh object this asset uses its generator to modify.
/// </summary>
public Mesh mesh { get { return _mesh; } }
public void OnValidate() {
if (_mesh != null && _meshGenerator != null) {
_mesh.name = generatedMeshName;
}
}
/// <summary>
/// Refreshes the mesh generated by this mesh generator asset.
/// </summary>
public void RefreshMesh() {
if (_meshGenerator == null) {
_mesh.Clear();
}
else {
_meshGenerator.Generate(_mesh);
}
}
#region Mesh Generator Asset Creation
#if UNITY_EDITOR
public const string DEFAULT_ASSET_NAME = "Mesh Generator";
public const string DEFAULT_MESH_NAME = "Generated Mesh";
[MenuItem("Assets/Create/Mesh Generator", priority = 306)]
private static void createNewMeshGeneratorAsset(MenuCommand command) {
string path = "Assets";
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object),
SelectionMode.Assets)) {
path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path) && File.Exists(path)) {
path = Path.GetDirectoryName(path);
break;
}
path = Path.Combine(path, DEFAULT_ASSET_NAME + ".asset");
path = AssetDatabase.GenerateUniqueAssetPath(path);
MeshGeneratorAsset asset = CreateInstance<MeshGeneratorAsset>();
asset.name = DEFAULT_ASSET_NAME;
AssetDatabase.CreateAsset(asset, path);
Mesh mesh = new Mesh();
mesh.name = DEFAULT_MESH_NAME;
asset._mesh = mesh;
AssetDatabase.AddObjectToAsset(mesh, asset);
AssetDatabase.SaveAssets();
Selection.activeObject = asset;
}
}
#endif
#endregion
}
}9b89c12bbThis file is pinned to the selected release. Download the original to open it in your design tool.