Пример #1
0
 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();
     }
          );
 }
Пример #2
0
        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();
        }
Пример #3
0
    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);
        }
    }
Пример #4
0
 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();
 }
Пример #5
0
        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);
            }
        }
Пример #6
0
 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();
 }
Пример #7
0
        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);
            }
        }
Пример #8
0
 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;
             }
         }
     }
 }
Пример #9
0
        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);
        }
Пример #10
0
 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);
 }
Пример #11
0
 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);
 }