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
ISUCON14公式反省会LT: 社内ISUCONの話
astj
PRO
0
180
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
270
WebDriver BiDiとは何なのか
yotahada3
1
140
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
360
定理証明プラットフォーム lapisla.net
abap34
1
1.7k
Immutable ActiveRecord
megane42
0
130
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
41
15k
昭和の職場からアジャイルの世界へ
kumagoro95
1
350
DROBEの生成AI活用事例 with AWS
ippey
0
130
Rails アプリ地図考 Flush Cut
makicamel
1
110
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
最近のVS Codeで気になるニュース 2025/01
74th
1
250
Featured
See All Featured
Thoughts on Productivity
jonyablonski
69
4.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
A Tale of Four Properties
chriscoyier
158
23k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Statistics for Hackers
jakevdp
797
220k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
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͔Βऔಘ͢Δ……? • Ұ։͘ͷͨ͘͠ͳ͍
͝ଘͷํɺώϯτԼ͍͞
͋Γ͕ͱ͏͍͟͝·ͨ͠