Yingcai Xiao Programming and Debugging in Unity Yingcai Xiao.

Slides:



Advertisements
Similar presentations
Chapter 2 Types & Exceptions Yingcai Xiao. Part I Moving from C++/Java to C#
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
Using XCode © 2013 Surajit A Bose De Anza College.
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#
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
CS 225 Lab #2 - Pointers, Copy Constructors, Destructors, and DDD.
Lecture 9 Concepts of Programming Languages
ASP.NET Programming with C# and SQL Server First Edition
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
C# vs. C++ What's Different & What's New. An example C# public sometype myfn { get; set; } C++ public: sometype myfn { sometype get (); void set (sometype.
OOP Languages: Java vs C++
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.
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.
Neal Stublen Class Objectives  Develop an understanding of the.NET Framework  Gain proficiency using Visual Studio  Begin learning.
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
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.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
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.
SE 320 – Introduction to Game Development Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: Gazihan Alankuş Please look at the last two slides.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
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,
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
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.
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++
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
1 9/6/05CS360 Windows Programming CS360 Windows Programming.
Digging into the GAT API Comparing C, C++ and Python API‘s Hartmut Kaiser
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 Software Development 4. C# data types, objects and references.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
CHAPTER 10 ERROR HANDLING & DEBUGGING JavaScript can be hard to learn. Everyone makes mistakes when writing it.
C# - Inheritance Ashima Wadhwa. Inheritance One of the most important concepts in object- oriented programming is inheritance. Inheritance allows us to.
1 Introduction to Object Oriented Programming Chapter 10.
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 –
Barbara Doyle Jacksonville University What’s New with Visual Studio and C#?
Value Types. 2 Objectives Discuss concept of value types –efficiency –memory management –value semantics –boxing –unboxing –simple types Introduce struct.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
Tutorial 1 Writing Your First C++ Program CSC1110C Introduction to Computer Programming By Paul Pun Acknowledgement: Special thanks to Dr. Michael Fung.
Pointer to an Object Can define a pointer to an object:
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Classes C++ representation of an object
Java Yingcai Xiao.
Programming and Debugging
Understand the Fundamentals of Classes
Testing and Debugging.
Computer Programming I
Review: Two Programming Paradigms
classes and objects review
C# - Inheritance and Polymorphism
Chapter 5 Classes.
CS360 Windows Programming
C# for Unity3D Yingcai Xiao.
Programming and Debugging
What about multi-dimensional arrays?
Classes C++ representation of an object
By: Matt Boggus Some material based on Roger Crawfis’ C# slides
Presentation transcript:

Yingcai Xiao Programming and Debugging in Unity 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# 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

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

// 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 define a class (user-defined data type)

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++. Example: How to use a class 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 Collectionfree using#include Single inheritanceMultiple inheritance

Differences between C++ & C# DifferenceC++C# Ending a block with a semicolon Class myClass{ … }; Class myClass{ … } Object instance creation myClass myObject; //myObject is an instance myClass *myPointer = new myClass(); //myPointer is a pointer to an instance myClass myReference = new myClass(); //myReference is a reference (an internal pointer) to an instance DereferencingmyPointer-> myReference. Class members Fields: member variables Methods: member functions 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 

Debugging in Unity3D (Contributed by Sai Goud Durgappagari)

Two ways of debugging: (1)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 DreamSpark 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. Click on "Attach to Unity" available at the top of editor(highlighted Yellow in below picture). Wait for some time to see Stop Button at the same place at the top of the editor. 5. Then go to Unity 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.