77using UnitySettingsProvider = UnityEditor . SettingsProvider ;
88using FishNet . Configuring ;
99using System . IO ;
10- using System . Xml . Linq ;
10+ using System ;
11+ using System . Text . RegularExpressions ;
1112
1213
1314namespace FishNet . Editing . NewNetworkBehaviourScript
@@ -16,8 +17,10 @@ internal static class SettingsProvider
1617 {
1718
1819
19- private static PrefabGeneratorConfigurations _settings ;
20- static string templatePath ;
20+ private static CreateNewNetworkBehaviourConfigurations _settings ;
21+ static string templatePath ;
22+ private static GUIContent _folderIcon ;
23+ private static readonly Regex SlashRegex = new ( @"[\\//]" ) ;
2124 [ UnitySettingsProvider ]
2225 private static UnitySettingsProvider Create ( )
2326 {
@@ -39,25 +42,70 @@ private static UnitySettingsProvider Create()
3942
4043 private static void OnGUI ( string searchContext )
4144 {
42- if ( templatePath == null ) templatePath = Application . dataPath + "/FishnetNBTemplate.txt" ;
45+ if ( _settings == null )
46+ _settings = Configuration . Configurations . CreateNewNetworkBehaviour ;
47+
48+ if ( _folderIcon == null )
49+ _folderIcon = EditorGUIUtility . IconContent ( "d_FolderOpened Icon" ) ;
50+
51+ EditorGUI . BeginChangeCheck ( ) ;
52+
53+ GUILayoutOption iconWidthConstraint = GUILayout . MaxWidth ( 32.0f ) ;
54+ GUILayoutOption iconHeightConstraint = GUILayout . MaxHeight ( EditorGUIUtility . singleLineHeight ) ;
4355
4456 if ( GUILayout . Button ( "Edit template" ) )
4557 {
58+ templatePath = Path . Combine ( _settings . templateDirectoryPath , "FishnetNBTemplate.txt" ) ;
59+
4660 if ( ! File . Exists ( templatePath ) )
4761 {
4862 CreateNewNetworkBehaviour . CopyExistingTemplate ( templatePath ) ;
4963 }
5064 System . Diagnostics . Process . Start ( templatePath ) ;
5165 }
52-
53- EditorGUILayout . LabelField ( $ "Template path: { templatePath } ") ;
54-
55- }
66+ GUILayout . Space ( 20 ) ;
67+ EditorGUILayout . BeginHorizontal ( ) ;
68+ GUILayout . Label ( "Template directory: " , GUILayout . MaxWidth ( 150 ) ) ;
69+ string newDirectoryPath ;
70+
71+ newDirectoryPath = EditorGUILayout . DelayedTextField ( _settings . templateDirectoryPath , GUILayout . MaxWidth ( 600 ) ) ;
72+ if ( newDirectoryPath . StartsWith ( "Assets" ) && Directory . Exists ( newDirectoryPath ) )
73+ {
74+ _settings . templateDirectoryPath = newDirectoryPath ;
75+ }
76+ else
77+ {
78+ EditorWindow . focusedWindow . ShowNotification ( new ( $ "Directory must be inside the Assets folder.") , 2 ) ;
79+ }
5680
57-
5881
59-
82+ if ( GUILayout . Button ( _folderIcon , iconHeightConstraint , iconWidthConstraint ) )
83+ {
84+ newDirectoryPath = EditorUtility . OpenFolderPanel ( "Select template directory" , _settings . templateDirectoryPath , "" ) ;
85+ }
86+ if ( newDirectoryPath . StartsWith ( Application . dataPath , StringComparison . OrdinalIgnoreCase ) )
87+ {
88+ newDirectoryPath = SlashRegex . Replace ( newDirectoryPath . Remove ( 0 , Path . GetDirectoryName ( Application . dataPath ) . Length + 1 ) , Path . DirectorySeparatorChar . ToString ( ) ) ;
89+ _settings . templateDirectoryPath = newDirectoryPath ;
90+ }
91+ else if ( ! newDirectoryPath . StartsWith ( Application . dataPath , StringComparison . OrdinalIgnoreCase ) && ! newDirectoryPath . StartsWith ( "Assets" ) )
92+ {
93+ EditorWindow . focusedWindow . ShowNotification ( new ( $ "Directory must be inside the Assets folder.") , 2 ) ;
94+ }
95+
96+ EditorGUILayout . EndHorizontal ( ) ;
97+
98+ EditorGUILayout . HelpBox ( "By default MonoBehaviour script template will be copied" , MessageType . Info ) ;
99+ if ( EditorGUI . EndChangeCheck ( ) )
100+ Configuration . Configurations . Write ( true ) ;
101+
102+
103+
104+
105+
106+
107+ }
60108 }
61- }
62109
110+ }
63111#endif
0 commit comments