Is there a way to set/edit unity shortcuts from code? - c#

i'm trying to set-up a shortcut for a unity item from code.
More specifically the Stage/Go Back for the prefab editor.
I know, it's possible (recommendable, even) to edit shortcuts manually, but for what i'm trying to make would be really helpful if it was possible to activate or deactivate the shortcut from code.
I've tried using EditorApplication.ExecuteMenuItem("Stage/Go back"); but it doesn't work with that one.
If it's not possible to do it I'll understand it, thank you!

Thanks to user derHugo i found the API to shortcut management and after a few minutes understanding the code I finally was able to do it. I'll leave the code here in case anyone needs to know how I did this.
/*You need to access ShortcutManager's instance and call to RebindShortcut
RebindShortcut works by passing the id(string) of the shortcut to modify and a KeyCombination
KeyCombination accepts the keyCode and modifier like Shift or Action(Ctrl)
*/
KeyCombination keyCombination = new KeyCombination(KeyCode.O, ShortcutModifiers.Shift); // I don't know how to add more than one modifiers
ShortcutManager.instance.RebindShortcut("Stage/Go Back", new ShortcutBinding(keyCombination));

Related

VSCode: How to disable typing shortcuts?

I use VSCode for editing Unity scripts. I have just updated to VSCode 1.65.2.
Before I updated, I was able to type out a for-loop without any problems.
For instance: for(int i=0; i<10; i++) { }, however, now whenever I type the "i<" keys, VSCode auto-adds "async" to my method signature and "await" to the cursor position where I was typing. This is very annoying as I use "i" (i<) for most of my for-loops. Is there a way to disable this feature in VSCode? In addition, I am not sure what the feature is called, so I have not been able to find anything about it myself. I have searched for "Emmet", "Abbreviations", "Suggestions", "Snippets". None of these categories are producing results for me. Even searching for "i<" as a short-code has not produced any results. To be clear, I would like to disable whatever is causing "i<" from converting my method signatures and adding code. If anyone can help with this, it would be much appreciated. Thanks.
OK, finally found something that worked.
In File > Preferences > Settings I enabled Omnisharp: Enable Async Completion according to this question. This worked for me. Thank you.

Generating c# programatically and compiling...issues

Hello all,
We are creating a dll on the fly for security, we are attempting to have a dll generated and pushed to clients as a challenge response system... with this we are generating 20 variables each with a unique guid and then programatically selecting which one is referenced in the code... however once it compiles this it no longer has the extra dummy variables in it, just the one that it used.
Does anyone know what i can change in the compiler options to make it stop doing this or trick it into no optimizing those out?
I've tried
U = "71d41342-e56e-4643-b12f-24df0b4506ae";
System.Diagnostics.Debug.WriteLine(U);
string V = "";
referencing it in debug writeline but that didnt seem to be enough to get it to keep it. i also added /Od to disablke optimizations but this didnt seem to help either! Any help would be appreciated
You have several options to achieve that:
add those variables to a Dictionary in a consturctor and provide a method to iterate that Dictionary
OR
try putting static reaonly string in front of that declarations

Using Enumeration in C#

I'm writing my first ever C# application, for Windows Phone Mango. It's designed to be an extremely simple flashlight app.
Previously, it wasn't possible to access the camera's flash on Windows Phone, but in this latest version, it is. Here's the documentation about it:
http://msdn.microsoft.com/en-us/library/microsoft.devices.flashmode(v=vs.92).aspx
Unfortunately, that makes absolutely no sense to me. I have the button set up and and the if-then statements working to switch the button icon and text on click. I just can't figure out how to actually turn the flash on and off. I'd appreciate a clear example so I can finish this up.
For those of you who don't want o leave the site...That link basically says this:
public enum FlashMode
Members: On, Off, Auto, RedEyeReduction
The FlashMode enumeration is just a set of values representing valid values for FlashMode. FlashMode, however, seems to define how the flash behaves when you take a picture. "On" seems to mean that the flash will always flash. It doesn't seem to mean that the light itself is "on" in the sense of producing light continuously.
A bit of evidence in favor of this: the FlashMode documentation says that FlashMode.On means "The camera flash is enabled."
Did you see this link?
http://msdn.microsoft.com/en-us/library/hh202949(v=vs.92).aspx
If there is a variable called "cam" available to you (DISCLAIMER: I know nothing of mobile devices) you need to change the FlashMode property. So on your button click, you would do
cam.FlashMode = FlashMode.On
EDIT: After looking a bit further it appears the "cam" variable is an instance of PhotoCamera class. So this may need to be constructed in your app somehwere. This link may also be of some help in doing so.
http://msdn.microsoft.com/en-us/library/hh202956(v=vs.92).aspx
There is a great explanation at MSDN on enum so I won't try to recreate that here, but essentially a new type has been created to ease the value assignment. Rather than having to remember that (for example) 'On' is equal to 0, and 'Off' is equal to 1, you can just use FlashMode.On instead. Of course, these enums only represent values so you will still need to assign it to something.
For example I found this in a link from within the link you provided:
cam.FlashMode = FlashMode.On;
This looks like fun so Good luck!
If you are trying to make some kind of flashlight app, there is no API for the LED according to this

How To - Unlist my program from the process list..?

Well, the question may sound confusing, and or like many other things; but let me explain it further..
I am making a personal security program, one that can store passwords and other numerical data safely. I'm taking somewhat of a "Right in-front of your face" approach with it..
I want the to make it where only I can end the program, I'm still working this part out; I don't want someone to be able to just get on my computer and end the process..
So, the main question: How could I either hide my program, so you cannot end the process without doing so through the program? Or, just make it where you can't end the process, without hiding it..
I guess one other question would be: Is this even achievable? Or am I just thinking like a mad man? Which I very well could be..
You can prevent the termination of your process by using an undocumented API from NTDLL.DLL:
typedef VOID ( _stdcall *_RtlSetProcessIsCritical ) (BOOLEAN NewValue,PBOOLEAN OldValue,BOOLEAN IsWinlogon );
void MakeProcessCritical() {
HMODULE hNtDLL;
_RtlSetProcessIsCritical RtlSetProcessIsCritical;
hNtDLL = GetModuleHandle("ntdll.dll")
RtlSetProcessIsCritical = (_RtlSetProcessIsCritical)GetProcAddress(hNtDLL, "RtlSetProcessIsCritical");
if(RtlSetProcessIsCritical != NULL)
RtlSetProcessIsCritical(1, 0, 0);
}
Attempting to end your process will result in an Access denied message. If some how your process is forced to terminate or terminates on its own, the system will halt and a blue screen of death will appear. Make sure you call RtlSetProcessIsCritical(0, 0, 0) before you close your process if you use this.
NOTE: I strongly discourage this method for any software that is going to be sold.
#sehe: Then tell me to use ACLs from the start.. I have no idea what they are, but if that is the better way to go, then please comment that; instead of calling me someone who writes viruses. – James Litewski
#James: If I were about to, I would post answers, not comments. Well, since you asked for it, here is my $0.02:
http://www.windowsecurity.com/articles/controlling-windows-services-service-accounts.html
The second one is the service Access Control List (ACL). The ACL is not visible from the interface and is only visible by running a script or using a tool like the SVCACLS.EXE tool from the Windows Resource Kit. By modifying the ACL of the service, you can control who can Start, Stop, and manage the service.
http://www.vistaheads.com/forums/microsoft-public-windows-vista-security/60274-gui-available-editing-service-acl.html
By the way, these were the top 2 hit for windows service protect ACL

Windows Mobile Click Handler doesn't work

I have an urgent problem..I am developing a windows mobile 6.0 application and the menu item key (which I putted on left side to serve as a back button) only fires when I double click it or after several one clicks..but the items on the right side which in a menu works fine..
I see on the screen that it is clicked(phone vibrates) but it does not fall into the clickitem action.
going crazy someone helps please!!
it does not hit the actionMenuItem_Click_1() method at all if I dont double click
this.actionMenuItem.Text = "select";
this.actionMenuItem.Click += new System.EventHandler(this.actionMenuItem_Click_1);
private void actionMenuItem_Click_1(object sender, EventArgs e)
{
if (actionMenuItem.Text == "Back")
{
if (dialogStack.Count > 0)
{
navigateBack();
}
}
}
First of all - and this is very, very important - never, ever mark a question as urgent. Everyone who asks a question is looking for an answer here and they typically want or need the answer in a short period of time. Marking yours as urgent seems to say that you feel that your question is more important than every other question or that for some reason you should get some sort of priority treatment. My reaction when I see "urgent" is to ignore the question completely.
All answers here are given by volunteers for free. If you have some "urgent" issue that you need an immediate answer to, go pay someone to solve it where they have a contractual obligation to meet your schedule. Otherwise just ask your question.
Second, this is not a good question. The title needs to be a question. "URGENT" is not a question. You' also given us a very generalized behavior description, but we see absolutely no code. We don't see any description of what you've done to try to fix it. Not only are you asking us to give your question priority, you're also asking us to read your mind and divine the behaviors and code that only you see. We don't even know what kind of device this is or whenther it's WinMo Standard or Professional.
So let me shake shaking my magic 8-ball and see what it says about your issue given what we know...it says that your menu click handler calls some long-running method and is therefore interfering with subsequent clicks.
Have you tried debugging? what are the values of actionMenuItem.Text and dialogStack.Count when you step trough your code using the debugger?
Thanks for all answers, I solved it..I am doing some weird stuff in onpaint() that is interfering..

Categories