열차 목업의 내부 확인용 프로젝트
smchoi
2024-07-31 9fe33c1ae076b0f6501619388e6b4cc872b76f80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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<MeshFilter>().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);
    }
}