//---------------------------------------------------------------------------------------------------------------------- internal static string GetInstallInfoPath(DCCToolInfo info) { string localAppDataFolder = null; switch (Application.platform) { case RuntimePlatform.WindowsEditor: { localAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); break; } case RuntimePlatform.OSXEditor: { string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); localAppDataFolder = Path.Combine(userProfile, "Library/Application Support"); break; } case RuntimePlatform.LinuxEditor: { string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); localAppDataFolder = Path.Combine(userProfile, ".config/unity3d"); break; } default: { throw new NotImplementedException(); } } string desc = info.GetDescription().Replace(' ', '_'); string installInfoFolder = Path.Combine(localAppDataFolder, "Unity", "MeshSync"); return Path.Combine(installInfoFolder, $"UnityMeshSyncInstallInfo_{desc}.json"); }
//---------------------------------------------------------------------------------------------------------------------- #region Button callbacks void OnAddDCCToolButtonClicked() { string folder = EditorUtility.OpenFolderPanel("Add DCC Tool", m_lastOpenedFolder, ""); if (string.IsNullOrEmpty(folder)) { return; } m_lastOpenedFolder = folder; //Find the path to the actual app DCCToolType lastDCCToolType = DCCToolType.AUTODESK_MAYA; DCCToolInfo dccToolInfo = null; for (int i = 0; i < (int)(DCCToolType.NUM_DCC_TOOL_TYPES) && null == dccToolInfo; ++i) { lastDCCToolType = (DCCToolType)(i); dccToolInfo = DCCFinderUtility.FindDCCToolInDirectory(lastDCCToolType, null, m_lastOpenedFolder); } if (null == dccToolInfo) { EditorUtility.DisplayDialog("MeshSync Project Settings", "No DCC Tool is detected", "Ok"); return; } //Add MeshSyncEditorSettings settings = MeshSyncEditorSettings.GetOrCreateSettings(); if (settings.AddDCCTool(dccToolInfo)) { Setup(m_root); } }
void OnRemoveDCCToolButtonClicked(EventBase evt) { Button button = evt.target as Button; if (null == button) { Debug.LogWarning("[MeshSync] Failed to Remove DCC Tool"); return; } DCCToolInfo info = button.userData as DCCToolInfo; if (null == info || string.IsNullOrEmpty(info.AppPath)) { Debug.LogWarning("[MeshSync] Failed to Remove DCC Tool"); return; } MeshSyncEditorSettings settings = MeshSyncEditorSettings.GetOrCreateSettings(); if (settings.RemoveDCCTool(info.AppPath)) { //Delete install info too string installInfoPath = DCCPluginInstallInfo.GetInstallInfoPath(info); if (File.Exists(installInfoPath)) { File.Delete(installInfoPath); } Setup(m_root); } }
//---------------------------------------------------------------------------------------------------------------------- private string FindConfigFolder() { switch (Application.platform) { case RuntimePlatform.WindowsEditor: { //If MAYA_APP_DIR environment variable is setup, use that config folder //If not, use %USERPROFILE%\Documents\maya string path = Environment.GetEnvironmentVariable("MAYA_APP_DIR"); if (!string.IsNullOrEmpty(path)) { return(path); } path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName; if (Environment.OSVersion.Version.Major >= 6) { path = Directory.GetParent(path).ToString(); } path += @"\Documents\maya"; return(path); } case RuntimePlatform.OSXEditor: { return("/Users/Shared/Autodesk/modules/maya"); } case RuntimePlatform.LinuxEditor: { string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); DCCToolInfo dccToolInfo = GetDCCToolInfo(); return(Path.Combine(userProfile, "maya", dccToolInfo.DCCToolVersion)); } default: { throw new NotImplementedException(); } } }
//---------------------------------------------------------------------------------------------------------------------- protected override void FinalizeDCCConfigurationV() { DCCToolInfo dccToolInfo = GetDCCToolInfo(); EditorUtility.DisplayDialog("MeshSync", $"MeshSync plugin installed for {dccToolInfo.GetDescription()}", "Ok" ); }
//---------------------------------------------------------------------------------------------------------------------- protected override void FinalizeDCCConfigurationV() { DCCToolInfo dccToolInfo = GetDCCToolInfo(); EditorUtility.DisplayDialog("MeshSync", $"Launching {dccToolInfo.GetDescription()} for finalizing configuration", "Ok" ); }
//---------------------------------------------------------------------------------------------------------------------- protected override void FinalizeDCCConfigurationV() { DCCToolInfo dccToolInfo = GetDCCToolInfo(); EditorUtility.DisplayDialog("MeshSync", $"MeshSync plugin configured. Please restart {dccToolInfo.GetDescription()} to complete the installation.", "Ok" ); }
//---------------------------------------------------------------------------------------------------------------------- void AddDCCToolSettingsContainer(DCCToolInfo dccToolInfo, VisualElement top, VisualTreeAsset dccToolInfoTemplate) { string desc = dccToolInfo.GetDescription(); TemplateContainer container = dccToolInfoTemplate.CloneTree(); Label nameLabel = container.Query <Label>("DCCToolName").First(); nameLabel.text = desc; //Load icon Texture2D iconTex = LoadIcon(dccToolInfo.IconPath); if (null != iconTex) { container.Query <Image>("DCCToolImage").First().image = iconTex; } else { container.Query <Label>("DCCToolImageLabel").First().text = desc[0].ToString(); } container.Query <Label>("DCCToolPath").First().text = "Path: " + dccToolInfo.AppPath; BaseDCCIntegrator integrator = DCCIntegratorFactory.Create(dccToolInfo); DCCPluginInstallInfo installInfo = integrator.FindInstallInfo(); Label statusLabel = container.Query <Label>("DCCToolStatus").First(); if (null == installInfo || string.IsNullOrEmpty(installInfo.PluginVersion)) { statusLabel.text = "MeshSync Plugin not installed"; } else { statusLabel.AddToClassList("plugin-installed"); statusLabel.text = "MeshSync Plugin installed. Version: " + installInfo.PluginVersion; } //Buttons { Button button = container.Query <Button>("RemoveDCCToolButton").First(); button.clickable.clickedWithEventInfo += OnRemoveDCCToolButtonClicked; button.userData = dccToolInfo; } { Button button = container.Query <Button>("InstallPluginButton").First(); button.clickable.clickedWithEventInfo += OnInstallPluginButtonClicked; button.userData = integrator; } top.Add(container); }
internal static BaseDCCIntegrator Create(DCCToolInfo dccToolInfo) { switch (dccToolInfo.Type) { case DCCToolType.AUTODESK_MAYA: return(new MayaIntegrator(dccToolInfo)); case DCCToolType.AUTODESK_3DSMAX: return(new _3DSMaxIntegrator(dccToolInfo)); case DCCToolType.BLENDER: return(new BlenderIntegrator(dccToolInfo)); default: throw new NotImplementedException(); } }
//---------------------------------------------------------------------------------------------------------------------- //return true if there is any change internal bool AddInstalledDCCTools() { bool ret = false; Dictionary<string, DCCToolInfo> dccPaths = DCCFinderUtility.FindInstalledDCCTools(); foreach (var dcc in dccPaths) { DCCToolInfo info = dcc.Value; bool added = AddDCCTool(info, false); ret = ret || added; } SaveEditorSettings(); return ret; }
//---------------------------------------------------------------------------------------------------------------------- internal bool AddDCCTool(DCCToolInfo dccToolInfo, bool save=true) { if (m_dictionary.ContainsKey(dccToolInfo.AppPath)) return false; // m_dictionary.Add(dccToolInfo.AppPath, dccToolInfo); m_serializedDCCToolInfo.Add(dccToolInfo); if (save) { SaveEditorSettings(); } return true; }
//---------------------------------------------------------------------------------------------------------------------- /// <summary> /// Find DCC Tools by searching default installation folders, and looking at default environment variables. /// </summary> /// <returns>A dictionary containing the detected DCC tools, with their paths as keys</returns> public static Dictionary <string, DCCToolInfo> FindInstalledDCCTools() { List <string> vendorDirs = GetDefaultVendorDirectories(); Dictionary <string, DCCToolInfo> dccPaths = new Dictionary <string, DCCToolInfo>(); //From default Folders foreach (string vendorDir in vendorDirs) { foreach (var dcc in DEFAULT_DCC_TOOLS_BY_FOLDER) { string dir = Path.Combine(vendorDir, dcc.Key); if (!Directory.Exists(dir)) { continue; } DCCToolInfo dccToolInfo = dcc.Value; DCCToolInfo foundDCC = FindDCCToolInDirectory(dccToolInfo.Type, dccToolInfo.DCCToolVersion, dir); if (null == foundDCC) { continue; } dccPaths.Add(foundDCC.AppPath, foundDCC); } } //From default environment vars: foreach (var dcc in DEFAULT_DCC_TOOLS_BY_ENV_VAR) { string dir = Environment.GetEnvironmentVariable(dcc.Key); if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) { continue; } DCCToolInfo dccToolInfo = dcc.Value; DCCToolInfo foundDCC = FindDCCToolInDirectory(dccToolInfo.Type, dccToolInfo.DCCToolVersion, dir); if (null == foundDCC) { continue; } dccPaths.Add(foundDCC.AppPath, foundDCC); } return(dccPaths); }
//---------------------------------------------------------------------------------------------------------------------- protected override bool ConfigureDCCToolV(DCCToolInfo dccToolInfo, string pluginFileNameWithoutExt, string extractedTempPath) { string srcRoot = Path.Combine(extractedTempPath, pluginFileNameWithoutExt); if (!Directory.Exists(srcRoot)) { return(false); } string configFolder = FindConfigFolder(); const string AUTOLOAD_SETUP = "pluginInfo -edit -autoload true MeshSyncClientMaya;"; const string SHELF_SETUP = "UnityMeshSync_Shelf;"; //const string MAYA_CLOSE_COMMAND = "scriptJob -idleEvent quit;"; const string FINALIZE_SETUP = AUTOLOAD_SETUP + SHELF_SETUP; string copySrcFolder = srcRoot; string copyDestFolder = configFolder; string argFormat = null; string loadPluginCmd = null; switch (Application.platform) { case RuntimePlatform.WindowsEditor: { //C:\Users\Unity\Documents\maya\modules const string FOLDER_PREFIX = "modules"; copySrcFolder = Path.Combine(srcRoot, FOLDER_PREFIX); copyDestFolder = Path.Combine(configFolder, FOLDER_PREFIX); argFormat = "-command \"{0}\""; //Maya script only supports '/' as PathSeparator //Example: loadPlugin """C:/Users/Unity/Documents/maya/modules/UnityMeshSync/2019/plug-ins/MeshSyncClientMaya.mll"""; string mayaPluginPath = Path.Combine(copyDestFolder, "UnityMeshSync", dccToolInfo.DCCToolVersion, @"plug-ins\MeshSyncClientMaya.mll").Replace('\\', '/'); loadPluginCmd = "loadPlugin \"\"\"" + mayaPluginPath + "\"\"\";"; break; } case RuntimePlatform.OSXEditor: { argFormat = @"-command '{0}'"; //Example: "/Users/Shared/Autodesk/Modules/maya/UnityMeshSync/2020/plug-ins/MeshSyncClientMaya.bundle"; string mayaPluginPath = Path.Combine(copyDestFolder, "UnityMeshSync", dccToolInfo.DCCToolVersion, @"plug-ins/MeshSyncClientMaya.bundle"); loadPluginCmd = "loadPlugin \"" + mayaPluginPath + "\";"; break; } case RuntimePlatform.LinuxEditor: { //Example: /home/Unity/maya/2019/modules const string FOLDER_PREFIX = "modules"; copySrcFolder = Path.Combine(srcRoot, FOLDER_PREFIX); copyDestFolder = Path.Combine(configFolder, FOLDER_PREFIX); argFormat = @"-command '{0}'"; string mayaPluginPath = Path.Combine(copyDestFolder, "UnityMeshSync", dccToolInfo.DCCToolVersion, @"plug-ins/MeshSyncClientMaya.so"); loadPluginCmd = "loadPlugin \"" + mayaPluginPath + "\";"; break; } default: { throw new NotImplementedException(); } } //Copy files to config folder const string MOD_FILE = "UnityMeshSync.mod"; string scriptFolder = Path.Combine("UnityMeshSync", dccToolInfo.DCCToolVersion); string srcModFile = Path.Combine(copySrcFolder, MOD_FILE); if (!File.Exists(srcModFile)) { return(false); } try { Directory.CreateDirectory(copyDestFolder); File.Copy(srcModFile, Path.Combine(copyDestFolder, MOD_FILE), true); FileUtility.CopyRecursive(Path.Combine(copySrcFolder, scriptFolder), Path.Combine(copyDestFolder, scriptFolder), true); } catch { return(false); } //Auto Load string arg = string.Format(argFormat, loadPluginCmd + FINALIZE_SETUP); bool setupSuccessful = SetupAutoLoadPlugin(dccToolInfo.AppPath, arg); return(setupSuccessful); }
internal MayaIntegrator(DCCToolInfo dccToolInfo) : base(dccToolInfo) { }
//returns null when failed protected abstract bool ConfigureDCCToolV( DCCToolInfo dccToolInfo, string pluginFileNameWithoutExt, string extractedTempPath);
internal BaseDCCIntegrator(DCCToolInfo dccToolInfo) { m_dccToolInfo = dccToolInfo; }
internal _3DSMaxIntegrator(DCCToolInfo dccToolInfo) : base(dccToolInfo) { }
//---------------------------------------------------------------------------------------------------------------------- protected override bool ConfigureDCCToolV(DCCToolInfo dccToolInfo, string pluginFileNameWithoutExt, string extractedTempPath) { string extractedPluginRootFolder = Path.Combine(extractedTempPath, pluginFileNameWithoutExt); if (!Directory.Exists(extractedPluginRootFolder)) { return(false); } string appVersion = $"3dsMax{dccToolInfo.DCCToolVersion}"; //configFolder example: "C:\Users\Unity\AppData\Local\Unity\MeshSync\3dsMax2019" string appDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string configFolder = Path.Combine(appDataLocal, "Unity", "MeshSync", appVersion); Directory.CreateDirectory(configFolder); //Copy dlu file to configFolder string srcPluginPath = Path.Combine(extractedPluginRootFolder, appVersion); if (!Directory.Exists(srcPluginPath)) { return(false); } try { FileUtility.CopyRecursive(srcPluginPath, configFolder, true); } catch { return(false); } bool setupSuccessful = false; //Check version bool versionIsInt = int.TryParse(dccToolInfo.DCCToolVersion, out int versionInt); string installScriptPath = null; if (versionIsInt && versionInt <= 2018) { installScriptPath = CreateInstallScript("Install3dsMaxPlugin2018.ms", configFolder, extractedTempPath); //3dsmax -U MAXScript install_script.ms setupSuccessful = SetupAutoLoadPlugin(dccToolInfo.AppPath, $"-U MAXScript \"{installScriptPath}\""); } else { installScriptPath = CreateInstallScript("Install3dsMaxPlugin2019.ms", configFolder, extractedTempPath); string dccAppDir = Path.GetDirectoryName(dccToolInfo.AppPath); if (string.IsNullOrEmpty(dccAppDir)) { return(false); } //3dsmaxbatch.exe install_script.ms string dccBatchPath = Path.Combine(dccAppDir, "3dsmaxbatch.exe"); setupSuccessful = SetupAutoLoadPlugin(dccBatchPath, installScriptPath); } File.Delete(installScriptPath); return(setupSuccessful); }
internal DCCToolInfo(DCCToolInfo other) { Type = other.Type; DCCToolVersion = other.DCCToolVersion; AppPath = other.AppPath; }
internal BlenderIntegrator(DCCToolInfo dccToolInfo) : base(dccToolInfo) { }
//---------------------------------------------------------------------------------------------------------------------- protected override bool ConfigureDCCToolV(DCCToolInfo dccToolInfo, string pluginFileNameWithoutExt, string extractedTempPath) { //Go down one folder string extractedPath = null; foreach (string dir in Directory.EnumerateDirectories(extractedTempPath)) { extractedPath = dir; break; } if (string.IsNullOrEmpty(extractedPath)) { return(false); } //Must use '/' for the pluginFile which is going to be inserted into the template string ver = dccToolInfo.DCCToolVersion; string pluginFile = Path.Combine(extractedPath, $"blender-{ver}.zip").Replace(Path.DirectorySeparatorChar, '/'); if (!File.Exists(pluginFile)) { return(false); } //Prepare install script string installScriptFileName = $"InstallBlenderPlugin_{ver}.py"; string templatePath = Path.Combine(MeshSyncEditorConstants.DCC_INSTALL_SCRIPTS_PATH, installScriptFileName); if (!File.Exists(templatePath)) { return(false); } //Replace the path in the template with actual path. string installScriptFormat = File.ReadAllText(templatePath); string installScript = String.Format(installScriptFormat, pluginFile); string installScriptPath = Path.Combine(extractedTempPath, installScriptFileName); File.WriteAllText(installScriptPath, installScript); //Prepare remove script to remove old plugin string uninstallScriptFilename = $"UninstallBlenderPlugin_{ver}.py"; string uninstallScriptPath = Path.Combine(MeshSyncEditorConstants.DCC_INSTALL_SCRIPTS_PATH, uninstallScriptFilename); if (!File.Exists(uninstallScriptPath)) { return(false); } bool setupSuccessful = SetupAutoLoadPlugin(dccToolInfo.AppPath, Path.GetFullPath(uninstallScriptPath), Path.GetFullPath(installScriptPath) ); //Cleanup File.Delete(installScriptPath); return(setupSuccessful); }