const int MinD3DX9Version = 32; // DirectX SDK December 2006

        public static UnmanagedLibrary LoadDirectX9()
        {
            for (var ver = MaxD3DX9Version; ver >= MinD3DX9Version; --ver)
            {
                var dllname = "d3dx9_" + Convert.ToString(ver) + ".dll";
                var handle  = UnmanagedLibrary.LoadLibrary(
                    dllname,
                    false);
                if (handle != null)
                {
                    return(handle);
                }
            }
            throw new Exception("DX9 dll couldn't be located");
        }
Exemple #2
0
        private static void InitializePlugin()
        {
            //Only try once during runtime
            if (s_triedLoading)
            {
                return;
            }

            UnmanagedLibrary libInstance = AssimpLibrary.Instance;

            //If already initialized, set flags and return
            if (libInstance.IsLibraryLoaded)
            {
                s_assimpAvailable = true;
                s_triedLoading    = true;
                return;
            }

            //First time initialization, need to set a probing path (at least in editor) to resolve the native dependencies
            string pluginsFolder            = Path.Combine(Application.dataPath, "Plugins");
            string editorPluginNativeFolder = Path.Combine(pluginsFolder, "AssimpNet", "Native");
            string native64LibPath          = null;
            string native32LibPath          = null;

            //Set if any platform needs to tweak the default name AssimpNet uses for the platform, null clears using an override at all
            string override64LibName = null;
            string override32LibName = null;

            //Setup DLL paths based on platforms. When run inside the editor, the path will be to the AssimpNet plugin folder structure. When in standalone,
            //Unity copies the native DLLs for the specific target architecture into a single Plugin folder.
            switch (Application.platform)
            {
            case RuntimePlatform.WindowsEditor:
                native64LibPath = Path.Combine(editorPluginNativeFolder, "win", "x86_64");
                native32LibPath = Path.Combine(editorPluginNativeFolder, "win", "x86");
                break;

            case RuntimePlatform.WindowsPlayer:
                //Seems like windows they are not added to any specific folder, just dropped inside Plugins folder
                native64LibPath = pluginsFolder;
                native32LibPath = pluginsFolder;
                break;

            case RuntimePlatform.LinuxEditor:
                native64LibPath = Path.Combine(editorPluginNativeFolder, "linux", "x86_64");
                native32LibPath = Path.Combine(editorPluginNativeFolder, "linux", "x86");
                break;

            case RuntimePlatform.LinuxPlayer:
                //Linux standalone creates subfolders presumably since it allows "universal" types
                native64LibPath = Path.Combine(pluginsFolder, "x86_64");
                native32LibPath = Path.Combine(pluginsFolder, "x86");
                break;

            case RuntimePlatform.OSXEditor:
                native64LibPath = Path.Combine(editorPluginNativeFolder, "osx", "x86_64");
                native32LibPath = Path.Combine(editorPluginNativeFolder, "osx", "x86");
                break;

            case RuntimePlatform.OSXPlayer:
                native64LibPath = pluginsFolder;
                native32LibPath = pluginsFolder;

                //In order to get unity to accept the dylib, had to rename it as *.bundle. Set an override name so we try and load that file. Seems to load
                //fine.
                string bundlelibName = Path.ChangeExtension(libInstance.DefaultLibraryName, ".bundle");
                override64LibName = bundlelibName;
                override32LibName = bundlelibName;
                break;
                //TODO: Add more platforms if you have binaries that can run on it
            }

            //If both null, then we do not support the platform
            if (native64LibPath == null && native32LibPath == null)
            {
                Debug.Log(string.Format("Assimp does not support platform: {0}", Application.platform.ToString()));
                s_assimpAvailable = false;
                return;
            }

            //Set resolver properties, null will clear the property
            libInstance.Resolver.SetOverrideLibraryName64(override64LibName);
            libInstance.Resolver.SetOverrideLibraryName32(override32LibName);
            libInstance.Resolver.SetProbingPaths64(native64LibPath);
            libInstance.Resolver.SetProbingPaths32(native32LibPath);
            libInstance.ThrowOnLoadFailure = false;

            //Try and load the native library, if failed we won't get an exception
            bool success = libInstance.LoadLibrary();

            s_assimpAvailable = success;
            s_triedLoading    = true;

            //Turn exceptions back on
            libInstance.ThrowOnLoadFailure = true;
        }