Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

[Feature] Dissonance is not compatible with Unity Packages #196

Open cliv3dev opened 4 years ago

cliv3dev commented 4 years ago

Context

In my project I split my code between several Unity packages image Dissonance SDK is in one of those packages.

Expected Behavior

Dissonance should work as intended when embedded in a package.

Actual Behavior

When I open a project using those packages, I get this error: image image

Workaround

We updated DissonanceRoothPath.cs with this fix: image

Steps to Reproduce

  1. put Dissonance SDK in a package
  2. Create a project and reference the package with dissonance

Your Environment

Thanks!

martindevans commented 4 years ago

Have you checked that the uses of the BasePath still work correctly after this change? e.g. Assets/Plugins/Dissonance/Core/Config/ChatRoomSettings.cs uses Resources.Load to load the path Path.Combine(DissonanceRootPath.BaseResourcePath, SettingsFileResourceName + ".asset"); - however from the documentation it looks like Resources.Load isn't intended to work with resources inside packages.

The Unity asset store team keep promising that the Unity Asset Store will support packages as a way to distribute assets. Once that's available we will definitely be moving over as soon as possible!

cliv3dev commented 4 years ago

Hi Martin, I finally had some time to propose a better solution. Here is my proposition change the file Startup.cs (see in attach). This solvves the warnings I have when using Dissonance as a package... Startup.cs.zip Tell me what you think...

martindevans commented 4 years ago

Thanks for this! I'll see if I can include it in the next release.

cliv3dev commented 4 years ago

Well, things are not over yet. Now when I instanciate a DissoanceSetup prefab from MirrorDissonance integration, the MirrorIgnoranceCommsNetwork script doesn't seem to compil but I don't have any errors in the Unity Console: image And when starting the game I get this error: image

I believe this comes from the fact that Dissonance is in a package... Do you see any workaround for this ? thanks!

martindevans commented 4 years ago

The most likely problem seems like something to do with assemblies (e.g. Mirror integration can't find some code it needs which is hidden away in the Dissonance assembly). I'm not sure precisely how asmdefs interact with packages. However I can't see how anything like that could lead to a situation where compile errors don't work properly!

cliv3dev commented 4 years ago

Thanks for the hint Martin ! I think I nailed it: after upgrading to latest version of both Dissonance (v7.0.2) and DissonanceForMirror (v7.0.1), here are the changes I made:

  1. moved DissonanceVoip.asmdef file to Dissonance root directory
  2. As I have Mirror in another package, I added the Mirror package in the GUIDs list of DissonanceVoip.asmdef
  3. I created a MirrorIgnoranceEditor.asmdef in Integrations/MirrorIgnorance/Editor
  4. In MirrorIgnoranceEditor.asmdef, I flagged Editor as unique Platform,
  5. In MirrorIgnoranceEditor.asmdef, I added DissonanceVoip.asmdef, DissonanceVoipEditor.asmdef, and Mirror.asmdef in the Use GUIDs list.

And that's it! No more problems. Everything seems fine now! dissonance can be put in a Unity package :) cheers,

JavelinIA commented 2 years ago

@cliv3dev Did you change anything at the Startup.cs or DissonanceRoothPath.cs or did you fix it just by adding assembly definitions?

cliv3dev commented 2 years ago

I had to do both: change the startup.cs + tweak assembly definition files to do the trick...

JavelinIA commented 2 years ago

Ouh, that was a quick reply. Thanks, i'll give it a try

darrencperry commented 1 year ago

For me, the modifications to Startup.cs didn't work, so I added some code to search for the file in all asset paths and then I could find and set the install directory path successfully. We can probably replace the maybePathFile section with this but someone with more time on the project might have to make that call! You may have to commit the changed DissonanceRootPath.cs to your package though...

// search everywhere for DissonanceComms.cs
string foundPath = null;
var installDirectoryProjPath="";
var allAssetPaths = AssetDatabase.GetAllAssetPaths();
var fileName = "DissonanceComms.cs";
for(int i = 0; i < allAssetPaths.Length; ++i)
{
    if (allAssetPaths[i].EndsWith(fileName))
    {
        foundPath = allAssetPaths[i].Replace(Path.DirectorySeparatorChar.ToString(), "/").Replace("/DissonanceComms.cs", "");
    }
}

if (foundPath != null) {
    installDirectoryProjPath = foundPath;
}
else {

    //Find the DissonanceComms.cs file
    var maybePathFile = Directory
        .GetFiles(Application.dataPath, "DissonanceComms.cs", SearchOption.AllDirectories)
        .SingleOrDefault();
    if (maybePathFile == null)
    {
        Debug.LogError(
            "Cannot Find DissonanceComms.cs! Dissonance has not been installed correctly. Please delete all Dissonance related files and import them again");
        return false;
    }

    //Convert into a full path with normalized file separators
    var fileFullPath =
        new FileInfo(Path.GetFullPath(maybePathFile)).FullName.Replace(
            Path.DirectorySeparatorChar.ToString(), "/");
    if (!fileFullPath.StartsWith(Application.dataPath.Replace(Path.DirectorySeparatorChar.ToString(), "/")))
        throw new InvalidOperationException(
            "Dissonance install directory is not a child directory of 'Application.dataPath'!");

    //Work out the path to the install directory (as a project path)
    installDirectoryProjPath = Application.dataPath.Split('/').Last() + "/" + fileFullPath
        .Substring(Application.dataPath.Length).TrimStart('/').Replace("/DissonanceComms.cs", "");

    //If the path is correct we're good to go
    if (installDirectoryProjPath == DissonanceRootPath.BasePath)
        return true;
}