Advertisement
Inksaver

Open SharpDevelop with Unity Editor

Nov 9th, 2018
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4.  
  5. namespace UnityStartSharpDevelop
  6. {
  7.     class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             /* From Unity Docs https://docs.unity3d.com/Manual/Preferences.html
  12.             $(ProjectPath) is replaced with the path to the open project.
  13.             Unity "$(ProjectPath) sends X:\PathToYourProject e.g C:\Users\graha\Dropbox\Computer Club\Unity\Brackeys Youtube Tutorial\
  14.             The project .sln file created by Unity/VS is in this folder with the same name as the project: Brackeys Youtube Tutorial.sln
  15.             Compile this project and place 'UnityStartSharpDevelop.exe' somewhere in the Unity installation folder.
  16.             Browse Unity preferences to use this file as the external editor.
  17.             Any C# file in your unity project will load the entire solution with all .cs files available.
  18.             Navigate the project to edit the script you are looking for
  19.             */
  20.            
  21.             // If SharpDevelop is already running, prevent a second instance starting
  22.             string processName = "SharpDevelop";
  23.             Process[] instances = Process.GetProcessesByName(processName);
  24.             if (instances.Length > 1)
  25.             {
  26.                 Environment.Exit(1);
  27.             }
  28.            
  29.             //Edit this path to SharpDevelop to suit your system
  30.             const string sharpDevelopAppPath = @"C:\Program Files (x86)\SharpDevelop\5.1\bin\SharpDevelop.exe";
  31.             string projectPath = string.Empty;
  32.             string projectName = string.Empty;
  33.             if(args.Length > 0) //Check args have been passed
  34.             {
  35.                 projectPath = args[0];
  36.                 projectName = new DirectoryInfo(projectPath).Name + ".sln";
  37.                 projectPath = Path.Combine(projectPath, projectName);
  38.                 if(File.Exists(projectPath))
  39.                 {
  40.                     projectPath = "\"" + projectPath + "\""; // surround pathname with quotes to prevent spaces causing errors
  41.                     try
  42.                     {
  43.                         ProcessStartInfo start = new ProcessStartInfo();
  44.                         start.Arguments = projectPath;
  45.                         start.FileName = sharpDevelopAppPath;
  46.                         Process.Start(start);
  47.                     }
  48.                     catch (Exception ex)
  49.                     {
  50.                         Console.WriteLine(ex.Message);
  51.                         ExitApp();
  52.                     }
  53.                 }
  54.                 else //file does not exist
  55.                 {
  56.                     Console.WriteLine("Solution file " + projectPath + "Not found. Please set Unity External Editor arguments to use '$(ProjectPath)");
  57.                     Console.WriteLine("Also make sure the solution name has the same name as the project directory.");
  58.                     ExitApp();
  59.                 }
  60.             }
  61.             else //no args passed
  62.             {
  63.                 Console.WriteLine("No args found. Please set Unity External Editor arguments to use '$(ProjectPath)");
  64.                 ExitApp();
  65.             }
  66.         }
  67.         private static void ExitApp()
  68.         {
  69.             Console.Write("Press any key to exit . . . ");
  70.             Console.ReadKey(true);
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement