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
400
俺はEditor拡張で行く ~ゼロから便利機能を作るまで
ゼロからEditor拡張をやるための足がかりになるかなと思いLTしました。
vailKAKO
October 09, 2020
Tweet
Share
More Decks by vailKAKO
See All by vailKAKO
俺はUniRxで行く
vailkako
0
52
Other Decks in Programming
See All in Programming
macOS でできる リアルタイム動画像処理
biacco42
9
2.3k
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
430
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.9k
Click-free releases & the making of a CLI app
oheyadam
2
110
CSC509 Lecture 09
javiergs
PRO
0
140
僕がつくった48個のWebサービス達
yusukebe
20
17k
みんなでプロポーザルを書いてみた
yuriko1211
0
220
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
540
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
200
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
420
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
17
4.3k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
4
2.1k
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
50
7.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Six Lessons from altMBA
skipperchong
27
3.5k
Side Projects
sachag
452
42k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
The Language of Interfaces
destraynor
154
24k
Adopting Sorbet at Scale
ufuk
73
9.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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͔Βऔಘ͢Δ……? • Ұ։͘ͷͨ͘͠ͳ͍
͝ଘͷํɺώϯτԼ͍͞
͋Γ͕ͱ͏͍͟͝·ͨ͠