How to refresh/recompile custom preprocessor - unity3d

I have a custom preprocessor in my PlayerSettings added to unity. According to unity documentation Unity Custom Define Link basically you just add the preprocessor in
Player Settings->OtherSettings->Scripting Define Symbols
and use that preprocessor in scripts #if preprocessor.
My problem is when I add it, the VS Editor does not change the code to compile enabled code and results in non complied code. Is there something else that I need to add to script after adding preprocessor. I have tried adding AssetDatabase.Refresh(); to but it did not work. Is something needs to be refreshed in memory? I did restarted unity but did not helped.
Update: Now I have used the following script to add the preprocessor during runtime
/// <summary>
/// Symbols that will be added to the editor
/// </summary>
public static readonly string[] Symbols = new string[] {
"MYPreprocessor1"
};
/// <summary>
/// Add define symbols as soon as Unity gets done compiling.
/// </summary>
static void AddDefineSymbols()
{
string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
List<string> allDefines = definesString.Split(';').ToList();
allDefines.AddRange(Symbols.Except(allDefines));
PlayerSettings.SetScriptingDefineSymbolsForGroup(
EditorUserBuildSettings.selectedBuildTargetGroup,
string.Join(";", allDefines.ToArray()));
}
The preprocessor blocks added via script works but I have to clear "Scripting Define Symbols" values and restarting unity allows the preprocessor block code to compile. But it wont work when you add it directly
Note: The above code adds the preprocessor blocks in to Scripting Define Symbols via scripting. If the preprocessor block is already existing it wont do anything else it will just add it.

Ok this was a problem with Visual Studio 2017. The preprocessor would not work if you just do reload solution. Whenever a change in preprocessor statement was detected the VS would give four option Reload, Reload solution , Ignore and Ignore All. I was always using reload solution to reload all the data after change but for preprocessors to get activated/refreshed the first option in VS ie Reload button had to be pressed. With that you don't need to add any of the additional scripts above. I have tested with mono also and mono seems to do above work automatically. This was the case of VS2017 community. Hope this helps someone.

AssetDatabase.Refresh or AssetDatabase.SaveAssets should do the job without any manual steps, at least for JetBrains Rider.
Check in your preferences that Editor attaching is enabled.

As ARMatt said, AssetDatabase.Refresh or AssetDatabase.SaveAssets, but I found in my case I needed both (saveassets first, but not sure if it matters). One or the other seemed to not retain the build info I was trying to store in the scriptable object.

Related

Any way to stop Visual Studio adding 'throw new NotImplementedException' on new functions? Causes namespace conflicts with Unity

Yes, I know this is good practise normally but the problem in Unity is it causes the System namespace to be added which breaks several Unity classes such as Random unless I fully qualify them which is tedious :). Is there any way to disable it from adding the throw? I've tried searching for a snippet for it but have drawn a blank. This happens when doing 'Generate Method' from Alt-Enter after typing in 'DoSomething();'
Yes, you can change this default behavior by changing the snippet that creates it. That snippet is located at the following location: (caveat...this will change it across the board for VS2017)
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Snippets\1033\Refactoring\MethodStub.snippet

Is there a way to turn off naming suggestions in a code snippet?

I'm writing Selenium page object classes in Java in Visual Studio Code. I created a custom code snippet that, when entered, looks more or less like this:
public WebElement ELEMENTNAME() {
return driver.findElementByCssSelector("CSSSELECTOR");
}
After I enter the snippet name and hit Tab, ELEMENTNAME gets the focus. I type the element name I've picked, such as ConfirmButton, and hit Tab...whereupon I find that my method now has the name ConfirmButtonElement, because VS Code decided to accept its own naming suggestion instead of what I typed.
How can I turn this "feature" off?
Usually VS Code's autocomplete suggestions are helpful, so I don't want to disable them entirely. But I definitely want to disable them in the case of naming things. Is there a way to do that?
(I'm not sure whether the behavior comes from VS Code itself or from an extension such as the Red Hat Java extensions.)
1. Extension to blame: It is actually happening because of Microsoft Java Extension Pack. Though it also includes the Red Hat Java Package
2. To disable this package: You can navigate to Extensions tab in VScode and search for Microsoft Java Extension Pack and click disable package.
I don't know when this may have been added to vscode, but have a look at:
// Control whether an active snippet prevents quick suggestions.
"editor.suggest.snippetsPreventQuickSuggestions": true,
true is the default, try false.

How does monodevelop summary autocompletion work

In monodevelop, if I declare a variable like so...
public int foo = 1;
Then in the line directly above it, i type ///, it will automatically generate this....
/// <summary>
/// The foo.
/// </summary>
How is this happening? Which files in unity are causing this behaviour? I want to know because I want to modify it to add some other generated code.
How is this happening? Which files in unity are causing this behaviour? I want to know because I want to modify it to add some other generated code.
You won't be able to modify Unity's MonoDevelop that easily. They are actually stuck in some old version (which presumably will make your life even more complicated if you want to change its behaviour) that is years old.
Some people use nowadays Xamarin Studio (instead of Unity's MonoDevelop) or the last version of MonoDevelop, with a Unity plugin. This would be a more reliable way for you to go ahead and change MonoDevelop's documentation-autocompletion behaviour, by looking at its upstream source code, and maybe creating an AddIn yourself for the desired functionality.

Can't make a method static in ReSharper because menus are greyed out

I'm trying to follow some steps to move methods from one class to another class with ReSharper 7.1.1. One of the steps to do this involves making the method static, however, the context menu entry Make Method Static... seems to be disabled and greyed out. The strange thing is it wasn't greyed out before on the same function, but after I discarded my changes to do it again, it seems to be greyed out now.
I've tried highlighting the function name and the whole function itself to try to make the menu entry active, but still no luck. How can I enable the Make Method Static... menu again?
Please check that your method is not virtual and is not used to implement an interface. Otherwise, please provide a code sample.

How can I make my Eclipse RCP app's keyboard shortcuts (accelerators) work immediately after startup?

Our Eclipse RCP application was originally built in the 3.1/3.2 era and was running on 3.2 until we switched to 3.6 recently. Its IApplication runs via PlatformUI.createAndRunWorkbench(...). The WorkbenchAdvisor we pass to that function overridescreateWorkbenchWindowAdvisor(...) to return a WorkbenchWindowAdvisor whose createActionBarAdvisor(...) returns an ActionBarAdvisor.
This ActionBarAdvisor's makeActions(...) creates and register()s a bunch of org.eclipse.jface.action.Actions, many of which do things like setAccelerator(SWT.CTRL | 'O'); in their constructors. The Actions are subsequently installed in the ActionBarAdvisor's fillMenuBar(...) and fillCoolBar(...) methods.
The problem we are having (now that we are on Eclipse RCP 3.6) is that these accelerators don't seem to be active until their menus are shown (even if no action is taken besides closing the menu again).
We see a relevant bug but are having some difficulty understanding how to apply its remedy to our situation. We recognize that instead of Actions we "ought" to be using commands, handlers, and key bindings. But we're hoping we don't have to go down that path just yet.
How can we make our accelerators "live" as soon as the application starts up?
If you don't choose to use o.e.ui.bindings extension point, then there isn't a better way. You should only force update the menuManager yourself as you have done in your answer.
As #Prakash mentioned, if you want to keep down that path in your RCP app you must render all of the main menus to see your accelerators.
There is a partial upgrade path that will get you on the right track to commands without forcing a complete switch over right away. For each action in your menu, define a command with an id and define a binding to the shortcut you want in your plugin.xml. Then, when you create the action in your ActionBarAdvisor, don't set the accelerator. Set the IAction.setActionDefinitionId(*) to the command id, can call register(action);
Then you no longer need to use menuManager.updateAll(true) to eagerly render all of your main menu.
After hunting around and experimenting a bit trying to apply the advice from the bug, we added the following to our WorkbenchWindowAdvisor, which seems to have done the trick:
#Override
public void postWindowCreate() {
getWindowConfigurer().getActionBarConfigurer().getMenuManager().updateAll(true);
}
We have no idea how well this fits with the Workbench's design expectations; there could be a better way.