@@ -99,25 +99,54 @@ public static void SLayer(in Rect pos, SP prop)
9999 }
100100 }
101101
102+ private static ( int , string , string ) GetScene ( int i )
103+ {
104+ string scenePath = SceneUtility . GetScenePathByBuildIndex ( i ) ;
105+ string sceneName = System . IO . Path . GetFileNameWithoutExtension ( scenePath ) ;
106+ return ( i , scenePath , sceneName ) ;
107+ }
108+
109+
102110 public static void Scene ( in Rect pos , SP prop )
103111 {
104112 var n = SceneManager . sceneCountInBuildSettings ;
105- Scene scene = default ;
113+ //Scene scene = default;
114+
115+
116+
117+
118+ ( int , string , string ) currentScene = ( - 1 , null , null ) ;
119+
106120 var label = "<invalid scene>" ;
121+
122+ int targetIndex = - 1 ;
123+
124+
107125 if ( prop . IsInt ( ) && prop . intValue > - 1 && prop . intValue < n )
108126 {
109- scene = SceneManager . GetSceneByBuildIndex ( prop . intValue ) ;
127+ //currentScene = GetScene(prop.intValue);
128+ targetIndex = prop . intValue ;
129+ //scene = SceneManager.GetSceneByBuildIndex(prop.intValue);
110130 }
111131
112132 if ( prop . IsString ( ) && ! string . IsNullOrEmpty ( prop . stringValue ) )
113133 {
114- scene = SceneManager . GetSceneByPath ( prop . stringValue ) ;
134+ targetIndex = SceneUtility . GetBuildIndexByScenePath ( prop . stringValue ) ;
135+ //scene = SceneManager.GetSceneByPath(prop.stringValue);
136+ }
137+
138+ if ( targetIndex > - 1 )
139+ {
140+ currentScene = GetScene ( targetIndex ) ;
115141 }
116142
117- var isUnset = scene . buildIndex == - 1 ;
143+
144+ var isUnset = currentScene . Item1 == - 1 ;
145+
146+ bool isValid = ! isUnset && currentScene . Item2 != null ;
118147
119148 if ( isUnset ) { label = EConstants . Label . POPUP_DEFAULT ; }
120- else if ( scene . IsValid ( ) ) { label = $ "{ scene . buildIndex } : { scene . name } "; }
149+ else if ( isValid ) { label = $ "{ currentScene . Item1 } : { currentScene . Item3 } "; }
121150
122151 if ( DrawerGUI . PopupButton ( pos , label ) )
123152 {
@@ -130,18 +159,25 @@ public static void Scene(in Rect pos, SP prop)
130159 prop . serializedObject . ApplyModifiedProperties ( ) ;
131160 } ) ;
132161 m . AddSeparator ( "" ) ;
162+
133163 if ( n == 0 ) { m . AddDisabledItem ( new GUIContent ( "No Options" ) ) ; }
164+
134165 for ( var i = 0 ; i < n ; i ++ )
135166 {
136- var cs = SceneManager . GetSceneByBuildIndex ( i ) ;
137- var active = prop . IsInt ( ) ? i == prop . intValue : cs . path == prop . stringValue ;
138- m . AddItem ( new GUIContent ( cs . name ) , active , ( ) =>
167+ int sceneIndex = i ;
168+ string scenePath = SceneUtility . GetScenePathByBuildIndex ( i ) ;
169+ string sceneName = System . IO . Path . GetFileNameWithoutExtension ( scenePath ) ;
170+
171+ var active = prop . IsInt ( ) ? i == prop . intValue : scenePath == prop . stringValue ;
172+ m . AddItem ( new GUIContent ( sceneName ) , active , ( ) =>
139173 {
140- if ( prop . IsInt ( ) ) { prop . intValue = cs . buildIndex ; }
141- else if ( prop . IsString ( ) ) { prop . stringValue = cs . path ; }
174+ if ( prop . IsInt ( ) ) { prop . intValue = sceneIndex ; }
175+ else if ( prop . IsString ( ) ) { prop . stringValue = scenePath ; }
142176 prop . serializedObject . ApplyModifiedProperties ( ) ;
143177 } ) ;
144178 }
179+
180+
145181 m . DropDown ( pos ) ;
146182 }
147183 }
0 commit comments