Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.IO;
- namespace UnityStartSharpDevelop
- {
- class Program
- {
- public static void Main(string[] args)
- {
- /* From Unity Docs https://docs.unity3d.com/Manual/Preferences.html
- $(ProjectPath) is replaced with the path to the open project.
- Unity "$(ProjectPath) sends X:\PathToYourProject e.g C:\Users\graha\Dropbox\Computer Club\Unity\Brackeys Youtube Tutorial\
- The project .sln file created by Unity/VS is in this folder with the same name as the project: Brackeys Youtube Tutorial.sln
- Compile this project and place 'UnityStartSharpDevelop.exe' somewhere in the Unity installation folder.
- Browse Unity preferences to use this file as the external editor.
- Any C# file in your unity project will load the entire solution with all .cs files available.
- Navigate the project to edit the script you are looking for
- */
- // If SharpDevelop is already running, prevent a second instance starting
- string processName = "SharpDevelop";
- Process[] instances = Process.GetProcessesByName(processName);
- if (instances.Length > 1)
- {
- Environment.Exit(1);
- }
- //Edit this path to SharpDevelop to suit your system
- const string sharpDevelopAppPath = @"C:\Program Files (x86)\SharpDevelop\5.1\bin\SharpDevelop.exe";
- string projectPath = string.Empty;
- string projectName = string.Empty;
- if(args.Length > 0) //Check args have been passed
- {
- projectPath = args[0];
- projectName = new DirectoryInfo(projectPath).Name + ".sln";
- projectPath = Path.Combine(projectPath, projectName);
- if(File.Exists(projectPath))
- {
- projectPath = "\"" + projectPath + "\""; // surround pathname with quotes to prevent spaces causing errors
- try
- {
- ProcessStartInfo start = new ProcessStartInfo();
- start.Arguments = projectPath;
- start.FileName = sharpDevelopAppPath;
- Process.Start(start);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- ExitApp();
- }
- }
- else //file does not exist
- {
- Console.WriteLine("Solution file " + projectPath + "Not found. Please set Unity External Editor arguments to use '$(ProjectPath)");
- Console.WriteLine("Also make sure the solution name has the same name as the project directory.");
- ExitApp();
- }
- }
- else //no args passed
- {
- Console.WriteLine("No args found. Please set Unity External Editor arguments to use '$(ProjectPath)");
- ExitApp();
- }
- }
- private static void ExitApp()
- {
- Console.Write("Press any key to exit . . . ");
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement