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
380
俺はEditor拡張で行く ~ゼロから便利機能を作るまで
ゼロからEditor拡張をやるための足がかりになるかなと思いLTしました。
vailKAKO
October 09, 2020
Tweet
Share
More Decks by vailKAKO
See All by vailKAKO
俺はUniRxで行く
vailkako
0
35
Other Decks in Programming
See All in Programming
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
220
Git Rebase
bkuhlmann
11
1.6k
Ruby GitHub Packages
bkuhlmann
0
640
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
1.3k
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
860
新宿ダンジョンを可視化してみた
satoshi7190
3
370
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
350
Fast JSX: Don't clone props object #28768
yossydev
1
160
Hanami and htmx
bkuhlmann
0
220
Implementing Design Systems in Swift
seyfoyun
1
440
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
140
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
6
1.1k
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
14
1k
Fireside Chat
paigeccino
22
2.6k
Embracing the Ebb and Flow
colly
80
4.2k
Producing Creativity
orderedlist
PRO
338
39k
Git: the NoSQL Database
bkeepers
PRO
423
63k
Designing with Data
zakiwarfel
96
4.8k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
The Cult of Friendly URLs
andyhume
74
5.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
22
1.6k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
19
6.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
32
46k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
79
43k
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͔Βऔಘ͢Δ……? • Ұ։͘ͷͨ͘͠ͳ͍
͝ଘͷํɺώϯτԼ͍͞
͋Γ͕ͱ͏͍͟͝·ͨ͠