Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android support to use assets created with the visual editor #10

Closed
RavenCastleSTU opened this issue Oct 17, 2012 · 3 comments
Closed

Comments

@RavenCastleSTU
Copy link

Testing GoKit on my game I deployed to an Android phone and found that the Assets where not loading . I made some modifications to the original method in charge of handling the loading process and managed to get it working.

Since I don't use Git here is the solution: (replace the current method with the code bellow)

Class: GoSpline.cs

    /// <summary>
/// helper to get a node list from an asset created with the visual editor
/// </summary>
private static List<Vector3> nodeListFromAsset( string pathAssetName )
{

if UNITY_WEBPLAYER

        Debug.LogError( "The Web Player does not support loading files from disk." );
        return null;

else

    var path = string.Empty;
    if( !pathAssetName.EndsWith( ".asset" ) )
        pathAssetName += ".asset";

    byte[] bytes = null;

    if (Application.platform == RuntimePlatform.Android)
    {
        path = Path.Combine("jar:file://" + Application.dataPath + "!/assets/", pathAssetName);

        WWW loadAsset = new WWW(path);
        while (loadAsset.isDone) { } // maybe make a safety check here
        bytes = loadAsset.bytes;
    }
    else
    {
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            // on iOS at runtime, we load from the dataPath
            path = Path.Combine(Path.Combine(Application.dataPath, "Raw"), pathAssetName);
        }
        else
        {
            // default to looking in the StreamingAssets folder
            path = Path.Combine(Path.Combine(Application.dataPath, "StreamingAssets"), pathAssetName);
        }

        bytes = File.ReadAllBytes(path);
    } 

    return bytesToVector3List( bytes );

endif

}
@prime31
Copy link
Owner

prime31 commented Oct 18, 2012

I am not a big fan of the deadlock while loop but I'll put it in the mainline now and do a refactor and proper fix later on

@prime31 prime31 closed this as completed Oct 18, 2012
@RavenCastleSTU
Copy link
Author

Sorry, I was too lazy to put a timer or a safety. But you got spirit.

:-)

@hannesdvl
Copy link

I know this one is closed but just wanted to say to get Android working I had to change this line:

 while( loadAsset.isDone ) { } // maybe make a safety check here

to this

 while( !loadAsset.isDone ) { } // maybe make a safety check here

By adding the !, we're actually waiting for the loading to complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants