├── PrefabDropdown
├── ProjectSettings
│ ├── ProjectVersion.txt
│ ├── TagManager.asset
│ ├── TimeManager.asset
│ ├── AudioManager.asset
│ ├── EditorSettings.asset
│ ├── InputManager.asset
│ ├── NavMeshAreas.asset
│ ├── NetworkManager.asset
│ ├── DynamicsManager.asset
│ ├── GraphicsSettings.asset
│ ├── ProjectSettings.asset
│ ├── QualitySettings.asset
│ ├── ClusterInputManager.asset
│ ├── EditorBuildSettings.asset
│ ├── Physics2DSettings.asset
│ └── UnityConnectSettings.asset
├── Assets
│ ├── test.unity
│ ├── Prefabs
│ │ ├── PrefabLevel.prefab
│ │ ├── PrefabPlayer.prefab
│ │ ├── Subfolder
│ │ │ ├── PrefabLevel2.prefab
│ │ │ └── PrefabLevel2.prefab.meta
│ │ ├── Subfolder.meta
│ │ ├── PrefabLevel.prefab.meta
│ │ └── PrefabPlayer.prefab.meta
│ ├── Level.cs
│ ├── test.unity.meta
│ ├── Arcturus.meta
│ ├── Prefabs.meta
│ ├── Arcturus
│ │ ├── Attributes.meta
│ │ └── Attributes
│ │ │ ├── Editor.meta
│ │ │ ├── PrefabDropdownAttribute.cs.meta
│ │ │ ├── Editor
│ │ │ ├── PrefabDropdownDrawer.cs.meta
│ │ │ └── PrefabDropdownDrawer.cs
│ │ │ └── PrefabDropdownAttribute.cs
│ └── Level.cs.meta
└── .gitignore
├── PrefabDropdown.unitypackage
└── README.md
/PrefabDropdown/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 5.6.1f1
2 |
--------------------------------------------------------------------------------
/PrefabDropdown.unitypackage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown.unitypackage
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/test.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/Assets/test.unity
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs/PrefabLevel.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/Assets/Prefabs/PrefabLevel.prefab
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs/PrefabPlayer.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/Assets/Prefabs/PrefabPlayer.prefab
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/NavMeshAreas.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/GraphicsSettings.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/ClusterInputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/ClusterInputManager.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/Physics2DSettings.asset
--------------------------------------------------------------------------------
/PrefabDropdown/ProjectSettings/UnityConnectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/ProjectSettings/UnityConnectSettings.asset
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs/Subfolder/PrefabLevel2.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Arcturus-Studio/PrefabDropdown/HEAD/PrefabDropdown/Assets/Prefabs/Subfolder/PrefabLevel2.prefab
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Level.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public class Level : MonoBehaviour {
4 |
5 | [PrefabDropdown("Subfolder")]
6 | public Level levelToLoad;
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/test.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bbecffb517274744b974d15608895007
3 | timeCreated: 1498159124
4 | licenseType: Free
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Arcturus.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 87fd6676460b8c74a8e4fb54661c9637
3 | folderAsset: yes
4 | timeCreated: 1498157464
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4faca90e76e231a47ba487e0da8e66a8
3 | folderAsset: yes
4 | timeCreated: 1498158554
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Arcturus/Attributes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a19384478f5f2d44cbb2acead252ad74
3 | folderAsset: yes
4 | timeCreated: 1494440956
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs/Subfolder.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 515383240d2eabb44a4f4e39774a854e
3 | folderAsset: yes
4 | timeCreated: 1498158817
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Arcturus/Attributes/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0fb48bf537419f44e85d1adb1f7734ae
3 | folderAsset: yes
4 | timeCreated: 1495204917
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs/PrefabLevel.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c3e2696fd1ca53347961d1e648fb70d0
3 | timeCreated: 1498158556
4 | licenseType: Free
5 | NativeFormatImporter:
6 | mainObjectFileID: 100100000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs/PrefabPlayer.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3252015bc8a7c5140989626a6c7533fc
3 | timeCreated: 1498160826
4 | licenseType: Free
5 | NativeFormatImporter:
6 | mainObjectFileID: 100100000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Prefabs/Subfolder/PrefabLevel2.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0a1df53a06c298347b7217ac5a22ea4a
3 | timeCreated: 1498158556
4 | licenseType: Free
5 | NativeFormatImporter:
6 | mainObjectFileID: 100100000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Level.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 929a183753ff01241ba6e24ff017b5db
3 | timeCreated: 1498158020
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Arcturus/Attributes/PrefabDropdownAttribute.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 02429eb5b953c9d4291a8919bb11ac97
3 | timeCreated: 1494426537
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Arcturus/Attributes/Editor/PrefabDropdownDrawer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c610387874b48b040ad34de63824c43a
3 | timeCreated: 1494426623
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/PrefabDropdown/.gitignore:
--------------------------------------------------------------------------------
1 | /[Ll]ibrary/
2 | /[Tt]emp/
3 | /[Oo]bj/
4 | /[Bb]uild/
5 | /[Bb]uilds/
6 | /Assets/AssetStoreTools*
7 |
8 | # Visual Studio 2015 cache directory
9 | /.vs/
10 |
11 | # Autogenerated VS/MD/Consulo solution and project files
12 | ExportedObj/
13 | .consulo/
14 | *.csproj
15 | *.unityproj
16 | *.sln
17 | *.suo
18 | *.tmp
19 | *.user
20 | *.userprefs
21 | *.pidb
22 | *.booproj
23 | *.svd
24 | *.pdb
25 |
26 | # Unity3D generated meta files
27 | *.pidb.meta
28 |
29 | # Unity3D Generated File On Crash Reports
30 | sysinfo.txt
31 |
32 | # Builds
33 | *.apk
34 | *.unitypackage
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PrefabDropdown
2 | An attribute tag to speed up finding and selecting prefabs in Unity
3 |
4 | Just add the tag above a variable to have it display in the editor as a dropdown consisting of any prefabs that contain a component of the same type as the attributed variable
5 | ```
6 | [PrefabDropdown] //displays all corresponding prefabs in "Assets/Prefabs"
7 | public Level levelToLoad;
8 | ```
9 |
10 | You can also pass a string argument to limit the search to a specific subfolder
11 | ```
12 | [PrefabDropdown("Levels/Subfolder")] //displays all corresponding prefabs in "Assets/Prefabs/Levels/Subfolder"
13 | public Level levelToLoad;
14 | ```
15 |
16 | Read the full article on Medium
17 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Arcturus/Attributes/PrefabDropdownAttribute.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public class PrefabDropdownAttribute : PropertyAttribute
4 | {
5 | public const string PrefabDefaultPath = "Prefabs";
6 |
7 | public string path = PrefabDefaultPath;
8 | public string propertyType;
9 |
10 | ///
11 | /// Use default path
12 | ///
13 | public PrefabDropdownAttribute()
14 | {
15 | }
16 |
17 | ///
18 | /// Use a subfolder of the default path
19 | ///
20 | ///
21 | public PrefabDropdownAttribute(string subfolderPath)
22 | {
23 | if(!string.IsNullOrEmpty(subfolderPath))
24 | path = string.Format("{0}{1}{2}", PrefabDefaultPath, System.IO.Path.DirectorySeparatorChar, subfolderPath);
25 | }
26 |
27 | ///
28 | /// Override defaults, define subfolders
29 | ///
30 | ///
31 | ///
32 | public PrefabDropdownAttribute(string rootPath, params string[] subfolderPaths)
33 | {
34 | path = rootPath;
35 | for (int i = 0; i < subfolderPaths.Length; i++)
36 | {
37 | path += System.IO.Path.DirectorySeparatorChar + subfolderPaths[i];
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/PrefabDropdown/Assets/Arcturus/Attributes/Editor/PrefabDropdownDrawer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using UnityEngine;
3 | using UnityEditor;
4 |
5 | [CustomPropertyDrawer(typeof(PrefabDropdownAttribute))]
6 | public class PrefabDropdownDrawer : PropertyDrawer
7 | {
8 | PrefabDropdownAttribute prefabDropdown;
9 | List prefabs;
10 | string[] names;
11 | int index = -1;
12 | bool validPath = false;
13 | string none = "- null -";
14 |
15 | static GUISkin editorSkin;
16 | static GUIStyle prefabSelectStyle;
17 |
18 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
19 | {
20 | prefabDropdown = attribute as PrefabDropdownAttribute;
21 |
22 | if(editorSkin == null)
23 | GetStyles();
24 |
25 | //finding all prefabs with the desired component
26 | if (prefabs == null)
27 | FindPrefabs(property);
28 |
29 | //displaying a message if the user provided an invalid path
30 | if (!validPath)
31 | {
32 | EditorGUI.HelpBox(position, string.Format("{0} - path \"{1}\" does not exist in Assets", label.text, prefabDropdown.path), MessageType.Error);
33 | return;
34 | }
35 |
36 | //displaying a message if there are no matching prefabs in the folder
37 | if (prefabs.Count == 0)
38 | {
39 | EditorGUI.HelpBox(position, label.text + " - No prefabs of type at path", MessageType.Error);
40 | return;
41 | }
42 |
43 | //finding the correct index when the component with this drawer is reshown in the inspector
44 | if (index == -1)
45 | index = Mathf.Max(0, 1+prefabs.IndexOf((GameObject)property.objectReferenceValue));
46 |
47 | position.width -= 20;
48 | //showing the popup, setting the properties object refrence when index is changed
49 | int i = EditorGUI.Popup(position, label.text, index, names);
50 | if (i != index || property.objectReferenceValue==null)
51 | {
52 | index = i;
53 | if (index == 0)
54 | property.objectReferenceValue = null;
55 | else if (prefabDropdown.propertyType == "GameObject")
56 | property.objectReferenceValue = ((Component)prefabs[i-1]).gameObject;
57 | else
58 | property.objectReferenceValue = prefabs[i-1];
59 | }
60 |
61 | position.x += position.width - 1;
62 | position.width = 21;
63 |
64 | EditorGUI.BeginDisabledGroup (!property.objectReferenceValue);
65 | //displaying a button to allow you to quickly find the selected object in the project window
66 | if (GUI.Button(position, GUIContent.none, prefabSelectStyle))
67 | {
68 | if (property.objectReferenceValue != null)
69 | {
70 | if (prefabDropdown.propertyType == "GameObject")
71 | Selection.activeGameObject = (GameObject)property.objectReferenceValue;
72 | else
73 | Selection.activeGameObject = ((Component)property.objectReferenceValue).gameObject;
74 | }
75 | }
76 | EditorGUI.EndDisabledGroup();
77 | }
78 |
79 | public void FindPrefabs(SerializedProperty property)
80 | {
81 | //finding the type of the property we are drawing
82 | if (prefabDropdown.propertyType == null)
83 | prefabDropdown.propertyType = property.type.Substring(6, property.type.Length - 7);
84 |
85 | //only scanning for gameobjects in the specified folder
86 | prefabs = FindPrefabsContaining(prefabDropdown.path, prefabDropdown.propertyType);
87 | //filling name array with the names of each prefab found for display in the dropdown
88 | names = new string[prefabs.Count+1];
89 | names[0] = none;
90 | for (int i = 0; i < prefabs.Count; i++)
91 | names[i+1] = prefabs[i].name;
92 |
93 | //ensures the index is adjusted in case a prefab was added/removed and the original index no longer represents the refrenced prefab
94 | if (prefabDropdown.propertyType == "GameObject")
95 | index = Mathf.Max(0, 1+prefabs.IndexOf(((GameObject)property.objectReferenceValue).GetComponent(prefabDropdown.propertyType)));
96 | else
97 | index = Mathf.Max(0,1+ prefabs.IndexOf(property.objectReferenceValue));
98 | }
99 |
100 | public List FindPrefabsContaining(string path, string type)
101 | {
102 | if (!AssetDatabase.IsValidFolder("Assets"+System.IO.Path.DirectorySeparatorChar+path))
103 | {
104 | validPath = false;
105 | return new List();
106 | }
107 | validPath = true;
108 | List result = new List();
109 | //searching for all .prefab files in the specified path and subfolders
110 | string[] fileEntries = System.IO.Directory.GetFiles(Application.dataPath + System.IO.Path.DirectorySeparatorChar + path, "*.prefab", System.IO.SearchOption.AllDirectories);
111 | foreach (string fileName in fileEntries)
112 | {
113 | //getting only the part of the path that resides within the unity project
114 | int assetPathIndex = fileName.IndexOf("Assets");
115 | string localPath = fileName.Substring(assetPathIndex);
116 | //loading the asset so we can confirm if it contains the component we are looking for
117 | GameObject t = (GameObject)AssetDatabase.LoadMainAssetAtPath(localPath);
118 | if (t == null)
119 | continue;
120 | UnityEngine.Object o = t.GetComponent(type);
121 | if (o != null)
122 | result.Add(o);
123 | }
124 | return result;
125 | }
126 |
127 | private void GetStyles()
128 | {
129 | editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
130 | var guiStyleState = EditorGUIUtility.isProSkin ? editorSkin.GetStyle("IN ObjectField").focused : editorSkin.GetStyle("IN ObjectField").normal;
131 | prefabSelectStyle = new GUIStyle(){ normal = guiStyleState };
132 | }
133 |
134 | }
--------------------------------------------------------------------------------