using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System; [CustomEditor(typeof(CustomMesh))] public class CustomMeshEditor : Editor { CustomMesh customMesh; private void OnEnable() { customMesh = target as CustomMesh; } public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("SaveMesh")) { string name = customMesh.name; string filePath = EditorUtility.SaveFilePanel("Save Mesh", Application.dataPath, name, "asset"); if (SaveMesh(filePath) == null) { EditorUtility.DisplayDialog("error", "에셋을 생성할 수 없습니다.", "확인"); } } } Mesh SaveMesh(string path) { if (customMesh.Mf != null) { UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(path, (Type)typeof(object)); if (asset == null) { Debug.Log(path); AssetDatabase.CreateAsset(customMesh.Mf.sharedMesh, path); Mesh loadMesh = (Mesh)AssetDatabase.LoadAssetAtPath(path, (Type)typeof(object)); Debug.Log(loadMesh); customMesh.Mf.GetComponent().sharedMesh = loadMesh; Debug.Log("Saved mesh asset: " + path); return loadMesh; } else { Debug.LogWarningFormat("{0} file exists.", name); return customMesh.Mf.sharedMesh; } } else { Debug.LogErrorFormat("Save Mesh faild. {0}, {1}", name, path); return null; } } public Mesh SaveMesh(string name, string assetFilePath) { string path = assetFilePath + name + ".asset"; return SaveMesh(path); } }