Creating a Card Preview with Odin
1. Creating a PreviewCardScene
using UnityEditor . SceneManagement ;
using UnityEngine ;
public class PreviewCardScene : PreviewSceneStage
{
protected override GUIContent CreateHeaderContent ( )
{
return new GUIContent ( "Preview Card" ) ;
}
}
2. Add preview feature to Card Editor
using Sirenix . OdinInspector . Editor ;
using System ;
using System . Collections . Generic ;
using UnityEditor ;
using UnityEngine ;
using TcgEngine ;
using Sirenix . Utilities . Editor ;
using Sirenix . OdinInspector . Demos . RPGEditor ;
using Sirenix . OdinInspector ;
using System . Reflection ;
using Sirenix . Utilities ;
using Unity . VisualScripting ;
using UnityEngine . WSA ;
using UnityEditor . SceneManagement ;
using TcgEngine . UI ;
public class CardEditor : OdinMenuEditorWindow
{
public UnityEngine . Object prefab ;
public UnityEngine . Object variant ;
public PreviewCardScene scene ;
private void Update ( )
{
if ( scene != null && variant != null && MenuTree ? . Selection ? . SelectedValue != null )
{
var selected = MenuTree . Selection . SelectedValue as CardData ;
var card_preview = scene . scene . GetRootGameObjects ( ) [ 0 ] . GetComponent < CardUI > ( ) ;
card_preview . SetCard ( selected , variant as VariantData ) ;
}
}
protected override void OnBeginDrawEditors ( )
{
if ( MenuTree == null ) return ;
prefab = EditorGUILayout . ObjectField ( prefab , typeof ( GameObject ) , false ) ;
variant = EditorGUILayout . ObjectField ( variant , typeof ( VariantData ) , false ) ;
SirenixEditorGUI . BeginHorizontalToolbar ( MenuTree . Config . SearchToolbarHeight ) ;
{
//...
if ( SirenixEditorGUI . ToolbarButton ( new GUIContent ( "Preview" ) ) )
{
scene = new PreviewCardScene ( ) ;
StageUtility . GoToStage ( scene , true ) ;
var go = Instantiate ( prefab ) ;
go . AddComponent < Canvas > ( ) ;
EditorSceneManager . MoveGameObjectToScene ( go as GameObject , scene . scene ) ;
}
}
}
}