public static void Layout(SerializedProperty property, string newFilePreffix) { EditorGUILayout.BeginHorizontal(); bool valid = (property.objectReferenceValue != null) && (property.objectReferenceValue is T); var id = -1; if (valid) { id = PrefabCache <T> .Cache.IndexOf(property.objectReferenceValue as T); } id++; var iconSize = 20; if (id == 0 && newFilePreffix != null) { if (IconButton.Layout("add", iconSize, '+', "Create new " + typeof(T).ToString() + " prefab", Color.green)) { property.objectReferenceValue = K10EditorGUIUtils.CreateSequentialGO <T>(newFilePreffix + typeof(T)); PrefabCache <T> .Refresh(); } } else { PreviewButton.Layout(iconSize, property.objectReferenceValue as T); } var nid = EditorGUILayout.Popup(id, PrefabCache <T> .NamesWithNone); if (nid != id) { nid--; if (nid < 0) { property.objectReferenceValue = null; } else { property.objectReferenceValue = PrefabCache <T> .Cache[nid]; } } if (IconButton.Layout("refreshButton", iconSize, 'R', "Refresh prefabs loaded", Color.blue)) { PrefabCache <T> .Refresh(); } EditorGUILayout.EndHorizontal(); }
public static void Draw(Rect area, SerializedProperty property, string addFolder) { bool valid = (property.objectReferenceValue != null) && (property.objectReferenceValue is T); var id = -1; if (valid) { id = PrefabCache <T> .Cache.IndexOf(property.objectReferenceValue as T); } id++; var iconSize = Mathf.Min(area.height, area.width / 4); var iconArea = area.CutRight(area.width - iconSize).RequestHeight(iconSize); if (id == 0 && addFolder != null) { if (IconButton.Draw(iconArea, "add", '+', "Create new " + typeof(T).ToString() + " prefab", Color.green)) { property.objectReferenceValue = K10EditorGUIUtils.CreateSequentialGO <T>(addFolder + "/New" + typeof(T).ToString()); PrefabCache <T> .Refresh(); } } else { PreviewButton.Draw(iconArea, property.objectReferenceValue as T); } area = area.CutLeft(iconSize).RequestHeight(EditorGUIUtility.singleLineHeight); var nid = EditorGUI.Popup(area.CutRight(iconSize), id, PrefabCache <T> .NamesWithNone); if (nid != id) { nid--; if (nid < 0) { property.objectReferenceValue = null; } else { property.objectReferenceValue = PrefabCache <T> .Cache[nid]; } } if (IconButton.Draw(area.CutLeft(area.width - iconSize).RequestHeight(iconSize), "refreshButton", 'R', "Refresh prefabs loaded", Color.blue)) { PrefabCache <T> .Refresh(); } }
public static void Layout <T>(SerializedProperty prop, string newFolderPath) where T : Behaviour { var obj = prop.objectReferenceValue; if (obj == null) { var create = GUILayout.Button(IconCache.Get("match").Texture, new GUIStyle(), GUILayout.Width(16)); if (create) { var go = K10EditorGUIUtils.CreateSequentialGO <T>(newFolderPath + prop.ToFileName()); prop.objectReferenceValue = go; prop.serializedObject.ApplyModifiedProperties(); } } Layout <T>(prop, false); }
public static void Draw <T>(Rect r, SerializedProperty prop, string newFolderPath) where T : MonoBehaviour { var obj = prop.objectReferenceValue; if (obj == null) { var iconSize = 16; var create = GUI.Button(new Rect(r.x, r.y + (r.height - iconSize) / 2, iconSize, iconSize), IconCache.Get("match").Texture, new GUIStyle()); if (create) { var go = K10EditorGUIUtils.CreateSequentialGO <T>(newFolderPath + prop.ToFileName()); prop.objectReferenceValue = go; prop.serializedObject.ApplyModifiedProperties(); } r.x += iconSize + 2; r.width -= iconSize + 2; } Draw <T>(r, prop, false); }