briochie / wow.unity

A collection of assets to make working with wow.export easier in Unity.
MIT License
18 stars 8 forks source link

POSIX path support #13

Closed fnio5 closed 1 year ago

fnio5 commented 1 year ago

Changed some of the hard coded directory separator to Path.DirectorySeparatorChar, now it partially work on linux also. Screenshot_2023-06-10_19-36-20

briochie commented 1 year ago

Do you have any other feedback about what is missing for Linux compatibility? I’d love to see that be a thing.

fnio5 commented 1 year ago

Main problem with linux and mac is going to be the paths so I would suggest maybe using the FileInfo class more and Path.Combine() to avoid any pitfalls instead of doing any string manipulations. Other than that not sure if its a linux thing but there was a thing with the PreLegion custom function not being linked up in the shader by default I though it was broken but it just needed to to be linked up.

oyvind-stromsvik commented 1 year ago

but there was a thing with the PreLegion custom function not being linked up in the shader by default I though it was broken but it just needed to to be linked up.

It was the same for me. I have no prior experience with Shader Graph so didn't dare assume it was wrong in this repo, but I guess it's fair to assume it is then. I can make a PR for this sooner or later, unless you beat me to it :)

fnio5 commented 1 year ago

Here is a example change that might work.

public static M2 ReadMetadataFor(string path)
{
    string pathToMetadata = Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + ".json";
    if (!File.Exists(pathToMetadata))
    {
        return null;
    }

    var sr = new StreamReader(Application.dataPath.Replace("Assets", "") + pathToMetadata);
    var fileContents = sr.ReadToEnd();
    sr.Close();

    return JsonConvert.DeserializeObject<M2>(fileContents);
}

changed to

public static M2 ReadMetadataFor(FileInfo modelFile)
{
    FileInfo jsonFile = new FileInfo(Path.ChangeExtension(modelFile.FullName, ".json"));
    if (!jsonFile.Exists)
    {
        return null;
    }

    using (var sr = jsonFile.OpenText())
    {
        return JsonConvert.DeserializeObject<M2>(sr.ReadToEnd());
    }
}