private void OnGUI() { //header help boxes EditorGUILayout.HelpBox("Previews generated with this window are in low quality because they are based on Unity asset previews.", MessageType.Warning); EditorGUILayout.HelpBox("To create your preview drag/select an object to use.", MessageType.Info); //create a field that accept only asset objects obj = (GameObject)EditorGUILayout.ObjectField("Object:", obj, typeof(GameObject), false); if (obj != null) { CreatePreview(); } GUILayout.Label("Save path: " + ObjectPreview.savePath); GUILayout.Space(10); //button to create preview if (GUILayout.Button("Create Preview")) { ObjectPreview.CreateAndSaveAssetPreview(obj); } EditorGUILayout.HelpBox("If there just an asset with the same name, it will be overwriden!", MessageType.Warning); //show texture preview before save if (currentPreview != null) { EditorGUI.DrawPreviewTexture(new Rect(TextureMargin, VerticalSize - HorizontalSize - TextureMargin, HorizontalSize - (2 * TextureMargin), HorizontalSize), currentPreview); } }
/// <summary> /// [EDITOR ONLY] Generate automatic preview and assign it to item /// </summary> /// <param name="g">Object to use for preview</param> public void SetAutomaticPreview(GameObject g) { string path = ObjectPreview.CreateAndSaveAssetPreview(g); if (path == "") { return; } UiPicture = (Sprite)AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)); //save new reference EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); Debug.Log("Preview Set to " + path); }