Slide 1

Slide 1 text

Զ͸Editor֦ுͰߦ͘ θϩ͔ΒศརػೳΛ࡞Δ·Ͱ Speaker : Kako Time : about 10m

Slide 2

Slide 2 text

ࣗݾ঺հ Ճݹ(27)……Ұࣇͷ෕ ϑϦʔϥϯεˠࠓ݄ήʔϜձࣾೖࣾ༧ఆ ࠷ۙͷϒʔϜ͸ϛχήʔϜ࡞ΓͱྉཧͷऔΓճ͠ࢥߟ

Slide 3

Slide 3 text

͜Μͳ͜ͱ͋Γ·͢ΑͶ???Ͷ?????? • ϓϩδΣΫτͰԿ͔͠ΒͷίϯϙʔωϯτΛ୳͍ͨ͠ • ಉ͡ܗࣜͷ΋ͷΛԿ౓΋ೖྗ͢Δ͔Βָʹ͍ͨ͠ • ඪ४ػೳͰͰ͖Δ͚Ͳɺ΋͏ͪΐͬͱ΍Γ͍ͨ͜ͱ͕͋Δ • ΤσΟλͰ࣮ߦதͰ΋อଘ͕͍ͨ͠! etc.

Slide 4

Slide 4 text

େମEditor֦ுͰͰ͖·͢!

Slide 5

Slide 5 text

Editor֦ுͬͯ? • ࣗ࡞ͷWindowग़ͤͨΓ͢Δ • ޷͖ͳػೳΛ݁ߏ͚ͭΒΕΔ • ௨ৗͰ͖ͳ͍͜ͱ΋Ͱ͖ΔΑ͏ʹͳͬͨΓ͢Δ • खಈͰ΍Δ͜ͱΛҰ෦ࣗಈԽͰ͖ͨΓ͢Δ

Slide 6

Slide 6 text

ͱ͋ΔUnityΤϯδχΞ1໊(2018೥౰࣌)ͷ੠ • ฉ͍ͨ͜ͱ͋Δ͚ͲΑ͘Θ͔Μͳ͍ • ΰϦϥͳਓͨͪͷ͍ٕ͢͝ज़Ͱ͠ΐ? • ·͊खಈͰͰ͖Δ͠…… • Ͳ͏ͤීஈͱશ͘ҧ͏͜ͱΛ͢ΔΜͰ͠ΐ?

Slide 7

Slide 7 text

݁ߏָʹͰ͖·͢!

Slide 8

Slide 8 text

࣮ࡍͷྲྀΕ ᶃ C#εΫϦϓτΛ࡞Δ ᶄ ͱΓ͋͑ͣWindowΛग़͢ ᶅ ϘλϯͰͳʹ͔͢Δ ᶆ ศར!

Slide 9

Slide 9 text

ᶄͱΓ͋͑ͣWindowΛग़͢ using UnityEditor; public class StartEditor : EditorWindow { //։͔Εํͱɺ։͔Εͨͱ͖ͷڍಈ [MenuItem("StartEditor/OpenDAZE")] private static void Open() { GetWindow("Start editor DAZE"); } }

Slide 10

Slide 10 text

ᶄͱΓ͋͑ͣWindowΛग़͢

Slide 11

Slide 11 text

ᶄϘλϯͰͳʹ͔͢Δ private void OnGUI() { if (GUILayout.Button("Nanikoe?")) { Debug.Log("Shiranai!"); } }

Slide 12

Slide 12 text

ᶄϘλϯͰͳʹ͔͢Δ

Slide 13

Slide 13 text

ᶄϘλϯͰͳʹ͔͢Δ2 private void OnGUI() { if (GUILayout.Button("Nanikoe?")) { var objs = FindObjectsOfType(); Debug.Log($"{objs.Length}"); foreach (var obj in objs) { Debug.Log(obj.name); } } }

Slide 14

Slide 14 text

ᶄϘλϯͰͳʹ͔͢Δ2

Slide 15

Slide 15 text

ศར!!!!!!!Ҏ্!!!!

Slide 16

Slide 16 text

ศར!!!!!!!Ҏ্!!!! Ͱ΋͜ͷ··ͩͱTransform͚ͩͩ͠ ͋ͱ͔Βม͍͑ͨͳΒϋʔυίʔσΟϯά?

Slide 17

Slide 17 text

ೖྗͰγʔϯ͔Βऔಘͯ͠ΈΔαϯϓϧ ᶃ ೖྗ૭Λ࡞Δ ᶄ ComponentࣗମΛऔಘ ᶅ ComponentΛؚΉ΋ͷΛग़͢ ᶆ ຐվ଄ͱ঺հ

Slide 18

Slide 18 text

ᶄೖྗ૭Λ࡞Δ private string _targetComponentName; private void OnGUI() { //Editorʹ࿮Λग़ͯ͠ɺೖྗΛ_targetComponentNameʹ֨ೲ͢Δ EditorGUILayout.BeginHorizontal(); _targetComponentName = EditorGUILayout.TextField("Target Component Name: ", _targetComponentName); EditorGUILayout.EndHorizontal(); . . .

Slide 19

Slide 19 text

ᶄೖྗ૭Λ࡞Δ

Slide 20

Slide 20 text

ᶄComponentࣗମΛऔಘ private static IEnumerable 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; }

Slide 21

Slide 21 text

ᶅComponentΛؚΉ΋ͷΛग़͢ private static Dictionary> _typeDict; private static Type GetType(string className) { if (_typeDict == null) { // Dictionary࡞੒ _typeDict = new Dictionary>(); var components = GetTypes(); foreach (var type in components) { if (!_typeDict.ContainsKey(type.Name)) { _typeDict.Add(type.Name, new List()); } _typeDict[type.Name].Add(type); } } return _typeDict[className][0]; }

Slide 22

Slide 22 text

ᶅComponentΛؚΉ΋ͷΛग़͢ if (GUILayout.Button("Search?")) { var objs = FindObjectsOfType(GetType(_targetComponentName) ?? null); Debug.Log($"{objs.Length}"); foreach (var obj in objs) { Debug.Log(obj.name); } }

Slide 23

Slide 23 text

׬੒……?

Slide 24

Slide 24 text

᩵୔ʹ!!! ᶃ ࣗ࡞Ϋϥε΋औಘͰ͖ΔΑ͏ʹ͢Δ ᶄ ॲཧΛܰ͘͢Δ ᶅ ΫϦοΫͨ͠Βࢀরݩʹඈͼ͍ͨΑͶ? ᶆ ͍ͬͦͷ͜ͱγʔϯʹͳ͍Prefab΋औಘ͠Α͏ͥ

Slide 25

Slide 25 text

͏͓͓͓͓͓͓͓͓͓͓͓͓͓͓͓ 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 _foundAssets = new List(); private Vector2 _currentScrollPosition; private static IEnumerable _cashedComponents; private static Dictionary> _typeDict; static MonoScript[] _monoScripts; private static bool _isFirstTime = true; //։͔Εํͱɺ։͔Εͨͱ͖ͷڍಈ [MenuItem("ReferenceFinder/Search")] private static void Open() { //։͔ΕΔࡍʹ͸ҰԠऔಘ _cashedComponents = GetAllTypes(); GetWindow("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(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);

Slide 26

Slide 26 text

͏͓͓͓͓͓͓(Unityͷίϯϙʔωϯτ)

Slide 27

Slide 27 text

͏͓͓͓͓͓͓(ࣗ࡞Ϋϥε)

Slide 28

Slide 28 text

׬੒ͨ͠΋ͷ͕ͪ͜ΒͰ͢(൒෼એ఻) https://www.kakovail.info/entry/2020/03/09/170855

Slide 29

Slide 29 text

໰୊఺ ։͍ͯͳ͍γʔϯ͸औಘͰ͖ͳ͍(γʔϯʹͳ͍Prefab͸औΕΔ) • ಡΈࠐΜͰͳ͍͔Βͳʹ΋ಡΈࠐΊͳ͍(౰વ) • SceneσʔλΛจࣈͱͯ͠GUID͔Βऔಘ͢Δ……? • Ұ౓։͘ͷ͸ͨ͘͠ͳ͍

Slide 30

Slide 30 text

໰୊఺ ͝ଘ஌ͷํɺώϯτԼ͍͞

Slide 31

Slide 31 text

͋Γ͕ͱ͏͍͟͝·ͨ͠