When I create C# script (Create -> C# Script
) via Unity3d
or delete it from Unity3d
- Visual Studio
shows me the warning window.
it's annoying.
Is there any way to force "ReloadAll" in solution Explorer without the window?
So, what we have.
Developer from the VS Tools for Unity team
said that it is one of their most voted feature requests.
And it's surprisingly not trivial to fix, they are working on it.
However, I found some script which can use.. I found it on russian unity community.
Great thanks to DbIMok. Also he posted this script yesterday on forum.unity3d.com
Need to create C# script named as FileModDialogCloser.cs
and put it into the Editor
folder.
Here is the code:
using System;
using System.Runtime.InteropServices;
using UnityEditor;
[InitializeOnLoad]
public class FileModDialogCloser {
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
const string search = "File Modification Detected";
static IntPtr hwnd;
static void Check() {
hwnd = FindWindowByCaption(IntPtr.Zero, search);
if ((int)hwnd != 0) {
ShowWindow(hwnd, 5);
keybd_event(0x0D, 0, 0, 0);
}
}
static FileModDialogCloser() {
EditorApplication.update += Check;
}
}
Wondering!
It works for creating and deleting C# scripts via Unity.
As you can see the code has a line keybd_event(0x0D, 0, 0, 0);
. This is simulate pressing of Enter button. And that means Reload realization. if you need ReloadAll then you have to do like that:
keybd_event(0x09, 0, 0, 0);
keybd_event(0x0D, 0, 0, 0);
This is pressing of Tab button and then Enter.
SMALL FAULT: When you are creating/deleting script: confirm window opens, runs keybd_event
, the window closes. It happen very fast, so you don't need to click any button. But you can see this window on few milliseconds anyway.
I think, for now there is no better way to do that.
ADDITIONALLY:
You can create C# script for Unity projects (not just simple C# script) within Visual Studio
. Unity
will add the file automatically without confirmation window.
The first method (simlple):
If I got it right: when you are using Visual Studio Tools for Unity
- that tool are integrating already templates for creating Unity C# scripts into the VS
.
So, right click on Solution and chose Add -> NewItem
. You can see two templates for Unity:
However, these templates can contains a lot of unnecessary information, comments for example // Use this for initialization
, // Update is called once per frame
e.t.c.
And, as @wondra in comments said: you can add own custom item template for unity scripts.
The second method:
Next
, Next
Finish
c:\Users\YOUR_PROFILE\Documents\Visual Studio 2015\My Exported Templates\
folder, also into the c:\Users\YOUR_PROFILE\Documents\Visual Studio 2015\Templates\ItemTemplates\
.
After VS
restart you can see this template in the list just as VS Tools for Unity
templates:Here is the video explanation.
Happy End!
You can add the new script directly on Visual Studio on your intended directory in Unity. In that case you will not need to reload.
But you will have to do something else. New script in Visual Studio will have some namespaces that used default. You may change or remove them. You will have to add using UnityEngine;
at first for Unity related privileges. You will have to add void Start()
or void Update()
by yourself if you need.
New Class should look like: