using UnityEngine; using UnityEditor; namespace SoftKitty { public class MeshPreview : EditorWindow { Editor gameObjectEditor; static GameObject gameObject; public static MeshRenderer renderer; public static MeshPreview instance; public static void ShowPreview(string _meshPath, string _matPath, string _path) { gameObject = (GameObject)AssetDatabase.LoadAssetAtPath(_path, typeof(GameObject)); if (_meshPath != "") { MeshFilter _mf = gameObject.GetComponentInChildren(); _mf.mesh = Instantiate(Resources.Load(_meshPath)); } if (_matPath!="") { renderer = gameObject.GetComponentInChildren(); Material _mat = Instantiate(Resources.Load(_matPath)); ; renderer.material = _mat; renderer.sharedMaterial = _mat; } instance=GetWindowWithRect(new Rect(0, 0, 256, 256)); } private void OnDestroy() { renderer = null; } void OnGUI() { GUIStyle bgColor = new GUIStyle(); if (gameObjectEditor == null) { gameObjectEditor = Editor.CreateEditor(gameObject); } gameObjectEditor.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(256, 256), bgColor); } } }