/// <summary> /// Let the user select what king of scriptable object it desires to create and do so /// </summary> public void OnGUI() { Setup(); // Check if we can go directly to the Scriptable Object instance if (selectedScriptableTypeIdx == 0) { MonoScript script = Selection.activeObject as MonoScript; if (script != null) { int idx = typesList.IndexOf(script.GetClass()); if (idx > 0) { selectedScriptableTypeIdx = idx; } } } EditorGUILayout.BeginVertical(); { selectedScriptableTypeIdx = EditorGUILayout.Popup(selectedScriptableTypeIdx, names.ToArray <string>()); EditorGUILayout.Space(); EditorGUI.BeginDisabledGroup(selectedScriptableTypeIdx == 0); if (GUILayout.Button("Enter")) { ScriptableObjectMenu.CreateItem(typesList[selectedScriptableTypeIdx]); Close(); } EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndVertical(); }
public static void FastInstantiation() { MonoScript script = Selection.activeObject as MonoScript; if (script == null) { Debug.LogError("Selected item is not a ScriptableObject script"); return; } Attribute[] customAttributes = script.GetClass().GetCustomAttributes(false) as Attribute[]; foreach (Attribute attribute in customAttributes) { if (attribute is ScriptableAttribute) { ScriptableObjectMenu.CreateItem(script.GetClass()); return; } } Debug.LogError("Selected item is not a valid ScriptableObject or doesn't have the ScriptableAttribute attribute tag"); }