Search Unity

How to find built EXE path?

Discussion in 'Scripting' started by coin-god, Feb 17, 2012.

  1. coin-god

    coin-god

    Joined:
    Jan 21, 2010
    Posts:
    325
    I made a Image loader that will get all the images I need from an external folder and load them in unity. This is so I (and other players) can edit thouse images once the game is built.

    This is part of the code:

    Code (csharp):
    1.  
    2. private ArrayList imageBuffer = new ArrayList();
    3.  
    4. ......
    5.  
    6. void Start () {
    7.  
    8. ............       
    9.         LoadImages();
    10.         flag = (Texture2D) imageBuffer[ (int) Random.Range(0.0F, 223.0F) ]; //Use random flag
    11.    
    12. }
    13.  
    14. .............
    15.  
    16. private void LoadImages() {
    17.        
    18.     string pathPrefix = @"file://";
    19.     string pathImageAssets = @"C:\TestUnity\";
    20.     string pathSmall = @"flags\";
    21.     string filename = @"flag";
    22.     string fileSuffix = @".png";
    23.  
    24.     //loads flag1.png ..... flag224.png
    25.     for (int i=0; i < 223; i++)
    26.     {
    27.         string indexSuffix = "";
    28.         indexSuffix += (i+1);
    29.  
    30.         string fullFilename = pathPrefix + pathImageAssets + pathSmall + filename + indexSuffix + fileSuffix;
    31.  
    32.         WWW www = new WWW(fullFilename);
    33.         Texture2D texTmp = new Texture2D(184, 106, TextureFormat.ARGB32, false);
    34.         www.LoadImageIntoTexture(texTmp);
    35.        
    36.     imageBuffer.Add(texTmp);
    37.     }
    38. }
    39.  
    Basicly it goes to this path: "C:\TestUnity\flags" and loads all the images. Wich works great.
    But I don't want to use that path now. I need a way of finding the path were the game is installed (where the Executable is) and load the iamges from the FLAG folder in there.

    How can I do this?
     
  2. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    534
    u can use Applicaiton.dataPath to find exact location of exe and put ur images in _Data folder
     
    Ran-Crump likes this.
  3. coin-god

    coin-god

    Joined:
    Jan 21, 2010
    Posts:
    325
    Thanks! That was it. :)
     
    sasimoon30 likes this.