1- using System . IO ;
2- using UnityEditor ;
1+ using UnityEditor ;
32using UnityEditorInternal ;
43using UnityEngine ;
54
@@ -13,13 +12,11 @@ static void ShowWindow()
1312 GetWindow < AssetDanshariWindow > ( ) ;
1413 }
1514
16- private AssetDanshariSetting m_AssetDanshariSetting ;
1715 private Vector2 m_ScrollViewVector2 ;
1816 private ReorderableList m_ReorderableList ;
1917 private bool m_IsForceText ;
2018 private bool m_ShowGrepSetting ;
2119
22- private static readonly string kUserSettingsPath = "UserSettings/AssetDanshariSetting.asset" ;
2320
2421 private void Awake ( )
2522 {
@@ -41,24 +38,24 @@ private void OnGUI()
4138 EditorGUILayout . BeginHorizontal ( EditorStyles . toolbar ) ;
4239 GUILayout . FlexibleSpace ( ) ;
4340 EditorGUI . BeginChangeCheck ( ) ;
44- m_ShowGrepSetting = GUILayout . Toggle ( m_ShowGrepSetting , string . IsNullOrEmpty ( m_AssetDanshariSetting . ripgrepPath ) ?
41+ m_ShowGrepSetting = GUILayout . Toggle ( m_ShowGrepSetting , string . IsNullOrEmpty ( AssetDanshariSetting . Get ( ) . ripgrepPath ) ?
4542 style . grepNotSet : style . grepEnabled , EditorStyles . toolbarButton ) ;
4643 if ( EditorGUI . EndChangeCheck ( ) )
4744 {
48- SaveSetting ( ) ;
45+ AssetDanshariSetting . SaveSetting ( ) ;
4946 }
5047 EditorGUILayout . EndHorizontal ( ) ;
5148 if ( m_ShowGrepSetting )
5249 {
5350 EditorGUILayout . BeginHorizontal ( ) ;
54- m_AssetDanshariSetting . ripgrepPath = EditorGUILayout . TextField ( style . grepPath , m_AssetDanshariSetting . ripgrepPath ) ;
51+ AssetDanshariSetting . Get ( ) . ripgrepPath = EditorGUILayout . TextField ( style . grepPath , AssetDanshariSetting . Get ( ) . ripgrepPath ) ;
5552 if ( GUILayout . Button ( "O" , GUILayout . ExpandWidth ( false ) ) )
5653 {
5754 var path = EditorUtility . OpenFilePanel ( style . grepPath . text , "" , "*" ) ;
5855 if ( ! string . IsNullOrEmpty ( path ) )
5956 {
6057 GUI . FocusControl ( null ) ;
61- m_AssetDanshariSetting . ripgrepPath = path ;
58+ AssetDanshariSetting . Get ( ) . ripgrepPath = path ;
6259 }
6360 }
6461 EditorGUILayout . EndHorizontal ( ) ;
@@ -75,45 +72,18 @@ private void OnGUI()
7572
7673 private void Init ( )
7774 {
78- if ( m_AssetDanshariSetting == null )
75+ if ( m_ReorderableList == null )
7976 {
8077 m_IsForceText = EditorSettings . serializationMode == SerializationMode . ForceText ;
8178 if ( ! m_IsForceText )
8279 {
8380 return ;
8481 }
85-
86- Object [ ] objects = InternalEditorUtility . LoadSerializedFileAndForget ( kUserSettingsPath ) ;
87- if ( objects != null && objects . Length > 0 )
88- {
89- m_AssetDanshariSetting = objects [ 0 ] as AssetDanshariSetting ;
90- }
91- if ( m_AssetDanshariSetting == null )
92- {
93- string [ ] guids = AssetDatabase . FindAssets ( "t:" + typeof ( AssetDanshariSetting ) . Name ) ;
94- if ( guids . Length > 0 )
95- {
96- string path = AssetDatabase . GUIDToAssetPath ( guids [ 0 ] ) ;
97- m_AssetDanshariSetting = AssetDatabase . LoadAssetAtPath < AssetDanshariSetting > ( path ) ;
98- }
99- }
100- if ( m_AssetDanshariSetting == null )
101- {
102- if ( AssetDanshariHandler . onCreateSetting != null )
103- {
104- m_AssetDanshariSetting = AssetDanshariHandler . onCreateSetting ( ) ;
105- }
106- else
107- {
108- m_AssetDanshariSetting = CreateInstance < AssetDanshariSetting > ( ) ;
109- }
110- SaveSetting ( ) ;
111- }
11282 }
11383
11484 if ( m_ReorderableList == null )
11585 {
116- m_ReorderableList = new ReorderableList ( m_AssetDanshariSetting . assetReferenceInfos , null , true , true , true , true ) ;
86+ m_ReorderableList = new ReorderableList ( AssetDanshariSetting . Get ( ) . assetReferenceInfos , null , true , true , true , true ) ;
11787 m_ReorderableList . drawHeaderCallback = OnDrawHeaderCallback ;
11888 m_ReorderableList . drawElementCallback = OnDrawElementCallback ;
11989 m_ReorderableList . elementHeight += 60 ;
@@ -127,13 +97,13 @@ private void OnDrawHeaderCallback(Rect rect)
12797
12898 private void OnDrawElementCallback ( Rect rect , int index , bool isactive , bool isfocused )
12999 {
130- if ( m_AssetDanshariSetting == null || m_AssetDanshariSetting . assetReferenceInfos . Count < index )
100+ if ( AssetDanshariSetting . Get ( ) == null || AssetDanshariSetting . Get ( ) . assetReferenceInfos . Count < index )
131101 {
132102 return ;
133103 }
134104
135105 var style = AssetDanshariStyle . Get ( ) ;
136- var info = m_AssetDanshariSetting . assetReferenceInfos [ index ] ;
106+ var info = AssetDanshariSetting . Get ( ) . assetReferenceInfos [ index ] ;
137107 rect . height = EditorGUIUtility . singleLineHeight ;
138108 rect . y += 2 ;
139109
@@ -151,9 +121,8 @@ private void OnDrawElementCallback(Rect rect, int index, bool isactive, bool isf
151121 bool valueChanged = EditorGUI . EndChangeCheck ( ) ;
152122 if ( GUI . Button ( rect4 , style . assetReferenceCheckRef ) )
153123 {
154- SaveSetting ( ) ;
155- AssetBaseWindow . CheckPaths < AssetReferenceWindow > ( info . referenceFolder ,
156- info . assetFolder , info . assetCommonFolder , m_AssetDanshariSetting . ripgrepPath ) ;
124+ AssetDanshariSetting . SaveSetting ( ) ;
125+ DisplayReferenceWindow ( info . referenceFolder , info . assetFolder , info . assetCommonFolder ) ;
157126 }
158127
159128 rect2 . y += EditorGUIUtility . singleLineHeight + 2 ;
@@ -167,15 +136,13 @@ private void OnDrawElementCallback(Rect rect, int index, bool isactive, bool isf
167136 valueChanged |= EditorGUI . EndChangeCheck ( ) ;
168137 if ( GUI . Button ( rect4 , style . assetReferenceCheckDup ) )
169138 {
170- SaveSetting ( ) ;
171- AssetBaseWindow . CheckPaths < AssetDuplicateWindow > ( info . referenceFolder ,
172- info . assetFolder , info . assetCommonFolder , m_AssetDanshariSetting . ripgrepPath ) ;
139+ AssetDanshariSetting . SaveSetting ( ) ;
140+ DisplayDuplicateWindow ( info . referenceFolder , info . assetFolder , info . assetCommonFolder ) ;
173141 }
174142 if ( GUI . Button ( rect5 , style . assetReferenceDepend ) )
175143 {
176- SaveSetting ( ) ;
177- AssetBaseWindow . CheckPaths < AssetDependenciesWindow > ( info . referenceFolder ,
178- info . assetFolder , info . assetCommonFolder , m_AssetDanshariSetting . ripgrepPath ) ;
144+ AssetDanshariSetting . SaveSetting ( ) ;
145+ DisplayDependenciesWindow ( info . referenceFolder , info . assetFolder , info . assetCommonFolder ) ;
179146 }
180147
181148 rect2 . y += EditorGUIUtility . singleLineHeight + 2 ;
@@ -222,26 +189,31 @@ private string OnDrawElementAcceptDrop(Rect rect, string label)
222189 return label ;
223190 }
224191
225- private void SaveSetting ( )
192+ /// <summary>
193+ /// 显示引用查找窗口
194+ /// </summary>
195+ /// <param name="refPaths">引用的文件、目录集合</param>
196+ /// <param name="resPaths">资源的文件、目录集合</param>
197+ /// <param name="commonPaths">公共资源目录集合</param>
198+ public static void DisplayReferenceWindow ( string refPaths , string resPaths , string commonPaths = "" )
226199 {
227- if ( m_AssetDanshariSetting == null )
228- {
229- return ;
230- }
231-
232- var settingPath = AssetDatabase . GetAssetPath ( m_AssetDanshariSetting ) ;
233- if ( ! string . IsNullOrEmpty ( settingPath ) )
234- {
235- return ;
236- }
200+ AssetBaseWindow . CheckPaths < AssetReferenceWindow > ( refPaths , resPaths , commonPaths , AssetDanshariSetting . Get ( ) . ripgrepPath ) ;
201+ }
237202
238- string folderPath = Path . GetDirectoryName ( kUserSettingsPath ) ;
239- if ( ! Directory . Exists ( folderPath ) )
240- {
241- Directory . CreateDirectory ( folderPath ) ;
242- }
203+ /// <summary>
204+ /// 显示被引用查找窗口
205+ /// </summary>
206+ public static void DisplayDependenciesWindow ( string refPaths , string resPaths , string commonPaths = "" )
207+ {
208+ AssetBaseWindow . CheckPaths < AssetDependenciesWindow > ( refPaths , resPaths , commonPaths , AssetDanshariSetting . Get ( ) . ripgrepPath ) ;
209+ }
243210
244- InternalEditorUtility . SaveToSerializedFileAndForget ( new [ ] { m_AssetDanshariSetting } , kUserSettingsPath , true ) ;
211+ /// <summary>
212+ /// 显示重复资源检查窗口
213+ /// </summary>
214+ public static void DisplayDuplicateWindow ( string refPaths , string resPaths , string commonPaths = "" )
215+ {
216+ AssetBaseWindow . CheckPaths < AssetDuplicateWindow > ( refPaths , resPaths , commonPaths , AssetDanshariSetting . Get ( ) . ripgrepPath ) ;
245217 }
246218 }
247219}
0 commit comments