Search Unity

Seach for and load asset bundle.....

Discussion in 'Scripting' started by hosse, Mar 15, 2011.

  1. hosse

    hosse

    Joined:
    Feb 22, 2011
    Posts:
    61
    Hi guys, got a bit of a task at hand here which is way too difficult for me, was hoping for some help...

    I'm trying to create a search function in my app which will search for asset bundles by name, located in a folder on a server.

    Then print the search results as a list and then be able to select one of the bundles from the list and load it into my app positioned by its centre of mass on an empty object.

    When you search again and load a new object, it kills the previous one, so only one bundle is allowed at any time.

    I know its a bit of a job, but if anyone can begin to point me in the right direction in terms of scripting I'd really appreciate it.!

    -Hosse.
     
    Last edited: Mar 15, 2011
  2. hosse

    hosse

    Joined:
    Feb 22, 2011
    Posts:
    61
    As an after thought,
    If its any easier, instead of having a search function which finds asset bundles by name... this could be replaced by a "List" function which just lists all asset bundles in the server folder alphabetically..

    Would this be easier to create?

    -Hosse
     
  3. hosse

    hosse

    Joined:
    Feb 22, 2011
    Posts:
    61
    Ok I have my PHP script on my server,

    http://hosse.co.uk/files/files.php

    How can I get unity to see this php folder content list and generate GUItext for each model, which then can be clicked to download?
     
    Last edited: Mar 15, 2011
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You can use the WWW class to get the PHP output from the URL. If you configure the file listing as separate lines of text then you can separate the filenames using the System.String.Split function, which will give you an array of strings with each filename in its own array element. The most straightforward GUI control for displaying the strings would be the selection grid, since this takes a string array and creates a grid of buttons, only one of which can be active at once. The asset bundle files can be loaded using WWW, as with the PHP data, and you just need to use the list of filenames to generate the appropriate URLs.
     
  5. hosse

    hosse

    Joined:
    Feb 22, 2011
    Posts:
    61
    Thanks for the reply Andeeee,

    This is my PHP script;

    http://pastie.org/private/cf9prbaml4zzn5tit1mgvw

    How do I configure the file listing as separate lines of text? If my assetbundles are called
    "someasset_01.unity3d"


    Really appreciate it .!

    -Hosse
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Currently you have
    Code (csharp):
    1. echo "$file<br>";
    ...which adds the HTML linebreak <br> between the filenames for display by the browser. If you take out the <br> and replace it with \n
    Code (csharp):
    1. echo "$file\n";
    ...then the data pulled in by the Unity project will just contain the list of filenames separated by the linebreak character. You could just as easily use spaces, tabs or any other character that doesn't appear in the filenames. In the Unity code, you need the standard WWW code as detailed in the manual along with the call to split the text at the breaks:-
    Code (csharp):
    1. var bundleNames: String[];
    2.  
    3. function LoadBundleNames() {
    4.   var www : WWW = new WWW (url);
    5.   yield www;
    6.   bundleNames = www.text.Split();
    7. }
    Then, in your OnGUI function, pass the array of strings into GUI.SelectionGrid to display them:-
    Code (csharp):
    1. var selected: int;
    2. function OnGUI() {
    3.   selected = SelectionGrid (gridScreenRect, selected, bundleNames, 1);
    4. }
    This will show the names in a simple grid control and the "selected" variable will contain the array index of the one that has been chosen. You will then just need to load the asset bundle with that name (again with WWW), instantiate the prefab and position it.
     
  7. hosse

    hosse

    Joined:
    Feb 22, 2011
    Posts:
    61
    Hi andeeee
    Ok having some trouble, I changed the PHP script, the files now are listed with spaces.

    http://hosse.co.uk/files.php

    http://pastie.org/private/uahlvsgd3uhnmz0mgxxaw

    Code (csharp):
    1. var bundleNames: String[];
    2.  
    3. function LoadBundleNames() {
    4.   var www : WWW = new WWW ("http://www.hosse.co.uk/files.php");
    5.   yield www;
    6.   bundleNames = www.text.Split();
    7. }
    I don't know what to enter in the www.text.Split(); part...

    Code (csharp):
    1. var selected: int;
    2. function OnGUI() {
    3.   selected = SelectionGrid (gridScreenRect, selected, bundleNames, 1);
    4. }
    I don't even get this part... nor how to link the selected grid to load the assetbundle and instantiate... it makes no sense at all... I'm a script noobie.. a bit more guidance if you will please Andeeee...

    Thanks,
    -Hosse
     
    Last edited: Mar 16, 2011
  8. hosse

    hosse

    Joined:
    Feb 22, 2011
    Posts:
    61
    Can anybody shed some light on this, i'm totally stuck..
     
    Last edited: Mar 16, 2011
  9. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You would have these two code sections in the same script file. I'm not sure exactly when/where the menu should be displayed but you will likely call the LoadBundleNames function from the Start function (or you might even be able to place its code directly inside the Start function, depending on what you are doing). OnGUI will then use the names you have loaded into the array to display the selection grid (see this manual page for more information about selection grids and other controls). The line with the call to the Split function works as it is. The result of splitting the www.text string (ie, an array of strings with an element for each name returned by the PHP) is assigned to the bundleNames variable which is then used to display the selection grid.
     
  10. hosse

    hosse

    Joined:
    Feb 22, 2011
    Posts:
    61
    The menu needs to be displayed when you click the list button, then once you have chosen your model, the menu needs to be killed. I'm having real trouble piecing this together..