Unity editor - How to stop field from turning blue when its edited - unity3d

I am making a tool in Unity to build your project for muliple platforms when you press a button.
I started with the preferences window for the tool, and came up with an anoying thing. Whenever I change the enum value of the EnumPopup field, the field turns blue in the editor window. Is there a way to disable this?
See how in the 2nd picture the field is not blue, and in the 3rd picture the field has changed to blue? How do I prevent this from happening?
Thanks in advance!

Difficult to help without having the rest of your code.
This is Unity built-in behaviour. I tried a lot of stuff see here to disable / overwrite the built-in coloring of prefix labels but had no luck so far.
A workarround however might be to instead use an independent EditorGUI.LabelField which will not be affected by the EnumPopup together with the EditorGUIUtility.labelWidth:
var LabelRect = new Rect(
FILEMANAGEMENT_ENUMFIELD_RECT.x,
FILEMANAGEMENT_ENUMFIELD_RECT.y,
// use the current label width
EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.height
);
var EnumRect = new Rect(
FILEMANAGEMENT_ENUMFIELD_RECT.x + EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.y,
FILEMANAGEMENT_ENUMFIELD_RECT.width - EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.height
);
EditorGUI.LabelField(LabelRect, "File relative to");
QuickBuilder.Settings.Relation = (QuickBuilder.Settings.PathRelation)EditorGUI.EnumPopup(EnumRect, QuickBuilder.Settings.Relation);
As you can see the label is not turned blue while the width keeps being flexible
Sidenotes
Instead of setting values via edito scripts directly like
QuickBuilder.Settings.Relation = you should always try and use the proper SerializedProperty. It handles things like Undo/Redo and also marks the according objects and scenes as dirty.
Is there also a special reason why you use EditorGUI instead of EditorGUILayout? In the latter you don't need to setup Rects.
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("File relative to", GUILayout.Width(EditorGUIUtility.labelWidth));
QuickBuilder.Settings.Relation = (QuickBuilder.Settings.PathRelation)EditorGUILayout.EnumPopup(QuickBuilder.Settings.Relation);
}
EditorGUILayout.EndHorizontal();

Related

VSCode API: Access the minimap

Is there any way to access the "minimap" that optionally appears next to the scroll bar on the right hand side of the editor?
Preferably I would like to access that panel's width in pixels.
The best I could do to get the values I want is to read the current editor configuration (also settable from the vscode settings UI/JSON).
const editorConfig = vscode.workspace.getConfiguration('editor');
const minimapOn = editorConfig.get("minimap.enabled");
const minimapWidth = editorConfig.get("minimap.maxColumn");
But this only lists the maximum width, not the current one.
Configuring the Width of the Editor's Minimap
The Minimaps with is configurable, not by pixels, but by characters.
The reason it is configurable by characters is because it gives developers a way of setting the minimap's width to the exact width that there longest lines of code are. This is beneficial, as it makes the minimap as wide as needed, without taking up any unnecessary space.
Below is the setting that changes the width of the editor's minimap.
// #file Globally Scoped "settings.json" file
{
"editor.minimap.maxColumn": 75
}
75 can be set to any amount of characters you choose.
Now the part about the API
Anytime you have a setting that does what you want, you can use the API to apply it to your extension. I don't want to continue explaining anything byond the scope of this question, so I will provide a link to the documentation that covers the method used to change a setting using the VS Code API, and a snippet showing you how to use the method to change the minimap's columns width.
Below shows the code an extension might include to change the size of the minimap.
await vscode.workspace
.getConfiguration()
.update(
'editor.minimap.maxColumn',
100,
vscode.ConfigurationTarget.Global
);
NOTE: I wrote the example above off the top of my head. I know that the semantics are all correct, but you will probably have to play with it to get it to do exactly what it is your going for.
Here are a couple links to help you understand what your doing.
"vscode.workspace.getConfiguration()" This is can be interpreted as the base of program-interface that changes settings. From this part of the API, a few methods, objects, constants, and events extend, all of which are used to set, get, and mutate configurations within VS Code.
"The Configuration target" sets the settings.json file you are targeting. Global is a good bet, I prefer "workspace" (which is not the same as "workspace folder".

How to have custom script icons other than using "Assets/Gizmos" in Unity3D

I know this was asked a lot of times probably .. but it is very often answered wrong.
What I want is:
Use a custom icon for specific components/scripts in the Inspector (e.g. Figure 2 and Figure 3) and the ProjectView (e.g. Figure 1)
What I do so far:
For each component/class that shall have the icon I have an accroding Icon file in the folder
Assets/Gizmos/<Path>/<To>/<Namespace>/<ClassName> icon
and in the Import Settigns set TextureType to Editor GUI and Legacy GUI
This is working fine .. and until now the only way how I could achieve that (having in mind the below section What I definitely do NOT want).
But
However, I wondered if there is really no better way having to have a unique Icon file for each script. This makes the project/UnityPackage unnecessarily huge. Also if I rename a class I always have to rename the according icon file as well ... This imply doesn't feel right!
Most Unity build-in Behaviours and Components have a unique icon. But also external Packages coming from the new PackageManager have built-in icons and sometimes a Gizmos folder but it is not following the above naming rule ... so apparently the icon is configured somehow else for them.
Therefore my questions:
Is there any better way to have those icons for scripts/components?
Preferably scripted and reusing ONE single icon file instead of having the same icon in multiple differently named files.
And/or also Where/How are those icons defined for the scripts coming from the PackageManager?
!NOTE! What I definitely do NOT want:
Show the Icon also in the SceneView for all GameObjects having those components attached (e.g. Figure 4). This is caused by either selecting the icon for this script via the Inspector as in Figure 5 (as allways suggested e.g. in this post or here and even by Unity - Assign Icons ) or using OnDrawGizmos or DrawGizmo. This is not happening using the approach I use currently with the Gizmos folder!
Update
Because this was suggested in this answer: I also know that I could do that and turn them off via the Gizmos settings of the SceneView. But imagine I have like 25 different modules and various different icons each. I don't want to have to disable their Gizmos in the SceneView settings one by one on a per project basis! Even the provided script seems like a vast hackaround. Reflection would be the very last resort I would ever take. Also I'ld prefer to not even have those icons appear as possible Gizmos at all instead of disabling them all.
You can set the icon with figure 5 and then turn the gizmos for that icon off from the gizmos drop down.
Edit: Injunction with the step above you could try this script derived from here it uses reflection to find the class responsible for turning off the the gizmos and icons. This would execute any time your scripts recompiled to keep those icons off or if you added any new icons to the autohide icon file. Note: scriptClass will be an empty string for built in components eg.Camera, AudoSource
using UnityEditor;
using System;
using System.Reflection;
public class DisableAllGizmos
{
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
var Annotation = Type.GetType("UnityEditor.Annotation, UnityEditor");
var ClassId = Annotation.GetField("classID");
var ScriptClass = Annotation.GetField("scriptClass");
var Flags = Annotation.GetField("flags");
var IconEnabled = Annotation.GetField("iconEnabled");
Type AnnotationUtility = Type.GetType("UnityEditor.AnnotationUtility, UnityEditor");
var GetAnnotations = AnnotationUtility.GetMethod("GetAnnotations", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
var SetIconEnabled = AnnotationUtility.GetMethod("SetIconEnabled", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
Array annotations = (Array)GetAnnotations.Invoke(null, null);
foreach (var a in annotations)
{
int classId = (int)ClassId.GetValue(a);
string scriptClass = (string)ScriptClass.GetValue(a);
int flags = (int)Flags.GetValue(a);
int iconEnabled = (int)IconEnabled.GetValue(a);
// this is done to ignore any built in types
if (string.IsNullOrEmpty(scriptClass))
{
continue;
}
// load a json or text file with class names
const int HasIcon = 1;
bool hasIconFlag = (flags & HasIcon) == HasIcon;
// Added for refrence
//const int HasGizmo = 2;
//bool hasGizmoFlag = (flags & HasGizmo) == HasGizmo;
if (/*Compare class names in file to scriptClass == true*/)
{
if (hasIconFlag && (iconEnabled != 0))
{
UnityEngine.Debug.LogWarning(string.Format("Script:'{0}' is not ment to show its icon in the scene view and will auto hide now. " +
"Icon auto hide is checked on script recompile, if you'd like to change this please remove it from the config",scriptClass));
SetIconEnabled.Invoke(null, new object[] { classId, scriptClass, 0 });
}
}
}
}
}
Shown in the inspector with a gizmo
Hide Icon from gizmos dropdown
Icon still appears in the inspector and in the project view but not in the scene
So I did a bit more research about built in types as well as packages coming from the package manager and the asset store. Anything that is external (packagemanager or assetstore) if it has a custom icon for the script and inspector it will Always have a gizmo in the scene view. As it has its icon set using your figure 5 example, as seen in the screenshots with the debug inspector.
Also if you want to set the icon with a script or hide it ,currently reflection is your only option as these APIs are not publicly accessible.
My Script showing the debug inspector for its script
PixelPerfect package script from the packagemanager in the debug inspector
PixelPerfect Icon showing in the scene
I was hoping to add this as a comment to your original question but not enough rep yet.

Bokeh - How to use box tool without default selections?

I have built a bokeh app that allows users to select windows in data and run python code to find and label (with markers) extreme values within these limits. For ease of interaction, I use the box select tool for the range selection. My problem arises when repeating this process for subsequent cases. After markers are placed for the results, they are rendered invisible by setting alpha to zero and another case needs to be chosen. When the new select box includes previous markers, they become visible based on the selection. How do I override this default behavior? Can markers be made unselectable? or can I add code to the customJS to hide them after they are selected?
Thanks in advance for any help!
There are a few possible approaches. If you just want non-selected glyphs to "disappear" visually, you can set a policy to do that as described here:
http://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs
Basically, for bokeh.plotting, pass
nonselection_fill_alpha=0.0,
nonselection_line_alpha=0.0,
as arguments to your plot.circle call or whatever. Or if you are using the low level bokeh.models interface, something like:
renderer.nonselection_glyph = Circle(fill_alpha=0.0, line_alpha=0.0)
But be aware (I think you already are) that the invisible markers are still there, and still selectable if the user happens to draw a box over them with the selection tool.
If you truly want only a subset of the data to be visible and selectable after a selection, I'd say you want to replace the data in the column data source wholesale with the subset in your selection callback.

GWT Read-only TextArea will not resize

GWT newbie here. I have found that when I make a TextArea read-only useful features such as dynamic expansion and even word-wrapping stops working. My intention was to move a string from one text area, append it some way to some more strings, and then add this string into my read-only TextArea. I have doing something like this:
// Temporarily enable the field to set the value of the TextArea
logTextArea.setEnabled(true);
String remarks = // my string to add into the box
if (remarks.length() > 0) {
logTextArea.setEnabled.setValue(remarks);
}
// set read-only again
logTextArea.setEnabled.setEnabled(false);
I also have to work out how many lines I now span and explicitly set the height of the box (via setVisibleLines()). I have now found that it does not word-wrap, so I've had to add some more horrible bodge-code to further split up this string.
So I'm writing code to emulate functionality that comes for free on a normal writable TextArea. Has anyone else found this issue after setting a text-field read-only? Is there another widget I could possibly use to display a list of read-only strings that will auto resize and auto wrap for me?
Many thanks for your time,
tom
Text Area is fine for re-sizing and auto word wrap, even you have your text
area as read only.
Tested now by creating a test project for gwt and it is working fine.
Also Word Wrap is the default behavior of Text area if you want to turn it off then you need to explicitly do this "getElement().setAttribute("wrap","off");

programmatically change the background color in eclipse

I have a question related to eclipse plugin development. Is there any means
by which I can programmatically change the background color in eclipse.
I am able to change the text foreground color by calling
setTextColor(color, offset, length, controlRedraw) in ITextViewer
but I don't find any function by which I can change the background
color of the text.
If anyone has been through this kindly share your thoughts.
Thanks
arav
I am not sure this can be done easily, short of extending your own version of a Text Editor, here you provide a Configuration Class which inturn accepts a PresentationReconciler Class which is like a Rule Class that tells you if you need to put a Foreground or a Background Color
See this document
PresentationReconciler
IPresentationDamager: define dirty region given a text change
IPresentationRepairer: recreate presentation for dirty region
DefaultDamagerRepairer does both, based on a token scanner
ITokenScanner: parse text into a token stream
RuleBasedScanner uses simple rules
Extract from the presentation
From Text Editor Recipes, Season’s recipes for your text editor
Tom Eicher, IBM Eclipse Team
Here, the null background color means, takes the default system background for that widget. (so here: white).
But you could specify whatever color you want, based on the partitioning of your document and on the rules that would apply.
I know this was asked a while ago, but in case anyone is looking for another solution, I thought I would post the following:
Since you are able to use the setTextColor method, then you should be able to use the changeTextPresentation method as well.
In the case of my plug-in, I have a TextListener that calls the TextChanged method I overwrote. I did the following to add background color using the changeTextPresentation method. In doing so, I was able to get a Green background with Black foreground. Not that I would want this, of course, but just for testing purposes.
public void TextChanged(TextEvent event){
...
TextPresentation presentation = new TextPresentation();
TextAttribute attr = new TextAttribute(new ColorManager().getColor(MyConstants.BLACK),
new ColorManager().getColor(MyConstants.GREEN), style);
presentation.addStyleRange(new StyleRange(startOffset, tokLength, attr.getForeground(),
attr.getBackground());
sourceViewer.changeTextPresentation(presentation, true); //sourceViewer is a global variable passed to my TextListener class constructor.
}