33using UnityEngine ;
44using UnityEditor ;
55
6- namespace EmojiUI
7- {
8- [ CustomEditor ( typeof ( InlineManager ) , true ) ]
9- [ CanEditMultipleObjects ]
10- public class InlineManagerEditor : Editor
11- {
12- SerializedProperty m_Script ;
13-
14- private bool foldout = true ;
15-
16- private Dictionary < string , SpriteAsset > assetDic = new Dictionary < string , SpriteAsset > ( ) ;
17-
18- protected virtual void OnEnable ( )
19- {
20- m_Script = serializedObject . FindProperty ( "m_Script" ) ;
21- }
22-
23- public override void OnInspectorGUI ( )
24- {
25- InlineManager manager = target as InlineManager ;
26- EditorGUILayout . PropertyField ( m_Script ) ;
27-
28- EditorGUILayout . Space ( ) ;
29- serializedObject . Update ( ) ;
6+ namespace EmojiUI
7+ {
8+ [ CustomEditor ( typeof ( InlineManager ) , true ) ]
9+ [ CanEditMultipleObjects ]
10+ public class InlineManagerEditor : Editor
11+ {
12+ SerializedProperty m_Script ;
13+
14+ private bool foldout = true ;
15+
16+ private Dictionary < string , SpriteAsset > assetDic = new Dictionary < string , SpriteAsset > ( ) ;
17+
18+ protected virtual void OnEnable ( )
19+ {
20+ m_Script = serializedObject . FindProperty ( "m_Script" ) ;
21+ }
22+
23+ public override void OnInspectorGUI ( )
24+ {
25+ InlineManager manager = target as InlineManager ;
26+ EditorGUILayout . PropertyField ( m_Script ) ;
27+
28+ EditorGUILayout . Space ( ) ;
29+ serializedObject . Update ( ) ;
3030
3131 manager . OpenDebug = EditorGUILayout . Toggle ( "Debug" , manager . OpenDebug ) ;
32- manager . renderType = ( EmojiRenderType ) EditorGUILayout . EnumPopup ( "Rendetype" , manager . renderType ) ;
33- manager . AnimationSpeed = EditorGUILayout . Slider ( "AnimationSpeed" , manager . AnimationSpeed , 0 , 100 ) ;
34-
35- foldout = EditorGUILayout . Foldout ( foldout , "prepared:" + manager . PreparedAtlas . Count ) ;
36- if ( foldout )
37- {
38- EditorGUI . indentLevel ++ ;
39- for ( int i = 0 ; i < manager . PreparedAtlas . Count ; ++ i )
40- {
41- string resName = manager . PreparedAtlas [ i ] ;
42- SpriteAsset asset = null ;
43- if ( ! string . IsNullOrEmpty ( resName ) )
44- {
45- if ( ! assetDic . ContainsKey ( resName ) )
32+ manager . RenderType = ( EmojiRenderType ) EditorGUILayout . EnumPopup ( "Rendetype" , manager . RenderType ) ;
33+ manager . AnimationSpeed = EditorGUILayout . Slider ( "AnimationSpeed" , manager . AnimationSpeed , 0 , 100 ) ;
34+
35+ foldout = EditorGUILayout . Foldout ( foldout , "prepared:" + manager . PreparedAtlas . Count ) ;
36+ if ( foldout )
37+ {
38+ EditorGUI . indentLevel ++ ;
39+ for ( int i = 0 ; i < manager . PreparedAtlas . Count ; ++ i )
40+ {
41+ string resName = manager . PreparedAtlas [ i ] ;
42+ SpriteAsset asset = null ;
43+ if ( ! string . IsNullOrEmpty ( resName ) )
44+ {
45+ if ( ! assetDic . ContainsKey ( resName ) )
4646 {
4747
4848 string fixname = System . IO . Path . GetFileNameWithoutExtension ( resName ) ;
@@ -56,51 +56,51 @@ public override void OnInspectorGUI()
5656 asset = assetDic [ resName ] = AssetDatabase . LoadAssetAtPath < SpriteAsset > ( path ) ;
5757 break ;
5858 }
59- }
60- }
61- else
62- {
63- asset = assetDic [ resName ] ;
64- }
65- }
66-
67- SpriteAsset newasset = ( SpriteAsset ) EditorGUILayout . ObjectField ( i . ToString ( ) , asset , typeof ( SpriteAsset ) , false ) ;
68- if ( newasset != asset )
69- {
70- if ( newasset == null )
71- {
72- manager . PreparedAtlas [ i ] = "" ;
73- }
74- else
75- {
76- manager . PreparedAtlas [ i ] = System . IO . Path . GetFileNameWithoutExtension ( AssetDatabase . GetAssetPath ( newasset ) ) ;
77- assetDic [ manager . PreparedAtlas [ i ] ] = newasset ;
78- }
79- EditorUtility . SetDirty ( manager ) ;
80- }
81-
82- }
83-
84- EditorGUI . indentLevel -- ;
85-
86- EditorGUILayout . BeginHorizontal ( ) ;
87-
88- if ( GUILayout . Button ( "add" , GUILayout . Width ( 100 ) ) )
89- {
90- manager . PreparedAtlas . Add ( "" ) ;
91- }
92-
93- if ( GUILayout . Button ( "remove" , GUILayout . Width ( 100 ) ) )
94- {
95- if ( manager . PreparedAtlas . Count > 0 )
96- manager . PreparedAtlas . RemoveAt ( manager . PreparedAtlas . Count - 1 ) ;
97- }
98- EditorGUILayout . EndHorizontal ( ) ;
99- }
100-
101- serializedObject . ApplyModifiedProperties ( ) ;
102- }
103- }
59+ }
60+ }
61+ else
62+ {
63+ asset = assetDic [ resName ] ;
64+ }
65+ }
66+
67+ SpriteAsset newasset = ( SpriteAsset ) EditorGUILayout . ObjectField ( i . ToString ( ) , asset , typeof ( SpriteAsset ) , false ) ;
68+ if ( newasset != asset )
69+ {
70+ if ( newasset == null )
71+ {
72+ manager . PreparedAtlas [ i ] = "" ;
73+ }
74+ else
75+ {
76+ manager . PreparedAtlas [ i ] = System . IO . Path . GetFileNameWithoutExtension ( AssetDatabase . GetAssetPath ( newasset ) ) ;
77+ assetDic [ manager . PreparedAtlas [ i ] ] = newasset ;
78+ }
79+ EditorUtility . SetDirty ( manager ) ;
80+ }
81+
82+ }
83+
84+ EditorGUI . indentLevel -- ;
85+
86+ EditorGUILayout . BeginHorizontal ( ) ;
87+
88+ if ( GUILayout . Button ( "add" , GUILayout . Width ( 100 ) ) )
89+ {
90+ manager . PreparedAtlas . Add ( "" ) ;
91+ }
92+
93+ if ( GUILayout . Button ( "remove" , GUILayout . Width ( 100 ) ) )
94+ {
95+ if ( manager . PreparedAtlas . Count > 0 )
96+ manager . PreparedAtlas . RemoveAt ( manager . PreparedAtlas . Count - 1 ) ;
97+ }
98+ EditorGUILayout . EndHorizontal ( ) ;
99+ }
100+
101+ serializedObject . ApplyModifiedProperties ( ) ;
102+ }
103+ }
104104}
105105
106106
0 commit comments