Using Enumeration in C# - 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

Related

Unity Ar foundation body tracking. Is it possible to track multiple bodies?

If you use the latest version of AR foundation (I had to manually edit Packages/manifest.json to get it) and also have an iphone with an A12 processor or later, you can have body tracking.
You can track 3d or 2d human bodies.
I am interested in the 2d tracking.
In Unity's demo they are using this line of code to get the human body data
var joints = m_HumanBodyManager.GetHumanBodyPose2DJoints(Allocator.Temp);
Which seems to only return info for one body even if the phone can see 2 or more.
I am wondering if tracking multiple bodies is possible, some functions of the humanBodyManager class seem to hint at this being possible. eg.
This function
OnTrackablesChanged(List<ARHumanBody>, List<ARHumanBody>, List<ARHumanBody>)
List<ARHumanBody> added
The list of human bodies added to the set of trackables.
List<ARHumanBody> updated
The list of human bodies updated in the set of trackables.
List<ARHumanBody> removed
The list of human bodies removed to the set of trackables.
and this event
public event Action<ARHumanBodiesChangedEventArgs> humanBodiesChanged
The event that is fired when a change to the detected human bodies is reported.
That function is protected, and I have tried subscribing to that event but it doesnt ever seem to be called. Its also very weird as its an event which wants to call functions which return an action that takes ARHumanBodiesChangedEventArgs as a paramater... I dunno why anyone would ever write a thing like that tbh.
Anyway writing visual debug code and then building to iOS to test all these semi documented classes is a massive pain. If someone could just let me know if multiple body tracking is even possible with ar foundation that would help me a lot. Thanks!

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

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));

Xceed AvalonDock 3.2 DockWidth/Height has no effect

I'm using AvalonDock(Extended.Wpf.Toolkit, free version) in an app for my employer. Setting DockWidth or DockHeight in either LayoutAnchorablePane or LayoutDocumentPane has no(visible) effect. Instead, each pane occupies an equivalent amount of space relative to its siblings(they default to 1*).
They can be resized at runtime with the built-in splitters, but that doesn't help programmatically or at design time. I've used some workarounds such as:
Setting DockMinWidth/DockMaxWidth to the
same value, but obviously the splitters stop moving.
Using reflection to brute-force change the size. This is quite fragile.
Both of which are dirty hacks that I'd like to avoid.
I'm aware that this was done in the past with ResizingPanel, but it's been long since removed. See this for related information.
I've yet to find the answer in the documentation or the source code.
See my answer.
Here's a simplified example demonstrating the problem.
This post pointed me in the right direction.
The issue is indeed internal code. The following fixed it:
Add a flag to ILayoutPositionableElement.cs. I named it ForceFixedDockSize.
Implement it in LayoutPositionableGroup.cs.
Inside of every override of OnFixChildrenDockLengths, check if the flag is true before setting DockWidth or DockHeight.
I suspect the reason this behavior exists is to make default layouts look consistent. This change makes that behavior optional.
See my fork.

Automated 'PrtScn' keystroke acts like 'Alt+PrtScrn'

We need a screenshot of our app for a unit test. CaptureScreen() and CopyFromScreen() somehow ignore the app and return pictures of an empty desktop. So we wrote this to fake a PrtScn keystroke:
public static Bitmap GetAltScreenshot()
{
Clipboard.Clear();
SendKeys.SendWait("{PRTSC}");
while (!Clipboard.ContainsImage())
{
Thread.Sleep(500);
}
return new Bitmap(Clipboard.GetImage());
}
Alt isn't part of the keystroke, so this should return a bitmap of the entire screen. Yet somehow this snippet returns just the focused window. Which is fine, that solves our problem - but we don't understand how.
Why does this return a shot of just the focused window, instead of the entire monitor?
There is in fact a "reason", turn to the MSDN Library article that documents the key abbreviations you can use. Note the entry for PRINT SCREEN:
{PRTSC} (reserved for future use)
The is a somewhat clumsy way of saying "We know it doesn't work, maybe will fix that some day". That day hasn't yet arrived. So you are probably testing the failure mode of this key and actually like the way it works. This is of course not healthy, they may actually fix the problem some day and break your program.
Do note the Note about the <appSettings> entry that you can add to your .config file, further down that same MSDN page. I suspect, but do not know for a fact, that the SendInput method is more reliable.

FMOD gapless loop and sequence playback

I started using FMOD library, because I need to play sounds without gaps in C# application (both one sound in a loop and many sounds in a sequence). Can anyone show me the correct way to do it? I tried make something based on examples, but it's not working as I would like it to work.
Firstly, when I try to set if the sound is looped, while it's playing,
if (value)
sound1.setMode(FMOD.MODE.LOOP_NORMAL);
else
sound1.setMode(FMOD.MODE.LOOP_OFF);
nothing is going on. It only works fine, when I set th mode, before I start playback.
The second issue is: how can I be notified that the sound has reached the end? I tried to do it this way:
channel.setCallback(eofCallback);
where eofCallback is a reference to SoundEndCallback
private FMOD.RESULT SoundEndCallback(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, IntPtr commanddata1, IntPtr commanddata2)
{
FMOD.RESULT result;
if (type == FMOD.CHANNEL_CALLBACKTYPE.END)
{
//logic here
}
return FMOD.RESULT.OK;
}
But this callback is reached only when I manually invoke stop() on channel, not when the track ends.
Or eventually do you know any other library that would give me easily what I need? I chose FMOD, because it's quite popular, but I don't like its oldschool C++-like way of coding (no events, no exceptions, etc.).
And I have teh answer for my second question: to get notified you have to firstly set callback as mentioned before, and after that you've got to use System.update() method (it must be called periodically in a loop). This is a kind of polling,
To set the loop mode of a sound at runtime use Channel::setMode, Sound::setMode is like setting the defaults for any channels played from that sound (it won't affect currently playing sounds).
As for Channel::setCallback, make sure you are calling System::update regularly to have the callbacks fire for events like the sound playing to the end.

Categories