Skip to content

Commit a3a4fd2

Browse files
committed
ProjectSettingのビューの目処が立った
1 parent 6c04179 commit a3a4fd2

23 files changed

Lines changed: 1705 additions & 119 deletions
Lines changed: 152 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1+
// using System.IO;
2+
3+
using System.Collections.Generic;
4+
using System.Text;
5+
16
using UnityEditor;
27

38
using UnityEngine;
49

510
namespace ADONEGames.ResolutionCalcCache.Editor
611
{
712
/// <summary>
8-
/// PlayerSettingsに解像度を設定した構造体を生成する項目を追加する
13+
/// Adds an item to generate a structure that sets the resolution in PlayerSettings.
914
/// </summary>
15+
/// <remarks>
16+
/// PlayerSettingsに解像度を設定した構造体を生成する項目を追加する。
17+
/// </remarks>
1018
internal class ProjectSetting : SettingsProvider
1119
{
1220
private const string ProjectSettingPath = "Project/ADONEGames-Tools/Generator/ResolutionCalcCache-ResolutionData";
21+
private readonly string[] _projectSettingKeywords = { "ResolutionCalcCache", "ResolutionData" };
22+
23+
private ResolutionProjectDataEditor _resolutionProjectDataEditor;
1324

1425
/// <summary>
1526
/// Constructor
1627
/// </summary>
17-
/// <param name="path"></param>
18-
/// <param name="scopes"></param>
28+
/// <remarks>
29+
/// このコンストラクタは、指定されたパスと設定スコープで ProjectSetting クラスの新しいインスタンスを初期化します。
30+
/// </remarks>
31+
/// <param name="path">設定ファイルのパス</param>
32+
/// <param name="scopes">設定のスコープ</param>
1933
private ProjectSetting( string path, SettingsScope scopes = SettingsScope.Project ) : base( path, scopes )
2034
{
21-
ProjectSettingData.instance.SetDefaultDirectory();
35+
_resolutionProjectDataEditor = _resolutionProjectDataEditor != null ? _resolutionProjectDataEditor : ResolutionProjectDataEditor.CreateOrLoad();
36+
_resolutionProjectDataEditor.SetDefaultDirectory();
2237
}
2338

2439
/// <summary>
@@ -27,45 +42,160 @@ private ProjectSetting( string path, SettingsScope scopes = SettingsScope.Projec
2742
/// <param name="searchContext"></param>
2843
public override void OnGUI( string searchContext )
2944
{
30-
ProjectSettingData.instance.OnGUI();
45+
EditorGUILayout.Space();
3146

32-
using( new EditorGUI.DisabledScope( ProjectSettingData.instance.ResolutionDataFolder == null ) )
47+
_resolutionProjectDataEditor.OnGUI();
48+
using( new EditorGUI.DisabledScope( _resolutionProjectDataEditor.ResolutionDataFolder == null ) )
3349
using( new EditorGUILayout.HorizontalScope() )
3450
{
3551
GUILayout.FlexibleSpace();
3652

3753
// 生成ボタン
38-
if( !GUILayout.Button( "Generate" ) )
39-
return;
54+
if( GUILayout.Button( "Generate" ) )
55+
{
56+
// 生成
57+
var result = new ResolutionDataTemplateEditor( _resolutionProjectDataEditor ).Generate();
4058

41-
// 生成
42-
var result = new ResolutionDataTemplateEditor( ProjectSettingData.instance ).Generate();
59+
{
60+
// 通知
61+
var assembly = typeof( EditorWindow ).Assembly;
62+
var type = assembly.GetType( "UnityEditor.ProjectSettingsWindow" );
4363

44-
{
45-
// 通知
46-
var assembly = typeof( EditorWindow ).Assembly;
47-
var type = assembly.GetType( "UnityEditor.ProjectSettingsWindow" );
64+
var sb = new StringBuilder();
65+
if (result.writePaths != null)
66+
{
67+
foreach (var path in result.writePaths)
68+
{
69+
sb.AppendLine(path);
70+
}
71+
var message = $"Successful file generation\n\n{sb}";
72+
EditorWindow.GetWindow( type ).ShowNotification( new GUIContent( message ) );
73+
}
74+
else
75+
{
76+
EditorWindow.GetWindow( type ).ShowNotification( new GUIContent( $"File Generation Failure" ) );
77+
}
4878

49-
EditorWindow.GetWindow( type ).ShowNotification( new GUIContent( result.result ? $"{result.writePath}\n\nSuccessful file generation" : $"{result.writePath}\n\nFile generation failure" ) );
50-
}
51-
79+
EditorWindow.GetWindow( type ).ShowNotification( new GUIContent( result.result ? $"Successful file generation\n\n{sb}" : $"File generation failure" ) );
80+
}
5281

53-
// 更新
54-
AssetDatabase.Refresh();
82+
// 更新
83+
AssetDatabase.Refresh();
84+
}
85+
EditorGUILayout.Space(10);
5586
}
5687

5788
EditorGUILayout.Space();
5889

59-
EditorGUILayout.LabelField( "" );
90+
// EditorGUILayout.LabelField( "aaa" );
91+
// var dw = Display.main.colorBuffer;
92+
// var dh = Display.main.systemHeight;
93+
// EditorGUILayout.LabelField( $"Display.main.systemWidth: {Display.main.systemWidth}, Display.main.systemHeight: {Display.main.systemHeight}" );
94+
// EditorGUILayout.LabelField( $"Screen.width: {Screen.width}, Screen.height: {Screen.height}" );
95+
// EditorGUILayout.LabelField( $"Screen.mainWindowDisplayInfo.width: {Screen.mainWindowDisplayInfo.width}, Screen.mainWindowDisplayInfo.height: {Screen.mainWindowDisplayInfo.height}" );
96+
6097
}
6198

6299
/// <summary>
63-
/// SettingsProviderを生成する
100+
/// Generates a SettingsProvider.
64101
/// </summary>
102+
/// <remarks>
103+
/// SettingsProviderを生成する
104+
/// </remarks>
105+
/// <returns>SettingsProvider</returns>
65106
[SettingsProvider]
66107
public static SettingsProvider CreateMyCustomSettingsProvider()
67108
{
68-
return new ProjectSetting( ProjectSettingPath );
109+
var provider = new ProjectSetting( ProjectSettingPath, SettingsScope.Project );
110+
provider.keywords = provider._projectSettingKeywords;
111+
112+
return provider;
113+
}
114+
}
115+
116+
117+
internal class ResolutionCalcCacheSystemData
118+
{
119+
private const string AssetPath = "../ProjectSettings/ResolutionCalcCacheSystemData.asset";
120+
121+
public List<string> ResolutionDataTyepNames = new();
122+
123+
public static ResolutionCalcCacheSystemData Create()
124+
{
125+
var instance = new ResolutionCalcCacheSystemData();
126+
instance.GetSearchType();
127+
return instance;
128+
}
129+
130+
public void GetSearchType()
131+
{
132+
ResolutionDataTyepNames ??= new List<string>();
133+
134+
{
135+
// 仮リスト
136+
ResolutionDataTyepNames.Add( "aaa" );
137+
ResolutionDataTyepNames.Add( "bbb" );
138+
return;
139+
}
140+
141+
var assembly = typeof( ResolutionCalcCacheSystemData ).Assembly; // 仮
142+
var types = assembly.GetTypes();
143+
144+
foreach( var type in types )
145+
{
146+
if( !type.IsValueType ) continue;
147+
if( !type.IsEnum ) continue;
148+
149+
ResolutionDataTyepNames.Add( type.Name );
150+
}
151+
}
152+
}
153+
154+
// [assembly: Dependency(typeof(ResolutionCalcCacheSystemData))]
155+
internal class ResolutionCalcCacheSystemDataEditor : ScriptableObject
156+
{
157+
[SerializeField]
158+
private ResolutionCalcCacheSystemData _systemData;
159+
160+
[SerializeField]
161+
private int _systemDataSelectIndex;
162+
163+
164+
private GUIContent _refreshIconContent;
165+
166+
public void OnGUI()
167+
{
168+
_systemData ??= ResolutionCalcCacheSystemData.Create();
169+
170+
_refreshIconContent ??= EditorGUIUtility.IconContent( "d_Refresh" );
171+
172+
using( var check = new EditorGUI.ChangeCheckScope() )
173+
using( new EditorGUILayout.HorizontalScope( "box" ) )
174+
{
175+
EditorGUILayout.LabelField( "Edit ResolutionType" );
176+
var selectIndex = EditorGUILayout.Popup( _systemDataSelectIndex, _systemData.ResolutionDataTyepNames.ToArray() );
177+
if( check.changed )
178+
{
179+
Undo.RecordObject( this, "Change ResolutionCalcCache-SystemDataIndex" );
180+
_systemDataSelectIndex = selectIndex;
181+
182+
// EditorUtility.SetDirty( this );
183+
}
184+
185+
if( GUILayout.Button( new GUIContent( "", _refreshIconContent.image ), GUILayout.Width( 20 ), GUILayout.Height( 20 ) ) )
186+
{
187+
_systemData.GetSearchType();
188+
}
189+
}
190+
}
191+
192+
public static ResolutionCalcCacheSystemDataEditor Create()
193+
{
194+
var instance = CreateInstance<ResolutionCalcCacheSystemDataEditor>();
195+
instance._systemData = ResolutionCalcCacheSystemData.Create();
196+
instance.hideFlags |= HideFlags.HideAndDontSave;
197+
198+
return instance;
69199
}
70200
}
71201
}

0 commit comments

Comments
 (0)