Tag Archives: C#

Unity 3D – C# script – save and load file.

This is a simple C# script example for a C# class Player.
The class Player come with this content into Player.cs C# script:

To make this C# script for saving the Player into one file I used this C# script named SaveLoadManager.cs:

The script come with two parts for save and load files.
I used Serializable property to save binary file named player.sav.
This script used also the Application.persistentDataPath to take the path of application.
I used a Debug log output but if you want to used into real application then is no need to use.
You can deal with any player settings and make new like: player.magic or player.status.
Take a look at the comments in the script and that script highlights design issues.

Posted in 3D, All, C#, Game engine, Programming, Unity 3D. Tagged with , , , , , , .

Programming with C# and Unity 3D game engine – part 003 .

In this tutorials I will show how to deal with lists and enumerations.
First you need to make one C# script under Unity 3D. If don’t know how to do it then read this tutorial.
The list is an object which holds variables in a specific order.
The enumeration is an object with one distinct type that consists of a set of named constants called the enumerator list.
Let’s start with lists.
You need to put this on your script:

Now you can create list under your class , see the example with one class named YourClass:

We can see the List’s syntax is at first confusing. If you take a look to types – int, sting and GameObject and variables – ages, names and objects then the base remain this: List<...> … = new List<...>(); where types are into <> and variables can be created with = new … ().
Now will add one value to names with:

To reverse one list in-place then use this:

If you want then can remove one:

We can use an array to initialize a List named animals:

Loop into the list animals and print the list:

To get the number of elements from animals list, use this:

To clean the list just use this:

The next step is enumerations and is define by the enum type.
An enum type internally contains an enumerator list like this example:

In this enum named animals, cat will be zero (unless given another value explicitly), dog will be one, and fox will be two …
To print out the enum values, you can call ToString on the enum variable in a program.
The Console.WriteLine can automatically call the ToString method.
Using GetValues method with foreach to returns an array that contains a value for each member of the enumType enumeration.

Sometimes we have a string value that we want to convert to an equivalent enum and we can use Parse().
Also you can used many enum like: Enum.Parse, Enum.TryParse, Enum.Format, Enum.IsDefined…
You can get values from enum , see the example:

Convert enums to list:

Posted in C#, Game engine, Unity 3D, Visual Studio, Windows 10. Tagged with , , , , , , .

VS 2015 – tips and tricks – part 001.

This tutorial show you some of the basic tips and features of the Visual Studio 2015.
First I will provides a succinct overview of the Web programming over Visual Studio 2015.
Just open your Visual Studio and create one Web Site with : File – New – Web Site .
Then if you want to use C# then use this :
You can add some new scripts and features by using packages. This will come from NuGet Package Manager.
In the next image I used : Tool
to install the jQuery.
You can do many things to improve your performance with Visual Studio 2015.
For example use this
and will have one good vertical scroll bar.
This will map your source code page.
Also you can split your source code by drag from icon of the bottom of this scroll bar map .
If you want you can add line numbers into your left of your source code page.
Use this:
Before to you run your application can put one breakpoint to stop it for debug.
Also you can see your variables using watch options.
Some short keys can help you to deal with your source code.
For example:
– use Ctr+K and then Ctr+X keys to use snippet into your source code;
– use Ctr+K and then Ctr+C keys to entire selections of your source code;
– use Alt+arrows keys to move your selection of code;
– use Ctr+Q for a quick search and then will find what you need ( ex: search Solution Explorer and will see also the short key : Ctr+Alt+L )

Posted in All, C#, Programming, Visual Studio, Windows 10. Tagged with , , , , , , .

LINQ and LinkPad – part 001.

LINQ stands for Language Integrated Query and enadbles us to query any type of data store, like SQL Server , XML documents, Objects in memory etc.
You don’t need to know the syntax specific to data source because LINQ enables us to work with different data source.
The great goal is that it provides intellisense and compile time error checking.
If we development one application and this working with databases , xml documents and / or in memory objects then we can use LINQ.
LINQ query can be using any .NET supported programmiing language, because LINQ component between the LINQ query and the data source.
LinqPad tool can be downloaded for free from here.Now I help you to learn , write and test LINQ.
Today I will try to use C# with LinqPad.
LinqPad help you to under C# to make it converted to Intermediate Language (IL) which is also known as Microsoft Intermediate Language or Common Intermediate Language.
If you try to use LinqPad without source code then the oonly error under C# will come into C#Statement : ; expected
Press F4 button then press Add button (Query Properties ) and type WindowsBase.dll (Add Custom Assembly References – window) then press Ok button.
Let’s test all. Wrote this example and under Results tab click under IL.

Example 1
C# Expression

Result IL

Example 2
C# Statement

Result IL:

this can a little dizzy for you but will come with future details.

Example 3
C# Program

Results IL :

This examples will show us the results over IL.
Using LinqPad with assemblies .NET .
Under C# the most simple DLL example can be:

If we wrote into LinqPad under C# Statement and then run it.

Console.WriteLine(“tutorial LinqPad -001”);
… the result will be :

The next step is to create one new file into our C# project named Test.dll with this source code:

If you parse this code you will see under call I need to add this :

This is just one simple example about LinqPad.This software it’s very good when working with SQL , ASP , data , arrays.
To make the DLL file you need this : ilasm.exe
Run the command under cmd.exe:

The result will be: Test.dll .
Let test it:
Make another file with notepad , named DllTest.cs and put this source code:

Use cmd.exe to complile this into exe file format :

If you run this using cmd.exe the the output will be:

Posted in All, C#, Programming, Windows 7, Windows 8. Tagged with , , , , , , .

Using Speech with C# and Visual Studio 2013.

This example will show you how to use Speech with C# an Visual Studio 2013 to recognition your words , speak your words from your list and also to command the exit appplication.
Create one empty project from File – New Project.
You have now one Form and you will add 3 buttons and one TextBox.
After that will need to select MultiLine by using right click on the arrow of TextBox.
The next image show you this 3 buttons and TextBox.
Speek C#
You need to activate Speech from Visual Sudio 2013 IDE:
Go to right panel and Add Reference ( use right click and select it – see next image).
Speek C#
Then select Speech and click Apply – see next image:
Speek C#
All buttons will have source code, just double click on buttons and will have the functions for all buttons.
Also If you want to renamed the buttons just search Properties and then Text and rename buttons or Form title.
I used Speak, Start and Stop for buttons.
I used also one if-else with exit word from list, to stop application.
The list will have all words to recognition your words from list.
You need also to have hardware microphone or portable microphone and also you must activate it unde windows.
Now, the source code of your form is this:

Using F7 Buil Solution and then Start Debugging – F5 you will run the application.

Posted in All, C#, Programming. Tagged with , , , , .