Programming and Debugging

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Chapter 2 Types & Exceptions Yingcai Xiao. Part I Moving from C++/Java to C#
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Finding and Debugging Errors
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
ASP.NET Programming with C# and SQL Server First Edition
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Programming Languages and Paradigms Object-Oriented Programming.
Java and C++, The Difference An introduction Unit - 00.
Lecture 5 What is object-oriented programming OOP techniques How Windows Forms applications rely on OOP.
Neal Stublen Class Objectives  Develop an understanding of the.NET Framework  Gain proficiency using Visual Studio  Begin learning.
Yingcai Xiao EDP Scripting Yingcai Xiao. Why do we need EDP? What is EDP? How to implement EDP? How can we take advantages of EDP in game design and implement?
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
Managed C++. Objectives Overview to Visual C++.NET Concepts and architecture Developing with Managed Extensions for C++ Use cases Managed C++, Visual.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
C# Yingcai Xiao. Part I Moving from Java to C# .NET Framework ’ s Data Types: CTS Six categories of data types in CTS: system-defined: Primitives (int,
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Fundamentals of C++ Yingcai Xiao 09/03/08. Outline Class Definition IO Template vector C Pointer Dynamic Memory Allocation.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
1 9/6/05CS360 Windows Programming CS360 Windows Programming.
Managing C++ CHRIS DAHLBERG MID-TIER DEVELOPER SCOTTRADE.
PerlNET: The Camel Talks.NET Jan Dubois The Perl Conference 6 San Diego, July 26 th 2002.
Introduction to Object-Oriented Programming Lesson 2.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
C# - Inheritance Ashima Wadhwa. Inheritance One of the most important concepts in object- oriented programming is inheritance. Inheritance allows us to.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Yingcai Xiao Programming and Debugging in Unity Yingcai Xiao.
Barbara Doyle Jacksonville University What’s New with Visual Studio and C#?
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
C# Diline Giriş.
Pointer to an Object Can define a pointer to an object:
Procedural and Object-Oriented Programming
C# for C++ Programmers 1.
Creating Your Own Classes
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Classes C++ representation of an object
Java Yingcai Xiao.
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Programming and Debugging
Static data members Constructors and Destructors
CIS 200 Test 01 Review.
Java Programming Language
Testing and Debugging.
Computer Programming I
Review: Two Programming Paradigms
classes and objects review
C# - Inheritance and Polymorphism
Introduction to Classes
Structs.
CS360 Windows Programming
C# A Quick Guide for HCI Yingcai Xiao.
C# for Unity3D Yingcai Xiao.
Introduction to Classes
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
What about multi-dimensional arrays?
IDE’s and Debugging.
Classes C++ representation of an object
BlueJ: a very quick introduction
Classes: Arrays group many objects of the same type (in order)
By: Matt Boggus Some material based on Roger Crawfis’ C# slides
IS 135 Business Programming
Presentation transcript:

Programming and Debugging in Unity Yingcai Xiao Yingcai Xiao

Programming in Unity with C#

Scripting in Unity Unity supports: C# for heavy duty programing JavaScripts for simple interactions Boo: “compiled Python”, CLI, .NET, Mono compatible

C# Allow users to define events. The de facto programming language for .NET OS platform independent Needs CLR (Common Language Runtime): .NET, Mono. Unity uses Mono. Supports: Class, Struct, Interface, Enum, Delegates Allow users to define events.

C# Classes Class: a group of code and data to be instantiated to form objects. Four categories of class members: Fields: member variables Methods: member functions Properties: fields exposed using accessor (get and set) methods Events: notifications a class is capable of firing

Example: How to define a class in C# class Rectangle { // Fields protected int width = 1; protected int height = 1; // Methods public Rectangle () { } public Rectangle (int cx, int cy) width = cx; height = cy; }

Example: How to define a class (user-defined data type) // Accessor Methods public void setWidth(int w) { width = w; } public int getWidth() { return width; } public void setHeight(int h) { height = h; } public int getHeight() { return height; } } // End of Rectangle class // No “;” at the end of class definition.

Example: How to use a class in C# Rectangle rect = new Rectangle(2,4); rect.setHeight(8); rect.setWidth(rect.getWidth() * 2); double darea = (double) (rect.getWidth() * rect.getHeight() ); Note: (1) “Rectangle rect” creats a reference, not object. (2) Treat “Rectangle rect = new Rectangle();” in C# as “Rectangle rect;” in C++. (3) Use “rect.” to dereference in C# instead of “rect->” as in C++.

Garbage Collection CLR controls garbage collection. No need to free memory dynamically allocated with “new” on the heap in C#, hence, no destructors in C#. CLR uses a reference counter to keep track the number of references pointing the memory. CLR will free the memory when the reference counter becomes 0. The Finalize() method (inherited from Object class) is called during garbage collection. CLR decides when to perform garbage collection. Force a garbage collection by calling GC.Collect (). (expensive) Implement a Dispose method and call it when needed to cleanup when an object is not needed any more.

Example of Exception Handling CLR’s Exception Handling Mechanism: try, catch, finally, and throw File file = null; // Do not define it in the try block. Why? try { file = new File ("Readme.txt"); if(file != null) { /* Do the work here. */} … } catch (FileNotFoundException e) { Console.WriteLine (e.Message); } catch ( … ) { … } finally { // Always come here even if there were exceptions. if (file != null) file.Close ();

C# vs. C++ C# C++ class myClass { } class myClass { } ; Rectangle rect = new Rectangle(); Rectangle rect; “rect.” to dereference “rect->” to dereference No destructors ~className(); Garbage Collection free using #include Single inheritance Multiple inheritance

Differences between C++ & C# Ending a block with a semicolon Class myClass{ … }; } Object instance creation myClass myObject; //myObject is an instance myClass *myPointer = new myClass(); //myPointer is a pointer to an instance myClass myReference //myReference is a reference (an internal pointer) to an instance Dereferencing myPointer-> myReference. Class members Fields: member variables Methods: member functions Properties: fields exposed using accessor (get and set) methods Events: notifications a class is capable of firing Freeing heap memory free(myPointer); Automatically by garbage collection when myReference is out of extent.

C# Books and Tutorials http://www.tutorialspoint.com/csharp/ http://www.cs.uakron.edu/~xiao/windows/syllabus.html

Debugging in Unity3D (Contributed by Sai Goud Durgappagari)

Two ways of debugging: Print to a console window. void SetCountText() { count ++; countText.text = “Count:” + count.ToString(); // to score board print(“countText.text = ” + countText.text); // to console } (2) Use the debugger in the IDE. Unity3D uses debugger from Visual Studio.

Debugging in Unity 1. Debugging needs Visual Studio installed on your System. Visual Studio is available free @ DreamSpark http://www.cs.uakron.edu/~xiao/msdnaa.html 2. After opening Unity 5 project and your script in Visual Studio, insert Breakpoints at respective lines of code to Debug 3. To insert Breakpoints, move your mouse to grey strip towards left side of editor and right click. Create as many Breakpoints needed and save the script.

Debugging in Unity 4. Debug->Debugging. If there is only one unity IDE is running, it will attach the process of the running unity IDE. Otherwise, it will ask you to select a process to attach if there are more than one unity programs are running. 5. Then go to Unity IDE and play the game. 6. The game pauses when it comes across one of your Breakpoints and Visual Studio gets highlighted.

Debugging in Unity 7. Go to Visual Studio and hover on variables to read their values. 8. Click on Continue to continue Debugging the game.