コード例 #1
0
    public void OnGUI()
    {
        // Make sure everything is initialized
        if (m_logo == null)
        {
            FetchWwiseLogo();
        }
        if (m_welcomeStyle == null)
        {
            InitGuiStyles();
        }

        GUILayout.BeginHorizontal("box");
        {
            GUILayout.Label(m_logo, GUILayout.Width(m_logo.width));
            GUILayout.Label("Welcome to Wwise " + m_newIntegrationVersion + "!", m_welcomeStyle, GUILayout.Height(m_logo.height));
        }
        GUILayout.EndHorizontal();

        // Make the HelpBox font size a little bigger
        GUILayout.Label("A previous Wwise Unity Integration has been detected. The Unity project will be migrated from Wwise Unity Integration " + m_installedIntegrationVersion + " to Wwise Unity Integration " + m_newIntegrationVersion + ". " +
                            "This Unity project should be backed up since this action is not reversible. If the Unity project is under source control, make sure to check out the Unity project folder before starting the migration.\n" +
                            "Click start when ready",
                            m_helpStyle
                        );

        if (m_platformsToDelete.Count != 0)
        {
            GUIStyle style = new GUIStyle(GUI.skin.label);
            style.normal.textColor = Color.red;
            GUILayout.Label("The following platforms integrations are now outdated and will be removed. Make sure to import the Wwise Unity Integration " + m_newIntegrationVersion + " for these platforms after migration has completed:",
                                style
                            );

            m_scrollViewPos = GUILayout.BeginScrollView(m_scrollViewPos);
            {
                for (int i = 0; i < m_platformsToDelete.Count; i++)
                {
                    GUILayout.Label("\t-" + m_platformsToDelete[i], style);
                }
            }
            GUILayout.EndScrollView();
        }

        GUILayout.BeginVertical();
        {
            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();

                if (state == MigrationWindowState.WAIT_FOR_USER)
                {
                    if (GUILayout.Button("Start", GUILayout.Width(200)))
                    {
                        Debug.Log("Starting migration...");
                        state = MigrationWindowState.IMPORT;
                    }

                    if (GUILayout.Button("Cancel", GUILayout.Width(200)))
                    {
                        state = MigrationWindowState.CANCEL;
                    }
                }
                else
                {
                    GUILayout.Label("Please wait until this window closes before continuing.");
                }
                GUILayout.FlexibleSpace();

            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
        }
        GUILayout.EndVertical();
    }
コード例 #2
0
    void MigrateGameObjects()
    {
        //Get the name of the currently opened scene
        string currentScene = EditorApplication.currentScene.Replace('/', '\\');

        for (int i = 0; i < m_scenes.Length; i++)
        {
            //Save the current scene and open a new one
            EditorApplication.SaveScene();
            EditorApplication.OpenScene(m_scenes[i]);

            foreach (string file in m_intermediateFiles)
            {
                //Since monobehaviour scripts need to have the same name as the class it contains, we can use it to get the type of the object
                Type objectType = Type.GetType(Path.GetFileNameWithoutExtension(file) + ", Assembly-CSharp");

                //Get all objects in the scene with the specified type
                UnityEngine.Object[] objects = UnityEngine.Object.FindObjectsOfType(objectType);

                //Get the migration method
                MethodInfo migrateInfo = objectType.GetMethod("Migrate", BindingFlags.Public | BindingFlags.Instance);

                if (migrateInfo != null)
                {
                    //call the migration method of each object
                    foreach (UnityEngine.Object currentObject in objects)
                    {
                        migrateInfo.Invoke(currentObject, null);
                    }
                }

                MethodInfo staticMigrateInfo = objectType.GetMethod("StaticMigrate", BindingFlags.Public | BindingFlags.Static);
                // Look for static migration functions
                if (staticMigrateInfo != null)
                {
                    staticMigrateInfo.Invoke(null, null);
                }
            }
        }

        //Reopen the scene that was opened before the migration process started
        EditorApplication.SaveScene();
        EditorApplication.OpenScene(currentScene);

        if ((m_installedIntegrationNumber + m_completedMigrations) == m_newIntegrationNumber)
        {
            state = MigrationWindowState.DONE;
            Close();
        }
        else
        {
            state = MigrationWindowState.RECOMPILE;
        }
    }
コード例 #3
0
    void Recompile()
    {
        try
        {
            FileInfo[] files = new DirectoryInfo(Application.dataPath + "/Wwise").GetFiles("*.migration_" + (m_installedIntegrationNumber + m_completedMigrations), SearchOption.AllDirectories);

            //Needed for the MigrateGameObjects function
            m_intermediateFiles = new string[files.Length];

            // Special case for old (pre 2013.2.8) project migration
            string WwiseDeploymentPath = Path.Combine(Path.Combine(Application.dataPath, "Wwise"), "Deployment");
            if (File.Exists(Path.Combine(Path.Combine(WwiseDeploymentPath, "Examples"), "AkGlobalSoundEngineInitializer.cs")))
            {
                string scriptName = Path.Combine(Path.Combine(WwiseDeploymentPath, "Components"), "AkOldVersionMigrator.migration_special");
                if (File.Exists(scriptName))
                {
                    m_intermediateFiles = new string[files.Length + 1];
                    m_intermediateFiles[files.Length] = scriptName;
                    string newName = Path.ChangeExtension(scriptName, ".cs");
                    File.Move(scriptName, newName);
                    File.SetLastWriteTime(newName, DateTime.Now);
                }
            }

            for (int i = 0; i < files.Length; i++)
            {
                m_intermediateFiles[i] = files[i].Name;
            }

            //We delete the scripts that are not compatible with the new integration
            //and replace them with intermediate scripts that are compatible with both versions
            foreach (FileInfo file in files)
            {
                string cSharpScript = Path.ChangeExtension(file.FullName, ".cs");

                File.Delete(cSharpScript);
                File.Move(file.FullName, cSharpScript);
                File.SetLastWriteTime(cSharpScript, DateTime.Now);
            }

            m_completedMigrations++;

            if (files.Length != 0)
            {
                state = MigrationWindowState.POST_RECOMPILE;
                AssetDatabase.Refresh();
            }
            else
            {
                // Unity won't call the PostImportCallback if nothing has changed, skip directly to the next step.
                state = MigrationWindowState.MIGRATE_GAME_OBJECTS;
            }
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
コード例 #4
0
    void Import()
    {
        try
        {
            FileInfo[] files;

            //We empty all the generated source files from the old integration because some of them may have been deleted in the new version
            files = new DirectoryInfo(Application.dataPath + "/Wwise/Deployment/API/Generated").GetFiles("*.cs", SearchOption.AllDirectories);
            foreach (FileInfo file in files)
            {
                if( !File.Exists(Application.dataPath + "/Wwise/Deployment/API/Generated" + Path.GetFileNameWithoutExtension(file.Name) + ".new") )
                {
                    // This API file was removed from the new integration, simply delete it.
                    File.Delete(file.FullName);
                }
                else
                {
                    string[] lines = { "public class " + Path.GetFileNameWithoutExtension(file.Name) + "{}" };
                    System.IO.File.WriteAllLines(file.FullName, lines);
                }
            }

            //Classes which we dont want to compile their new version(.new extension)
            List<string> noCompileList = new List<string>();

            //Get the names of all the migration files so we can know which files with the .new extension we don't want to compile right now
            files = new DirectoryInfo(Application.dataPath + "/Wwise").GetFiles("*.migration_*", SearchOption.AllDirectories);
            foreach (FileInfo file in files)
            {
                noCompileList.Add(Path.GetFileNameWithoutExtension(file.Name));
            }

            //We don't want to compile the new inspectors. So we add them to the list.
            files = new DirectoryInfo(Application.dataPath + "/Wwise/Editor/WwiseComponents").GetFiles("*.new", SearchOption.AllDirectories);
            foreach (FileInfo file in files)
            {
                noCompileList.Add(Path.GetFileNameWithoutExtension(file.Name));
            }

            //We rename the .new files so they can be compiled by unity
            Debug.Log("Importing new script...");
            files = new DirectoryInfo(Application.dataPath + "/Wwise").GetFiles("*.new", SearchOption.AllDirectories);
            foreach (FileInfo file in files)
            {
                //Only classes that are not in  the noCompileList are renamed
                if (!noCompileList.Contains(Path.GetFileNameWithoutExtension(file.Name)))
                {
                    File.Delete(Path.ChangeExtension(file.FullName, ".cs"));
                    File.Move(file.FullName, Path.ChangeExtension(file.FullName, ".cs"));
                }
            }

            //We empty the inspector classes so they don't cause any errors
            Debug.Log("Emptying old inspector scripts...");
            files = new DirectoryInfo(Application.dataPath + "/Wwise/Editor/WwiseComponents").GetFiles("*.cs", SearchOption.AllDirectories);
            foreach (FileInfo file in files)
            {
                string[] lines = { "using UnityEditor;", "public class " + Path.GetFileNameWithoutExtension(file.Name) + " : Editor {}" };
                System.IO.File.WriteAllLines(file.FullName, lines);
            }

            //Delete all plugins from Assets/Plugins since they are outdated.
            Debug.Log("Uninstalling old plugins...");
            string pluginsPath = Path.Combine(Application.dataPath, "plugins");
            if (Directory.Exists(pluginsPath))
            {
                DirectoryInfo pluginsDirectory = new DirectoryInfo(pluginsPath);

                // A .bundle is a folder, and not a file. We need to treat it as so...
                DirectoryInfo[] bundleDirectories = pluginsDirectory.GetDirectories("*AkSoundEngine*", SearchOption.AllDirectories);
                foreach (DirectoryInfo bundle in bundleDirectories)
                {
                    bundle.Delete(true);
                    if (Directory.Exists(bundle.FullName))
                    {
                        Debug.LogError("Access denied: " + bundle.FullName + "\nWhen the migration is completed, reopen your Unity project and install the " + m_editorPlatform + " platform by going to Assets->Wwise->Install Plugins->" + m_editorPlatform);
                    }
                }

                FileInfo[] foundPlugins = pluginsDirectory.GetFiles("*AkSoundEngine*", SearchOption.AllDirectories);
                foreach (FileInfo file in foundPlugins)
                {
                    string nameToDelete = "Assets" + file.FullName.Substring(Application.dataPath.Length);
                    Debug.Log("Deleting old plugin: " + nameToDelete);
                    AssetDatabase.DeleteAsset(nameToDelete);
                    if (!file.Name.Contains(".meta") && File.Exists(file.FullName))
                    {
                        Debug.LogError("Access denied: " + file.FullName + "\nWhen the migration is completed, reopen your Unity project and install the " + m_editorPlatform + " platform by going to Assets->Wwise->Install Plugins->" + m_editorPlatform);
                    }
                }
            }

            //Delete all plugins since they are outdated except for the platform we're currently installing
            List<string> platformsTokeep = new List<string>(2);
            platformsTokeep.Add(m_patformToInstall);
            platformsTokeep.Add(m_editorPlatform);

            RemovePlatfromFolders("Wwise/Editor/WwiseMenu", platformsTokeep);
            RemovePlatfromFolders("Wwise/Deployment/API/Generated", platformsTokeep);

            platformsTokeep[0] += "_new";
            platformsTokeep[1] += "_new";

            RemovePlatfromFolders("Wwise/Deployment/Plugins", platformsTokeep);

            AssetDatabase.RenameAsset("Assets/Wwise/Deployment/Plugins/" + m_patformToInstall + "_new", m_patformToInstall);
            if (m_patformToInstall != m_editorPlatform)
            {
                AssetDatabase.RenameAsset("Assets/Wwise/Deployment/Plugins/" + m_editorPlatform + "_new", m_editorPlatform);
            }

            state = MigrationWindowState.POST_IMPORT;

            //Refresh the assets database to trigger a recompilation
            Debug.Log("Compile scripts...");
            AssetDatabase.Refresh();
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
            state = MigrationWindowState.CANCEL;
        }
    }