public static void Draw(Type type, SerializedProperty prop, GUIContent gui, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound) { Draw(type, prop.objectReferenceValue, gui, onAssetsLoaded, onAssetsFound, (picked) => { prop.objectReferenceValue = picked; prop.serializedObject.ApplyModifiedProperties(); } ); }
void BuildMenu <T> (T current, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, Action <T> onPicked, Func <AssetSelectorElement, T> getObj) where T : class { List <AssetSelectorElement> elements = BuildElements(onAssetsLoaded, onAssetsFound, true, logToConsole: false); GenericMenu menu = new GenericMenu(); for (int i = 0; i < elements.Count; i++) { T e = getObj(elements[i]); menu.AddItem(new GUIContent(elements[i].displayName), e == current, () => onPicked(e)); } menu.ShowAsContext(); }
public void LoadAssets(System.Type type) { for (int ii = 0; ii < assetPackages.Length; ii++) { string folderName = assetPackages[ii].folderPath; assetPackages[ii].assets = Resources.LoadAll(folderName, type); } if (OnAssetsLoaded != null) { OnAssetsLoaded.Invoke(assetPackages); } }
void DrawName(string current, GUIContent gui, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, Action <string> onPicked) { EditorGUILayout.BeginHorizontal(); DrawLabel(gui); if (GUITools.Button(GetGUI(current), GUITools.popup)) { BuildMenu(current, onAssetsLoaded, onAssetsFound, onPicked, (e) => e.assetName); } if (GUITools.IconButton(pingGUI)) { PingAssetWithName(current, onAssetsLoaded, onAssetsFound); } EditorGUILayout.EndHorizontal(); }
void DrawName(Rect pos, string current, GUIContent gui, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, Action <string> onPicked) { float x = pos.x; DrawLabel(ref x, pos.y, gui); if (DrawButton(x, pos, GetGUI(current))) { BuildMenu(current, onAssetsLoaded, onAssetsFound, onPicked, (e) => e.assetName); } if (GUITools.IconButton(pos.x + (pos.width - GUITools.iconButtonWidth), pos.y, pingGUI)) { PingAssetWithName(current, onAssetsLoaded, onAssetsFound); } }
void Draw(Object current, GUIContent gui, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, Action <Object> onPicked) { EditorGUILayout.BeginHorizontal(); DrawLabel(gui); if (GUITools.Button(GetGUI(current), GUITools.popup)) { BuildMenu(current, onAssetsLoaded, onAssetsFound, onPicked, (e) => e.asset); } if (GUITools.IconButton(pingGUI)) { EditorGUIUtility.PingObject(current); } EditorGUILayout.EndHorizontal(); }
void Draw(Rect pos, Object current, GUIContent gui, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, Action <Object> onPicked) { float x = pos.x; DrawLabel(ref x, pos.y, gui); if (DrawButton(x, pos, GetGUI(current))) { BuildMenu(current, onAssetsLoaded, onAssetsFound, onPicked, (e) => e.asset); } if (GUITools.IconButton(pos.x + (pos.width - GUITools.iconButtonWidth), pos.y, pingGUI)) { EditorGUIUtility.PingObject(current); } }
void PingAssetWithName(string name, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound) { if (name != null) { List <AssetSelectorElement> elements = BuildElements(onAssetsLoaded, onAssetsFound, false, logToConsole: false); for (int i = 0; i < elements.Count; i++) { if (elements[i].asset.name == name) { EditorGUIUtility.PingObject(elements[i].asset); break; } } } }
List <AssetSelectorElement> BuildElements(OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, bool addNull, bool logToConsole) { List <Object> assets = AssetTools.FindAssetsByType(type, logToConsole, onAssetsFound); List <AssetSelectorElement> r = new List <AssetSelectorElement>(); for (int i = 0; i < assets.Count; i++) { r.Add(new AssetSelectorElement(assets[i], type.Name)); } if (onAssetsLoaded != null) { r = onAssetsLoaded(r); } if (addNull) { r.Insert(0, new AssetSelectorElement(null, type.Name)); } return(r); }
public static void DrawName(Type type, string current, GUIContent gui, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, Action <string> onPicked) { GetSelector(type).DrawName(current, gui, onAssetsLoaded, onAssetsFound, onPicked); }
public static void Draw(Type type, Rect pos, Object current, GUIContent gui, OnAssetsLoaded onAssetsLoaded, Func <List <Object>, List <Object> > onAssetsFound, Action <Object> onPicked) { GetSelector(type).Draw(pos, current, gui, onAssetsLoaded, onAssetsFound, onPicked); }