SlideShare a Scribd company logo
1 of 36
Download to read offline
 Ivanov Michael
 Lead Programmer R&D,Neurotech Solutions LTD
 Writer for Packt Publishing.,”Away3D Cookbook”
 Expert in Flex/AIR, Open Source Flash 3d engines.
 Spare time:Unity,UnrealEngine,OpenGL,Java3D
 Visit my tech blog:http://blog.alladvanced.net
 How many of you have never heard of Unity?
 How many of you are designers ?
 How many of you come from Flash/ActionScript background?
 How many of you programmed in Unity? What language?
 How many of you accomplished commercial projects with
Unity ?
 Unity engine API model
 Unity programming paradigm
 Scripting Languages
 Scripting practices
 Unity GameObject structure
 Examples walkthrough
 How to program(You should learn by yourselves)
 Level design(designers –sorry)
 Advanced programming
 Shaders
 Much more cool and important stuff because of time limitation.

P.S
For the rest of disclaimer please refer to:GNU General Public License
Stay tuned for Unity3D workshop announcement
Unity3D Programming
Audio Engine
Particle System Engine
Terrain Engine
Physics Engine
GUI System
Animation Engine
Network API
Shaders programmingAPI
Unity Engine Core
C#
JavaScript
Boo(Python)
ShaderLab,Cg,GLSL
Sealed
WindZone
LightCamera
Rigid Body Collider
Mesh Filter
Particle
Emitter
Audio
Source
Custom GameObject
Camera
FPSControl
ler
AudioListe
ner
GameObject
Shader Prefab Material
Script File AnimationAssets
Customized
Game Object
Components
(Resource Library)
UnityScript(JavaScript) MONO(C#)
Pros •20X faster than web JS
•Flexible coding(no need in data types
declaration, no class body explicit typing
required)
•Beginners friendly
•Well documented in Unity docs
•C family(fast adaptation for experienced devs)
•Strong typing
•Robust .NET Framework(Event Model,threads,structs and
more C# specific)
•External IDE software availability
•Piles of docs in theWeb
•Portability to other platforms
•DLL libs support
Cons •No explicit variable types declaration required
•iPhone builds are bigger than C#(additional libs
added)
•language specific restrictions: No multi-
dimensional arrays definition, no pass values by
reference into functions(needs workaround),no
Char data type , no multiple interface
implementation only one class or interface are
allowed to be extended
•Poor Even Model(custom approach is slow)
•Partial implementation of .NET(no virtual classes allowed,
no namespaces, limited multi-threading,Timer..
•Less documented in Unity docs
class MyClass extends MonoBehaviour {
var myVar = 1;
function Start() {
Debug.Log("hello world!");
}
}
class MyClass : MonoBehaviour {
public int myVar = 1;
void Start() {
Debug.Log("hello world!");
}
}
Java Script C#
Surprisingly you can write with both of them in one
project!(one way communication only)
Script
Script
Script
Script
Standard Assets
((Compiled first
My Scripts Folder(Outside)
(Compiled last)
C#JavaScript
Script
Script
Script
Script
Player
GameObject
Enemy
GameObject
WeaponPickUps
GameObject
GUI Module
GameObject
Script Script
Script
Script
Script
Script
Script
Script
(Main())GameObject
(Entry point)Script
ScoreManagerSoundManager LevelManager BackEndManager
Script ScriptScriptScript
using UnityEngine;
using System.Collections;
public class MyNewBehaviour : MonoBehaviour {
public static AudioClip playingClip;//////---accessible from outside to all
void Start () {
}
void Update () {///////// see also FixedUpdate
}
void OnMouseDown(){
}
void OnCollisionEnter(){
}
public void SpawnEnemy(){////////-------------------your custom method
}
}
“TF2 Dancing Spy” demo
FPSController
SceneManager
CharacterManager
AudioManager
GUIManager
Generic Scripts
VideoManager
LightProjector
AnimatedCamera ScriptsInit
DirectionalLight
TileManager
SpectrumReader
ProjectorTransformer
WallGenerator
Tile(dynamic add)
WallSyntezator
iTween
Utils
Spy
Monitor1
Monitor2
Monitor3
FPSControllerSceneManager
CharacterManager
AudioManager GUIManager
Generic Scripts
VideoManager
LightProjector
AnimatedCamera
DirectionalLight
TileManager
SpectrumReader
ProjectorTransformer
WallGenerator
Tile(dynamic add)
WallSyntezator
iTween
Spy
Animation
Button
Resources
MP3MP3
Generic Scripts
iTween
Monitor1
Monitor2
video
Hovermobile Demo
Fire Ball Demo
Unity3D Programming
 Time.time
 Time.deltaTime
 C# System.Timers.Timer
Update() and FixedUpdate()
FixedUpdate synchronized with Physics Engine steps while Update() runs on each
frame
Always use FixedUpdate() for physics!
F F F F F
0.1 seconds0.0 seconds
U U U U U U U U U U
 Time.time
 Time.deltaTime
 C# System.Timers.Timer
Update() and FixedUpdate()
FixedUpdate synchronized with Physics Engine steps while Update() runs on each
frame
Always use FixedUpdate() for physics!
F F F F F
0.1 seconds0.0 seconds
U U U U U U U U U U
TileManager tlm = tile.GetComponent<TileManager> ();
void locateAndAssignCams(){
camFPS=GameObject.Find("MainCamera");
camAnim=GameObject.Find("AnimatedCam");
}
Public variables reference.(Set via component interface)
•GetComponent:
•Find() ,FindObjectOfType(),FindObjectsOfType()
Light light = FindObjectOfType(typeof(Light));
if(AudioManager.spectrumData!=null&&AudioManager.spectrumData.Length>0){
currentSpectrum=AudioManager.spectrumData;
}
Direct access via static members
AudioClip aclip=(AudioClip)Resources.Load("Sounds/gagaSong");
_audioSource.clip=aclip;
playingClip=aclip;
_audioSource.Play();
Create object in runtime:
Instantiate Prefab
GameObject tile = (GameObject)Instantiate (tilePF,Vector3.zero, Quaternion.identity);
void Start () {
_light=new GameObject("Light1");
_light.AddComponent<Light>();
_light.light.type=LightType.Point;
_light.light.range=400;
_light.light.color=Color.red;
_light.transform.Translate(newVector3(1000,200,1000));
}
Dynamic resource assets loading
What are these matrices and vectors anyways?
Core Classes:
 Mathf .(Also C# System.Math )
 Matrix4x4
 Vector2/3/4
 Quaternion –all Rotations are Quaternion based
“In Physics Land talk Physics”
Core Classes:
•Physics- Global physics properties and helper methods.
•RigidBody-contains all essential physics methods and properties for a body
AddTorque()
RigidBody
SpaceCraft
GameObject
gravity
AddForce()
Colliders
AddForceAtPosition()
 Self attachment
_audioSource=gameObject.AddComponent<AudioSource>();
 Indirect attachment
GameObject tile = (GameObject)Instantiate (tilePF,Vector3.zero, Quaternion.identity);
AudioSource audioSource=tile.AddComponent<AudioSource>();
//adding audio source component to the tile and accessing it at the same time//
 Yield
Ensures that the function will continue from the line after the yield statement next
time it is called
Can’t be used inside “Time” methods like Update(),FixedUpdate()
 Coroutine
Suspends its execution until givenYield instruction finishes.
Requires a method to be IEnumerator
IEnumerator Start ()
{
print ("first");
yield return new WaitForSeconds(2f);
print ("2 seconds later");
}
Yield
using UnityEngine;
using System.Collections;
public class StupidLoop : MonoBehaviour{
private bool buttonPressed= false;
void Update ()
{
if(!buttonPressed)
{
if(Input.GetButtonDown("Jump"))
{
StartGame();
}
}
print("looping...");
}
void StartGame()
{
buttonPressed= true;
print("Game Started");
}
}
NoYield & Coroutines scenario(Ugly one)
void Start(){
StartCoroutine(WaitForKeyPress("Jump"));
}
public IEnumerator WaitForKeyPress(string _button)
{
while(!buttonPresed)
{
if(Input.GetButtonDown (_button))
{
StartGame();
yield break;
}
print("Awaiting key input.");
yield return 0;
}
}
private void StartGame()
{
buttonPressed= true;
print("Starting the game officially!");
}
}
Simple example
void Start () {
glEffect=GameObject.Find("Main Camera").GetComponent<GlowEffect>();
StartCoroutine("explodeCounter");
}
IEnumerator explodeCounter(){
onTimerElaps();
if(amount<15){
yield return new WaitForSeconds(0.01F);
}else{
Mesh myMesh = GetComponent<MeshFilter>().mesh;
GameObject.Destroy(myMesh);
yield break;
}
StartCoroutine("explodeCounter");
}
void onTimerElaps(){
amount+=Mathf.Sin(Time.time)/5;
glEffect.glowIntensity=amount/2;
ExplodeMesh(amount);
}
Practical example
IEnumerator Start () {
yield return StartCoroutine(MyWaitFunction (4.0f));
print ("4 seconds passed");
yield return StartCoroutine(MyWaitFunction (5.0f));
print ("9 seconds passed");
}
IEnumerator MyWaitFunction (float delay) {
float timer =Time.time + delay;
while (Time.time < timer) {
Debug.Log(Time.time);
yield return true;
}
}
Sequential Coroutines calls
Unity built-in event system
 SendMessage()-Calls the method on every MonoBehaviour in this game object.
 BroadcastMessage()- Calls the method on every MonoBehaviour in this game
object or any of its children.
Downside:
Need to target methods by their name (Errors prone)
Work only within the object's transform hierarchy
 Controller Class registers all the classes to be notified of changes via reference
Downside :
Flexibility & Scalability
Nightmare for big projects
 Dispatcher class
public class EventSender : MonoBehaviour {
public delegate void GameObjectPressHandler(GameObject e);
public event GameObjectPressHandler OnGameObjectPress;
private void DispatchPressEvent () {
if (OnGameObjectPress != null){
OnGameObjectPress (this.gameObject);//event has been fired!
}
}
}
public GameObject gm;
EventSender myEventSender=gm.getComponent<EventSender>();
myEventSender.OnGameObjectPress+=new GameObjectPressHandler(onGMPress);
Private void onGMPress(GameObjject gm){
print(gm+”was has been!”);
}
Listener Class
Thank you and good luck!

More Related Content

What's hot

Unreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) PresentationUnreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) PresentationNitin Sharma
 
The Basics of Unity - The Game Engine
The Basics of Unity - The Game EngineThe Basics of Unity - The Game Engine
The Basics of Unity - The Game EngineOrisysIndia
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game DevelopmentSumit Jain
 
06. Game Architecture
06. Game Architecture06. Game Architecture
06. Game ArchitectureAmin Babadi
 
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...Gerke Max Preussner
 
Unity 2D game development
Unity 2D game developmentUnity 2D game development
Unity 2D game developmentThe NineHertz
 
Game Development with Unity
Game Development with UnityGame Development with Unity
Game Development with Unitydavidluzgouveia
 
What Is A Game Engine
What Is A Game EngineWhat Is A Game Engine
What Is A Game EngineSeth Sivak
 
The Art of Game Development
The Art of Game DevelopmentThe Art of Game Development
The Art of Game DevelopmentAmir H. Fassihi
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game DevelopmentiTawy Community
 
Intro to VR with Unreal Engine
Intro to VR with Unreal Engine   Intro to VR with Unreal Engine
Intro to VR with Unreal Engine Unreal Engine
 
Game engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignGame engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignPrashant Warrier
 
Game development life cycle
Game development life cycleGame development life cycle
Game development life cycleSarah Alazab
 
Process of Game Design
Process of Game DesignProcess of Game Design
Process of Game DesignVincent Clyde
 
Introduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First GameIntroduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First GameSarah Sexton
 

What's hot (20)

Unreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) PresentationUnreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) Presentation
 
The Basics of Unity - The Game Engine
The Basics of Unity - The Game EngineThe Basics of Unity - The Game Engine
The Basics of Unity - The Game Engine
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Unity 3d Basics
Unity 3d BasicsUnity 3d Basics
Unity 3d Basics
 
06. Game Architecture
06. Game Architecture06. Game Architecture
06. Game Architecture
 
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
 
Unity 2D game development
Unity 2D game developmentUnity 2D game development
Unity 2D game development
 
Game Development with Unity
Game Development with UnityGame Development with Unity
Game Development with Unity
 
What Is A Game Engine
What Is A Game EngineWhat Is A Game Engine
What Is A Game Engine
 
The Art of Game Development
The Art of Game DevelopmentThe Art of Game Development
The Art of Game Development
 
Unity 3D, A game engine
Unity 3D, A game engineUnity 3D, A game engine
Unity 3D, A game engine
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Intro to VR with Unreal Engine
Intro to VR with Unreal Engine   Intro to VR with Unreal Engine
Intro to VR with Unreal Engine
 
UNITY 3D.pptx
UNITY 3D.pptxUNITY 3D.pptx
UNITY 3D.pptx
 
Game engines and Their Influence in Game Design
Game engines and Their Influence in Game DesignGame engines and Their Influence in Game Design
Game engines and Their Influence in Game Design
 
Game development life cycle
Game development life cycleGame development life cycle
Game development life cycle
 
First-person Shooters
First-person ShootersFirst-person Shooters
First-person Shooters
 
Process of Game Design
Process of Game DesignProcess of Game Design
Process of Game Design
 
Introduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First GameIntroduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First Game
 
Practical usage of Lightmass in Architectural Visualization (Kenichi Makaya...
Practical usage of Lightmass in  Architectural Visualization  (Kenichi Makaya...Practical usage of Lightmass in  Architectural Visualization  (Kenichi Makaya...
Practical usage of Lightmass in Architectural Visualization (Kenichi Makaya...
 

Viewers also liked

Unity introduction for programmers
Unity introduction for programmersUnity introduction for programmers
Unity introduction for programmersNoam Gat
 
Unity Programming
Unity Programming Unity Programming
Unity Programming Sperasoft
 
An Introduction To Game development
An Introduction To Game developmentAn Introduction To Game development
An Introduction To Game developmentAhmed
 
Mobile AR Lecture6 - Introduction to Unity 3D
Mobile AR Lecture6 - Introduction to Unity 3DMobile AR Lecture6 - Introduction to Unity 3D
Mobile AR Lecture6 - Introduction to Unity 3DMark Billinghurst
 
PRESENTATION ON Game Engine
PRESENTATION ON Game EnginePRESENTATION ON Game Engine
PRESENTATION ON Game EngineDiksha Bhargava
 
From Unity3D to Unreal Engine 4
From Unity3D to Unreal Engine 4From Unity3D to Unreal Engine 4
From Unity3D to Unreal Engine 4Martin Pernica
 
Unity Презентация
Unity ПрезентацияUnity Презентация
Unity ПрезентацияDmitriy Bolshakov
 
Academy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. ScriptingAcademy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. ScriptingBinary Studio
 
Introductory Virtual Reality in Unity3d
Introductory Virtual Reality in Unity3dIntroductory Virtual Reality in Unity3d
Introductory Virtual Reality in Unity3dBond University
 
Pathfinding - Part 2: Examples in Unity
Pathfinding - Part 2: Examples in UnityPathfinding - Part 2: Examples in Unity
Pathfinding - Part 2: Examples in UnityStavros Vassos
 
Cross-Platform Developement with Unity 3D
Cross-Platform Developement with Unity 3DCross-Platform Developement with Unity 3D
Cross-Platform Developement with Unity 3DMartin Ortner
 
20161125 Unity-Android連携の発表資料
20161125 Unity-Android連携の発表資料20161125 Unity-Android連携の発表資料
20161125 Unity-Android連携の発表資料WheetTweet
 
브릿지 Unity3D 기초 스터디 1회
브릿지 Unity3D 기초 스터디 1회브릿지 Unity3D 기초 스터디 1회
브릿지 Unity3D 기초 스터디 1회BridgeGames
 
How to Start Monetizing Your Game with Unity IAP | Angelo Ferro
How to Start Monetizing Your Game with Unity IAP | Angelo FerroHow to Start Monetizing Your Game with Unity IAP | Angelo Ferro
How to Start Monetizing Your Game with Unity IAP | Angelo FerroJessica Tams
 

Viewers also liked (20)

Unity presentation
Unity presentationUnity presentation
Unity presentation
 
Unity introduction for programmers
Unity introduction for programmersUnity introduction for programmers
Unity introduction for programmers
 
Unity Programming
Unity Programming Unity Programming
Unity Programming
 
Unity is strength presentation slides
Unity is strength presentation slidesUnity is strength presentation slides
Unity is strength presentation slides
 
Unity 5 Overview
Unity 5 OverviewUnity 5 Overview
Unity 5 Overview
 
An Introduction To Game development
An Introduction To Game developmentAn Introduction To Game development
An Introduction To Game development
 
Unity 3d scripting tutorial
Unity 3d scripting tutorialUnity 3d scripting tutorial
Unity 3d scripting tutorial
 
Mobile AR Lecture6 - Introduction to Unity 3D
Mobile AR Lecture6 - Introduction to Unity 3DMobile AR Lecture6 - Introduction to Unity 3D
Mobile AR Lecture6 - Introduction to Unity 3D
 
PRESENTATION ON Game Engine
PRESENTATION ON Game EnginePRESENTATION ON Game Engine
PRESENTATION ON Game Engine
 
From Unity3D to Unreal Engine 4
From Unity3D to Unreal Engine 4From Unity3D to Unreal Engine 4
From Unity3D to Unreal Engine 4
 
Maya To Unity3D
Maya To Unity3DMaya To Unity3D
Maya To Unity3D
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Unity Презентация
Unity ПрезентацияUnity Презентация
Unity Презентация
 
Academy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. ScriptingAcademy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. Scripting
 
Introductory Virtual Reality in Unity3d
Introductory Virtual Reality in Unity3dIntroductory Virtual Reality in Unity3d
Introductory Virtual Reality in Unity3d
 
Pathfinding - Part 2: Examples in Unity
Pathfinding - Part 2: Examples in UnityPathfinding - Part 2: Examples in Unity
Pathfinding - Part 2: Examples in Unity
 
Cross-Platform Developement with Unity 3D
Cross-Platform Developement with Unity 3DCross-Platform Developement with Unity 3D
Cross-Platform Developement with Unity 3D
 
20161125 Unity-Android連携の発表資料
20161125 Unity-Android連携の発表資料20161125 Unity-Android連携の発表資料
20161125 Unity-Android連携の発表資料
 
브릿지 Unity3D 기초 스터디 1회
브릿지 Unity3D 기초 스터디 1회브릿지 Unity3D 기초 스터디 1회
브릿지 Unity3D 기초 스터디 1회
 
How to Start Monetizing Your Game with Unity IAP | Angelo Ferro
How to Start Monetizing Your Game with Unity IAP | Angelo FerroHow to Start Monetizing Your Game with Unity IAP | Angelo Ferro
How to Start Monetizing Your Game with Unity IAP | Angelo Ferro
 

Similar to Unity3D Programming

Game programming with Groovy
Game programming with GroovyGame programming with Groovy
Game programming with GroovyJames Williams
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsNick Pruehs
 
Porting unity games to windows - London Unity User Group
Porting unity games to windows - London Unity User GroupPorting unity games to windows - London Unity User Group
Porting unity games to windows - London Unity User GroupLee Stott
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - IntroductionFrancis Seriña
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 MinigamesSusan Gold
 
Chapt 6 game testing and publishing
Chapt 6   game testing and publishingChapt 6   game testing and publishing
Chapt 6 game testing and publishingMuhd Basheer
 
Project Report Tron Legacy
Project Report Tron LegacyProject Report Tron Legacy
Project Report Tron LegacyManpreet Singh
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software DevelopmentZeeshan MIrza
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsLuca Galli
 
XNA and Windows Phone
XNA and Windows PhoneXNA and Windows Phone
XNA and Windows PhoneGlen Gordon
 
Academy PRO: Unity 3D. Environment
Academy PRO: Unity 3D. EnvironmentAcademy PRO: Unity 3D. Environment
Academy PRO: Unity 3D. EnvironmentBinary Studio
 
Windows phone 7 xna
Windows phone 7 xnaWindows phone 7 xna
Windows phone 7 xnaGlen Gordon
 
Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA GameSohil Gupta
 
Getting started with Verold and Three.js
Getting started with Verold and Three.jsGetting started with Verold and Three.js
Getting started with Verold and Three.jsVerold
 
Sony Erricson X1 Panel Development
Sony Erricson X1 Panel DevelopmentSony Erricson X1 Panel Development
Sony Erricson X1 Panel DevelopmentSeo Jinho
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidVlatko Kosturjak
 

Similar to Unity3D Programming (20)

Game programming with Groovy
Game programming with GroovyGame programming with Groovy
Game programming with Groovy
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Porting unity games to windows - London Unity User Group
Porting unity games to windows - London Unity User GroupPorting unity games to windows - London Unity User Group
Porting unity games to windows - London Unity User Group
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - Introduction
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
 
Chapt 6 game testing and publishing
Chapt 6   game testing and publishingChapt 6   game testing and publishing
Chapt 6 game testing and publishing
 
Project Report Tron Legacy
Project Report Tron LegacyProject Report Tron Legacy
Project Report Tron Legacy
 
Unity3 d devfest-2014
Unity3 d devfest-2014Unity3 d devfest-2014
Unity3 d devfest-2014
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
 
Presentación Unity
Presentación UnityPresentación Unity
Presentación Unity
 
XNA and Windows Phone
XNA and Windows PhoneXNA and Windows Phone
XNA and Windows Phone
 
Academy PRO: Unity 3D. Environment
Academy PRO: Unity 3D. EnvironmentAcademy PRO: Unity 3D. Environment
Academy PRO: Unity 3D. Environment
 
Windows phone 7 xna
Windows phone 7 xnaWindows phone 7 xna
Windows phone 7 xna
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA Game
 
How to make a game app.pptx
How to make a game app.pptxHow to make a game app.pptx
How to make a game app.pptx
 
Getting started with Verold and Three.js
Getting started with Verold and Three.jsGetting started with Verold and Three.js
Getting started with Verold and Three.js
 
Sony Erricson X1 Panel Development
Sony Erricson X1 Panel DevelopmentSony Erricson X1 Panel Development
Sony Erricson X1 Panel Development
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 

Unity3D Programming

  • 1.  Ivanov Michael  Lead Programmer R&D,Neurotech Solutions LTD  Writer for Packt Publishing.,”Away3D Cookbook”  Expert in Flex/AIR, Open Source Flash 3d engines.  Spare time:Unity,UnrealEngine,OpenGL,Java3D  Visit my tech blog:http://blog.alladvanced.net
  • 2.  How many of you have never heard of Unity?  How many of you are designers ?  How many of you come from Flash/ActionScript background?  How many of you programmed in Unity? What language?  How many of you accomplished commercial projects with Unity ?
  • 3.  Unity engine API model  Unity programming paradigm  Scripting Languages  Scripting practices  Unity GameObject structure  Examples walkthrough
  • 4.  How to program(You should learn by yourselves)  Level design(designers –sorry)  Advanced programming  Shaders  Much more cool and important stuff because of time limitation.  P.S For the rest of disclaimer please refer to:GNU General Public License Stay tuned for Unity3D workshop announcement
  • 6. Audio Engine Particle System Engine Terrain Engine Physics Engine GUI System Animation Engine Network API Shaders programmingAPI Unity Engine Core C# JavaScript Boo(Python) ShaderLab,Cg,GLSL Sealed
  • 7. WindZone LightCamera Rigid Body Collider Mesh Filter Particle Emitter Audio Source Custom GameObject Camera FPSControl ler AudioListe ner GameObject Shader Prefab Material Script File AnimationAssets Customized Game Object Components (Resource Library)
  • 8. UnityScript(JavaScript) MONO(C#) Pros •20X faster than web JS •Flexible coding(no need in data types declaration, no class body explicit typing required) •Beginners friendly •Well documented in Unity docs •C family(fast adaptation for experienced devs) •Strong typing •Robust .NET Framework(Event Model,threads,structs and more C# specific) •External IDE software availability •Piles of docs in theWeb •Portability to other platforms •DLL libs support Cons •No explicit variable types declaration required •iPhone builds are bigger than C#(additional libs added) •language specific restrictions: No multi- dimensional arrays definition, no pass values by reference into functions(needs workaround),no Char data type , no multiple interface implementation only one class or interface are allowed to be extended •Poor Even Model(custom approach is slow) •Partial implementation of .NET(no virtual classes allowed, no namespaces, limited multi-threading,Timer.. •Less documented in Unity docs
  • 9. class MyClass extends MonoBehaviour { var myVar = 1; function Start() { Debug.Log("hello world!"); } } class MyClass : MonoBehaviour { public int myVar = 1; void Start() { Debug.Log("hello world!"); } } Java Script C#
  • 10. Surprisingly you can write with both of them in one project!(one way communication only) Script Script Script Script Standard Assets ((Compiled first My Scripts Folder(Outside) (Compiled last) C#JavaScript Script Script Script Script
  • 12. using UnityEngine; using System.Collections; public class MyNewBehaviour : MonoBehaviour { public static AudioClip playingClip;//////---accessible from outside to all void Start () { } void Update () {///////// see also FixedUpdate } void OnMouseDown(){ } void OnCollisionEnter(){ } public void SpawnEnemy(){////////-------------------your custom method } }
  • 19.  Time.time  Time.deltaTime  C# System.Timers.Timer Update() and FixedUpdate() FixedUpdate synchronized with Physics Engine steps while Update() runs on each frame Always use FixedUpdate() for physics! F F F F F 0.1 seconds0.0 seconds U U U U U U U U U U
  • 20.  Time.time  Time.deltaTime  C# System.Timers.Timer Update() and FixedUpdate() FixedUpdate synchronized with Physics Engine steps while Update() runs on each frame Always use FixedUpdate() for physics! F F F F F 0.1 seconds0.0 seconds U U U U U U U U U U
  • 21. TileManager tlm = tile.GetComponent<TileManager> (); void locateAndAssignCams(){ camFPS=GameObject.Find("MainCamera"); camAnim=GameObject.Find("AnimatedCam"); } Public variables reference.(Set via component interface) •GetComponent: •Find() ,FindObjectOfType(),FindObjectsOfType() Light light = FindObjectOfType(typeof(Light)); if(AudioManager.spectrumData!=null&&AudioManager.spectrumData.Length>0){ currentSpectrum=AudioManager.spectrumData; } Direct access via static members
  • 22. AudioClip aclip=(AudioClip)Resources.Load("Sounds/gagaSong"); _audioSource.clip=aclip; playingClip=aclip; _audioSource.Play(); Create object in runtime: Instantiate Prefab GameObject tile = (GameObject)Instantiate (tilePF,Vector3.zero, Quaternion.identity); void Start () { _light=new GameObject("Light1"); _light.AddComponent<Light>(); _light.light.type=LightType.Point; _light.light.range=400; _light.light.color=Color.red; _light.transform.Translate(newVector3(1000,200,1000)); } Dynamic resource assets loading
  • 23. What are these matrices and vectors anyways? Core Classes:  Mathf .(Also C# System.Math )  Matrix4x4  Vector2/3/4  Quaternion –all Rotations are Quaternion based
  • 24. “In Physics Land talk Physics”
  • 25. Core Classes: •Physics- Global physics properties and helper methods. •RigidBody-contains all essential physics methods and properties for a body
  • 27.  Self attachment _audioSource=gameObject.AddComponent<AudioSource>();  Indirect attachment GameObject tile = (GameObject)Instantiate (tilePF,Vector3.zero, Quaternion.identity); AudioSource audioSource=tile.AddComponent<AudioSource>(); //adding audio source component to the tile and accessing it at the same time//
  • 28.  Yield Ensures that the function will continue from the line after the yield statement next time it is called Can’t be used inside “Time” methods like Update(),FixedUpdate()  Coroutine Suspends its execution until givenYield instruction finishes. Requires a method to be IEnumerator
  • 29. IEnumerator Start () { print ("first"); yield return new WaitForSeconds(2f); print ("2 seconds later"); } Yield
  • 30. using UnityEngine; using System.Collections; public class StupidLoop : MonoBehaviour{ private bool buttonPressed= false; void Update () { if(!buttonPressed) { if(Input.GetButtonDown("Jump")) { StartGame(); } } print("looping..."); } void StartGame() { buttonPressed= true; print("Game Started"); } } NoYield & Coroutines scenario(Ugly one)
  • 31. void Start(){ StartCoroutine(WaitForKeyPress("Jump")); } public IEnumerator WaitForKeyPress(string _button) { while(!buttonPresed) { if(Input.GetButtonDown (_button)) { StartGame(); yield break; } print("Awaiting key input."); yield return 0; } } private void StartGame() { buttonPressed= true; print("Starting the game officially!"); } } Simple example
  • 32. void Start () { glEffect=GameObject.Find("Main Camera").GetComponent<GlowEffect>(); StartCoroutine("explodeCounter"); } IEnumerator explodeCounter(){ onTimerElaps(); if(amount<15){ yield return new WaitForSeconds(0.01F); }else{ Mesh myMesh = GetComponent<MeshFilter>().mesh; GameObject.Destroy(myMesh); yield break; } StartCoroutine("explodeCounter"); } void onTimerElaps(){ amount+=Mathf.Sin(Time.time)/5; glEffect.glowIntensity=amount/2; ExplodeMesh(amount); } Practical example
  • 33. IEnumerator Start () { yield return StartCoroutine(MyWaitFunction (4.0f)); print ("4 seconds passed"); yield return StartCoroutine(MyWaitFunction (5.0f)); print ("9 seconds passed"); } IEnumerator MyWaitFunction (float delay) { float timer =Time.time + delay; while (Time.time < timer) { Debug.Log(Time.time); yield return true; } } Sequential Coroutines calls
  • 34. Unity built-in event system  SendMessage()-Calls the method on every MonoBehaviour in this game object.  BroadcastMessage()- Calls the method on every MonoBehaviour in this game object or any of its children. Downside: Need to target methods by their name (Errors prone) Work only within the object's transform hierarchy  Controller Class registers all the classes to be notified of changes via reference Downside : Flexibility & Scalability Nightmare for big projects
  • 35.  Dispatcher class public class EventSender : MonoBehaviour { public delegate void GameObjectPressHandler(GameObject e); public event GameObjectPressHandler OnGameObjectPress; private void DispatchPressEvent () { if (OnGameObjectPress != null){ OnGameObjectPress (this.gameObject);//event has been fired! } } } public GameObject gm; EventSender myEventSender=gm.getComponent<EventSender>(); myEventSender.OnGameObjectPress+=new GameObjectPressHandler(onGMPress); Private void onGMPress(GameObjject gm){ print(gm+”was has been!”); } Listener Class
  • 36. Thank you and good luck!

Editor's Notes

  1. Attention Deficit/Hyperactivity Disorder
  2. Attention Deficit/Hyperactivity Disorder
  3. Attention Deficit/Hyperactivity Disorder
  4. Attention Deficit/Hyperactivity Disorder