├── .gitignore
├── CHANGELOG.md
├── CHANGELOG.md.meta
├── Documentation~
└── index.md
├── Editor.meta
├── Editor
├── Processor.meta
├── Processor
│ ├── IProcessChain.cs
│ ├── IProcessChain.cs.meta
│ ├── TemplateSettingCodeArrayProcessor.cs
│ ├── TemplateSettingCodeArrayProcessor.cs.meta
│ ├── TemplateSettingCodeProcessor.cs
│ └── TemplateSettingCodeProcessor.cs.meta
├── Setting.meta
├── Setting
│ ├── TemplateGroupSetting.cs
│ ├── TemplateGroupSetting.cs.meta
│ ├── TemplateGroupSettingEditor.cs
│ ├── TemplateGroupSettingEditor.cs.meta
│ ├── TemplateSetting.cs
│ ├── TemplateSetting.cs.meta
│ ├── TemplateSettingEditor.cs
│ ├── TemplateSettingEditor.cs.meta
│ ├── TemplateSettingPropertyGetter.cs
│ └── TemplateSettingPropertyGetter.cs.meta
├── SyntaxHilightEditor.meta
├── SyntaxHilightEditor
│ ├── Editor.meta
│ └── Editor
│ │ ├── Setting.meta
│ │ ├── Setting
│ │ ├── Group.meta
│ │ ├── Group
│ │ │ ├── CSharpGroupSetting.asset
│ │ │ └── CSharpGroupSetting.asset.meta
│ │ ├── Patterns.meta
│ │ ├── Patterns
│ │ │ ├── Comment.asset
│ │ │ ├── Comment.asset.meta
│ │ │ ├── Replace.asset
│ │ │ ├── Replace.asset.meta
│ │ │ ├── ReservedWords.asset
│ │ │ ├── ReservedWords.asset.meta
│ │ │ ├── String.asset
│ │ │ ├── String.asset.meta
│ │ │ ├── SubsetReservedWords.asset
│ │ │ └── SubsetReservedWords.asset.meta
│ │ ├── SyntaxHighlightGroupSetting.cs
│ │ ├── SyntaxHighlightGroupSetting.cs.meta
│ │ ├── SyntaxHighlightSetting.cs
│ │ ├── SyntaxHighlightSetting.cs.meta
│ │ ├── SyntaxhighlightSettingEditor.cs
│ │ └── SyntaxhighlightSettingEditor.cs.meta
│ │ ├── SyntaxHighlightMenuitem.cs
│ │ ├── SyntaxHighlightMenuitem.cs.meta
│ │ ├── SyntaxHighlightUtility.cs
│ │ ├── SyntaxHighlightUtility.cs.meta
│ │ ├── TextAreaSyntaxHighlightEditor.cs
│ │ └── TextAreaSyntaxHighlightEditor.cs.meta
├── TemplateEditor.asmdef
├── TemplateEditor.asmdef.meta
├── TemplateTool.meta
├── TemplateTool
│ ├── AssetsMenuItemCreator.meta
│ ├── AssetsMenuItemCreator
│ │ ├── AssetsMenuItemProcessor.cs
│ │ ├── AssetsMenuItemProcessor.cs.meta
│ │ ├── AssetsMenuItemSetting.asset
│ │ ├── AssetsMenuItemSetting.asset.meta
│ │ ├── IAssetsMenuItem.cs
│ │ └── IAssetsMenuItem.cs.meta
│ ├── CustomEditorCreator.meta
│ ├── CustomEditorCreator
│ │ ├── CustomEditorCreateWindow.cs
│ │ ├── CustomEditorCreateWindow.cs.meta
│ │ ├── Setting.meta
│ │ └── Setting
│ │ │ ├── CustomEditorCreatorGroupSetting.asset
│ │ │ ├── CustomEditorCreatorGroupSetting.asset.meta
│ │ │ ├── CustomEditorSetting.asset
│ │ │ ├── CustomEditorSetting.asset.meta
│ │ │ ├── PropertyGetterSetting.asset
│ │ │ └── PropertyGetterSetting.asset.meta
│ ├── DefaultTemplates.meta
│ ├── DefaultTemplates
│ │ ├── EditorWindowSetting.asset
│ │ ├── EditorWindowSetting.asset.meta
│ │ ├── MonoBehaviourSetting.asset
│ │ ├── MonoBehaviourSetting.asset.meta
│ │ ├── PureCSharpSetting.asset
│ │ ├── PureCSharpSetting.asset.meta
│ │ ├── ScriptableObjectSetting.asset
│ │ └── ScriptableObjectSetting.asset.meta
│ ├── ResourcesSupport.meta
│ ├── ResourcesSupport
│ │ ├── ResourcesSupportSetting.asset
│ │ ├── ResourcesSupportSetting.asset.meta
│ │ ├── Scripts.meta
│ │ └── Scripts
│ │ │ ├── Parameters.meta
│ │ │ ├── Parameters
│ │ │ ├── AudioClipParameter.asset
│ │ │ ├── AudioClipParameter.asset.meta
│ │ │ ├── GameObjectParameter.asset
│ │ │ ├── GameObjectParameter.asset.meta
│ │ │ ├── LoadParameter.cs
│ │ │ ├── LoadParameter.cs.meta
│ │ │ ├── SpriteParameter.asset
│ │ │ ├── SpriteParameter.asset.meta
│ │ │ ├── TextParameter.asset
│ │ │ ├── TextParameter.asset.meta
│ │ │ ├── TextureParameter.asset
│ │ │ ├── TextureParameter.asset.meta
│ │ │ ├── VideoClipParameter.asset
│ │ │ └── VideoClipParameter.asset.meta
│ │ │ ├── ResourcesLoaderSetting.asset
│ │ │ ├── ResourcesLoaderSetting.asset.meta
│ │ │ ├── ResourcesLoaderSetting.cs
│ │ │ ├── ResourcesLoaderSetting.cs.meta
│ │ │ ├── Utility.meta
│ │ │ └── Utility
│ │ │ ├── EnumFlagsAttributeDrawer.cs
│ │ │ ├── EnumFlagsAttributeDrawer.cs.meta
│ │ │ ├── IUsings.cs
│ │ │ ├── IUsings.cs.meta
│ │ │ ├── ResourcesLoaderUtility.cs
│ │ │ ├── ResourcesLoaderUtility.cs.meta
│ │ │ ├── StringBuilderExtension.cs
│ │ │ └── StringBuilderExtension.cs.meta
│ ├── ToolExecutor.cs
│ ├── ToolExecutor.cs.meta
│ ├── UnityCSharpTemplateChanger.meta
│ ├── UnityCSharpTemplateChanger
│ │ ├── UnityCSharpTemplatePathProcessor.cs
│ │ ├── UnityCSharpTemplatePathProcessor.cs.meta
│ │ ├── UnityCSharpTemplateSetting.asset
│ │ └── UnityCSharpTemplateSetting.asset.meta
│ ├── VisualTreeNameTableCreator.meta
│ └── VisualTreeNameTableCreator
│ │ ├── VisualTreeNameCreatorWindow.cs
│ │ ├── VisualTreeNameCreatorWindow.cs.meta
│ │ ├── VisualTreeNameGetProcessor.asset
│ │ ├── VisualTreeNameGetProcessor.asset.meta
│ │ ├── VisualTreeNameGetProcessor.cs
│ │ ├── VisualTreeNameGetProcessor.cs.meta
│ │ ├── VisualTreeNameTableSetting.asset
│ │ └── VisualTreeNameTableSetting.asset.meta
├── TreeView.meta
├── TreeView
│ ├── PrefabTreeView.cs
│ ├── PrefabTreeView.cs.meta
│ ├── PrefabTreeViewWindow.cs
│ └── PrefabTreeViewWindow.cs.meta
├── UserSetting.meta
├── UserSetting
│ ├── DefaultUserSetting.asset
│ ├── DefaultUserSetting.asset.meta
│ ├── UserSetting.cs
│ ├── UserSetting.cs.meta
│ ├── UserSettingCopyWindow.cs
│ └── UserSettingCopyWindow.cs.meta
├── Utility.meta
└── Utility
│ ├── EditorExtension.cs
│ ├── EditorExtension.cs.meta
│ ├── EditorPreviewWindow.cs
│ ├── EditorPreviewWindow.cs.meta
│ ├── EnumArrayAttribute.cs
│ ├── EnumArrayAttribute.cs.meta
│ ├── ProcessDictionary.cs
│ ├── ProcessDictionary.cs.meta
│ ├── ReplaceProcessor.cs
│ ├── ReplaceProcessor.cs.meta
│ ├── ScriptableObjectUtility.meta
│ ├── ScriptableObjectUtility
│ ├── EmptyScriptableObject.cs
│ ├── EmptyScriptableObject.cs.meta
│ ├── ScriptableObjectUtility.cs
│ └── ScriptableObjectUtility.cs.meta
│ ├── TemplateMenuItem.cs
│ ├── TemplateMenuItem.cs.meta
│ ├── TemplatePrefabCreator.cs
│ ├── TemplatePrefabCreator.cs.meta
│ ├── TemplateUtility.cs
│ ├── TemplateUtility.cs.meta
│ ├── UnityCallbackReceiver.cs
│ └── UnityCallbackReceiver.cs.meta
├── LICENSE
├── LICENSE.meta
├── README.md
├── README.md.meta
├── package.json
└── package.json.meta
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 | [Bb]uild/
5 | [Bb]uilds/
6 | Assets/AssetStoreTools*
7 |
8 | # Visual Studio cache directory
9 | .vs/
10 |
11 | # Autogenerated VS/MD/Consulo solution and project files
12 | ExportedObj/
13 | .consulo/
14 | *.csproj
15 | *.unityproj
16 | *.sln
17 | *.suo
18 | *.tmp
19 | *.user
20 | *.userprefs
21 | *.pidb
22 | *.booproj
23 | *.svd
24 | *.pdb
25 | *.opendb
26 |
27 | # Unity3D generated meta files
28 | *.pidb.meta
29 | *.pdb.meta
30 |
31 | # Unity3D Generated File On Crash Reports
32 | sysinfo.txt
33 |
34 | # Builds
35 | *.apk
36 | *.unitypackage
37 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ### v1.2.4
2 |
3 | - CustomEditorのテンプレートを生成する機能を追加
4 | - VisualTreeName Table を作成する機能の仕様を変更
5 |
6 | ### v1.2.3
7 |
8 | - Unity 2019より前でも動作するように
9 |
10 | ### v1.2.2
11 |
12 | - VisualTreeName Table を作成する機能を追加
13 |
14 | ### v1.2.1
15 |
16 | - Resources Support機能を更新
17 | - VideoClipに対応
18 |
19 | ### v1.2.0
20 |
21 | - Template Tool を追加
22 | - Resources Support機能を本機能に統合
23 | - Unity C# Script のTemplateを変更する機能を追加
24 |
25 | ### v1.1.0
26 |
27 | - 置き換え文字中の置き換え文字に対応
28 | - SyntaxHighlightEditorへの参照方法を変更
29 |
30 | ### v1.0.0
31 |
32 | 正式リリース
33 |
34 | ### v0.4.0
35 |
36 | - PackageManager対応
37 | - Join置き換え削除(breaking change)
38 | - Codeエリアの最小、最大を指定できるように
39 | - Codeエリアのスクロール位置を保持するように
40 | - Foldout状態を保持するように
41 |
42 | ### v0.3.0
43 |
44 | - Prefabのパス指定を変更(breaking change)
45 | - 「Create Prefab Path」に指定していた情報が破棄されます
46 |
47 | ### v0.2.1
48 |
49 | - Resources Support機能にEnumで使用できない文字を変換する処理を追加
50 |
51 | ### v0.2.0
52 |
53 | - Resources Support機能を試験的に追加
54 |
55 | ### v0.1.0
56 |
57 | ファーストリリース
--------------------------------------------------------------------------------
/CHANGELOG.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4a7ec18538fd14264bf4498a9268fdb1
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Documentation~/index.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 17f9f115039cd4d8cad228b0eeafefbd
3 | folderAsset: yes
4 | timeCreated: 1509949366
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/Processor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 89dcf449e741b44da9aeb27c2898cb19
3 | folderAsset: yes
4 | timeCreated: 1515319975
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/Processor/IProcessChain.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace TemplateEditor
4 | {
5 | public interface IProcessChain
6 | {
7 | void Process(ProcessMetadata metadata, ProcessDictionary result);
8 | string[] GetReplaceWords();
9 | string GetDescription();
10 | }
11 |
12 | ///
13 | /// Process実行時のメタデータ
14 | ///
15 | public class ProcessMetadata
16 | {
17 | public TemplateSetting setting { get; private set; }
18 |
19 | public ProcessMetadata(TemplateSetting setting)
20 | {
21 | this.setting = setting;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Editor/Processor/IProcessChain.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 649ab7bb09eee4e278840b92d31b3227
3 | timeCreated: 1515056693
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Processor/TemplateSettingCodeArrayProcessor.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 | using System.Collections.Generic;
3 | using UnityEngine;
4 | using System;
5 |
6 | namespace TemplateEditor
7 | {
8 | public class TemplateSettingCodeArrayProcessor : TemplateSettingCodeProcessor
9 | {
10 | private static readonly string[] RepalceWords = {"TemplateSettingCodeArray"};
11 |
12 | #region IProcessChain implementation
13 |
14 | public override void Process(ProcessMetadata metadata, ProcessDictionary result)
15 | {
16 | var code = ReplaceCode(result);
17 | if (string.IsNullOrEmpty(code))
18 | {
19 | return;
20 | }
21 |
22 | result.Add(RepalceWords[0], code.Split('\n'));
23 | }
24 |
25 | public override string[] GetReplaceWords()
26 | {
27 | return RepalceWords;
28 | }
29 |
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Editor/Processor/TemplateSettingCodeArrayProcessor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5133f6a6721dd49b4b27cb31d40716c9
3 | timeCreated: 1515315777
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Processor/TemplateSettingCodeProcessor.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using UnityEngine;
5 |
6 | namespace TemplateEditor
7 | {
8 | public class TemplateSettingCodeProcessor : IProcessChain
9 | {
10 | private static readonly string[] RepalceWords = {"TemplateSettingCode"};
11 |
12 | #region IProcessChain implementation
13 |
14 | public virtual void Process(ProcessMetadata metadata, ProcessDictionary result)
15 | {
16 | result.Add(RepalceWords[0], ReplaceCode(result));
17 | }
18 |
19 | public virtual string[] GetReplaceWords()
20 | {
21 | return RepalceWords;
22 | }
23 |
24 | public string GetDescription()
25 | {
26 | return "一つ前のテンプレート設定のコード部分を渡します";
27 | }
28 |
29 | #endregion
30 |
31 | protected string ReplaceCode(ProcessDictionary result)
32 | {
33 | object obj;
34 | result.TryGetValue(result.GetLastConvertReplaceWord(TemplateSetting.ResultKey), out obj);
35 | var setting = obj as TemplateSetting;
36 | if (setting == null)
37 | {
38 | Debug.LogErrorFormat("Not {0} object", TemplateSetting.ResultKey);
39 | return null;
40 | }
41 |
42 | var status = new TemplateSettingStatus(new SerializedObject(setting));
43 |
44 | TemplateSettingEditor.ExecuteChain(status, result);
45 | var words = ReplaceProcessor.GetReplaceWords(
46 | status.GetProperty(TemplateSettingPropertyGetter.Property.Path).stringValue,
47 | status.GetProperty(TemplateSettingPropertyGetter.Property.ScriptName).stringValue,
48 | status.GetProperty(TemplateSettingPropertyGetter.Property.Code).stringValue
49 | );
50 | var replaces = TemplateSettingEditor.CreateReplaceList(new List(0), words.ToArray());
51 | foreach (var replace in replaces)
52 | {
53 | result.Add(replace.Key, replace.ReplaceWord);
54 | }
55 |
56 | return TemplateSettingEditor.Replace(
57 | status.GetProperty(TemplateSettingPropertyGetter.Property.Code).stringValue,
58 | result
59 | );
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Editor/Processor/TemplateSettingCodeProcessor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 74d837795805848d38ee15c9b05d4de4
3 | timeCreated: 1515315777
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Setting.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d419ba095c70f4376997de0ddcf03fc5
3 | folderAsset: yes
4 | timeCreated: 1510921601
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateGroupSetting.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System;
3 | using UnityEngine.Serialization;
4 |
5 | namespace TemplateEditor
6 | {
7 | public class TemplateGroupSetting : ScriptableObject, IAssetsMenuItem
8 | {
9 | [SerializeField]
10 | public TemplateSetting[] Settings;
11 |
12 | [SerializeField]
13 | private bool AssetsMenuItem;
14 |
15 | #region IAssetsMenuItem implementation
16 |
17 | public bool IsAssetsMenuItem { get { return AssetsMenuItem; } set { AssetsMenuItem = value; } }
18 |
19 | #endregion
20 |
21 | [SerializeField]
22 | private string Description;
23 |
24 | [NonSerialized]
25 | public Action OnChangedSettings;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateGroupSetting.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f14bca261b81e4c66a1a2a293cfd3893
3 | timeCreated: 1510572810
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateGroupSettingEditor.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 | using UnityEngine;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | namespace TemplateEditor
7 | {
8 | [CanEditMultipleObjects]
9 | [CustomEditor(typeof(TemplateGroupSetting))]
10 | public class TemplateGroupSettingEditor : Editor
11 | {
12 | private static readonly TemplateSettingPropertyGetter.Property[] ReplaceProperty = new TemplateSettingPropertyGetter.Property[]
13 | {
14 | TemplateSettingPropertyGetter.Property.Path,
15 | TemplateSettingPropertyGetter.Property.ScriptName,
16 | TemplateSettingPropertyGetter.Property.Code,
17 | };
18 |
19 | private TemplateGroupSetting _groupSetting;
20 | private SerializedProperty _settingsProperty;
21 | private SerializedProperty _isAssetsMenuItemProperty;
22 | private SerializedProperty _descriptionProperty;
23 | private FoldoutInfo _descriptionFoldout;
24 | private List _statusList = new List();
25 | private List _foldoutList = new List();
26 | private List _replaceList = new List();
27 | private bool _isUpdateSetting;
28 |
29 | void OnEnable()
30 | {
31 | _groupSetting = target as TemplateGroupSetting;
32 | _settingsProperty = serializedObject.FindProperty("Settings");
33 | _isAssetsMenuItemProperty = serializedObject.FindProperty("AssetsMenuItem");
34 | _descriptionProperty = serializedObject.FindProperty("Description");
35 | _descriptionFoldout = new FoldoutInfo("Description", DrawDescription);
36 | BuildSettingList();
37 | }
38 |
39 | public override void OnInspectorGUI()
40 | {
41 | var isChanged = false;
42 | serializedObject.Update();
43 | {
44 | isChanged = DrawSettingList();
45 |
46 | EditorGUIHelper.DrawFoldouts(_foldoutList);
47 | TemplateSettingEditor.DrawReplace(_replaceList, _groupSetting.GetInstanceID().ToString());
48 | DrawIsAssetsMenuItem();
49 | DrawCreate();
50 | EditorGUIHelper.DrawFoldout(_descriptionFoldout);
51 |
52 | UpdateReplaceList();
53 | }
54 | serializedObject.ApplyModifiedProperties();
55 |
56 | if (isChanged)
57 | {
58 | BuildSettingList();
59 | }
60 | }
61 |
62 | private bool DrawSettingList()
63 | {
64 | EditorGUI.BeginChangeCheck();
65 | EditorGUILayout.PropertyField(_settingsProperty, new GUIContent("Template Settings"), true);
66 |
67 | return EditorGUI.EndChangeCheck();
68 | }
69 |
70 | private void BuildSettingList()
71 | {
72 | _foldoutList.Clear();
73 | _statusList.Clear();
74 |
75 | if (_groupSetting.Settings != null)
76 | {
77 | foreach (var setting in _groupSetting.Settings)
78 | {
79 | if (setting == null)
80 | {
81 | continue;
82 | }
83 |
84 | var status = new TemplateSettingStatus(new SerializedObject(setting));
85 | var foldout = new FoldoutInfo(setting.name, () =>
86 | {
87 | status.TargetSerializedObject.Update();
88 | DrawSetting(status);
89 | status.TargetSerializedObject.ApplyModifiedProperties();
90 | }
91 | );
92 |
93 | foldout.IsFoldout = false;
94 | _foldoutList.Add(foldout);
95 | _statusList.Add(status);
96 | }
97 | }
98 |
99 | UpdateReplaceList(true);
100 | }
101 |
102 | private void DrawSetting(TemplateSettingStatus status)
103 | {
104 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
105 | {
106 | TemplateSettingEditor.DrawHeader(status);
107 | TemplateSettingEditor.DrawCode(status);
108 | TemplateSettingEditor.DrawChain(status);
109 | TemplateSettingEditor.DrawOverwrite(status);
110 | TemplateSettingEditor.DrawPrefab(status);
111 | }
112 | EditorGUILayout.EndVertical();
113 | }
114 |
115 | private void DrawIsAssetsMenuItem()
116 | {
117 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
118 | {
119 | var cache = _groupSetting.IsAssetsMenuItem;
120 | EditorGUILayout.PropertyField(_isAssetsMenuItemProperty, new GUIContent("Add Assets Menu"));
121 |
122 | // 生成時に設定反映が間に合わないため
123 | _groupSetting.IsAssetsMenuItem = _isAssetsMenuItemProperty.boolValue;
124 |
125 | if (cache != _groupSetting.IsAssetsMenuItem)
126 | {
127 | AssetsMenuItemProcessor.Execute();
128 | }
129 | }
130 | EditorGUILayout.EndVertical();
131 | }
132 |
133 | private void DrawCreate()
134 | {
135 | EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle());
136 | {
137 | if (GUILayout.Button("Create"))
138 | {
139 | CreateScript(_replaceList, true);
140 | return;
141 | }
142 |
143 | if (GUILayout.Button("No Refresh Create"))
144 | {
145 |
146 | CreateScript(_replaceList, false);
147 | return;
148 | }
149 | }
150 | EditorGUILayout.EndHorizontal();
151 | }
152 |
153 | public void CreateScript(List replaceList, bool isRefresh, ProcessDictionary result = null)
154 | {
155 | foreach (var status in _statusList)
156 | {
157 | TemplateSettingEditor.CreateScript(status, replaceList, result, isRefresh);
158 | }
159 | }
160 |
161 | private void DrawDescription()
162 | {
163 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
164 | {
165 | _descriptionProperty.stringValue = EditorGUILayout.TextArea(_descriptionProperty.stringValue);
166 | }
167 | EditorGUILayout.EndVertical();
168 | }
169 |
170 | private void UpdateReplaceList(bool isForce = false)
171 | {
172 | if (isForce == false && _statusList.Any(status => status.IsUpdateText) == false)
173 | {
174 | // 更新なし
175 | return;
176 | }
177 |
178 | var texts = new string[_statusList.Count * ReplaceProperty.Length];
179 | for (int i = 0; i < _statusList.Count; ++i)
180 | {
181 | _statusList[i].IsUpdateText = false;
182 |
183 | var index = i * ReplaceProperty.Length;
184 | for (int j = 0; j < ReplaceProperty.Length; ++j)
185 | {
186 | texts[index + j] = _statusList[i].GetProperty(ReplaceProperty[j]).stringValue;
187 | }
188 | }
189 |
190 | var words = ReplaceProcessor.GetReplaceWords(texts);
191 | foreach (var status in _statusList)
192 | {
193 | TemplateSettingEditor.RemoveChainWords(words, status.TargetTemplateSetting.Chain);
194 | }
195 |
196 | _replaceList = TemplateSettingEditor.CreateReplaceList(_replaceList, words.ToArray());
197 |
198 | TemplateSettingEditor.SetReplaceListFromConfigValue(_replaceList, _groupSetting.GetInstanceID().ToString());
199 | }
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateGroupSettingEditor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 65902bc4f1a2f4d26a159e7206dcddcc
3 | timeCreated: 1511693987
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateSetting.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS0649
2 |
3 | using UnityEngine;
4 | using System.Collections.Generic;
5 |
6 | namespace TemplateEditor
7 | {
8 | public class TemplateSetting : ScriptableObject, IProcessChain, IAssetsMenuItem
9 | {
10 | public static readonly string ResultKey = "TemplateSetting";
11 | private static readonly string[] ReplaceWords = {ResultKey};
12 |
13 | public void Process(ProcessMetadata metadata, ProcessDictionary result)
14 | {
15 | result.Add(
16 | ReplaceWords[0],
17 | this
18 | );
19 | }
20 |
21 | public string[] GetReplaceWords()
22 | {
23 | return ReplaceWords;
24 | }
25 |
26 | public string GetDescription()
27 | {
28 | return "自身のインスタンスを渡します";
29 | }
30 |
31 | [SerializeField]
32 | public string Path;
33 |
34 | [SerializeField]
35 | public string ScriptName;
36 |
37 | [SerializeField]
38 | public string Code;
39 |
40 | [SerializeField]
41 | public float CodeAreaHeight = 200f;
42 |
43 | [SerializeField]
44 | public TemplateUtility.OverwriteType Overwrite;
45 |
46 | [SerializeField]
47 | public UnityEngine.Object[] Chain;
48 |
49 | [SerializeField]
50 | public GameObject DuplicatePrefab;
51 |
52 | [SerializeField]
53 | public GameObject AttachTarget;
54 |
55 | [SerializeField]
56 | public string PrefabPath;
57 |
58 | [SerializeField]
59 | public string PrefabName;
60 |
61 | [SerializeField]
62 | private bool AssetsMenuItem;
63 |
64 | [SerializeField]
65 | public string Description;
66 |
67 | [SerializeField]
68 | public List IsFoldouts;
69 |
70 | [SerializeField]
71 | public Vector2 ScrollPos;
72 |
73 | #region IAssetMenuItem implementation
74 |
75 | public bool IsAssetsMenuItem { get { return AssetsMenuItem; } set { AssetsMenuItem = value; } }
76 |
77 | #endregion
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateSetting.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 56a3a9f3b9043415681fb03d3faa50c2
3 | timeCreated: 1509959272
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateSettingEditor.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS0618
2 |
3 | using UnityEditor;
4 | using UnityEngine;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Text;
8 | using System.Linq;
9 | using System.Text.RegularExpressions;
10 | using SyntaxHighlightEditor;
11 | using UnityEditorInternal;
12 |
13 | namespace TemplateEditor
14 | {
15 | public class TemplateSettingStatus
16 | {
17 | public readonly SerializedObject TargetSerializedObject;
18 | public readonly TemplateSetting TargetTemplateSetting;
19 | public readonly ReorderableList ChainReorderableList;
20 | public bool IsUpdateText;
21 |
22 | private readonly TemplateSettingPropertyGetter _propertyGetter;
23 |
24 | public TemplateSettingStatus(SerializedObject targetSerializedObject)
25 | {
26 | TargetSerializedObject = targetSerializedObject;
27 | TargetTemplateSetting = targetSerializedObject.targetObject as TemplateSetting;
28 | _propertyGetter = new TemplateSettingPropertyGetter(targetSerializedObject);
29 |
30 | ChainReorderableList = new ReorderableList(targetSerializedObject, GetProperty(TemplateSettingPropertyGetter.Property.Chain))
31 | {
32 | drawElementCallback = DrawChainListElement,
33 | drawHeaderCallback = (rect) => { EditorGUI.LabelField(rect, "List"); },
34 | };
35 | }
36 |
37 | private void DrawChainListElement(Rect rect, int index, bool isActive, bool isFocuse)
38 | {
39 | var element = GetProperty(TemplateSettingPropertyGetter.Property.Chain).GetArrayElementAtIndex (index);
40 | rect.height -= 4f;
41 | rect.y += 2f;
42 | rect.xMin += 20f;
43 | EditorGUI.PropertyField(rect, element, GUIContent.none);
44 | }
45 |
46 | public SerializedProperty GetProperty(TemplateSettingPropertyGetter.Property type)
47 | {
48 | return _propertyGetter.GetProperty(type);
49 | }
50 | }
51 |
52 | public class ReplaceInfo
53 | {
54 | public string Key;
55 | public string ReplaceWord;
56 | }
57 |
58 | [CanEditMultipleObjects]
59 | [CustomEditor(typeof(TemplateSetting))]
60 | public class TemplateSettingEditor : Editor
61 | {
62 | public TemplateSettingStatus SettingStatus;
63 | private FoldoutInfo[] _foldouts;
64 | private FoldoutInfo _descriptionFoldout;
65 | private List _replaceList = new List();
66 | private string _instanceId;
67 | private Vector2 _scrollPos;
68 |
69 | private void OnEnable()
70 | {
71 | _instanceId = target.GetInstanceID().ToString();
72 | SettingStatus = new TemplateSettingStatus(serializedObject);
73 |
74 | _foldouts = new FoldoutInfo[]
75 | {
76 | new FoldoutInfo("Code", () => DrawCode(SettingStatus)),
77 | new FoldoutInfo("Replace Texts", () => DrawReplace(_replaceList, _instanceId)),
78 | new FoldoutInfo("Pre Process", () => DrawChain(SettingStatus)),
79 | };
80 |
81 | var property = SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.IsFoldouts);
82 | for (int i = 0; i < _foldouts.Length; ++i)
83 | {
84 | if (property.arraySize <= i)
85 | {
86 | break;
87 | }
88 |
89 | _foldouts[i].IsFoldout = property.GetArrayElementAtIndex(i).boolValue;
90 | }
91 |
92 | _descriptionFoldout = new FoldoutInfo("Description", DrawDescription);
93 | _descriptionFoldout.IsFoldout = string.IsNullOrEmpty(SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.Description).stringValue) == false;
94 |
95 | UpdateReplaceList(true);
96 | }
97 |
98 | public override void OnInspectorGUI()
99 | {
100 | SettingStatus.TargetSerializedObject.Update();
101 | {
102 | _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
103 | {
104 | DrawHeader(SettingStatus);
105 | EditorGUIHelper.DrawFoldouts(_foldouts);
106 | DrawOverwrite(SettingStatus);
107 | DrawIsAssetsMenuItem();
108 | DrawPrefab(SettingStatus);
109 | EditorGUIHelper.DrawFoldout(_descriptionFoldout);
110 | }
111 | EditorGUILayout.EndScrollView();
112 |
113 | DrawCreate();
114 | UpdateFoldout();
115 | UpdateReplaceList();
116 | }
117 | SettingStatus.TargetSerializedObject.ApplyModifiedProperties();
118 | }
119 |
120 | public static void DrawHeader(TemplateSettingStatus status)
121 | {
122 | EditorGUI.BeginChangeCheck();
123 | {
124 | // setting create path
125 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
126 | {
127 | var property = status.GetProperty(TemplateSettingPropertyGetter.Property.Path);
128 | EditorGUILayout.PropertyField(property, new GUIContent("Create Path"));
129 |
130 | var paths = EditorGUIHelper.DrawDragAndDropArea();
131 | if (paths != null && paths.Length > 0)
132 | {
133 | // Index 0 のパスを使用する
134 | property.stringValue = TemplateUtility.GetDirectoryPath(paths[0]);
135 | }
136 |
137 | var createPath = status.TargetTemplateSetting.Path;
138 | if (string.IsNullOrEmpty(createPath))
139 | {
140 | EditorGUILayout.HelpBox("If empty, the script will be created in active folder", MessageType.Info);
141 |
142 | }
143 | EditorGUILayout.HelpBox("Example: Assets/Folder", MessageType.Info);
144 | }
145 | EditorGUILayout.EndVertical();
146 |
147 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
148 | {
149 | EditorGUILayout.PropertyField(status.GetProperty(TemplateSettingPropertyGetter.Property.ScriptName), new GUIContent("Script Name"));
150 | if (string.IsNullOrEmpty(status.TargetTemplateSetting.ScriptName))
151 | {
152 | EditorGUILayout.HelpBox("Example: Example.cs", MessageType.Info);
153 | }
154 | else if (Regex.IsMatch(status.TargetTemplateSetting.ScriptName, @"\..+$", RegexOptions.Compiled) == false)
155 | {
156 | EditorGUILayout.HelpBox("Extension required", MessageType.Warning);
157 | }
158 | }
159 | EditorGUILayout.EndVertical();
160 | }
161 |
162 | if (EditorGUI.EndChangeCheck())
163 | {
164 | status.IsUpdateText = true;
165 | Undo.IncrementCurrentGroup();
166 | }
167 | }
168 |
169 | public static void SetReplaceListFromConfigValue(List replaces, string prefix)
170 | {
171 | foreach (var replace in replaces)
172 | {
173 | replace.ReplaceWord = TemplateUtility.GetConfigValue(prefix + replace.Key);
174 | }
175 | }
176 |
177 | public static void DrawChain(TemplateSettingStatus status)
178 | {
179 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
180 | {
181 | status.ChainReorderableList.DoLayoutList();
182 |
183 | var selectIndex = status.ChainReorderableList.index;
184 | if (selectIndex >= 0)
185 | {
186 | var select = status.ChainReorderableList.serializedProperty.GetArrayElementAtIndex(selectIndex);
187 | var chain = TemplateUtility.ConvertProcessChianInstanceFromObject(select.objectReferenceValue);
188 | if (chain != null)
189 | {
190 | var builder = new StringBuilder();
191 | builder.AppendLine("[Used Variables]");
192 | foreach (var word in chain.GetReplaceWords())
193 | {
194 | builder.AppendLine(ReplaceProcessor.GetReplaceText(word));
195 | }
196 |
197 | // TODO : Cache
198 | var style = new GUIStyle(GUI.skin.label)
199 | {
200 | wordWrap = true,
201 | };
202 | var label = builder.ToString();
203 | var content = new GUIContent(label);
204 | var rect = GUILayoutUtility.GetRect(content, style);
205 | EditorGUI.SelectableLabel(rect, label, style);
206 | EditorGUILayout.LabelField("[Description]\n" + chain.GetDescription(), style);
207 | }
208 | }
209 | else
210 | {
211 | EditorGUILayout.HelpBox("When you select item, description will be displayed", MessageType.Info, true);
212 | }
213 | }
214 | EditorGUILayout.EndVertical();
215 | }
216 |
217 | public static void DrawOverwrite(TemplateSettingStatus status)
218 | {
219 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
220 | {
221 | var property = status.GetProperty(TemplateSettingPropertyGetter.Property.Overwrite);
222 | EditorGUILayout.PropertyField(property, new GUIContent("Overwrite Type"));
223 | }
224 | EditorGUILayout.EndVertical();
225 | }
226 |
227 | public static void CreateScript(TemplateSettingStatus status, List replaces, ProcessDictionary result = null, bool isRefresh = true)
228 | {
229 | if (result == null)
230 | {
231 | result = new ProcessDictionary();
232 | }
233 |
234 | if (replaces != null)
235 | {
236 | foreach (var replace in replaces)
237 | {
238 | if (string.IsNullOrEmpty(replace.ReplaceWord))
239 | {
240 | continue;
241 | }
242 |
243 | result[replace.Key] = replace.ReplaceWord;
244 | }
245 | }
246 |
247 | ExecuteChain(status, result);
248 |
249 | // 生成ディレクトリが指定されていなければアクティブなパスへ作成
250 | var createDirectory = status.GetProperty(TemplateSettingPropertyGetter.Property.Path).stringValue;
251 | var createPath = Path.Combine(
252 | string.IsNullOrEmpty(createDirectory) == false ? createDirectory : TemplateUtility.GetActiveFolder(),
253 | status.GetProperty(TemplateSettingPropertyGetter.Property.ScriptName).stringValue
254 | );
255 | var code = status.GetProperty(TemplateSettingPropertyGetter.Property.Code).stringValue;
256 |
257 | var path = Replace(createPath, result);
258 | TemplateUtility.CreateScript(
259 | path,
260 | Replace(code, result),
261 | (TemplateUtility.OverwriteType) status.GetProperty(TemplateSettingPropertyGetter.Property.Overwrite).enumValueIndex
262 | );
263 |
264 | if (isRefresh)
265 | {
266 | AssetDatabase.ImportAsset(path);
267 | TemplateUtility.RefreshEditor();
268 | }
269 |
270 | // プレハブ生成登録
271 | var prefabObject = status.GetProperty(TemplateSettingPropertyGetter.Property.DuplicatePrefab).objectReferenceValue as GameObject;
272 | if (prefabObject != null)
273 | {
274 | TemplatePrefabCreator.AddTempCreatePrefabSetting(status.TargetTemplateSetting, path);
275 | }
276 | }
277 |
278 | public static string Replace(string text, Dictionary result)
279 | {
280 | return ReplaceProcessor.ReplaceProcess(
281 | text,
282 | result
283 | );
284 | }
285 |
286 | public static void ExecuteChain(TemplateSettingStatus status, ProcessDictionary result)
287 | {
288 | var metadata = new ProcessMetadata(status.TargetTemplateSetting);
289 | var property = status.GetProperty(TemplateSettingPropertyGetter.Property.Chain);
290 | for (int i = 0; i < property.arraySize; ++i)
291 | {
292 | TemplateUtility.ExecuteProcessChain(property.GetArrayElementAtIndex(i).objectReferenceValue, metadata, result);
293 | }
294 | }
295 |
296 | public static void DrawReplace(List replaces, string savePrefix)
297 | {
298 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
299 | if (replaces.Count == 0)
300 | {
301 | EditorGUILayout.HelpBox("{} in 'Create Path' and 'Script Name' and 'Code' will be replace\nNote: Variables used in 'Pre Process' are not listed here.", MessageType.Info);
302 | }
303 | else
304 | {
305 | foreach (var replace in replaces)
306 | {
307 | var str = EditorGUILayout.TextField(ReplaceProcessor.GetReplaceText(replace.Key), replace.ReplaceWord);
308 | if (str == replace.ReplaceWord)
309 | {
310 | continue;
311 | }
312 |
313 | // 置き換え文字をUnityへキャッシュ
314 | replace.ReplaceWord = str;
315 | TemplateUtility.SetConfigValue(savePrefix + replace.Key, replace.ReplaceWord);
316 | }
317 | }
318 | EditorGUILayout.EndVertical();
319 | }
320 |
321 | public static void DrawCode(TemplateSettingStatus status)
322 | {
323 | var height = status.GetProperty(TemplateSettingPropertyGetter.Property.CodeAreaHeight);
324 |
325 | EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle());
326 | {
327 | EditorGUILayout.PropertyField(height, new GUIContent("Min Height"));
328 | }
329 | EditorGUILayout.EndHorizontal();
330 |
331 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
332 | {
333 | var code = status.GetProperty(TemplateSettingPropertyGetter.Property.Code).stringValue;
334 | var scrollPos = status.GetProperty(TemplateSettingPropertyGetter.Property.ScrollPos);
335 | var scroll = scrollPos.vector2Value;
336 | var editedCode = SyntaxHighlightUtility.DrawCSharpCode(ref scroll, code, 12, height.floatValue, height.floatValue);
337 | scrollPos.vector2Value = scroll;
338 | if (editedCode != code)
339 | {
340 | status.GetProperty(TemplateSettingPropertyGetter.Property.Code).stringValue = editedCode;
341 | status.IsUpdateText = true;
342 | Undo.IncrementCurrentGroup();
343 | }
344 | }
345 | EditorGUILayout.EndVertical();
346 | }
347 |
348 | public static void DrawPrefab(TemplateSettingStatus status)
349 | {
350 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
351 | {
352 | var prefabProperty = status.GetProperty(TemplateSettingPropertyGetter.Property.DuplicatePrefab);
353 | var targetProperty = status.GetProperty(TemplateSettingPropertyGetter.Property.AttachTarget);
354 |
355 | var oldObj = prefabProperty.objectReferenceValue as GameObject;
356 | EditorGUILayout.PropertyField(prefabProperty, new GUIContent("Attach Prefab"), true);
357 |
358 | var obj = prefabProperty.objectReferenceValue as GameObject;
359 | if (obj == null || PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab)
360 | {
361 | targetProperty.objectReferenceValue = null;
362 |
363 | EditorGUILayout.EndVertical();
364 | return;
365 | }
366 |
367 | if (oldObj != obj)
368 | {
369 | prefabProperty.objectReferenceValue = PrefabUtility.FindRootGameObjectWithSameParentPrefab(obj);
370 | targetProperty.objectReferenceValue = null;
371 | }
372 |
373 | EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle());
374 | {
375 | if (GUILayout.Button("Change Attach Target"))
376 | {
377 | PrefabTreeViewWindow.Open(obj, targetProperty.objectReferenceValue as GameObject, (targetObj) =>
378 | {
379 | status.TargetSerializedObject.Update();
380 | status.GetProperty(TemplateSettingPropertyGetter.Property.AttachTarget).objectReferenceValue = targetObj;
381 | status.TargetSerializedObject.ApplyModifiedProperties();
382 | });
383 | }
384 |
385 | EditorGUILayout.LabelField(targetProperty.objectReferenceValue == null ? string.Empty : targetProperty.objectReferenceValue.name);
386 | }
387 | EditorGUILayout.EndHorizontal();
388 |
389 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
390 | {
391 | var pathProperty = status.GetProperty(TemplateSettingPropertyGetter.Property.PrefabPath);
392 | EditorGUILayout.PropertyField(pathProperty, new GUIContent("Create Prefab Path"), true);
393 |
394 | var paths = EditorGUIHelper.DrawDragAndDropArea();
395 | if (paths != null && paths.Length > 0)
396 | {
397 | pathProperty.stringValue = paths[0];
398 | }
399 |
400 | if (string.IsNullOrEmpty(pathProperty.stringValue))
401 | {
402 | EditorGUILayout.HelpBox("If empty, the script will be created in active folder", MessageType.Info);
403 | }
404 |
405 | EditorGUILayout.HelpBox("Example: Assets/Folder", MessageType.Info);
406 | }
407 | EditorGUILayout.EndVertical();
408 |
409 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
410 | {
411 | var nameProperty = status.GetProperty(TemplateSettingPropertyGetter.Property.PrefabName);
412 | EditorGUILayout.PropertyField(nameProperty, new GUIContent("Prefab Name"), true);
413 |
414 | if (string.IsNullOrEmpty(nameProperty.stringValue))
415 | {
416 | EditorGUILayout.HelpBox("Example: ExamplePrefab", MessageType.Info);
417 | }
418 | }
419 | EditorGUILayout.EndVertical();
420 | }
421 | EditorGUILayout.EndVertical();
422 | }
423 |
424 | private void DrawIsAssetsMenuItem()
425 | {
426 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
427 | {
428 | var cache = SettingStatus.TargetTemplateSetting.IsAssetsMenuItem;
429 | var isAssetMenuProperty = SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.AssetsMenuItem);
430 | EditorGUILayout.PropertyField(isAssetMenuProperty, new GUIContent("Add Asset Menu"));
431 |
432 | // 生成時に設定反映が間に合わないため
433 | SettingStatus.TargetTemplateSetting.IsAssetsMenuItem = isAssetMenuProperty.boolValue;
434 |
435 | if (cache != SettingStatus.TargetTemplateSetting.IsAssetsMenuItem)
436 | {
437 | AssetsMenuItemProcessor.Execute();
438 | }
439 |
440 | EditorGUILayout.HelpBox("Add a menu item to \"Assets/Create/Template/~\"", MessageType.Info);
441 | }
442 | EditorGUILayout.EndVertical();
443 | }
444 |
445 | private void DrawCreate()
446 | {
447 | EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle());
448 | {
449 | if (GUILayout.Button("Create"))
450 | {
451 | Create(null, true);
452 | return;
453 | }
454 |
455 | if (GUILayout.Button("No Refresh Create"))
456 | {
457 |
458 | Create(null, false);
459 | return;
460 | }
461 | }
462 | EditorGUILayout.EndHorizontal();
463 | }
464 |
465 | public void Create(ProcessDictionary result = null, bool isRefresh = true)
466 | {
467 | CreateScript(SettingStatus, _replaceList, result, isRefresh);
468 | }
469 |
470 | private void DrawDescription()
471 | {
472 | EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
473 | {
474 | var property = SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.Description);
475 | // TODO : Cache
476 | var style = new GUIStyle(GUI.skin.textArea)
477 | {
478 | wordWrap = true,
479 | };
480 | property.stringValue = EditorGUILayout.TextArea(property.stringValue, style);
481 | }
482 | EditorGUILayout.EndVertical();
483 | }
484 |
485 | private void UpdateFoldout()
486 | {
487 | var property = SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.IsFoldouts);
488 | for (int i = 0; i < _foldouts.Length; ++i)
489 | {
490 | if (property.arraySize <= i)
491 | {
492 | property.InsertArrayElementAtIndex(i);
493 | }
494 |
495 | var isFoldoutProperty = property.GetArrayElementAtIndex(i);
496 | isFoldoutProperty.boolValue = _foldouts[i].IsFoldout;
497 | }
498 | }
499 |
500 | private void UpdateReplaceList(bool isForce = false)
501 | {
502 | if (isForce == false && SettingStatus.IsUpdateText == false)
503 | {
504 | // 更新なし
505 | return;
506 | }
507 |
508 | SettingStatus.IsUpdateText = false;
509 | var words = ReplaceProcessor.GetReplaceWords(
510 | SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.Path).stringValue,
511 | SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.ScriptName).stringValue,
512 | SettingStatus.GetProperty(TemplateSettingPropertyGetter.Property.Code).stringValue
513 | );
514 |
515 | RemoveChainWords(words, SettingStatus.TargetTemplateSetting.Chain);
516 | _replaceList = CreateReplaceList(_replaceList, words.ToArray());
517 | SetReplaceListFromConfigValue(_replaceList, _instanceId);
518 | }
519 |
520 | public static void RemoveChainWords(ICollection words, object[] objects)
521 | {
522 | if (objects == null)
523 | {
524 | return;
525 | }
526 |
527 | var chains = new List();
528 | foreach (var obj in objects)
529 | {
530 | var chain = TemplateUtility.ConvertProcessChianInstanceFromObject(obj);
531 | if (chain != null)
532 | {
533 | chains.Add(chain);
534 | }
535 | }
536 |
537 | foreach (var chain in chains)
538 | {
539 | foreach (var word in chain.GetReplaceWords())
540 | {
541 | words.Remove(word);
542 |
543 | // ToArray = 遅延実行だとエラーになるため
544 | var regex = new Regex(string.Format(ProcessDictionary.ConvertWordPattern, word, @"\d+"), RegexOptions.IgnoreCase);
545 | foreach (var matchWord in words.Where(w => regex.IsMatch(w)).ToArray())
546 | {
547 | words.Remove(matchWord);
548 | }
549 | }
550 | }
551 | }
552 |
553 | public static List CreateReplaceList(List oldReplaces, string[] words)
554 | {
555 | var replaces = new List();
556 | foreach (var word in words)
557 | {
558 | var replace = oldReplaces.FirstOrDefault(info => info.Key == word) ??
559 | new ReplaceInfo()
560 | {
561 | Key = word
562 | };
563 |
564 | replaces.Add(replace);
565 | }
566 |
567 | return replaces;
568 | }
569 | }
570 | }
571 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateSettingEditor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0a4221a5269a049c3aa48f31f377b5a3
3 | timeCreated: 1509959741
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Setting/TemplateSettingPropertyGetter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEditor;
3 |
4 | public partial class TemplateSettingPropertyGetter
5 | {
6 | public enum Property
7 | {
8 | @Path,
9 | @ScriptName,
10 | @Code,
11 | @CodeAreaHeight,
12 | @Overwrite,
13 | @Chain,
14 | @DuplicatePrefab,
15 | @AttachTarget,
16 | @PrefabPath,
17 | @PrefabName,
18 | @AssetsMenuItem,
19 | @Description,
20 | @IsFoldouts,
21 | @ScrollPos,
22 | }
23 |
24 | private readonly SerializedProperty[] _properties;
25 |
26 | public TemplateSettingPropertyGetter(SerializedObject targetSerializedObject)
27 | {
28 | var names = Enum.GetNames(typeof(Property));
29 | _properties = new SerializedProperty[names.Length];
30 | for (int i = 0; i < _properties.Length; ++i)
31 | {
32 | _properties[i] = targetSerializedObject.FindProperty(names[i]);
33 | }
34 | }
35 |
36 | public SerializedProperty GetProperty(Property type)
37 | {
38 | return _properties[(int) type];
39 | }
40 | }
--------------------------------------------------------------------------------
/Editor/Setting/TemplateSettingPropertyGetter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d551f3cdeb622415395ba474bf7d7d8d
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6dba137c48663430283ef75753854292
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: edd2533cbffee43f58b763c3681fe50c
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b5837b01d087944fcac788ab47874b0e
3 | folderAsset: yes
4 | timeCreated: 1511098395
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Group.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c12009d55a5074879b7dc808535a2a72
3 | folderAsset: yes
4 | timeCreated: 1511102861
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Group/CSharpGroupSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 9e941bf24431d40e896812ec95fef8c5, type: 3}
12 | m_Name: CSharpGroupSetting
13 | m_EditorClassIdentifier:
14 | Settings:
15 | - {fileID: 11400000, guid: 2ebb28d90281c494ea4482bc607f5ca6, type: 2}
16 | - {fileID: 11400000, guid: 9efcf6842513e4ddd927d0318702dedb, type: 2}
17 | - {fileID: 11400000, guid: 610215da0b7314223ba73f14519053a8, type: 2}
18 | - {fileID: 11400000, guid: 58414467eaf3a4a1bad5fc6fade9b75a, type: 2}
19 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Group/CSharpGroupSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d81e71d8a3f0b48438a3f3a25bfe3248
3 | timeCreated: 1511106563
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2ada920699a994210ab2d8131d929da4
3 | folderAsset: yes
4 | timeCreated: 1511110682
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns/Comment.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 275fdc00e05454525a874cb22e40bfc4, type: 3}
12 | m_Name: Comment
13 | m_EditorClassIdentifier:
14 | Format: (?<{0}>({1}))
15 | FormatTypeText: Normal
16 | Color: 4CF22CFF
17 | Patterns:
18 | - /\*[\s\S]*?\*/|//.*
19 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns/Comment.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2ebb28d90281c494ea4482bc607f5ca6
3 | timeCreated: 1511104634
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns/Replace.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 275fdc00e05454525a874cb22e40bfc4, type: 3}
12 | m_Name: Replace
13 | m_EditorClassIdentifier:
14 | Format: (?<{0}>({1}))
15 | FormatTypeText: Normal
16 | Color: F1FF04FF
17 | Patterns:
18 | - '{<[\s\S]+?>}'
19 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns/Replace.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9efcf6842513e4ddd927d0318702dedb
3 | timeCreated: 1511104634
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns/ReservedWords.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 275fdc00e05454525a874cb22e40bfc4, type: 3}
12 | m_Name: ReservedWords
13 | m_EditorClassIdentifier:
14 | Format: (?<{0}>(?({1}))
15 | FormatTypeText: Normal
16 | Color: FF5F51FF
17 | Patterns:
18 | - (\"[^\"\\n]*\")
19 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns/String.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 610215da0b7314223ba73f14519053a8
3 | timeCreated: 1511104634
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/Patterns/SubsetReservedWords.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 275fdc00e05454525a874cb22e40bfc4, type: 3}
12 | m_Name: SubsetReservedWords
13 | m_EditorClassIdentifier:
14 | Format: (?<{0}>(? string.Format(
17 | setting.Format,
18 | setting.GetInstanceID(),
19 | string.Join("|", setting.Patterns))
20 | ).ToArray();
21 |
22 | var combinedPattern = string.Format("({0})", string.Join("|", patterns));
23 |
24 | _regex = new Regex(combinedPattern, RegexOptions.Compiled);
25 | _evaluator = match =>
26 | {
27 | foreach (var setting in Settings)
28 | {
29 | // TODO : check ToString
30 | if (match.Groups[setting.GetInstanceID().ToString()].Success)
31 | {
32 | return string.Format("{0}", match.Value, setting.Color);
33 | }
34 | }
35 |
36 | return match.Value;
37 | };
38 | }
39 |
40 | public string Highlight(string text)
41 | {
42 | if (string.IsNullOrEmpty(text))
43 | {
44 | return text;
45 | }
46 |
47 | return _regex.Replace(text, _evaluator);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/SyntaxHighlightGroupSetting.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9e941bf24431d40e896812ec95fef8c5
3 | timeCreated: 1511100799
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/SyntaxHighlightSetting.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace SyntaxHighlightEditor
4 | {
5 | public class SyntaxHighlightSetting : ScriptableObject
6 | {
7 | public string Format;
8 | public string FormatTypeText;
9 | public string Color;
10 | public string[] Patterns;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/SyntaxHighlightSetting.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 275fdc00e05454525a874cb22e40bfc4
3 | timeCreated: 1511098429
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/Setting/SyntaxhighlightSettingEditor.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 | using UnityEngine;
3 | using System;
4 |
5 | namespace SyntaxHighlightEditor
6 | {
7 | [CustomEditor(typeof(SyntaxHighlightSetting))]
8 | public class SyntaxhighlightSettingEditor : Editor
9 | {
10 | ///
11 | /// Property.
12 | /// SyntaxhighlightSetting のメンバ名と同じにする
13 | ///
14 | public enum Property
15 | {
16 | Format,
17 | FormatTypeText,
18 | Color,
19 | Patterns
20 | }
21 |
22 | private enum Format
23 | {
24 | Custom = -1,
25 | Normal,
26 | Delimit,
27 | }
28 |
29 | private static readonly string[] Formats =
30 | {
31 | "(?<{0}>({1}))",
32 | "(?<{0}>(?
18 | /// C#のコードエリアを表示
19 | ///
20 | public static string DrawCSharpCode(ref Vector2 scrollPos, string code, int fontSize = DefaultFontSize, float minHeight = -1f, float maxHeight = -1f)
21 | {
22 | string editedCode;
23 |
24 | minHeight = minHeight <= 0f ? DefaultMinHeight : minHeight;
25 | maxHeight = maxHeight <= 0f ? Screen.height : maxHeight;
26 |
27 | scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.MinHeight(minHeight), GUILayout.MaxHeight(maxHeight));
28 | {
29 | if (_style == null)
30 | {
31 | _style = new GUIStyle(GUI.skin.textArea)
32 | {
33 | padding = new RectOffset(4, 4, 4, 4),
34 | wordWrap = false,
35 | };
36 | }
37 | _style.fontSize = fontSize;
38 |
39 | editedCode = GetCSharpEditor().Draw(code, _style, GUILayout.ExpandHeight(true));
40 | }
41 | EditorGUILayout.EndScrollView();
42 |
43 | return editedCode;
44 | }
45 |
46 | public static TextAreaSyntaxHighlightEditor GetCSharpEditor()
47 | {
48 | if (_syntaxHighlightGroupSetting == null)
49 | {
50 | var path = AssetDatabase.GUIDToAssetPath(CSharpGroupSettingGuid);
51 | _syntaxHighlightGroupSetting = AssetDatabase.LoadAssetAtPath(path);
52 | }
53 |
54 | if (_editor == null)
55 | {
56 | _editor = new TextAreaSyntaxHighlightEditor();
57 | _editor.BackgroundColor = Color.gray;
58 | _editor.TextColor = Color.white;
59 |
60 | _syntaxHighlightGroupSetting.Initialize();
61 | _editor.Highlighter = _syntaxHighlightGroupSetting.Highlight;
62 | }
63 |
64 | return _editor;
65 | }
66 |
67 | public static void ResetCSharpEditor()
68 | {
69 | _editor = null;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/SyntaxHighlightUtility.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 73928e07e6ef6440a8c6af2fb5237f0b
3 | timeCreated: 1511102675
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/TextAreaSyntaxHighlightEditor.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UnityEditor;
3 |
4 | namespace SyntaxHighlightEditor
5 | {
6 | ///
7 | /// Code editor.
8 | ///
9 | public class TextAreaSyntaxHighlightEditor
10 | {
11 | public Color BackgroundColor { get; set; }
12 |
13 | public Color TextColor { get; set; }
14 |
15 | public System.Func Highlighter { get; set; }
16 |
17 | public string CachedHighlightedCode { get; set; }
18 |
19 | private string _cachedCode;
20 |
21 | public TextAreaSyntaxHighlightEditor()
22 | {
23 | BackgroundColor = Color.black;
24 | TextColor = Color.white;
25 | Highlighter = code => code;
26 | }
27 |
28 | public string Draw(string code, GUIStyle style, params GUILayoutOption[] options)
29 | {
30 | // 文字を透明にする
31 | var backStyle = new GUIStyle(style);
32 | SetStyleTextColor(backStyle, Color.gray);
33 |
34 | // 現在の色を保存
35 | var preBackgroundColor = GUI.backgroundColor;
36 | var preColor = GUI.color;
37 |
38 | // 編集用のテキストエリアを描画
39 | GUI.backgroundColor = BackgroundColor;
40 | var editedCode = EditorGUILayout.TextArea(code, backStyle, options);
41 |
42 | // シンタックスハイライトさせたコードを更新
43 | if (editedCode != _cachedCode)
44 | {
45 | CachedHighlightedCode = Highlighter(editedCode);
46 | _cachedCode = editedCode;
47 | }
48 |
49 | // 文字(シンタックスハイライトされない部分)を指定色にする
50 | var forwardStyle = new GUIStyle(style);
51 | SetStyleTextColor(forwardStyle, TextColor);
52 | forwardStyle.richText = true;
53 |
54 | // シンタックスハイライト用のテキストエリアを表示
55 | GUI.backgroundColor = Color.clear;
56 | EditorGUI.TextArea(GUILayoutUtility.GetLastRect(), CachedHighlightedCode, forwardStyle);
57 |
58 | // 色を元に戻す
59 | GUI.backgroundColor = preBackgroundColor;
60 | GUI.color = preColor;
61 |
62 | return editedCode;
63 | }
64 |
65 | private void SetStyleTextColor(GUIStyle style, Color color)
66 | {
67 | style.normal.textColor = color;
68 | style.hover.textColor = color;
69 | style.active.textColor = color;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Editor/SyntaxHilightEditor/Editor/TextAreaSyntaxHighlightEditor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9e05ceecc09ff40cf86cd254ceca1342
3 | timeCreated: 1509959133
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateEditor.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TemplateEditor",
3 | "references": [],
4 | "optionalUnityReferences": [],
5 | "includePlatforms": [
6 | "Editor"
7 | ],
8 | "excludePlatforms": [],
9 | "allowUnsafeCode": false,
10 | "overrideReferences": false,
11 | "precompiledReferences": [],
12 | "autoReferenced": true,
13 | "defineConstraints": [],
14 | "versionDefines": []
15 | }
--------------------------------------------------------------------------------
/Editor/TemplateEditor.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6ab527da90c0d46acb7464acbcbb22db
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor/TemplateTool.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cd19160480675452aa5113fce590cbe9
3 | folderAsset: yes
4 | timeCreated: 1517392829
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/AssetsMenuItemCreator.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e9fb1287ecb3a40218874ef197c1f123
3 | folderAsset: yes
4 | timeCreated: 1517392857
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/AssetsMenuItemCreator/AssetsMenuItemProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using UnityEditor;
4 |
5 |
6 | namespace TemplateEditor
7 | {
8 | public class AssetsMenuItemProcessor : IProcessChain
9 | {
10 | private static readonly string AssetsMenuItemScriptName = "TemplateEditorAssetsMenuItem";
11 |
12 | private enum ReplaceWordType
13 | {
14 | Settings,
15 | GroupSettings,
16 | CreatePath,
17 | ScriptName,
18 | }
19 |
20 | private static readonly string[] ReplaceWords =
21 | {
22 | "Settings",
23 | "GroupSettings",
24 | "CreatePath",
25 | "ScriptName",
26 | };
27 |
28 | ///
29 | /// 生成を実行
30 | ///
31 | public static void Execute()
32 | {
33 | var setting = ToolExecutor.GetUseUserSetting().GetSetting(UserSetting.SettingType.AssetsMenuItemCreator);
34 | TemplateUtility.ExecuteSetting(setting);
35 | }
36 |
37 | private List BuildMenuItemList() where T : UnityEngine.Object
38 | {
39 | var list = new List();
40 | foreach (var guid in TemplateUtility.FindAssetGuids(typeof(T)))
41 | {
42 | var path = AssetDatabase.GUIDToAssetPath(guid);
43 | var setting = AssetDatabase.LoadAssetAtPath(path) as IAssetsMenuItem;
44 | if (setting == null || setting.IsAssetsMenuItem == false)
45 | {
46 | continue;
47 | }
48 |
49 | var name = Path.GetFileNameWithoutExtension(path);
50 | var array = new string[2];
51 | array[0] = name;
52 | array[1] = guid;
53 | list.Add(array);
54 | }
55 |
56 | return list;
57 | }
58 |
59 | public void Process(ProcessMetadata metadata, ProcessDictionary result)
60 | {
61 | var createPath = TemplateUtility.GetFilePathFromFileName(AssetsMenuItemScriptName + ".cs") ?? "Assets/TemplateEditorTool/Editor";
62 | result.Add(ReplaceWords[(int) ReplaceWordType.Settings], BuildMenuItemList());
63 | result.Add(ReplaceWords[(int) ReplaceWordType.GroupSettings], BuildMenuItemList());
64 | result.Add(ReplaceWords[(int) ReplaceWordType.CreatePath], createPath);
65 | result.Add(ReplaceWords[(int) ReplaceWordType.ScriptName], AssetsMenuItemScriptName);
66 | }
67 |
68 | public string[] GetReplaceWords()
69 | {
70 | return ReplaceWords;
71 | }
72 |
73 | public string GetDescription()
74 | {
75 | return "TemplateをAssetメニューへ追加するための情報を提供します";
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/AssetsMenuItemCreator/AssetsMenuItemProcessor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d5ff4f963aaf6468baa7eaee66e3e384
3 | timeCreated: 1522849718
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/AssetsMenuItemCreator/AssetsMenuItemSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: AssetsMenuItemSetting
14 | m_EditorClassIdentifier:
15 | Path: '{}'
16 | ScriptName: '{}.cs'
17 | Code: "using UnityEditor;\nusing TemplateEditor;\n\npublic class {}\n{\n
18 | private const string MenuItemPrefix = \"Assets/Create/Template/\";\n\n [MenuItem(MenuItemPrefix,
19 | false, 0)]\n public static void Dummy()\n {\n }\n{}\n{}\n}\n"
24 | CodeAreaHeight: 200
25 | Overwrite: 1
26 | Chain:
27 | - {fileID: 11500000, guid: d5ff4f963aaf6468baa7eaee66e3e384, type: 3}
28 | DuplicatePrefab: {fileID: 0}
29 | AttachTarget: {fileID: 0}
30 | PrefabPath:
31 | PrefabName:
32 | AssetsMenuItem: 0
33 | Description: "\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u30E1\u30CB\u30E5\u30FC\u3078\u8FFD\u52A0\u3059\u308B\u305F\u3081\u306E\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u3067\u3059\u3002\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u30A8\u30C7\u30A3\u30BF\u81EA\u8EAB\u304C\u4F7F\u7528\u3057\u3066\u3044\u307E\u3059\u3002\u57FA\u672C\u7684\u306B\u5909\u66F4\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002"
34 | IsFoldouts: 010000
35 | ScrollPos: {x: 0, y: 217}
36 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/AssetsMenuItemCreator/AssetsMenuItemSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1c95e1425131048ba82aeb753fe906b4
3 | timeCreated: 1517392896
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/AssetsMenuItemCreator/IAssetsMenuItem.cs:
--------------------------------------------------------------------------------
1 | namespace TemplateEditor
2 | {
3 | public interface IAssetsMenuItem
4 | {
5 | bool IsAssetsMenuItem { get; set; }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/AssetsMenuItemCreator/IAssetsMenuItem.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e274080a37c884d6094f6281f11f63d0
3 | timeCreated: 1522849860
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2cafc8dd80ff34a47891a43d599468c2
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/CustomEditorCreateWindow.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using UnityEngine;
6 | using UnityEditor;
7 | using Object = UnityEngine.Object;
8 |
9 | namespace TemplateEditor
10 | {
11 | public class CustomEditorCreateWindow : EditorWindow
12 | {
13 | public static void Open()
14 | {
15 | GetWindow(true);
16 | }
17 |
18 | private ScriptableObject _targetScriptableObject;
19 | private MonoScript _targetScriptableClass;
20 |
21 | private void OnGUI()
22 | {
23 | _targetScriptableObject = EditorGUILayout.ObjectField(_targetScriptableObject, typeof(ScriptableObject), false) as ScriptableObject;
24 | EditorGUILayout.LabelField(" or");
25 | _targetScriptableClass = EditorGUILayout.ObjectField(_targetScriptableClass, typeof(MonoScript), false) as MonoScript;
26 |
27 | if (_targetScriptableObject == null && _targetScriptableClass == null)
28 | {
29 | return;
30 | }
31 |
32 | if (GUILayout.Button("生成") == false)
33 | {
34 | return;
35 | }
36 |
37 | var type = _targetScriptableClass.GetClass();
38 | if (_targetScriptableObject != null)
39 | {
40 | type = _targetScriptableObject.GetType();
41 | }
42 |
43 | var path = Path.GetDirectoryName(AssetDatabase.GetAssetPath((Object)_targetScriptableObject ?? _targetScriptableClass));
44 | var targetScriptableObject = ScriptableObject.CreateInstance(type);
45 |
46 | var targetName = type.Name;
47 | var targetUseSerializeNames = ScriptableObjectUtility.GetSerializeNamesWithoutDefault(targetScriptableObject);
48 |
49 | var customEditorName = targetName + "Editor";
50 | var propertyGetterName = targetName + "PropertyGetter";
51 | var result = new ProcessDictionary();
52 | result.Add("TargetNamespace", "using " + type.Namespace + ";");
53 | result.Add("CustomEditorCreatePath", TemplateUtility.GetFilePathFromFileName(customEditorName + ".cs") ?? path);
54 | result.Add("PropertyGetterCreatePath", TemplateUtility.GetFilePathFromFileName(propertyGetterName + ".cs") ?? path);
55 | result.Add("TargetScriptableObjectName", targetName);
56 | result.Add("CustomEditorName", customEditorName);
57 | result.Add("PropertyGetterName", propertyGetterName);
58 | result.Add("TypeNames", targetUseSerializeNames.Select(StringBuilderExtension.ConvertEnumName).ToArray());
59 | result.Add("PropertyNames", targetUseSerializeNames);
60 |
61 | var setting = ToolExecutor.GetUseUserSetting().GetSetting(UserSetting.GroupSettingType.CustomEditorCreator);
62 | TemplateUtility.ExecuteGroupSetting(setting, result);
63 |
64 | DestroyImmediate(targetScriptableObject);
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/CustomEditorCreateWindow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 59c23c8ae288644d1ad76e370bc5a59a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/Setting.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9c3b49e90be58419db5636a69a6a48f3
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/Setting/CustomEditorCreatorGroupSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: f14bca261b81e4c66a1a2a293cfd3893, type: 3}
13 | m_Name: CustomEditorCreatorGroupSetting
14 | m_EditorClassIdentifier:
15 | Settings:
16 | - {fileID: 11400000, guid: 52949e797d3da490bb606e5c1111a060, type: 2}
17 | - {fileID: 11400000, guid: f23b83ea2ec5e470aa129be3fd5e5124, type: 2}
18 | AssetsMenuItem: 0
19 | Description:
20 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/Setting/CustomEditorCreatorGroupSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 39929be43dcc041049feecc87d7f23d3
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/Setting/CustomEditorSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: CustomEditorSetting
14 | m_EditorClassIdentifier:
15 | Path: '{}'
16 | ScriptName: '{}.cs'
17 | Code: "using UnityEditor;\nusing UnityEngine;\n{}\n\n[CanEditMultipleObjects]\n[CustomEditor(typeof({}))]\npublic
18 | class {} : Editor\n{\n private {} _propertyGetter;\n\n
19 | \ private void OnEnable()\n {\n _propertyGetter = new {}(serializedObject);\n
20 | \ }\n}"
21 | CodeAreaMinHeight: 200
22 | CodeAreaMaxHeight: 200
23 | Overwrite: 0
24 | Chain: []
25 | DuplicatePrefab: {fileID: 0}
26 | AttachTarget: {fileID: 0}
27 | PrefabPath:
28 | PrefabName:
29 | AssetsMenuItem: 0
30 | Description:
31 | IsFoldouts: 010101
32 | ScrollPos: {x: 0, y: 23}
33 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/Setting/CustomEditorSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 52949e797d3da490bb606e5c1111a060
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/Setting/PropertyGetterSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: PropertyGetterSetting
14 | m_EditorClassIdentifier:
15 | Path: '{}'
16 | ScriptName: '{}.cs'
17 | Code: "using System;\nusing UnityEditor;\n\npublic partial class {}\n{\n
18 | \ public enum Property\n {\n{}\n }\n\n
19 | \ private static readonly string[] PropertyNames =\n {\n{}\n
20 | \ };\n\n private readonly SerializedProperty[] _properties;\n\n public
21 | {}(SerializedObject targetSerializedObject)\n {\n var
22 | names = Enum.GetNames(typeof(Property));\n _properties = new SerializedProperty[names.Length];\n
23 | \ for (int i = 0; i < _properties.Length; ++i)\n {\n _properties[i]
24 | = targetSerializedObject.FindProperty(names[i]);\n }\n }\n\n public
25 | SerializedProperty GetProperty(Property type)\n {\n return _properties[(int)
26 | type];\n }\n}"
27 | CodeAreaMinHeight: 200
28 | CodeAreaMaxHeight: 200
29 | Overwrite: 1
30 | Chain: []
31 | DuplicatePrefab: {fileID: 0}
32 | AttachTarget: {fileID: 0}
33 | PrefabPath:
34 | PrefabName:
35 | AssetsMenuItem: 0
36 | Description:
37 | IsFoldouts: 010101
38 | ScrollPos: {x: 0, y: 0}
39 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/CustomEditorCreator/Setting/PropertyGetterSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f23b83ea2ec5e470aa129be3fd5e5124
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2298383a9548d4b8b96972f536dd9f33
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/EditorWindowSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: EditorWindowSetting
14 | m_EditorClassIdentifier:
15 | Path:
16 | ScriptName: '{}.cs'
17 | Code: "using UnityEngine;\nusing UnityEditor;\n\n[CreateAssetMenu]\npublic class
18 | {} : EditorWindow\n{\n [MenuItem(\"Test/Window/{}\")]\n
19 | \ public static void Open()\n {\n GetWindow<{}>(true);\n
20 | \ }\n\n private void OnGUI()\n {\n }\n}"
21 | CodeAreaHeight: 100
22 | Overwrite: 0
23 | Chain: []
24 | DuplicatePrefab: {fileID: 0}
25 | AttachTarget: {fileID: 0}
26 | PrefabPath:
27 | PrefabName:
28 | AssetsMenuItem: 0
29 | Description:
30 | IsFoldouts: 010101
31 | ScrollPos: {x: 0, y: 58.00049}
32 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/EditorWindowSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9027646eff5be417982da6abdd36a3ce
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/MonoBehaviourSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: MonoBehaviourSetting
14 | m_EditorClassIdentifier:
15 | Path:
16 | ScriptName: '{}.cs'
17 | Code: 'using UnityEngine;
18 |
19 |
20 | public class {} : MonoBehaviour
21 |
22 | {
23 |
24 | }'
25 | CodeAreaHeight: 100
26 | Overwrite: 0
27 | Chain: []
28 | DuplicatePrefab: {fileID: 0}
29 | AttachTarget: {fileID: 0}
30 | PrefabPath:
31 | PrefabName:
32 | AssetsMenuItem: 0
33 | Description:
34 | IsFoldouts: 010101
35 | ScrollPos: {x: 0, y: 0}
36 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/MonoBehaviourSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8bc6cbcc4a40f4052b7e86a88892abec
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/PureCSharpSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: PureCSharpSetting
14 | m_EditorClassIdentifier:
15 | Path:
16 | ScriptName: '{}.cs'
17 | Code: 'using UnityEngine;
18 |
19 |
20 | public class {}
21 |
22 | {
23 |
24 | }'
25 | CodeAreaHeight: 100
26 | Overwrite: 0
27 | Chain: []
28 | DuplicatePrefab: {fileID: 0}
29 | AttachTarget: {fileID: 0}
30 | PrefabPath:
31 | PrefabName:
32 | AssetsMenuItem: 0
33 | Description:
34 | IsFoldouts: 010101
35 | ScrollPos: {x: 0, y: 0}
36 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/PureCSharpSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 97b4a1e1e5de54dd2b95554ff3aaaf69
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/ScriptableObjectSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: ScriptableObjectSetting
14 | m_EditorClassIdentifier:
15 | Path:
16 | ScriptName: '{}.cs'
17 | Code: 'using UnityEngine;
18 |
19 |
20 | [CreateAssetMenu]
21 |
22 | public class {} : ScriptableObject
23 |
24 | {
25 |
26 | }'
27 | CodeAreaHeight: 100
28 | Overwrite: 0
29 | Chain: []
30 | DuplicatePrefab: {fileID: 0}
31 | AttachTarget: {fileID: 0}
32 | PrefabPath:
33 | PrefabName:
34 | AssetsMenuItem: 0
35 | Description:
36 | IsFoldouts: 010101
37 | ScrollPos: {x: 0, y: 0}
38 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/DefaultTemplates/ScriptableObjectSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 078b8aa44d22a45ae80dee4d3c52cbbb
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 655a8910d50e942348bb6eb436f0a283
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/ResourcesSupportSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: ResourcesSupportSetting
14 | m_EditorClassIdentifier:
15 | Path: '{}'
16 | ScriptName: '{}.cs'
17 | Code: "{}\n\npublic class {}\n{\n{}\n{}\n{({2}Paths[(int)type]);\n
21 | \ }:Methods>}\n}"
22 | CodeAreaMinHeight: 350
23 | CodeAreaMaxHeight: 350
24 | Overwrite: 1
25 | Chain:
26 | - {fileID: 11400000, guid: 2c9e7c9a1b39a426c8897063ec0a255c, type: 2}
27 | DuplicatePrefab: {fileID: 0}
28 | AttachTarget: {fileID: 0}
29 | PrefabPath:
30 | PrefabName:
31 | AssetsMenuItem: 0
32 | Description:
33 | IsFoldouts: 010101
34 | ScrollPos: {x: 0, y: 0}
35 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/ResourcesSupportSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c02be74c37b2340189ea293c5e5aedd0
3 | timeCreated: 1515150170
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2462425a3176a4f5f8d6ad55e722a532
3 | folderAsset: yes
4 | timeCreated: 1515150158
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9ae1f60abee2642569001b44d4c116d5
3 | folderAsset: yes
4 | timeCreated: 1512393435
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/AudioClipParameter.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 72a8e0263efa142989eedb02241af8b1, type: 3}
12 | m_Name: AudioClipParameter
13 | m_EditorClassIdentifier:
14 | TypeName: AudioClip
15 | EditLoadType: 1
16 | TargetExtensions:
17 | - mp3
18 | - ogg
19 | - wav
20 | - aiff
21 | - aif
22 | - mod
23 | - it
24 | - s3m
25 | - xm
26 | EditUsings:
27 | - UnityEngine
28 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/AudioClipParameter.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: db914c7639f4b41178041c8e99f275a0
3 | timeCreated: 1512393142
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/GameObjectParameter.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 72a8e0263efa142989eedb02241af8b1, type: 3}
12 | m_Name: GameObjectParameter
13 | m_EditorClassIdentifier:
14 | TypeName: GameObject
15 | EditLoadType: 1
16 | TargetExtensions:
17 | - prefab
18 | EditUsings:
19 | - UnityEngine
20 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/GameObjectParameter.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e48a4e00f62f24e2781b11a880a1f698
3 | timeCreated: 1512393142
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/LoadParameter.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System;
3 | using UnityEngine.Serialization;
4 |
5 | namespace TemplateEditor
6 | {
7 | public class LoadParameter : ScriptableObject, IUsings
8 | {
9 | public string TypeName;
10 |
11 | [EnumFlags]
12 | public ResourcesLoaderUtility.LoadType EditLoadType = ResourcesLoaderUtility.LoadType.Load;
13 |
14 | public string[] TargetExtensions;
15 |
16 | public string[] EditUsings;
17 | public string[] usings { get { return EditUsings; } }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/LoadParameter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 72a8e0263efa142989eedb02241af8b1
3 | timeCreated: 1512391491
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/SpriteParameter.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 72a8e0263efa142989eedb02241af8b1, type: 3}
12 | m_Name: SpriteParameter
13 | m_EditorClassIdentifier:
14 | TypeName: Sprite
15 | EditLoadType: 3
16 | TargetExtensions:
17 | - PSD
18 | - TIFF
19 | - JPG
20 | - TGA
21 | - PNG
22 | - GIF
23 | - BMP
24 | - IFF
25 | - PICT
26 | - EXR
27 | - HDR
28 | EditUsings:
29 | - UnityEngine
30 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/SpriteParameter.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 11f88f52f2d00442394580dff2c4bb08
3 | timeCreated: 1512393142
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/TextParameter.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 72a8e0263efa142989eedb02241af8b1, type: 3}
12 | m_Name: TextParameter
13 | m_EditorClassIdentifier:
14 | TypeName: TextAsset
15 | TargetExtensions:
16 | - txt
17 | - html
18 | - htm
19 | - xml
20 | - bytes
21 | - json
22 | - csv
23 | - yaml
24 | - fnt
25 | EditUsings:
26 | - UnityEngine
27 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/TextParameter.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5bcdcb123759c4c30bedf7592da26528
3 | timeCreated: 1512393142
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/TextureParameter.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 0}
8 | m_GameObject: {fileID: 0}
9 | m_Enabled: 1
10 | m_EditorHideFlags: 0
11 | m_Script: {fileID: 11500000, guid: 72a8e0263efa142989eedb02241af8b1, type: 3}
12 | m_Name: TextureParameter
13 | m_EditorClassIdentifier:
14 | TypeName: Texture
15 | EditLoadType: 1
16 | TargetExtensions:
17 | - PSD
18 | - TIFF
19 | - JPG
20 | - TGA
21 | - PNG
22 | - GIF
23 | - BMP
24 | - IFF
25 | - PICT
26 | - EXR
27 | - HDR
28 | EditUsings:
29 | - UnityEngine
30 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/TextureParameter.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d4466f578ceaf41dfb1f13d239e6894c
3 | timeCreated: 1512393142
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/VideoClipParameter.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 72a8e0263efa142989eedb02241af8b1, type: 3}
13 | m_Name: VideoClipParameter
14 | m_EditorClassIdentifier:
15 | TypeName: VideoClip
16 | EditLoadType: 5
17 | TargetExtensions:
18 | - asf
19 | - avi
20 | - dv
21 | - m4v
22 | - mov
23 | - mp4
24 | - mpg
25 | - mpeg
26 | - ogv
27 | - vp8
28 | - webm
29 | - wmv
30 | EditUsings:
31 | - UnityEngine
32 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Parameters/VideoClipParameter.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6ddca123992c6427c970ec944fd13867
3 | timeCreated: 1512393142
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/ResourcesLoaderSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 3dbb03e1ffa314ab8aa37d192f5d8a7d, type: 3}
13 | m_Name: ResourcesLoaderSetting
14 | m_EditorClassIdentifier:
15 | _parameters:
16 | - {fileID: 11400000, guid: db914c7639f4b41178041c8e99f275a0, type: 2}
17 | - {fileID: 11400000, guid: e48a4e00f62f24e2781b11a880a1f698, type: 2}
18 | - {fileID: 11400000, guid: 11f88f52f2d00442394580dff2c4bb08, type: 2}
19 | - {fileID: 11400000, guid: 5bcdcb123759c4c30bedf7592da26528, type: 2}
20 | - {fileID: 11400000, guid: d4466f578ceaf41dfb1f13d239e6894c, type: 2}
21 | - {fileID: 11400000, guid: 6ddca123992c6427c970ec944fd13867, type: 2}
22 | _editUsings:
23 | - UnityEngine
24 | - UnityEngine.Video
25 | _ignoreFileNames: []
26 | _ignorePathPatterns: []
27 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/ResourcesLoaderSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2c9e7c9a1b39a426c8897063ec0a255c
3 | timeCreated: 1512393019
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | mainObjectFileID: 11400000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/ResourcesLoaderSetting.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS0649
2 |
3 | using UnityEngine;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.IO;
7 | using System.Text.RegularExpressions;
8 | using System;
9 | using System.Text;
10 |
11 | namespace TemplateEditor
12 | {
13 | public class ResourcesLoaderSetting : ScriptableObject, IUsings, IProcessChain
14 | {
15 | private static readonly string ResourcesLoaderTemplateGuid = "c02be74c37b2340189ea293c5e5aedd0";
16 | private static readonly string ScriptName = "ResourcesLoader";
17 |
18 | private enum ReplaceWordType
19 | {
20 | CreatePath,
21 | ScriptName,
22 | Usings,
23 | Enums,
24 | Paths,
25 | Methods,
26 | }
27 |
28 | private static readonly string[] ReplaceWords =
29 | {
30 | "CreatePath",
31 | "ScriptName",
32 | "Usings",
33 | "Enums",
34 | "Paths",
35 | "Methods",
36 | };
37 |
38 | public static void Execute()
39 | {
40 | TemplateUtility.ExecuteSetting(ResourcesLoaderTemplateGuid);
41 | }
42 |
43 | #region IProcessChain implementation
44 |
45 | public void Process(ProcessMetadata metadata, ProcessDictionary result)
46 | {
47 | // ファイルパス取得
48 | var removeWord = "Resources/";
49 | var removeWordLength = removeWord.Length;
50 |
51 | // Assets内にあるResourcesフォルダの全てのパスを取得
52 | var resourcesPaths = Directory.GetDirectories("Assets", "Resources", SearchOption.AllDirectories);
53 |
54 | // Resourcesフォルダ内のファイルパスを取得
55 | // TODO : 最適化?
56 | var ignorePatterns = _ignorePathPatterns.Select(pattern => new Regex(pattern, RegexOptions.Compiled));
57 | var filePaths = ResourcesLoaderUtility.GetFilePaths(resourcesPaths, new string[] {".meta"})
58 | .Where(path => _ignoreFileNames.Contains(Path.GetFileNameWithoutExtension(path)) == false)
59 | .Where(path => ignorePatterns.Any(pattern => pattern.IsMatch(path)) == false)
60 | .OrderBy(path => Path.GetFileNameWithoutExtension(path));
61 |
62 | var filePathsList = new List();
63 | var fileNamesList = new List();
64 | var methodsList = new List();
65 | var enumValues = Enum.GetValues(typeof(ResourcesLoaderUtility.LoadType)).Cast().ToArray();
66 | foreach (var parameter in _parameters)
67 | {
68 | // 指定した拡張子のファイルパスを取得
69 | var paths = ResourcesLoaderUtility.FindByExtension(filePaths, parameter.TargetExtensions).Select(path =>
70 | {
71 | var startIndex = path.IndexOf(removeWord) + removeWordLength;
72 | var length = path.Length - startIndex - Path.GetExtension(path).Length;
73 | return path.Substring(startIndex, length);
74 | });
75 |
76 | if (paths.Any() == false)
77 | {
78 | continue;
79 | }
80 |
81 | // スペースは8文字に
82 | var tab = new string(' ', 8);
83 | filePathsList.Add(new string[] {parameter.TypeName, string.Join(",\n" + tab, paths.Select(path => "\"" + path + "\"").ToArray())});
84 |
85 | // ファイルパスからファイル名を取得
86 | // TODO : StringBuilderExtension.ConvertEnumName
87 | var fileNames = paths.Select(Path.GetFileNameWithoutExtension).Select(StringBuilderExtension.ConvertEnumName);
88 | fileNamesList.Add(new string[] {parameter.TypeName, string.Join(",\n" + tab, fileNames.ToArray())});
89 |
90 | var intValue = (int) parameter.EditLoadType;
91 | for (int i = 0; i < enumValues.Length; ++i)
92 | {
93 | if ((intValue & enumValues[i]) == 0)
94 | {
95 | continue;
96 | }
97 |
98 | methodsList.Add(new string[]
99 | {
100 | string.Format(ResourcesLoaderUtility.ReturnNamesFormat[i], parameter.TypeName),
101 | ResourcesLoaderUtility.LoadNames[i],
102 | parameter.TypeName
103 | });
104 | }
105 | }
106 |
107 | // 生成パス設定
108 | result.Add(ReplaceWords[(int)ReplaceWordType.CreatePath], TemplateUtility.GetFilePathFromFileName(ScriptName + ".cs") ?? "Assets");
109 |
110 | // スクリプト名設定
111 | result.Add(ReplaceWords[(int) ReplaceWordType.ScriptName], ScriptName);
112 |
113 | // Usings
114 | {
115 | var usingsList = new List(_parameters.Length + 1);
116 | usingsList.Add(this);
117 | usingsList.AddRange(_parameters);
118 |
119 | var usingNames = new HashSet();
120 | foreach (var usings in usingsList)
121 | {
122 | foreach (var names in usings.usings)
123 | {
124 | usingNames.Add(names);
125 | }
126 | }
127 |
128 | result.Add(
129 | ReplaceWords[(int) ReplaceWordType.Usings],
130 | usingNames.ToArray()
131 | );
132 | }
133 |
134 | // Enums
135 | {
136 | result.Add(
137 | ReplaceWords[(int) ReplaceWordType.Enums],
138 | fileNamesList
139 | );
140 | }
141 |
142 | // Paths
143 | {
144 | result.Add(
145 | ReplaceWords[(int) ReplaceWordType.Paths],
146 | filePathsList
147 | );
148 | }
149 |
150 | // Methods
151 | {
152 | result.Add(
153 | ReplaceWords[(int) ReplaceWordType.Methods],
154 | methodsList
155 | );
156 | }
157 | }
158 |
159 | public string[] GetReplaceWords()
160 | {
161 | return ReplaceWords;
162 | }
163 |
164 | public string GetDescription()
165 | {
166 | return "設定に従い、Resourcesフォルダ内のアセット情報を受け渡します";
167 | }
168 |
169 | #endregion
170 |
171 | [SerializeField]
172 | private LoadParameter[] _parameters;
173 |
174 | [SerializeField]
175 | private string[] _editUsings;
176 | public string[] usings { get { return _editUsings; } }
177 |
178 | [Header("除外ファイル名")]
179 | [SerializeField]
180 | private string[] _ignoreFileNames;
181 |
182 | [Header("除外ファイルパスの正規表現 Assetsから始まる")]
183 | [SerializeField]
184 | private string[] _ignorePathPatterns;
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/ResourcesLoaderSetting.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3dbb03e1ffa314ab8aa37d192f5d8a7d
3 | timeCreated: 1512389512
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 896586adc1cf04335adaf69de588ee52
3 | folderAsset: yes
4 | timeCreated: 1513517320
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/EnumFlagsAttributeDrawer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 | #if UNITY_EDITOR
4 | using UnityEditor;
5 |
6 | #endif
7 |
8 | namespace TemplateEditor
9 | {
10 | [AttributeUsage(AttributeTargets.Enum | AttributeTargets.Field)]
11 | public class EnumFlagsAttribute : PropertyAttribute
12 | {
13 | }
14 |
15 | #if UNITY_EDITOR
16 | [CustomPropertyDrawer(typeof(EnumFlagsAttribute))]
17 | public class EnumFlagsAttributeDrawer : PropertyDrawer
18 | {
19 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
20 | {
21 | var totalIntValue = 0;
22 | var labelWidth = EditorGUIUtility.labelWidth;
23 | var buttonWidth = (position.width - labelWidth) / property.enumNames.Length;
24 |
25 | EditorGUI.LabelField(new Rect(position.x, position.y, labelWidth, position.height), label);
26 |
27 | var buttonPos = new Rect(position.x + labelWidth, position.y, buttonWidth, position.height);
28 | for (int i = 0; i < property.enumNames.Length; i++)
29 | {
30 | var intValue = 1 << i;
31 | if (GUI.Toggle(buttonPos, (property.intValue & intValue) > 0, property.enumNames[i], "Button"))
32 | {
33 | totalIntValue += intValue;
34 | }
35 |
36 | buttonPos.x += buttonWidth;
37 | }
38 |
39 | property.intValue = totalIntValue;
40 | }
41 | }
42 | #endif
43 | }
44 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/EnumFlagsAttributeDrawer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ff7d158f3b108409cb138ce6fff53f11
3 | timeCreated: 1513501514
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/IUsings.cs:
--------------------------------------------------------------------------------
1 | namespace TemplateEditor
2 | {
3 | public interface IUsings
4 | {
5 | string[] usings { get; }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/IUsings.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 393c46159773f42989d29bed232cd872
3 | timeCreated: 1512390444
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/ResourcesLoaderUtility.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Text.RegularExpressions;
7 |
8 | namespace TemplateEditor
9 | {
10 | public class ResourcesLoaderUtility
11 | {
12 | [Flags]
13 | public enum LoadType
14 | {
15 | Load = 1,
16 | LoadAll = 1 << 1,
17 | LoadAsync = 1 << 2,
18 | }
19 |
20 | public static readonly string[] LoadNames = new string[]
21 | {
22 | "Load", "LoadAll", "LoadAsync",
23 | };
24 |
25 | public static readonly string[] ReturnNamesFormat = new string[]
26 | {
27 | "{0}", "{0}[]", "ResourceRequest",
28 | };
29 |
30 | public static IEnumerable GetFilePaths(IEnumerable paths, IEnumerable ignoreExtensions)
31 | {
32 | var filePathList = new List();
33 | foreach (var path in paths)
34 | {
35 | var files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
36 | filePathList.AddRange(files);
37 | }
38 |
39 | return filePathList
40 | .Where(path => !ignoreExtensions.Contains(Path.GetExtension(path))) // 無視する拡張子のファイルをフィルタリング
41 | .Select(path => path.Replace("\\", "/")); // ファイルパスの「¥」を「/」に変換(WindowsとMacの差を吸収するため)
42 | }
43 |
44 | ///
45 | /// 指定した拡張子のファイルパスを検索
46 | ///
47 | public static IEnumerable FindByExtension(IEnumerable paths, IEnumerable extensions)
48 | {
49 | var builder = new StringBuilder();
50 | foreach (var extension in extensions)
51 | {
52 | if (builder.Length == 0)
53 | {
54 | builder.Append(@".*\.(");
55 | }
56 | else
57 | {
58 | builder.Append("|");
59 | }
60 |
61 | builder.Append(extension);
62 | }
63 |
64 | builder.Append(")");
65 |
66 | var regex = new Regex(@builder.ToString(), RegexOptions.IgnoreCase);
67 |
68 | return paths.Where(path => regex.IsMatch(path));
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/ResourcesLoaderUtility.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2f99f45f75ea4409bb72d9f6a0f0b6b2
3 | timeCreated: 1515156101
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/StringBuilderExtension.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text.RegularExpressions;
5 |
6 | namespace TemplateEditor
7 | {
8 | public static class StringBuilderExtension
9 | {
10 | private static readonly char IndentChar = ' ';
11 | private static readonly int IndentLength = 4;
12 | private static readonly string FirstIdentifierPattern = @"(\p{Ll}|\p{Lu}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl})";
13 | private static readonly Regex NonIdentifierRegex = new Regex(string.Format(@"^[^{0}]|\W", FirstIdentifierPattern));
14 | private static readonly char ReplaceChar = '_';
15 |
16 | public static void AppendLineFormat(this StringBuilder builder, string format, params object[] arg0)
17 | {
18 | builder.AppendFormat(format + "\n", arg0);
19 | }
20 |
21 | public static void AppendUsing(this StringBuilder builder, int indent, params string[] usings)
22 | {
23 | if (usings == null)
24 | {
25 | return;
26 | }
27 |
28 | var indentString = GetIndentString(indent);
29 | foreach (var editUsing in usings)
30 | {
31 | if (string.IsNullOrEmpty(editUsing))
32 | {
33 | return;
34 | }
35 |
36 | builder.AppendLineFormat("{0}using {1};", indentString, editUsing);
37 | }
38 | }
39 |
40 | public static void AppendUsing(this StringBuilder builder, int indent, params IUsings[] usings)
41 | {
42 | foreach (var editUsings in usings)
43 | {
44 | builder.AppendUsing(indent, editUsings.usings);
45 | }
46 | }
47 |
48 | public static void AppendClass(this StringBuilder builder, string name, int indent = 0, string modifier = "", params string[] summaryArray)
49 | {
50 | builder.AppendSummary(indent, summaryArray);
51 |
52 | var indentString = GetIndentString(indent);
53 | builder.AppendLineFormat("{0}public {1}class {2}", indentString, string.IsNullOrEmpty(modifier) ? "" : modifier + " ", name);
54 | builder.AppendLine(indentString + "{");
55 | }
56 |
57 | public static void AppendEnum(this StringBuilder builder, string name, IEnumerable elements, int indent = 0, string elementPrefix = "", string elementSuffix = "", params string[] summaryArray)
58 | {
59 | builder.AppendSummary(indent, summaryArray);
60 |
61 | var indentString = GetIndentString(indent);
62 | builder.AppendLine(indentString + "public enum " + name);
63 | builder.AppendLine(indentString + "{");
64 | builder.AppendLine(Join(elements.Select(element => ConvertEnumName(element)), indent + 1, elementPrefix, elementSuffix) + ",");
65 | builder.AppendLine(indentString + "}");
66 | }
67 |
68 | public static void AppendSummary(this StringBuilder builder, int Indent = 0, params string[] summaryArray)
69 | {
70 | if (summaryArray == null || summaryArray.Length == 0)
71 | {
72 | return;
73 | }
74 |
75 | var prefix = GetIndentString(Indent) + "/// ";
76 |
77 | builder.AppendLine(prefix + "");
78 | foreach (var summary in summaryArray)
79 | {
80 | builder.AppendLine(prefix + summary);
81 | }
82 |
83 | builder.AppendLine(prefix + "");
84 | }
85 |
86 | public static string Join(IEnumerable elements, int indent = 0, string elementPrefix = "", string elementSuffix = "", string separator = ",\n")
87 | {
88 | var prefix = GetIndentString(indent) + elementPrefix;
89 | return string.Join(separator, elements.Select(element => prefix + element + elementSuffix).ToArray());
90 | }
91 |
92 | public static string GetIndentString(int indent)
93 | {
94 | return new string(IndentChar, indent * IndentLength);
95 | }
96 |
97 | public static string ConvertEnumName(string name)
98 | {
99 | if (string.IsNullOrEmpty(name))
100 | {
101 | return string.Empty;
102 | }
103 |
104 | var nameChars = name.ToCharArray();
105 | foreach (Match match in NonIdentifierRegex.Matches(name))
106 | {
107 | nameChars[match.Index] = ReplaceChar;
108 | }
109 |
110 | // キーワードと被ってしまった時のために「@」をつけておく
111 | return "@" + new string(nameChars);
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ResourcesSupport/Scripts/Utility/StringBuilderExtension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1bb7646fa5e8e49e2b60480f32c42d05
3 | timeCreated: 1512365210
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/ToolExecutor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEditor;
3 |
4 | namespace TemplateEditor
5 | {
6 | public static class ToolExecutor
7 | {
8 | private static readonly string DefaultSettingGuid = "18ecd24fd3c0a472096ada88c3a417ad";
9 |
10 | public static bool CheckCustomSetting()
11 | {
12 | var guids = TemplateUtility.FindAssetGuids(typeof(UserSetting));
13 | return guids.Length > 1;
14 | }
15 |
16 | public static UserSetting GetUseUserSetting()
17 | {
18 | var guids = TemplateUtility.FindAssetGuids(typeof(UserSetting));
19 | var targetPath = string.Empty;
20 | if (guids != null)
21 | {
22 | foreach (var guid in guids)
23 | {
24 | if (guid == DefaultSettingGuid)
25 | {
26 | continue;
27 | }
28 |
29 | targetPath = AssetDatabase.GUIDToAssetPath(guid);
30 | break;
31 | }
32 | }
33 |
34 | if (string.IsNullOrEmpty(targetPath))
35 | {
36 | targetPath = AssetDatabase.GUIDToAssetPath(DefaultSettingGuid);
37 | }
38 |
39 | return AssetDatabase.LoadAssetAtPath(targetPath);
40 | }
41 |
42 | public static void Execute(TemplateMenuItem.ToolPriority type)
43 | {
44 | var userSetting = GetUseUserSetting();
45 | switch (type)
46 | {
47 | case TemplateMenuItem.ToolPriority.ResourcesLoadSupport:
48 | TemplateUtility.ExecuteSetting(userSetting.GetSetting(UserSetting.SettingType.ResourcesLoader));
49 | break;
50 | case TemplateMenuItem.ToolPriority.CustomEditorCreator:
51 | CustomEditorCreateWindow.Open();
52 | break;
53 | case TemplateMenuItem.ToolPriority.UnityTemplateChange:
54 | TemplateUtility.OpenEditorWindow(userSetting.GetSetting(UserSetting.SettingType.UnityCSharpTemplate));
55 | break;
56 | #if UNITY_2019_1_OR_NEWER
57 | case TemplateMenuItem.ToolPriority.VisualTreeNameTableCreator:
58 | VisualTreeNameCreatorWindow.Open();
59 | break;
60 | #endif
61 | }
62 | }
63 |
64 | public static void ExecuteSimple(TemplateMenuItem.SimpleTemplatePriority type)
65 | {
66 | var userSetting = GetUseUserSetting();
67 | var setting = userSetting.GetSetting(type);
68 | TemplateUtility.OpenEditorWindow(setting);
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/Editor/TemplateTool/ToolExecutor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9b629ed7f19c943059c5fc215c7021ec
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/UnityCSharpTemplateChanger.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d5e0e5c27dd0e4953b4ddd16b4dccd75
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/UnityCSharpTemplateChanger/UnityCSharpTemplatePathProcessor.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 | using System.IO;
3 |
4 | namespace TemplateEditor
5 | {
6 | public class UnityCSharpTemplatePathProcessor : IProcessChain
7 | {
8 | private static readonly string UnityCSharpTemplateGuid = "9b879173632fa44d7a04ccf182477c2e";
9 |
10 | private static readonly string[] ReplaceWords =
11 | {
12 | "UnityTemplatePath",
13 | "UnityTemplateName",
14 | };
15 |
16 | public void Process(ProcessMetadata metadata, ProcessDictionary result)
17 | {
18 | result.Add(ReplaceWords[0], Path.Combine(EditorApplication.applicationContentsPath, "Resources/ScriptTemplates"));
19 | result.Add(ReplaceWords[1], "81-C# Script-NewBehaviourScript.cs.txt");
20 | }
21 |
22 | public string[] GetReplaceWords()
23 | {
24 | return ReplaceWords;
25 | }
26 |
27 | public string GetDescription()
28 | {
29 | return "UnityのC#テンプレートパスを渡します";
30 | }
31 |
32 | public static void Execute()
33 | {
34 | TemplateUtility.OpenEditorWindow(UnityCSharpTemplateGuid);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/UnityCSharpTemplateChanger/UnityCSharpTemplatePathProcessor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6d2f3b48b75494689bdff97b35b535ed
3 | timeCreated: 1516195982
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/UnityCSharpTemplateChanger/UnityCSharpTemplateSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: UnityCSharpTemplateSetting
14 | m_EditorClassIdentifier:
15 | Path: '{}'
16 | ScriptName: '{}'
17 | Code: 'using System.Collections;
18 |
19 | using System.Collections.Generic;
20 |
21 | using UnityEngine;
22 |
23 |
24 | public class #SCRIPTNAME#
25 |
26 | {
27 |
28 | }'
29 | CodeAreaMinHeight: 150
30 | CodeAreaMaxHeight: 150
31 | Overwrite: 1
32 | Chain:
33 | - {fileID: 11500000, guid: 6d2f3b48b75494689bdff97b35b535ed, type: 3}
34 | DuplicatePrefab: {fileID: 0}
35 | AttachTarget: {fileID: 0}
36 | PrefabPath:
37 | PrefabName:
38 | AssetsMenuItem: 0
39 | Description: "Unity\u306EC# Script\u306E\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u5909\u66F4\u3057\u307E\u3059"
40 | IsFoldouts: 010101
41 | ScrollPos: {x: 0, y: 0}
42 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/UnityCSharpTemplateChanger/UnityCSharpTemplateSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9b879173632fa44d7a04ccf182477c2e
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5000847799afc4ad1802d8a766906af3
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameCreatorWindow.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_2019_1_OR_NEWER
2 | using System.Collections.Generic;
3 | using UnityEngine;
4 | using UnityEditor;
5 |
6 | namespace TemplateEditor
7 | {
8 | public class VisualTreeNameCreatorWindow : EditorWindow
9 | {
10 | private static readonly string VisualTreeNameGetProcessorGuid = "84611633f6726434f8d0065957b8d1ea";
11 |
12 | public static void Open()
13 | {
14 | GetWindow(true);
15 | }
16 |
17 | private SerializedProperty _targetListProperty;
18 | private SerializedObject _serializedObject;
19 | private Vector2 _scrollPos;
20 | private UserSetting _userSetting;
21 |
22 | private void OnEnable()
23 | {
24 | var targetGetProcessor = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(VisualTreeNameGetProcessorGuid));
25 | _serializedObject = new SerializedObject(targetGetProcessor);
26 | _targetListProperty = _serializedObject.FindProperty("_targets");
27 |
28 | _userSetting = ToolExecutor.GetUseUserSetting();
29 | }
30 |
31 | private void OnGUI()
32 | {
33 | if (_targetListProperty == null)
34 | {
35 | return;
36 | }
37 |
38 | _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
39 | {
40 | _serializedObject.Update();
41 | EditorGUILayout.PropertyField(_targetListProperty, new GUIContent("Target VisualTreeAssets"), true);
42 | _serializedObject.ApplyModifiedProperties();
43 | }
44 | EditorGUILayout.EndScrollView();
45 |
46 | if (GUILayout.Button("Create"))
47 | {
48 | TemplateUtility.ExecuteSetting(_userSetting.GetSetting(UserSetting.SettingType.VisualTreeName));
49 | }
50 | }
51 | }
52 | }
53 | #endif
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameCreatorWindow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d959dbeb377a74b318abced7b21aeb13
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameGetProcessor.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: cda52c4d71f8e48328ecf4ba2fa2e7e2, type: 3}
13 | m_Name: VisualTreeNameGetProcessor
14 | m_EditorClassIdentifier:
15 | _targets: []
16 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameGetProcessor.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 84611633f6726434f8d0065957b8d1ea
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameGetProcessor.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_2019_1_OR_NEWER
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using UnityEditor;
5 | using UnityEngine;
6 | using UnityEngine.UIElements;
7 |
8 | namespace TemplateEditor
9 | {
10 | public class VisualTreeNameGetProcessor : ScriptableObject, IProcessChain
11 | {
12 | private static readonly string ScriptName = "VisualTreeNameTable";
13 |
14 | private static readonly string[] ReplaceWords =
15 | {
16 | "CreatePath",
17 | "ScriptName",
18 | "Types",
19 | "Names",
20 | "Methods"
21 | };
22 |
23 | [SerializeField]
24 | private VisualTreeAsset[] _targets = new VisualTreeAsset[1];
25 |
26 | public void Process(ProcessMetadata metadata, ProcessDictionary result)
27 | {
28 | var typeNameList = new List();
29 | var elementNameList = new List();
30 | var nameList = new HashSet();
31 | var targetNameList = new List();
32 | foreach (var target in _targets)
33 | {
34 | if (target == null)
35 | {
36 | continue;
37 | }
38 |
39 | GetNames(target.CloneTree().Children(), nameList);
40 | var tab = new string(' ', 8);
41 | typeNameList.Add(new[] {target.name, string.Join(",\n" + tab, nameList.Select(StringBuilderExtension.ConvertEnumName).ToArray())});
42 | elementNameList.Add(new[] {target.name, string.Join(",\n" + tab, nameList.Select(n => "\"" + n + "\"").ToArray())});
43 | nameList.Clear();
44 |
45 | targetNameList.Add(target.name);
46 | }
47 |
48 | result.Add(ReplaceWords[0], TemplateUtility.GetFilePathFromFileName(ScriptName + ".cs") ?? "Assets");
49 | result.Add(ReplaceWords[1], ScriptName);
50 | result.Add(ReplaceWords[2], typeNameList);
51 | result.Add(ReplaceWords[3], elementNameList);
52 | result.Add(ReplaceWords[4], targetNameList);
53 | }
54 |
55 | private void GetNames(IEnumerable children, HashSet nameList)
56 | {
57 | foreach (var child in children)
58 | {
59 | if (string.IsNullOrEmpty(child.name) == false)
60 | {
61 | nameList.Add(child.name);
62 | }
63 | GetNames(child.Children(), nameList);
64 | }
65 | }
66 |
67 | public string[] GetReplaceWords()
68 | {
69 | return ReplaceWords;
70 | }
71 |
72 | public string GetDescription()
73 | {
74 | return "Uxmlファイルから `name` 要素を取得します";
75 | }
76 | }
77 | }
78 | #endif
79 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameGetProcessor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cda52c4d71f8e48328ecf4ba2fa2e7e2
3 | timeCreated: 1516195982
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameTableSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 56a3a9f3b9043415681fb03d3faa50c2, type: 3}
13 | m_Name: VisualTreeNameTableSetting
14 | m_EditorClassIdentifier:
15 | Path: '{}'
16 | ScriptName: '{}.cs'
17 | Code: "public static class {}\n{\n{}\n{}\n{}\n}"
22 | CodeAreaMinHeight: 300
23 | CodeAreaMaxHeight: 300
24 | Overwrite: 1
25 | Chain:
26 | - {fileID: 11400000, guid: 84611633f6726434f8d0065957b8d1ea, type: 2}
27 | DuplicatePrefab: {fileID: 0}
28 | AttachTarget: {fileID: 0}
29 | PrefabPath:
30 | PrefabName:
31 | AssetsMenuItem: 0
32 | Description:
33 | IsFoldouts: 010101
34 | ScrollPos: {x: 0, y: 0}
35 |
--------------------------------------------------------------------------------
/Editor/TemplateTool/VisualTreeNameTableCreator/VisualTreeNameTableSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 92abed5f6c60344de969f42f7320a23b
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/TreeView.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b8e8dd8b5e9ba49fca737c3654ff0a03
3 | folderAsset: yes
4 | timeCreated: 1517837789
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Editor/TreeView/PrefabTreeView.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor.IMGUI.Controls;
2 | using System.Collections.Generic;
3 | using UnityEngine;
4 |
5 | public class PrefabTreeView : TreeView
6 | {
7 | ///
8 | /// 対象GameObject
9 | ///
10 | private GameObject _target;
11 |
12 | ///
13 | /// 対象GameObject内のTransformリスト
14 | ///
15 | private List _transforms = new List();
16 |
17 | public PrefabTreeView(TreeViewState state, GameObject obj) : base(state)
18 | {
19 | _target = obj;
20 | }
21 |
22 | ///
23 | /// ツリービュー初期化時に呼ばれるツリー構築を行うコールバック
24 | ///
25 | protected override TreeViewItem BuildRoot()
26 | {
27 | _transforms.Clear();
28 |
29 | int count = -1, depth = -1;
30 | var root = new TreeViewItem(count, depth, "root");
31 | var parent = new TreeViewItem(++count, ++depth, _target.name);
32 | root.children = new List {parent};
33 | parent.children = BuildTree(_target.transform, depth, ref count);
34 |
35 | return root;
36 | }
37 |
38 |
39 | ///
40 | /// ツリービューを構築
41 | ///
42 | private List BuildTree(Transform parent, int depth, ref int count)
43 | {
44 | _transforms.Add(parent);
45 |
46 | if (parent.childCount == 0)
47 | {
48 | return null;
49 | }
50 |
51 | ++depth;
52 | var items = new List();
53 | foreach (Transform child in parent)
54 | {
55 | var item = new TreeViewItem(++count, depth, child.name);
56 | var children = BuildTree(child, depth, ref count);
57 | if (children != null)
58 | {
59 | item.children = children;
60 | }
61 |
62 | items.Add(item);
63 | }
64 |
65 | return items;
66 | }
67 |
68 | ///
69 | /// 選択オブジェクト取得
70 | ///
71 | public GameObject GetSelectObject()
72 | {
73 | return _transforms[state.lastClickedID].gameObject;
74 | }
75 |
76 | ///
77 | /// 選択オブジェクト指定
78 | ///
79 | public void SelectObject(GameObject target)
80 | {
81 | if (target == null)
82 | {
83 | return;
84 | }
85 |
86 | SetParentExpanded(target.transform.parent);
87 | SetSelection(new int[] {FindIndex(target.transform)});
88 | }
89 |
90 | ///
91 | /// 指定したオブジェクトまでツリービューを開く
92 | ///
93 | private void SetParentExpanded(Transform transform)
94 | {
95 | if (transform == null)
96 | {
97 | return;
98 | }
99 |
100 | SetExpanded(FindIndex(transform), true);
101 | SetParentExpanded(transform.parent);
102 | }
103 |
104 | private int FindIndex(Transform transform)
105 | {
106 | return _transforms.IndexOf(transform);
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/Editor/TreeView/PrefabTreeView.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 881e521a4b14e467689f82235c8de1db
3 | timeCreated: 1517837804
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/TreeView/PrefabTreeViewWindow.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 | using UnityEditor.IMGUI.Controls;
3 | using UnityEngine;
4 | using System;
5 |
6 | public class PrefabTreeViewWindow : EditorWindow
7 | {
8 | private static PrefabTreeViewWindow _window;
9 |
10 | public static void Open(GameObject parent, GameObject target, Action changeAction)
11 | {
12 | _window = GetWindow(true);
13 | _window.Build(parent, target, changeAction);
14 | }
15 |
16 | private PrefabTreeView _treeView;
17 | private TreeViewState _state;
18 | private Action _changeAction;
19 |
20 | void Build(GameObject parent, GameObject target, Action changeAction)
21 | {
22 | _state = new TreeViewState();
23 | _treeView = new PrefabTreeView(_state, parent);
24 | _treeView.Reload();
25 | _treeView.SelectObject(target);
26 |
27 | _changeAction = changeAction;
28 | }
29 |
30 | void OnGUI()
31 | {
32 | EditorGUILayout.BeginHorizontal();
33 | {
34 | if (GUILayout.Button("Change"))
35 | {
36 | _changeAction.Invoke(_treeView.GetSelectObject());
37 | _window.Close();
38 | return;
39 | }
40 |
41 | if (GUILayout.Button("Quit"))
42 | {
43 | _window.Close();
44 | return;
45 | }
46 | }
47 |
48 | var lastRect = GUILayoutUtility.GetLastRect();
49 | _treeView.OnGUI(new Rect(0, lastRect.y + lastRect.height, position.width, position.height));
50 | }
51 |
52 | void OnDestroy()
53 | {
54 | _window = null;
55 | }
56 | }
--------------------------------------------------------------------------------
/Editor/TreeView/PrefabTreeViewWindow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b54955c794d3b4dcca78133771390151
3 | timeCreated: 1517838009
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/UserSetting.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6430a71a7b6c34cde96768139e987a52
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/UserSetting/DefaultUserSetting.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: 76f7aefeb89de449786ceec4c6f5a573, type: 3}
13 | m_Name: DefaultUserSetting
14 | m_EditorClassIdentifier:
15 | _settings:
16 | - {fileID: 11400000, guid: c02be74c37b2340189ea293c5e5aedd0, type: 2}
17 | - {fileID: 11400000, guid: 9b879173632fa44d7a04ccf182477c2e, type: 2}
18 | - {fileID: 11400000, guid: 92abed5f6c60344de969f42f7320a23b, type: 2}
19 | - {fileID: 11400000, guid: 1c95e1425131048ba82aeb753fe906b4, type: 2}
20 | _groupSettings:
21 | - {fileID: 11400000, guid: 39929be43dcc041049feecc87d7f23d3, type: 2}
22 | _simpleSettings:
23 | - {fileID: 11400000, guid: 97b4a1e1e5de54dd2b95554ff3aaaf69, type: 2}
24 | - {fileID: 11400000, guid: 8bc6cbcc4a40f4052b7e86a88892abec, type: 2}
25 | - {fileID: 11400000, guid: 9027646eff5be417982da6abdd36a3ce, type: 2}
26 | - {fileID: 11400000, guid: 078b8aa44d22a45ae80dee4d3c52cbbb, type: 2}
27 |
--------------------------------------------------------------------------------
/Editor/UserSetting/DefaultUserSetting.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 18ecd24fd3c0a472096ada88c3a417ad
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 11400000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/UserSetting/UserSetting.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS0649
2 |
3 | using UnityEngine;
4 |
5 | namespace TemplateEditor
6 | {
7 | public class UserSetting : ScriptableObject
8 | {
9 | public enum SettingType
10 | {
11 | ResourcesLoader,
12 | UnityCSharpTemplate,
13 | VisualTreeName,
14 | AssetsMenuItemCreator,
15 | }
16 |
17 | public enum GroupSettingType
18 | {
19 | CustomEditorCreator,
20 | }
21 |
22 | [EnumArray(typeof(SettingType))]
23 | [SerializeField]
24 | private TemplateSetting[] _settings;
25 |
26 | [EnumArray(typeof(GroupSettingType))]
27 | [SerializeField]
28 | private TemplateGroupSetting[] _groupSettings;
29 |
30 | [EnumArray(typeof(TemplateMenuItem.SimpleTemplatePriority))]
31 | [SerializeField]
32 | private TemplateSetting[] _simpleSettings;
33 |
34 | public TemplateSetting GetSetting(SettingType type)
35 | {
36 | return _settings[(int) type];
37 | }
38 |
39 | public TemplateGroupSetting GetSetting(GroupSettingType type)
40 | {
41 | return _groupSettings[(int) type];
42 | }
43 |
44 | public TemplateSetting GetSetting(TemplateMenuItem.SimpleTemplatePriority type)
45 | {
46 | return _simpleSettings[(int) type];
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Editor/UserSetting/UserSetting.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 76f7aefeb89de449786ceec4c6f5a573
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/UserSetting/UserSettingCopyWindow.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS0649
2 |
3 | using System.IO;
4 | using TemplateEditor;
5 | using UnityEditor;
6 | using UnityEngine;
7 |
8 | namespace TemplateEditor
9 | {
10 | public class UserSettingCopyWindow : EditorWindow
11 | {
12 | private static readonly string DefaultTemplateDirectory = "/TemplateTool/";
13 |
14 | public static void Open()
15 | {
16 | EditorWindow.GetWindow(true);
17 | }
18 |
19 | private UserSetting _userSetting;
20 | private string _namespace;
21 | private string _createFolder = "Assets/CustomTemplateSetting";
22 |
23 | private void OnEnable()
24 | {
25 | _userSetting = ToolExecutor.GetUseUserSetting();
26 | }
27 |
28 | private void OnGUI()
29 | {
30 | _createFolder = EditorGUILayout.TextField("Create Folder", _createFolder);
31 | _namespace = EditorGUILayout.TextField("Add Namespace", _namespace);
32 |
33 | if (GUILayout.Button("Create Custom Template"))
34 | {
35 | Copy(_userSetting, _createFolder, _namespace);
36 | }
37 | }
38 |
39 | private static void Copy(UserSetting target, string copyDirectory, string namespaceName)
40 | {
41 | if (copyDirectory.Contains("/Editor/") == false)
42 | {
43 | copyDirectory = Path.Combine(copyDirectory, "Editor");
44 | }
45 |
46 | Directory.CreateDirectory(copyDirectory);
47 |
48 | var targetPath = AssetDatabase.GetAssetPath(target);
49 | var copyPath = Path.Combine(copyDirectory, Path.GetFileName(targetPath).Replace("Default", "Custom"));
50 |
51 | if (ToolExecutor.CheckCustomSetting())
52 | {
53 | Debug.LogWarning("Already custom setting exists");
54 | return;
55 | }
56 |
57 | AssetDatabase.CopyAsset(targetPath, copyPath);
58 |
59 | var copyAsset = AssetDatabase.LoadAssetAtPath(copyPath);
60 | CopyChild(copyAsset, copyDirectory, namespaceName);
61 | }
62 |
63 | private static void CopyChild(Object target, string copyDirectory, string namespaceName)
64 | {
65 | var isNameSpaceInsert = target is TemplateSetting && string.IsNullOrEmpty(namespaceName) == false;
66 |
67 | var copyAssetSerialized = new SerializedObject(target);
68 | foreach (var property in ScriptableObjectUtility.GetSerializedProperties(copyAssetSerialized, true, true))
69 | {
70 | if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue != null)
71 | {
72 | if (property.objectReferenceValue is MonoScript)
73 | {
74 | continue;
75 | }
76 |
77 | var childTargetPath = AssetDatabase.GetAssetPath(property.objectReferenceValue);
78 | var childTargetDirectory = Path.GetDirectoryName(childTargetPath);
79 | var childCopyPath = Path.Combine(
80 | Path.Combine(
81 | copyDirectory,
82 | childTargetDirectory.Substring(childTargetDirectory.IndexOf(DefaultTemplateDirectory) + DefaultTemplateDirectory.Length)),
83 | Path.GetFileName(childTargetPath));
84 |
85 | Directory.CreateDirectory(Path.GetDirectoryName(childCopyPath));
86 | AssetDatabase.CopyAsset(childTargetPath, childCopyPath);
87 | var copyChildAsset = AssetDatabase.LoadAssetAtPath(childCopyPath, property.objectReferenceValue.GetType());
88 | property.objectReferenceValue = copyChildAsset;
89 | CopyChild(copyChildAsset, copyDirectory, namespaceName);
90 | }
91 | else if (isNameSpaceInsert && property.propertyType == SerializedPropertyType.String && property.name == "Code")
92 | {
93 | property.stringValue = TemplateUtility.InsertNamespace(property.stringValue, namespaceName);
94 | }
95 | }
96 |
97 | copyAssetSerialized.ApplyModifiedPropertiesWithoutUndo();
98 | }
99 | }
100 | }
--------------------------------------------------------------------------------
/Editor/UserSetting/UserSettingCopyWindow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 134092c14b8d04cb2a2afc10c860f59f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/Utility.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ea763f989a1444244afd97ac8f2cebfc
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/Utility/EditorExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using SyntaxHighlightEditor;
4 | using UnityEditor;
5 | using UnityEngine;
6 |
7 | namespace TemplateEditor
8 | {
9 | public class FoldoutInfo
10 | {
11 | public bool IsFoldout = true;
12 | public string DrawName;
13 | public Action DrawAction;
14 |
15 | public FoldoutInfo(string name, Action action)
16 | {
17 | DrawName = name;
18 | DrawAction = action;
19 | }
20 | }
21 |
22 | public static class EditorGUIHelper
23 | {
24 | private const float DefaultDDAreaHeight = 30.0f;
25 |
26 | ///
27 | /// ドラッグ&ドロップ エリアを表示
28 | ///
29 | public static string[] DrawDragAndDropArea(string dropName = "Drag & Drop a folder or file", float height = DefaultDDAreaHeight)
30 | {
31 | var dropRect = GUILayoutUtility.GetRect(0.0f, height, GUILayout.ExpandWidth(true));
32 |
33 | // TODO : Cache ?
34 | var style = new GUIStyle(GUI.skin.box);
35 | {
36 | style.normal.textColor = Color.white;
37 | }
38 | GUI.Box(dropRect, dropName, style);
39 |
40 | if (dropRect.Contains(Event.current.mousePosition) == false)
41 | {
42 | return null;
43 | }
44 |
45 | switch (Event.current.type)
46 | {
47 | case EventType.DragUpdated:
48 | {
49 | DragAndDrop.activeControlID = GUIUtility.GetControlID(FocusType.Passive);
50 | DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
51 | }
52 | break;
53 |
54 | case EventType.DragPerform:
55 | {
56 | DragAndDrop.activeControlID = GUIUtility.GetControlID(FocusType.Passive);
57 | DragAndDrop.AcceptDrag();
58 | Event.current.Use();
59 | }
60 | return DragAndDrop.paths;
61 | }
62 |
63 | return null;
64 | }
65 |
66 | ///
67 | /// 折りたたみ表示
68 | ///
69 | public static void DrawFoldouts(IEnumerable foldouts)
70 | {
71 | foreach (var foldout in foldouts)
72 | {
73 | DrawFoldout(foldout);
74 | }
75 | }
76 |
77 | ///
78 | /// 折りたたみ表示
79 | ///
80 | public static void DrawFoldout(FoldoutInfo foldout)
81 | {
82 | EditorGUI.indentLevel++;
83 | foldout.IsFoldout = EditorGUILayout.Foldout(foldout.IsFoldout, foldout.DrawName);
84 | EditorGUI.indentLevel--;
85 | if (foldout.IsFoldout == false)
86 | {
87 | return;
88 | }
89 |
90 | foldout.DrawAction();
91 | }
92 |
93 | ///
94 | /// スコープのスタイル取得
95 | ///
96 | public static GUIStyle GetScopeStyle()
97 | {
98 | return EditorStyles.helpBox;
99 | }
100 | }
101 | }
--------------------------------------------------------------------------------
/Editor/Utility/EditorExtension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 116fef00f4a634385b4a73464de6975a
3 | timeCreated: 1522849492
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Utility/EditorPreviewWindow.cs:
--------------------------------------------------------------------------------
1 | using UnityEditor;
2 |
3 | namespace TemplateEditor
4 | {
5 | ///
6 | /// エディタプレビュー用ウィンドウ
7 | ///
8 | public class EditorPreviewWindow : EditorWindow
9 | {
10 | public static void Open(Editor editor)
11 | {
12 | var window = GetWindow(true);
13 | window.SetEditor(editor);
14 | }
15 |
16 | private Editor _previewEditor;
17 |
18 | public void SetEditor(Editor editor)
19 | {
20 | _previewEditor = editor;
21 | }
22 |
23 | private void OnGUI()
24 | {
25 | if (_previewEditor == null)
26 | {
27 | return;
28 | }
29 |
30 | _previewEditor.OnInspectorGUI();
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/Editor/Utility/EditorPreviewWindow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2e145b5b232854526aa219eef5805f5d
3 | timeCreated: 1522849492
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Editor/Utility/EnumArrayAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 | using UnityEditor;
4 |
5 | namespace TemplateEditor
6 | {
7 | [CustomPropertyDrawer(typeof(EnumArrayAttribute))]
8 | public class EnumArrayAttributeDrawer : PropertyDrawer
9 | {
10 | private string[] _names;
11 |
12 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
13 | {
14 | try
15 | {
16 | if (_names == null)
17 | {
18 | _names = Enum.GetNames(((EnumArrayAttribute) attribute).TargetEnumType);
19 | }
20 |
21 | var pos = int.Parse(property.propertyPath.Split('[', ']')[1]);
22 | EditorGUI.PropertyField(position, property, new GUIContent(_names[pos]));
23 | }
24 | catch
25 | {
26 | EditorGUI.PropertyField(position, property, label);
27 | }
28 | }
29 | }
30 |
31 | [AttributeUsage(AttributeTargets.Field)]
32 | public class EnumArrayAttribute : PropertyAttribute
33 | {
34 | public readonly Type TargetEnumType;
35 |
36 | public EnumArrayAttribute(Type enumType)
37 | {
38 | TargetEnumType = enumType;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Editor/Utility/EnumArrayAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 58e6eda4f7e84d5eaa7243c15548c0e3
3 | timeCreated: 1567938511
--------------------------------------------------------------------------------
/Editor/Utility/ProcessDictionary.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace TemplateEditor
4 | {
5 | public class ProcessDictionary : Dictionary
6 | {
7 | public static readonly string ConvertWordPattern = "{0}_{1}";
8 |
9 | public new void Add(string key, object value)
10 | {
11 | base.Add(ConvertReplaceWord(key), value);
12 | }
13 |
14 | public string ConvertReplaceWord(string word)
15 | {
16 | var convertWord = word;
17 | var counter = 2;
18 | while (ContainsKey(convertWord))
19 | {
20 | convertWord = string.Format(ConvertWordPattern, word, counter);
21 | counter++;
22 | }
23 |
24 | return convertWord;
25 | }
26 |
27 | public string GetLastConvertReplaceWord(string word)
28 | {
29 | string convertWord = word;
30 | int counter = 2;
31 | while (true)
32 | {
33 | var nextWord = string.Format(ConvertWordPattern, convertWord, counter);
34 | if (ContainsKey(nextWord))
35 | {
36 | convertWord = nextWord;
37 | }
38 | else
39 | {
40 | break;
41 | }
42 |
43 | counter++;
44 | }
45 |
46 | return convertWord;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Editor/Utility/ProcessDictionary.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2192770cee61442980733cdd67146fed
3 | timeCreated: 1560837567
--------------------------------------------------------------------------------
/Editor/Utility/ReplaceProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.RegularExpressions;
3 | using System.Linq;
4 | using System;
5 | using System.Text;
6 | using UnityEngine;
7 |
8 | namespace TemplateEditor
9 | {
10 | public static class ReplaceProcessor
11 | {
12 | private const string ReplacePrefix = "{<";
13 | private const string ReplaceSuffix = ">}";
14 | private const string ReplaceInReplacePrefix = "{\\\\<";
15 | private const string ReplaceInReplaceSuffix = ">\\\\}";
16 | private static readonly Regex ReplaceRegex = new Regex(ReplacePrefix + "([\\s\\S]+?)" + ReplaceSuffix);
17 | private static readonly Regex ReplaceInReplaceRegex = new Regex(ReplaceInReplacePrefix + "([\\s\\S]+?)" + ReplaceInReplaceSuffix);
18 | private static readonly char SplitChar = ':';
19 |
20 | private static readonly Dictionary, string>> ProcessDic = new Dictionary, string>>()
21 | {
22 | {"Repeat", RepeatToProcess},
23 | };
24 |
25 | ///
26 | /// 置き換え文字置き換え ※{} 等
27 | ///
28 | public static string ReplaceProcess(string text, Dictionary replace, Regex regex = null)
29 | {
30 | if (regex == null)
31 | {
32 | regex = ReplaceRegex;
33 | }
34 |
35 | return regex.Replace(text, new MatchEvaluator((match) =>
36 | {
37 | var orderText = match.Groups[1].Value;
38 | var orders = orderText.Split(SplitChar);
39 |
40 | // マッチするものがなければ次へ
41 | var replaceWord = orders.Last();
42 | if (replace.ContainsKey(replaceWord) == false)
43 | {
44 | return match.Value;
45 | }
46 |
47 | // 置き換え命令がなければ単純に置き換えのみ
48 | if (orders.Length == 1 || ProcessDic.ContainsKey(orders[0]) == false)
49 | {
50 | return replace[replaceWord].ToString();
51 | }
52 |
53 | // 置き換え処理
54 | return ProcessDic[orders[0]].Invoke(orders, replace[replaceWord], replace);
55 | }
56 | ));
57 | }
58 |
59 | public static HashSet GetReplaceWords(params string[] texts)
60 | {
61 | var words = new HashSet();
62 | foreach (var text in texts)
63 | {
64 | foreach (Match match in ReplaceRegex.Matches(text))
65 | {
66 | var orderText = match.Groups[1].Value;
67 | var orders = orderText.Split(SplitChar);
68 | words.Add(orders.Last());
69 |
70 | // 置き換え文字中の置き換え文字チェック
71 | var writeText = GetWriteTextFromReplaceOrders(orders);
72 | foreach (Match inMatch in ReplaceInReplaceRegex.Matches(writeText))
73 | {
74 | words.Add(inMatch.Groups[1].Value.Split(SplitChar).Last());
75 | }
76 | }
77 | }
78 |
79 | return words;
80 | }
81 |
82 | public static string GetReplaceText(string word)
83 | {
84 | return ReplacePrefix + word + ReplaceSuffix;
85 | }
86 |
87 | public static bool Contains(string[] texts, string key)
88 | {
89 | foreach (var text in texts)
90 | {
91 | if (string.IsNullOrEmpty(text) == false && text.Contains(key))
92 | {
93 | return true;
94 | }
95 | }
96 |
97 | return false;
98 | }
99 |
100 | #region Process
101 |
102 | private static string RepeatToProcess(string[] orders, object replace, Dictionary replaceDic)
103 | {
104 | var objects = replace as System.Collections.IList;
105 | if (objects == null)
106 | {
107 | Debug.LogError("Repeat object is not list");
108 | return string.Empty;
109 | }
110 |
111 | // 最初と最後のSplitChar以外を一つに
112 | var writeText = GetWriteTextFromReplaceOrders(orders);
113 |
114 | // 置き換え文字中の置き換え文字に対応
115 | writeText = ReplaceProcess(writeText, replaceDic, ReplaceInReplaceRegex);
116 |
117 | // '{' or '}' をstring.Formatで使える形式に変換
118 | writeText = ConvertBrace(writeText);
119 |
120 | var builder = new StringBuilder();
121 | foreach (var obj in objects)
122 | {
123 | if (builder.Length != 0)
124 | {
125 | builder.AppendLine();
126 | }
127 |
128 | if (obj is ICollection