Dec 27, 2017

How to Find Out Which Build and Version of Windows 10 You Have

The new Settings app also offers build, edition, and version information in a user-friendly form. Hit Windows+I to open Settings. In the Settings window, navigate to System > About.  Scroll down a bit and you’ll see the information you’re after.


Dec 17, 2017

A Better Way to Data Bind Enums in WPF

Have you needed to data bind enums in WPF? Well, if you write WPF applications, you bet your ass you have! In this post, I would like to show you how I like to deal with enums in WPF. Fo this post, I will be using the following enum to bind to.

public enum Status
{
    Horrible,
    Bad,
    SoSo,
    Good,
    Better,
    Best
}

The WPF Way

Normally if you were going to data bind a control to your enum you would need to go through a number of steps.  First you need to add a XAML namespace for your local enum type and to System in MSCorLib.

xmlns:local="clr-namespace:BindingEnums"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Then you would to create an ObjectDataProvider as a resource.  Give it an x:Key so you can use it in your code, set the MethodName to “GetValues” which exists on the enum data type, and then set the ObjectType to that of the enum type.  But wait, you’re not done yet.  Next you need to set the ObjectDataProvider.MethodParameters to that of your enum type.  So you will end up with something like this.

<Window.Resources>
    <ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues"
                        ObjectType="{x:Type sys:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:Status"/>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>
Now, you you have something you can data bind to.  For example, if I wanted to data bind a ComboBox to this enum, I would have to set it’s ItemsSource to a new Binding, and set the source to that of our enum ObjectDataProvider we created above.  Like so:

<Grid>
    <ComboBox HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="150"
              ItemsSource="{Binding Source={StaticResource dataFromEnum}}"/>
</Grid>
And viola! Our enum is data bound.

This isn’t bad.  It works just fine, but it requires a lot more code than I would like to have to write over and over.  I would rather write the code once, and just change the enum type so I can reuse all that logic all over my application.  With the above approach we have to create a new ObjectDataProvider for each enum we have, which just means more code to maintain, and more chances of writing broken XAML.  Especially since you are more likely to copy and paste a previous ObjectDataProvider you created and just change some parameters.  Hence, it’s more error prone.

The Better Way

Let’s look at how we can use features of WPF to improve the usage and readability of our code when data binding to enums.  First, I want to encapsulate all that logic for creating a bindable list of enum values without the need of an ObjectDataProvider.  I also want to eliminate the need to create a Resource that must be defined in order to be used in my XAML.  Ideally I would just do everything inline like I would with a normal object binding.  To accomplish this, I am going to enlist the help of a custom MarkupExtension.  This extension will simply take an enum Type and then create a bindable list of enum values for my control.  It’s actually quite simple.  Take a look:

public class EnumBindingSourceExtension : MarkupExtension
{
    private Type _enumType;
    public Type EnumType
    {
        get { return this._enumType; }
        set
        {
            if (value != this._enumType)
            {
                if (null != value)
                {
                    Type enumType = Nullable.GetUnderlyingType(value) ?? value;                     if (!enumType.IsEnum)
                        throw new ArgumentException("Type must be for an Enum.");
                }
                this._enumType = value;
            }
        }
    }
    public EnumBindingSourceExtension() { }
    public EnumBindingSourceExtension(Type enumType)
    {
        this.EnumType = enumType;
    }
    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        if (null == this._enumType)
            throw new InvalidOperationException("The EnumType must be specified.");
        Type actualEnumType = Nullable.GetUnderlyingType(this._enumType) ?? this._enumType;
        Array enumValues = Enum.GetValues(actualEnumType);
        if (actualEnumType == this._enumType)
            return enumValues;
        Array tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1);
        enumValues.CopyTo(tempArray, 1);
        return tempArray;
    }
}

Now we can simplify our XAML and simply create an enum binding like this:
<Grid>
    <ComboBox HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="150"
              ItemsSource="{Binding Source={local:EnumBindingSource {x:Type local:Status}}}"/>
</Grid>
Same result, but without the need for an ObjectDataProvider.

Adding Description Support

Now that we have our enum binding working perfectly without the need for that silly ObjectDataProvider, we can improve our enum experience.  It is very common to have a enum to represent the values, while at the same time, give the enum value a description so that it is more readable to your user.  For example; let’s say you have an enum will all the state abbreviations (ID, TX, AZ, etc.), but you would much rather display the full state name (Texas, Idaho, Arizona, etc.).  Wouldn’t it be nice to have this ability?  Well, luckily for us, this is easy to.  We will just need to use a simple TypeConverter that we can attribute our enum with.  Check it out:

public class EnumDescriptionTypeConverter : EnumConverter
{
    public EnumDescriptionTypeConverter(Type type)
        : base(type)
    {
    }     public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
        if (destinationType == typeof(string))
        {
            if (value != null)
            {
                FieldInfo fi = value.GetType().GetField(value.ToString());
                if (fi != null)
                {
                    var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                    return ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();
                }
            }
            return string.Empty;
        }
        return base.ConvertTo(context, culture, value, destinationType);
    }
}

Now add the attribute and add some descriptions to our enum:
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
public enum Status
{
    [Description("This is horrible")]
    Horrible,
    [Description("This is bad")]
    Bad,
    [Description("This is so so")]
    SoSo,
    [Description("This is good")]
    Good,
    [Description("This is better")]
    Better,
    [Description("This is best")]
    Best
}
BAM!  We now have our descriptions display to our users, but the actual values remain intact.

That does it for this post.  Hopefully you will find this useful, and maybe even use this approach in your WPF applications.  Be sure to check out the source code, and start playing with it.  As always, feel free contact me on my blog, connect with me on Twitter (@brianlagunas), or leave a comment below for any questions or comments you may have.

REFERENCE: http://brianlagunas.com/a-better-way-to-data-bind-enums-in-wpf/
 

Dec 14, 2017

Steam and Unity Questions

1)* Is there a way I can start a standalone build and use the Steam Overlay?
If you launch the game from a shortcut in your steam library which points to the standalone build in your output folder then the overlay will be injected as the game starts.
I think if you use "Build and Run" in Unity that might work too, but only if you've already played in the editor in that session. (Because SteamAPI.Init() gets called, which injects the overlay, then build and run spawns your game as a child process and the overlay gets automatically injected into it.)
2)* Should I be able to start the game from the Steam Library?
Only if you've uploaded your game to steam and it's being correct downloaded into your steamapps/common folder. Your launch parameters in the Steamworks backend may be incorrect as well. (Don't forget to publish the changes!)
3)* If yes, should the steam_appid.txt file be next to the .exe or do I only need that when starting the .exe manually?
The steam_appid.txt is only required when testing locally, it's generally not recommended to ship it on steam to customers.
4)* Again, if yes, is it important that I put the build in the steamapps/common/my_game folder, or can the build reside in my usual UnityProject/Builds folder?
So, If you use SteamAPI.RestartAppIfNecessary, without having a steam_appid.txt then your game is literally doing a complete shutdown with Application.Quit() and then steam relaunches it once it quits. This relaunch is literally the exact same thing as double clicking the game in your steam library, so it kind of depends how you want to work. If you're testing with the overlay then having your builds output to your steamapps/common folder and just launching from your regular steam library icon may be best. Otherwise one of the other options above might be better.

REFERENCE: https://github.com/rlabrecque/Steamworks.NET/issues/142

Dec 11, 2017

Unity Script Collection

Navigation:

GameObjects & Transforms

Movement & Animation

Controls & Input

Character Controller

AI & Pathfinding

Physics

Particles

Meshes & Construction

Materials & Shading

2D

Networking

VR

Sound & Music

  • usfxr - procedual audio effects
  • Reaktion - audio reaction toolkit (mac only)
  • DefaultMicrophone - gets the default microphone (windows only)
  • Lasp - Low-latency Audio Signal Processing plugin for Unity

UI

Post-Processing & Rendering

Mobile

Debug

  • uREPL - runtime evaluation of c# expressions
  • UberLogger - advanced logging API, improved editor console & ingame console

Editor

Tools

Editors

Inspector Extensions

Importer

Serialization & Web

Social SDKs

API Extensions & Helper

Design Patterns

Other

REFERENCE: https://github.com/michidk/Unity-Script-Collection#tools

Dec 7, 2017

"There are no TAP-Windows adapters on this system" after updating Windows 10

If you can't connect to VPN after a cliche Windows Update, Just Uninstall VPN Tool (such as OpenVPN, Sophos etc.) andt install it. It will work, Thank you Windows for providing a traditional bug and a solution for us!

Example Error from VPN Client:

Thu Dec 07 20:59:03 2017 MANAGEMENT: Client disconnected
Thu Dec 07 20:59:03 2017 There are no TAP-Windows adapters on this system.  You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter.
Thu Dec 07 20:59:03 2017 Exiting due to fatal error

Myths and Facts of the Unity Game Engine

Unity is only for games

It’s a myth. Of course Unity has been created as a game engine, but it’s so flexible that it is successfully being used in other industries, such as architecture, medicine, and engineering. For an example, see 3RD Planet.
It is the largest online consumer event platform, showcasing the top tourist destinations in each country with Unity 3D.
The Coherentrx Suite
Another example is The Coherentrx Suite.
CoherentRx is a suite of point-of-care patient education applications that combine realtime 3D anatomy models with HIPAA-compliant doctor-patient messaging. CoherentRx apps currently address ten medical specialties, from orthopedics to opthalmology.
In the Unity Showcase there’s a separate category for non-game applications. Check it out yourself!

Unity is free

It’s a myth, but not entirely. You can download Unity for free. The free (personal) version of Unity has all the features that Unity Professional has (with some small exceptions). When your game is ready, you can publish it and make money out of it! It’s just like that! But if at one point your company exceeds a turnover of $100,000, then you are obligated to purchase the Unity Professional license. It’s not too expensive at that point, because the cost is $1500 US dollars. Sounds really cheap when compared to $100,000, doesn’t it?
The difference between free license and pro license is that in the former one mobile games and web games display a Unity logo for few seconds on startup. It’s not a big deal, but as a professional game developer you may want to get rid of it sometime in the future. Also, you aren’t allowed to use Unity editor pro skin and Cache Server.

You can only do small games with Unity

It’s a myth. The reason why there are so many small games created in Unity is that it is very indie-friendly. Unity does not constrain your game size in any way. You can create a clone of World of Warcraft if you really want to! All scenes can be loaded and merged in the run-time, so player won’t see any loading screens while playing. It’s also not true that Unity performance degrades when you have too much objects on your scene. Of course you have to optimize it in a special way. So it’s all about the experience.
One of the greatest examples of a large-scene and well-optimized Unity game is City Skylines.

Unity is worse than Unreal Engine

It’s a myth, but it really depends on what are your needs (it’s not worse in general). Unity has been always compared to Unreal Engine because the latter always had the upper hand in game development industry. Today the situation is a little different. While Unreal Engine was targeting PC and stationary consoles, Unity took its chances with mobile devices. Unreal was always about big games with stunning visuals, but this approach made it more difficult to learn and use. Unity on the other hand is based on the Mono platform. Thanks to that you can program your games using C# instead of C++ which is quite difficult to learn.
maxresdefault
Unity GDC demo – Adam – Part 1
Today Unity is trying to take over the Unreal Engine market. The first steps were made by Unity 5 graphics enhancements and by the optimization of scripting backend. On GDC 2016 Unity Technologies has published a stunning real-time demo of what Unity 5.3.4 is capable of. From today it will be more and more difficult to tell the difference between Unity and Unreal Engine graphics capabilities.

You don’t need programming knowledge to use Unity

It’s a fact. It’s easier when you have at least some programming knowledge, but you can easily build a complete game without it. One of the most popular editor extensions on the Asset Store is Playmaker. Playmaker allows you to build finite-state machines that will drive your entire game logic, and it does it well! If you need a good reference, then Dreamfall Chapters is a damn good one!
playmaker screen
Because of this fact many people may consider Unity as a toy rather than a serious tool for creating games. The truth is that Unity can be used by everyone, regardless of your skills!

You cannot spawn threads in Unity

Again, it’s a myth. Many people are confusing Unity coroutines with threads. Let’s get this straight: Coroutines have nothing to do with threads. Coroutine is only a way to delay code execution without too much effort. It’s really a great method of writing game code when some routines are needed to be executed in sequence over a time (like animations), but everything is still done in a single thread.
Yet you can create threads in Unity. You will not find too much about it in the official documentation, because there’s not much to be said. All you need to know is that Unity API is not thread safe, but it is a good thing! To learn more about how to use threads in Unity please read our article about threads.

All Unity games looks the same

It’s a myth, of course. Every developer who decides to use one game engine or another is asking himself a question how this game engine will help him and how it will constrain his ideas.  Unity is quite interesting because it’s easy to learn and hard to master. Yet if you will master it you will realize that you can do almost anything with it! You can even create your own game engine within! If you’re still wondering if Unity constrains your creativity, stop right now. It doesn’t!
You need to know that many of Unity components (like physics) can be replaced by anything you want. There’s no requirement of Unity game using components provided by Unity. This is a great deal if you have very specific needs.

Unity has a lot of bugs

It’s a fact. Since Unity 5 the developers were rushing forward with new features, but with a cost of stability. On GCD 2016 current Unity CEO John Riccitiello announced that Unity will take a road of increasing Unity releases’ quality. At the time Unity 5.3.4 has been released and Unity 5.4 entered a beta stage. Let’s hope for the best, because we all need a tool that is as stable as possible, and lately there was a serious fear of upgrading to a new release that could be heard in Unity community.

REFERENCE: http://blog.theknightsofunity.com/myths-and-facts-of-unity-game-engine/

Visual Studio Keyboard Shortcuts

Playing with keyboard shortcuts is very interesting and reduce the headache of using the mouse again and again while programming with visu...