Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
俺はEditor拡張で行く ~ゼロから便利機能を作るまで
Search
vailKAKO
October 09, 2020
Programming
0
410
俺はEditor拡張で行く ~ゼロから便利機能を作るまで
ゼロからEditor拡張をやるための足がかりになるかなと思いLTしました。
vailKAKO
October 09, 2020
Tweet
Share
More Decks by vailKAKO
See All by vailKAKO
俺はUniRxで行く
vailkako
0
53
Other Decks in Programming
See All in Programming
JavaScriptツール群「UnJS」を5分で一気に駆け巡る!
k1tikurisu
10
1.8k
Bedrock Agentsレスポンス解析によるAgentのOps
licux
2
720
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
660
2024年のWebフロントエンドのふりかえりと2025年
sakito
1
230
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
1
170
Spring gRPC について / About Spring gRPC
mackey0225
0
220
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
730
DROBEの生成AI活用事例 with AWS
ippey
0
130
時計仕掛けのCompose
mkeeda
1
280
Lottieアニメーションをカスタマイズしてみた
tahia910
0
120
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
160
最近のVS Codeで気になるニュース 2025/01
74th
1
250
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Making Projects Easy
brettharned
116
6k
Optimizing for Happiness
mojombo
376
70k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
It's Worth the Effort
3n
184
28k
The Language of Interfaces
destraynor
156
24k
How STYLIGHT went responsive
nonsquared
98
5.3k
A Philosophy of Restraint
colly
203
16k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Transcript
ԶEditor֦ுͰߦ͘ θϩ͔ΒศརػೳΛ࡞Δ·Ͱ Speaker : Kako Time : about 10m
ࣗݾհ Ճݹ(27)……Ұࣇͷ ϑϦʔϥϯεˠࠓ݄ήʔϜձࣾೖࣾ༧ఆ ࠷ۙͷϒʔϜϛχήʔϜ࡞ΓͱྉཧͷऔΓճ͠ࢥߟ
͜Μͳ͜ͱ͋Γ·͢ΑͶ???Ͷ?????? • ϓϩδΣΫτͰԿ͔͠ΒͷίϯϙʔωϯτΛ୳͍ͨ͠ • ಉ͡ܗࣜͷͷΛԿೖྗ͢Δ͔Βָʹ͍ͨ͠ • ඪ४ػೳͰͰ͖Δ͚Ͳɺ͏ͪΐͬͱΓ͍ͨ͜ͱ͕͋Δ • ΤσΟλͰ࣮ߦதͰอଘ͕͍ͨ͠! etc.
େମEditor֦ுͰͰ͖·͢!
Editor֦ுͬͯ? • ࣗ࡞ͷWindowग़ͤͨΓ͢Δ • ͖ͳػೳΛ݁ߏ͚ͭΒΕΔ • ௨ৗͰ͖ͳ͍͜ͱͰ͖ΔΑ͏ʹͳͬͨΓ͢Δ • खಈͰΔ͜ͱΛҰ෦ࣗಈԽͰ͖ͨΓ͢Δ
ͱ͋ΔUnityΤϯδχΞ1໊(2018࣌)ͷ • ฉ͍ͨ͜ͱ͋Δ͚ͲΑ͘Θ͔Μͳ͍ • ΰϦϥͳਓͨͪͷ͍ٕ͢͝ज़Ͱ͠ΐ? • ·͊खಈͰͰ͖Δ͠…… • Ͳ͏ͤීஈͱશ͘ҧ͏͜ͱΛ͢ΔΜͰ͠ΐ?
݁ߏָʹͰ͖·͢!
࣮ࡍͷྲྀΕ ᶃ C#εΫϦϓτΛ࡞Δ ᶄ ͱΓ͋͑ͣWindowΛग़͢ ᶅ ϘλϯͰͳʹ͔͢Δ ᶆ ศར!
ᶄͱΓ͋͑ͣWindowΛग़͢ using UnityEditor; public class StartEditor : EditorWindow { //։͔Εํͱɺ։͔Εͨͱ͖ͷڍಈ
[MenuItem("StartEditor/OpenDAZE")] private static void Open() { GetWindow<StartEditor>("Start editor DAZE"); } }
ᶄͱΓ͋͑ͣWindowΛग़͢
ᶄϘλϯͰͳʹ͔͢Δ private void OnGUI() { if (GUILayout.Button("Nanikoe?")) { Debug.Log("Shiranai!"); }
}
ᶄϘλϯͰͳʹ͔͢Δ
ᶄϘλϯͰͳʹ͔͢Δ2 private void OnGUI() { if (GUILayout.Button("Nanikoe?")) { var objs
= FindObjectsOfType<Transform>(); Debug.Log($"{objs.Length}"); foreach (var obj in objs) { Debug.Log(obj.name); } } }
ᶄϘλϯͰͳʹ͔͢Δ2
ศར!!!!!!!Ҏ্!!!!
ศར!!!!!!!Ҏ্!!!! Ͱ͜ͷ··ͩͱTransform͚ͩͩ͠ ͋ͱ͔Βม͍͑ͨͳΒϋʔυίʔσΟϯά?
ೖྗͰγʔϯ͔Βऔಘͯ͠ΈΔαϯϓϧ ᶃ ೖྗ૭Λ࡞Δ ᶄ ComponentࣗମΛऔಘ ᶅ ComponentΛؚΉͷΛग़͢ ᶆ ຐվͱհ
ᶄೖྗ૭Λ࡞Δ private string _targetComponentName; private void OnGUI() { //EditorʹΛग़ͯ͠ɺೖྗΛ_targetComponentNameʹ֨ೲ͢Δ EditorGUILayout.BeginHorizontal();
_targetComponentName = EditorGUILayout.TextField("Target Component Name: ", _targetComponentName); EditorGUILayout.EndHorizontal(); . . .
ᶄೖྗ૭Λ࡞Δ
ᶄComponentࣗମΛऔಘ private static IEnumerable<Type> GetTypes() { //Unityඪ४ͷΫϥελΠϓΛऔಘ͢Δ var types =
AppDomain.CurrentDomain.GetAssemblies() .SelectMany(asm => asm.GetTypes()) .Where(type => type != null && ! string.IsNullOrEmpty(type.Namespace)) .Where(type => type.Namespace.Contains("UnityEngine")); return types; }
ᶅComponentΛؚΉͷΛग़͢ private static Dictionary<string, List<Type>> _typeDict; private static Type GetType(string
className) { if (_typeDict == null) { // Dictionary࡞ _typeDict = new Dictionary<string, List<Type>>(); var components = GetTypes(); foreach (var type in components) { if (!_typeDict.ContainsKey(type.Name)) { _typeDict.Add(type.Name, new List<Type>()); } _typeDict[type.Name].Add(type); } } return _typeDict[className][0]; }
ᶅComponentΛؚΉͷΛग़͢ if (GUILayout.Button("Search?")) { var objs = FindObjectsOfType(GetType(_targetComponentName) ?? null);
Debug.Log($"{objs.Length}"); foreach (var obj in objs) { Debug.Log(obj.name); } }
……?
᩵ʹ!!! ᶃ ࣗ࡞ΫϥεऔಘͰ͖ΔΑ͏ʹ͢Δ ᶄ ॲཧΛܰ͘͢Δ ᶅ ΫϦοΫͨ͠Βࢀরݩʹඈͼ͍ͨΑͶ? ᶆ ͍ͬͦͷ͜ͱγʔϯʹͳ͍Prefabऔಘ͠Α͏ͥ
͏͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓ using System; using System.Collections.Generic; using System.Linq; using UnityEditor; using
UnityEngine; using UnityEngine.SceneManagement; public class ReferenceFinder : EditorWindow { private string _targetComponentName; private List<GameObject> _foundAssets = new List<GameObject>(); private Vector2 _currentScrollPosition; private static IEnumerable<Type> _cashedComponents; private static Dictionary<string, List<Type>> _typeDict; static MonoScript[] _monoScripts; private static bool _isFirstTime = true; //։͔Εํͱɺ։͔Εͨͱ͖ͷڍಈ [MenuItem("ReferenceFinder/Search")] private static void Open() { //։͔ΕΔࡍʹҰԠऔಘ _cashedComponents = GetAllTypes(); GetWindow<ReferenceFinder>("Components Reference Finder."); } private void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Never change Scene before reset this window"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("This window can search active scene objects and all prefabs"); EditorGUILayout.EndHorizontal(); //EditorʹΛग़ͯ͠ɺೖྗΛ_targetComponentNameʹ֨ೲ͢Δ EditorGUILayout.BeginHorizontal(); _targetComponentName = EditorGUILayout.TextField("Target Component Name: ", _targetComponentName); EditorGUILayout.EndHorizontal(); if (_foundAssets.Count > 0) { _currentScrollPosition = EditorGUILayout.BeginScrollView(_currentScrollPosition); foreach (var asset in _foundAssets) { EditorGUILayout.ObjectField(asset.name, asset, typeof(GameObject), false); } EditorGUILayout.EndScrollView(); } if (GUILayout.Button("Search")) { _foundAssets.Clear(); var guids = AssetDatabase.FindAssets("t:GameObject", null); foreach (var guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); var loadAsset = AssetDatabase.LoadAssetAtPath<GameObject>(path); var typeCash = GetType(_targetComponentName) ?? null; if (typeCash == null) { Debug.Log("No Type Found."); return; } var tmp = loadAsset.GetComponentsInChildren(GetType(_targetComponentName) ?? null); foreach (var kari in tmp) { _foundAssets.Add(kari.gameObject); } } var allObj = GetObjectsInAllScene(); foreach (var obj in allObj) { var typeCash = GetType(_targetComponentName) ?? null; var tmp = obj.GetComponentsInChildren(GetType(_targetComponentName) ?? null); if (typeCash == null) { Debug.Log("No Type Found."); return; } foreach (var kari in tmp) { _foundAssets.Add(kari.gameObject);
͏͓͓͓͓͓͓(Unityͷίϯϙʔωϯτ)
͏͓͓͓͓͓͓(ࣗ࡞Ϋϥε)
ͨ͠ͷ͕ͪ͜ΒͰ͢(એ) https://www.kakovail.info/entry/2020/03/09/170855
։͍ͯͳ͍γʔϯऔಘͰ͖ͳ͍(γʔϯʹͳ͍PrefabऔΕΔ) • ಡΈࠐΜͰͳ͍͔ΒͳʹಡΈࠐΊͳ͍(વ) • SceneσʔλΛจࣈͱͯ͠GUID͔Βऔಘ͢Δ……? • Ұ։͘ͷͨ͘͠ͳ͍
͝ଘͷํɺώϯτԼ͍͞
͋Γ͕ͱ͏͍͟͝·ͨ͠