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
5
180
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
300
最近のVS Codeで気になるニュース 2025/01
74th
1
240
Scaling your build logic
antalmonori
1
140
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
260
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
3
1k
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
140
為你自己學 Python
eddie
0
540
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
1
410
令和7年版 あなたが使ってよいフロントエンド機能とは
mugi_uno
12
6k
Flatt Security XSS Challenge 解答・解説
flatt_security
0
800
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
1
480
Featured
See All Featured
Side Projects
sachag
452
42k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
What's in a price? How to price your products and services
michaelherold
244
12k
Done Done
chrislema
182
16k
Designing Experiences People Love
moore
139
23k
How GitHub (no longer) Works
holman
312
140k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
How to train your dragon (web standard)
notwaldorf
89
5.8k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
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͔Βऔಘ͢Δ……? • Ұ։͘ͷͨ͘͠ͳ͍
͝ଘͷํɺώϯτԼ͍͞
͋Γ͕ͱ͏͍͟͝·ͨ͠