void OnInstallPluginButtonClicked(EventBase evt)
        {
            if (null == m_latestCompatibleDCCPluginVersion)
            {
                EditorUtility.DisplayDialog("MeshSync",
                                            $"DCC Plugin compatible with MeshSync@{MeshSyncEditorConstants.GetPluginVersion()} is not found",
                                            "Ok"
                                            );
                return;
            }

            BaseDCCIntegrator integrator = GetEventButtonUserDataAs <BaseDCCIntegrator>(evt.target);

            if (null == integrator)
            {
                Debug.LogWarning("[MeshSync] Failed to Install Plugin");
                return;
            }

            integrator.Integrate(m_latestCompatibleDCCPluginVersion.ToString(), () => {
                DCCToolInfo dccToolInfo = integrator.GetDCCToolInfo();
                if (!m_dccStatusLabels.TryGetValue(dccToolInfo.AppPath, out Label statusLabel))
                {
                    SetupInternal(m_root);
                    return;
                }

                UpdateDCCPluginStatusLabel(statusLabel);
            });
        }
        private void OnRemoveDCCToolButtonClicked(EventBase evt)
        {
            DCCToolInfo dccToolInfo = GetEventButtonUserDataAs <DCCToolInfo>(evt.target);

            if (null == dccToolInfo || string.IsNullOrEmpty(dccToolInfo.AppPath))
            {
                Debug.LogWarning("[MeshSync] Failed to remove DCC Tool");
                return;
            }

            MeshSyncEditorSettings settings = MeshSyncEditorSettings.GetOrCreateSettings();

            if (settings.RemoveDCCTool(dccToolInfo.AppPath))
            {
                //Delete install info too
                string installInfoPath = DCCPluginInstallInfo.GetInstallInfoPath(dccToolInfo);
                if (File.Exists(installInfoPath))
                {
                    DCCPluginInstallInfo installInfo = FileUtility.DeserializeFromJson <DCCPluginInstallInfo>(installInfoPath);
                    installInfo.RemovePluginVersion(dccToolInfo.AppPath);
                    FileUtility.SerializeToJson(installInfo, installInfoPath);
                }

                if (!m_dccContainers.TryGetValue(dccToolInfo.AppPath, out VisualElement container))
                {
                    SetupInternal(m_root);
                    return;
                }

                container.parent.Remove(container); //Remove the VisualElement container from the UI
            }
        }
        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);
            }
        }
//----------------------------------------------------------------------------------------------------------------------

        #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);
            }
        }
Example #5
0
//----------------------------------------------------------------------------------------------------------------------
        internal override bool ConfigureDCCToolV(DCCToolInfo dccToolInfo, string srcPluginRoot,
                                                 string tempPath)
        {
            Assert.IsTrue(Directory.Exists(srcPluginRoot));

            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(srcPluginRoot, appVersion);

            if (!Directory.Exists(srcPluginPath))
            {
                SetLastErrorMessage($"Can't find src directory: {srcPluginPath}");
                return(false);
            }

            try {
                FileUtility.CopyRecursive(srcPluginPath, configFolder, true);
            } catch {
                SetLastErrorMessage($"Failed to copy files to dest: {configFolder}");
                return(false);
            }

            bool setupSuccessful = false;

            //Check version
            bool   versionIsInt      = int.TryParse(dccToolInfo.DCCToolVersion, out int versionInt);
            string installScriptPath = CreateInstallScript(dccToolInfo.DCCToolVersion, configFolder, tempPath);

            if (versionIsInt && versionInt <= 2018)
            {
                //3dsmax -U MAXScript install_script.ms
                setupSuccessful = SetupAutoLoadPlugin(dccToolInfo.AppPath, $"-U MAXScript \"{installScriptPath}\"");
            }
            else
            {
                string dccAppDir = Path.GetDirectoryName(dccToolInfo.AppPath);
                if (string.IsNullOrEmpty(dccAppDir))
                {
                    SetLastErrorMessage($"Can't determine application directory from: {dccToolInfo.AppPath}");
                    return(false);
                }

                //3dsmaxbatch.exe install_script.ms
                string dccBatchPath = Path.Combine(dccAppDir, "3dsmaxbatch.exe");
                setupSuccessful = SetupAutoLoadPlugin(dccBatchPath, installScriptPath);
            }

            File.Delete(installScriptPath);


            return(setupSuccessful);
        }
Example #6
0
//----------------------------------------------------------------------------------------------------------------------
        void UpdateDCCPluginStatusLabel(Label statusLabel)
        {
            BaseDCCIntegrator dccIntegrator = statusLabel.userData as BaseDCCIntegrator;

            Assert.IsNotNull(dccIntegrator);
            DCCPluginInstallInfo installInfo = dccIntegrator.FindInstallInfo();

            const string NOT_INSTALLED = "MeshSync Plugin not installed";

            if (null == installInfo)
            {
                statusLabel.text = NOT_INSTALLED;
                return;
            }

            DCCToolInfo dccToolInfo = dccIntegrator.GetDCCToolInfo();
            string      installedPluginVersionStr = installInfo.GetPluginVersion(dccToolInfo.AppPath);

            if (string.IsNullOrEmpty(installedPluginVersionStr))
            {
                statusLabel.text = NOT_INSTALLED;
                return;
            }

            //Remove all known classes
            const string PLUGIN_INCOMPATIBLE_CLASS  = "plugin-incompatible";
            const string PLUGIN_INSTALLED_OLD_CLASS = "plugin-installed-old";
            const string PLUGIN_INSTALLED_CLASS     = "plugin-installed";

            statusLabel.RemoveFromClassList(PLUGIN_INCOMPATIBLE_CLASS);
            statusLabel.RemoveFromClassList(PLUGIN_INSTALLED_CLASS);
            statusLabel.RemoveFromClassList(PLUGIN_INSTALLED_OLD_CLASS);

            //The DCC Plugin is installed, and we need to check if it's compatible with this version of MeshSync
            bool parsed = PackageVersion.TryParse(installedPluginVersionStr, out PackageVersion installedPluginVersion);

            if (!parsed ||
                installedPluginVersion.Major != MeshSyncEditorConstants.PACKAGE_VERSION.Major ||
                installedPluginVersion.Minor != MeshSyncEditorConstants.PACKAGE_VERSION.Minor)
            {
                statusLabel.AddToClassList(PLUGIN_INCOMPATIBLE_CLASS);
                statusLabel.text = "Installed MeshSync Plugin is incompatible. Version: " + installedPluginVersionStr;
                return;
            }

            //Check if we have newer compatible DCCPlugin
            if (null != m_latestCompatibleDCCPluginVersion &&
                installedPluginVersion.Patch < m_latestCompatibleDCCPluginVersion.Patch)
            {
                statusLabel.AddToClassList(PLUGIN_INSTALLED_OLD_CLASS);
                statusLabel.text = $"Plugin {installedPluginVersionStr} installed. " +
                                   $"({m_latestCompatibleDCCPluginVersion} is available)";
                return;
            }

            statusLabel.AddToClassList(PLUGIN_INSTALLED_CLASS);
            statusLabel.text = $"Plugin {installedPluginVersionStr} installed";
        }
//----------------------------------------------------------------------------------------------------------------------

        private 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);

            Label statusLabel = container.Query <Label>("DCCToolStatus").First();

            statusLabel.userData = integrator;
            UpdateDCCPluginStatusLabel(statusLabel);

            m_dccStatusLabels[dccToolInfo.AppPath] = statusLabel;
            m_dccContainers[dccToolInfo.AppPath]   = container;


            //Buttons
            {
                Button button = container.Query <Button>("LaunchDCCToolButton").First();
                button.clickable.clickedWithEventInfo += OnLaunchDCCToolButtonClicked;
                button.userData = dccToolInfo;
            }
            {
                Button button = container.Query <Button>("InstallPluginButton").First();
                button.clickable.clickedWithEventInfo += OnInstallPluginButtonClicked;
                button.userData = integrator;
                button.SetEnabled(m_checkPluginUpdatesButton.enabledSelf);
                m_installPluginButtons.Add(button);
            }
            {
                Button button = container.Query <Button>("RemoveDCCToolButton").First();
                button.clickable.clickedWithEventInfo += OnRemoveDCCToolButtonClicked;
                button.userData = dccToolInfo;
            }



            top.Add(container);
        }
        void OnLaunchDCCToolButtonClicked(EventBase evt)
        {
            DCCToolInfo dccToolInfo = GetEventButtonUserDataAs <DCCToolInfo>(evt.target);

            if (null == dccToolInfo || string.IsNullOrEmpty(dccToolInfo.AppPath) || !File.Exists(dccToolInfo.AppPath))
            {
                Debug.LogWarning("[MeshSync] Failed to launch DCC Tool");
                return;
            }

            DiagnosticsUtility.StartProcess(dccToolInfo.AppPath);
        }
//----------------------------------------------------------------------------------------------------------------------

        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);
        }
        void OnAddDCCToolButtonClicked(EventBase evt)
        {
            string path = null;

            if (Application.platform == RuntimePlatform.OSXEditor)
            {
                path = OpenFilePanel();
            }
            else
            {
                path = OpenFolderPanel();
            }

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            //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, path);
            }

            if (null == dccToolInfo)
            {
                EditorUtility.DisplayDialog("MeshSync Project Settings", "No DCC Tool is detected", "Ok");
                return;
            }

            MeshSyncEditorSettings settings = MeshSyncEditorSettings.GetOrCreateSettings();

            if (settings.AddDCCTool(dccToolInfo))
            {
                //Add to ScrollView
                VisualTreeAsset dccToolInfoTemplate = UIElementsEditorUtility.LoadVisualTreeAsset(
                    MeshSyncEditorConstants.DCC_TOOL_INFO_TEMPLATE_PATH
                    );
                ScrollView scrollView = GetEventButtonUserDataAs <ScrollView>(evt.target);
                Assert.IsNotNull(scrollView);
                AddDCCToolSettingsContainer(dccToolInfo, scrollView, dccToolInfoTemplate);
            }
        }
Example #11
0
    internal static bool InstallDCCPlugin(BaseDCCIntegrator integrator, DCCToolInfo  dccToolInfo, string pluginVersion, string dccPluginLocalPath) {
        bool dccConfigured = false;
            
        //Extract
        string localPluginPath = dccPluginLocalPath;
        string tempPath        = FileUtil.GetUniqueTempPathInProject();        
        Directory.CreateDirectory(tempPath);
        ZipUtility.UncompressFromZip(localPluginPath, null, tempPath);

        //Go down one folder
        string[] extractedDirs = Directory.GetDirectories(tempPath);
        if (extractedDirs.Length > 0) {
            dccConfigured = integrator.ConfigureDCCToolV(dccToolInfo, extractedDirs[0],tempPath);
        } 
        
        //Cleanup
        FileUtility.DeleteFilesAndFolders(tempPath);
        
        if (!dccConfigured) {
            return false;
        }

        string installInfoPath   = DCCPluginInstallInfo.GetInstallInfoPath(dccToolInfo);
        string installInfoFolder = Path.GetDirectoryName(installInfoPath);
        if (null == installInfoPath || null == installInfoFolder) {
            integrator.SetLastErrorMessage($"Invalid path: {installInfoPath}");
            return false;
        }

        //Write DCCPluginInstallInfo for the version
        Directory.CreateDirectory(installInfoFolder);

        DCCPluginInstallInfo installInfo =  FileUtility.DeserializeFromJson<DCCPluginInstallInfo>(installInfoPath);
        if (null == installInfo) {
            installInfo = new DCCPluginInstallInfo();
        }
        installInfo.SetPluginVersion(dccToolInfo.AppPath, pluginVersion);

        try {
            FileUtility.SerializeToJson(installInfo, installInfoPath);
        } catch (Exception e) {
            integrator.SetLastErrorMessage(e.ToString());
            return false;
        }

        return true;        
    }
        void OnInstallPluginButtonClicked(EventBase evt)
        {
            BaseDCCIntegrator integrator = GetEventButtonUserDataAs <BaseDCCIntegrator>(evt.target);

            if (null == integrator)
            {
                Debug.LogWarning("[MeshSync] Failed to Install Plugin");
                return;
            }

            integrator.Integrate(() => {
                DCCToolInfo dccToolInfo = integrator.GetDCCToolInfo();
                if (!m_dccStatusLabels.ContainsKey(dccToolInfo.AppPath))
                {
                    Setup(m_root);
                    return;
                }

                UpdateDCCPluginStatus(integrator, m_dccStatusLabels[dccToolInfo.AppPath]);
            });
        }
//----------------------------------------------------------------------------------------------------------------------
        void UpdateDCCPluginStatus(BaseDCCIntegrator dccIntegrator, Label statusLabel)
        {
            DCCPluginInstallInfo installInfo = dccIntegrator.FindInstallInfo();

            const string NOT_INSTALLED = "MeshSync Plugin not installed";

            if (null == installInfo)
            {
                statusLabel.text = NOT_INSTALLED;
                return;
            }

            DCCToolInfo dccToolInfo   = dccIntegrator.GetDCCToolInfo();
            string      pluginVersion = installInfo.GetPluginVersion(dccToolInfo.AppPath);

            if (string.IsNullOrEmpty(pluginVersion))
            {
                statusLabel.text = NOT_INSTALLED;
                return;
            }

            statusLabel.AddToClassList("plugin-installed");
            statusLabel.text = "MeshSync Plugin installed. Version: " + pluginVersion;
        }