Вы находитесь на странице: 1из 68

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 1: INTRODUCTION i i

1.1 Topic of the System

Title: i- i“2D iPlatformer iGame”.

1.2 Project Abstract

The ipurpose iof ithis ireport i“2D iPlatformer iGame”, iis ito ilearn iand idevelop ia i2D igame
iusing iUnity iand iC# iprogramming ilanguage. iUnity iis ia icross-stage igame imotor icreated
iby iUnity iTechnologies, ifirst ideclared iand idischarged iin iJune i2005 iat iApple iInc's.
iWorldwide iDevelopers iConference ias ia iMac iOS iX-selective igame imotor. iC# iis ia
iuniversally iuseful, imulti-worldview iprogramming ilanguage iincorporating isolid icomposing,
ilexically iperused, ibasic, idecisive, ipractical, inonexclusive, iobject-situated, iand isegment
iarranged iprogramming idisciplines. iThis iproject iis ia idemonstration iof ia i2D ibased
iplatformer igame imade iusing iUnity iassets iand iC# iwith iinteractive icontrols iand ivisually
ipleasing igraphics.

1.3 Purpose of the Project


To icreate ian iinteractive iand ivisually ipleasing i2D igame ithat ican iprovide ihours iof
ientertainment iand ifun ifor iall igenerations iof ipeople. i

1.4 Target User


A ivideo igame iis ia igreat iway ito ipass itime iand iimprove iproblem isolving iskills iand iconcentration iand
i can ibe ienjoyed iby ipeople iof iall iages. I

1.5 Topic Background


Computer igames ihas imade iconsiderable iprogress isince. iThey ihave ibecome ia isignificant
ieffect ion ithe ieducational iplan iof ithe iadvanced imedia ioutlet. iFrom ifirst-individual ishooters
ito ipretending igames, ithe icomputer igame iindustry ihas igotten iavailable ito ialmost ievery
isort iof iplayer, iregardless iof iwhether iit ibe ian iindividual iwho iappreciates ifortifying
inarrating, ior isomeone iwho isimply ineeds ito ilessen iarmed iforces iinto ijust iridiculous
ishrapnel.

Panipat iInstitute iof iEngineering iand iTechnology i Page i1


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iBuilding iup ia isignificant igame ititle ican ibe ia inoteworthy iundertaking i– ischolars, igame
icreators, isound iarchitects, ivisual icraftsmen iand iincreasingly ishould icooperate ito imake ithe
igenuine igame. iPresent iday igame icreating iprogramming ilike iUnity, iUnreal iEngine ihas
imade ithe iprocedure iof igame iimprovement ia ilot isimpler iand iintuitive iand iconsiderably
iless imind iboggling.

1.6 Problem Context


With ithe iamount iof istress ithat ipeople igo ithrough ithese idays, ia ishort ibreak ican iprovide
ia imuch-needed ibreather ito isome. iA ivideo igame iis ia iperfect iway ito irelease istress iand
iimprove iconcentration. i

1.6.1 Rationale behindithe System: Why doiweineedithis System?


Unity iis ia ipowerful igame ideveloping isoftware ithat icomes iwith itons iof ifeatures iand iuser-
friendly iassets. iThis ican imake idevelopment iof igames imuch ieasier iand iless icomplex.

1.6.2 i Benefits of the System: What are the potential benefits derived?
1) iPlatform isupport i

The imotor iis iexceptionally ifavored ifor iits iall-inclusive ihelp ito i27 istages. iThe iapplication
icreated iand isent ican ibe ieffectively ishared ibetween iPC, iweb iand iportable istages. iAlso,
ithe ilight-footed itechnique iempowers ifast iprototyping iand iconsistent idischarges, iwhich
ithus iaccelerate ithe igame iadvancement. i

2) iIDE i

The icontent imanager iis igiven iby iIDE ito icompose ithe icode, iyet iin isome icases ian iunmistakable icode
i supervisor iis iadditionally iutilized iby ithe iengineers ito ireduce iperplexity. iFurthermore, ithe
i coordinated iimprovement ieditorial imanager isupport iJavaScript iand iC# ifor iscripting, iand
i furthermore ioffers ioutstanding ihighlights ithat iare iperfect ifor ithe igame iadvancement. i

3) iGraphics i

Panipat iInstitute iof iEngineering iand iTechnology i Page i2


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

The igreat isound iand ispecial ivisualizations iare ibolstered iby ithe imotor ithat ifacilitates ithe igame
i improvement. iThe ivisuals iare iversatile ion ieach iscreen iand igadget iwith ino itwisting ior ibargain iwith
i the ipicture iquality. i

4) iDocumentation i

It's ian iunquestionable irequirement ihave. iThe itenderfoot idesigners ineed ithe istraightforward
i documentation ithat iis igiven iin idetail iby ithe iUnity imotor. iThe ipoint iby ipoint idocumentation
i incorporates ithe iclarification iof ieach ilittle itheme. i

5) iDebugging i

The iinvestigating iand itweaking iare iincredibly isimpler iwith iUnity igame iimprovement isince iall ithe
i game ifactors iare ishown iduring iongoing iinteraction, iwhich ithusly ienable ithe iengineers ito
i troubleshoot ithe iprocedure iat iruntime.

1.7 Objectives of the System


1.7.1 Project iObjectives
 Develop ia i2D iplatformer igame iusing iUnity iand iC#.
 Platform iIndependent iProject. i
 Provide ihours iof ifun iand ientertainment iof iall.

1.7.2 Learning iObjectives


 Learning igame idevelopment iusing iUnity. i
 Learning ibasic iC# iprogramming ilanguage. i
 Learning ibasics i2D ianimation iand irigging. i
 Creating i2D ienvironment iusing itile imaps. i
1.8 Scope iof ithe iSystem
This i2D igame iis ivery iuser ifriendly iand irequires ivery iless ihardware irequirements iand ican irun ion
i almost iall imodern icomputers. i

1.9 Limitation iof ithe iSystem


Impediments iare iconstantly ia ipiece iof ieach itask. iThe iundertaking iextension iis iconstrained ito ia
i limited ilimit ias irecorded iunderneath: i

Panipat iInstitute iof iEngineering iand iTechnology i Page i3


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

 The icontrols iare irelatively ivery ieasy. i


 The igameplay ican iget irepetitive. i
 No ivariations iamong ienemies.
 The igame iis ibeing ideveloped ifor ionly iwindows-based icomputers.
 Simple ienemy iAI.

Panipat iInstitute iof iEngineering iand iTechnology i Page i4


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 2: OVERVIEW i i

Unity iis ia imultiplatform igame imotor ithat isupports i2D iand i3D iillustrations. iGames iwere iordinarily
i scripted iin iC# iand iUnityScript, ilike iJavaScript, iwhich imakes ithem ia ilot imore iobvious. i

2.1 i History

Unity iis ia icross-stage igame imotor ithat iwas icreated iby iUnity iTechnologies. iSolidarity
i Technologies iwas iestablished iby iDavid iHelgason, iNicholas iFrancis iand iJoachim iAnte iin i2004.
i Numerous iworldwide iorganizations ihelped iUnity iTechnologies iby isubsidizing ithe iventure, iin
i order ito idevelop ia imotor ieverybody icould ibear. iThe iUnity imotor iwas icreated iutilizing iC iand iC++
i programming idialects. iFor iscripting iand icoding, iC# iand iJava idialects iare iutilized. i

2.2 I Assets Store

In i2010 iUnity ipresented ithe iAsset iStore, iwhere iengineers iand idifferent iclients ican idownload
i resources iinside ithe iUnity imanager. iIt iis, iwhere iboth ifree iand ibusiness iresources ican ibe ifound.
i These iadvantages iwere imade iby iUnity iadvances iand iby idifferent iindividuals ifrom ithe inetwork. i

The ibenefits ithat iare iaccessible iin ithe iadvantages istore iare: i-

1. Animations i
2. Audio i
3. 3D iModels i
4. Particle isystems i
5. Scripting i
6. Shaders i
7. Textures i
8. Materials i
9. Unity iEssentials iand i
10. Services.

2.3 Licenses i
Unity igame imotor ichiefly ihas ithree iauthorizing ialternatives. iSolidarity iPersonal, iUnity iPlus iand
i Unity iPro. iThese ivary ifrom ione ianother ifor ithe imost ipart iin ithe ihighlights, ibug irevealing ior

Panipat iInstitute iof iEngineering iand iTechnology i Page i5


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

i needing iclient ihelp. iSolidarity iFree iform ican ibe idownloaded iby iany iclient iand iis ithe imost
i constrained iadaptation. iIt ihas iall ithe iimportant idevices iand ihighlights ito ibuild iup ia igame.
i Solidarity ilikewise igives ithe iclient ithe iopportunity ito imove iup ito iPro iin ithe icenter iof itask iwithout
i causing ispecialized iissues, ias ioverhauling ithe ipermit iwill ijust iadd inew ihighlights ito ithe iUI. i

According ito iUnity's iEULA iAgreement, iclients iutilizing ithe ifree iform iought inot ihave iyearly
i incomes imore ithan i100,000 iUSD, ior ielse itheir iconsent iwill ibe iwithdrawn. iAll ithings iconsidered
i clients iought ito ieither ioverhaul itheir iUnity ilicenses ito iPlus ior iPro, ias iUnity iPlus ipermits iyearly
i incomes iup ito i200,000 iUSD iand iUnity iPro idoesn't ihave ilimit. iSolidarity iPro ienables iclients ito
i alter itheir isprinkle iscreens iof ithe igame, iwhich iis iabsurd iin ithe ifree iform. iIt ihas ilikewise ithe
i alternative ito iimprove iexecution iand isubtleties iof ithe igames.

2.4 Unity Interface


Unity ihas ia iworked iin ieditor iinterface, iwhere iit iworks ias ithe iprimary iwindow ior iworkspace ifor ia
i venture. iIn ithe iworkspace ior ifundamental imanager iwindow, ithere iare ia ifew iother iselected
i windows, ieach ihaving ia iparticular ireason iand icapacity. iBy idefault, ithe imain ieditor iwindow
i includes: i

- iProject iWindow i
- iHierarchy iWindow i
- iScene iView i
- iGame iView i
- iInspector iand i
- iToolbar. i

Panipat iInstitute iof iEngineering iand iTechnology i Page i6


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

GRAPH i1 iUnity iEditor iLayout


The iProject iWindow ishows ievery ione iof ithe ienvelopes iand isub-organizers ithat iare iidentified iwith
i the iundertaking. iIt ishows ia irundown iof ibenefits iand icontents ithat iare iimported ito ithe iundertaking
i organizers. iResources ican ibe iutilized ilegitimately ifrom ithe itask iwindow iby ihauling ithem iinto ithe
i scene iview ior iutilizing ias ia icontent ifor ia ispecific iGameObject. iIt iis iadditionally iconceivable ito
i look iand ichoose iresources ifrom iUnity iresource istore ifrom ithe iProject iWindow. i

The iHierarchy iWindow icontains ia irundown iof iGameObjects ithat iare ibeing iused iin ithe ipresent
i scene. iWhen iGameObjects iare iincluded ior ievacuated iin ithe iscene, ithey itypically ishow iup ior
i vanish, iindividually, iin ithe iHierarchy iWindow. iBy iUnity's icomprehension iof ichild irearing, iit iis
i conceivable ito imake ia iGameObject ioffspring iof ianother iGameObject iby ihauling ithem ionto ia
i parent iin ithis iwindow. iIn isuch iprocedure, ithis iyoungster iGameObject iacquires ithe icharacteristics,
i for iexample, ithe iposition iand ithe iturn iestimations iof iits iparent iGameObject. i

The iToolbar iincorporates isome ifundamental icontrols iof ithe iundertaking. iThese iincorporate ichange
i devices iand ithingamajig iflips ifor ithe iscene isee, iplay/delay/step icatches ifor ithe igame iview, icloud
i catches ior iUnity iadministrations, ilayer idrop-down ifor ishowing iobjects iin ithe iscene iview iand
i format idrop-down ifor ithe igame iplan iof iperspectives. i

Panipat iInstitute iof iEngineering iand iTechnology i Page i7


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

The iInspector iWindow ishows ipoint iby ipoint idata iabout ithe ichose iGameObject, iincluding ithe
i entirety iof iits iproperties iand ithe iparts iconnected ito iit. iThis iwindow iempowers ithe iclient ito ialter ithe
i usefulness iof ithe iGameObject, ifor iexample, ialtering, iincluding ior ierasing inew icontents ior imaterial
i science i2D imaterials, iand irolling iout idifferent iimprovements ito ithe iscene.

Panipat iInstitute iof iEngineering iand iTechnology i Page i8


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 3: GAME DEVELOPMENT i i i

Toward ithe ibeginning iof iany iproject, ithere iought ito ibe ian iobjective iand ilegitimate iwanting ito imake
i progress. iA ireasonable iidea iabout ithe iobjectives imakes iit isimpler ito iprepare iand imake ithe
i important ichanges. iThere iare ilikewise isure inecessities ithat iare ishould ihave ibeen isatisfied, iso ias ito
i make ia igame iprogressively iintense. iTo imake ia igame iplayable iand ifascinating, iit imust ihave
i legitimate igame istructure, idesigns iand igame iplay. iWith ithe iassistance iof ia igame imotor,
i appropriate iarranging iand ia ireasonable ivision, iit iis isimpler ito imake ia ibasic iyet ilovely igame.

3.1 Planning and requirements


While idealing iwith ithe iventure, ia ifew istages iwere iarranged iin iadvance iso ithe iprocedure iwould iget
i simpler. iThe iinitial istep iwas ito iplan ithe igame, iwhich iwas ia igenuinely isimple iundertaking ias
i playing idifferent igames ihave iobtained iadequate iinformation iabout iplatformer ikind igames.
i Designing iis ito ikeep ithe iplayer iconnected iwith ithe igame iand ipresent inew idifficulties ieverywhere.
i The igoals ifor ifinishing ithe istages iwere ia ibasic ipiece iof ithe igame istructure. iThe iessential
i platformer iidea iis ito imove istarting iwith ione ipoint ithen ionto ithe inext, ihowever iby iremembering
i destinations ifor ieach ilevel, ithe iplayer iis irequired ito isatisfy ithese iso ias ito ifinish ithe ipresent ilevel. i

Obtaining isurfaces ifor ithe igame iillustrations iwas ithe imost isignificant iand ihardest ipart iduring ithe
i advancement. iAs iit iwas irequired ito ilook ithrough ia ifew isites iand iUnity's ibenefit istore ifor ithe iideal
i material, iwhich iis iallowed ito iutilize. iThere iwere ia ifew iminutes iduring ithe istructure istage iwhere ithe
i procedure iwas ichanged ibecause iof ithe ireality iof iinaccessible iresource. iWith ithe ifundamental
i thought iand iinformation iabout iillustrations istructure iand iPhotoshop, isuch iblocks ican ibe idodged.
i For ithe iongoing iinteraction ipart, ithe iinformation iwas ikept igenuinely ibasic iand iinstinctive, iwith ithe
i goal ithat iplayers ican iconcentrate ion ithe igame ias iopposed ito ion ithe icontrols. i

For ibuilding iup ithe igame, iit iis ifundamental ito icompose ithe icode. iThe icontents iare ijoined ito ithe
i gameObjects, iwhich iworks iin ithe igame iin ilike imanner. iMonoDevelop iis ithe iworked iin iIntegrated
i Development iEnvironment i(IDE) ithat iis igiven iof icourse iwhile idownloading ithe iUnity igame
i motor. iVisual iStudio ican ilikewise ibe iutilized ifor iscripting, iyet iit iis irequired ito iset ithe idefault iIDE
i from iinside iUnity.

Panipat iInstitute iof iEngineering iand iTechnology i Page i9


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

3.2 Scripting
So ias ito iadd ispeed iand imovement ito ithe iplayer icharacter, ifirst iwe ihave ito iadd ia icontent ienvelope ito
i the iplayer iGameObject iand ithink iof isome icode iin iit. iIt iis iconceivable ito imake ia icontent ijust iby
i right-tapping ion ithe iProject iWindow, iat ithat ipoint imake ia iC# icontent. iAnother iplausibility iis ito
i choose ithe iplayer ifrom ithe iHierarchy iview iand iinclude ia iNew iScript ipart. iOn iopening ithe icontent
i from iUnity, iit ivery iwell imay ibe iseen ithat ithe iclass imade igets ifrom ithe ibase iclass iMonoBehaviour.
i MonoBehaviour iis ia iclass iin iUnityEngine iand iit iis iimportant ito iget ifrom iit.

GRAPH i2. iDefault iUnity iC# iscript


Graph i2 ilikewise idelineates itwo icapacities, iStart iand iUpdate, iwhich iare icalled iby ithe igame iat
i different iinterims. iFor iinstance, ivoid iStart() iis icalled ipromptly iwhen ithe igame iis irun iand ivoid
i Update() iis icalled ionce iper ioutline. i

Aside ifrom ithese itwo icapacities iAwake(), iFixedUpdate() iand iLateUpdate() iare iadditionally
i utilized iin ispecific icases. iThe iAwake() iwork iis icalled ibefore iStart(), iand iis iexecuted iwhile ithe
i game iis ibeing istacked. iIn icontrast ito ithe iUpdate() iwork, ithe iFixedUpdate() iis icalled iduring ieach
i framerate ioutline, iwhich iimplies ithat ithe itime iinterim ibetween ieach iFixedUpdate() icalled iwill
i consistently ibe ithe iequivalent, ithough iit imight ifluctuate iin ithe ievent iof ithe iUpdate() iwork. iWhen
i working iwith imaterial iscience, ithe iFixedUpdate() iwork iis iutilized ias iit ichanges ithe imaterial
i science iof ian iitem ia ifew itimes ieach iedge. iThe iLateUpdate() iis icalled iafter iall iother iUpdate
i capacities iare icalled. iIt iis iessentially iutilized ifor ithe icamera ito ipursue ias iit iwill ibe iexecuted iafter ia

Panipat iInstitute iof iEngineering iand iTechnology i Page i10


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

i specific iarticle iis imoved iin ithe iUpdate icapacities. iAll istrategies iand icapacities imust ibe ibrought iin
i Update() ior iFixedUpdate() iwork, ias ithese iare ithe iprimary itechniques ifor iMonoBehaviour.

3.3 Unity 2D features

The iUnity igame imotor ihas iworked iin i2D itoolsets, iwhich iare ifundamental iin icreating i2D igames.
i Without ithese itoolsets, ibeforehand igame iengineers ihosted ito iutilize ithird igathering iprogramming
i to ialter isprites. iIllustrations ior isurfaces iin i2D iutilizes isprite irenderer iwhile iin i3D ia iwork irenderer
i is iutilized. iPresent i2Dtoolsets iare iadditionally iused ito imodify iand iadjust ithe imaterial iscience
i mechanics iof ithe isprites, imaking iadvancement iof i2D igames ia ilot isimpler iand iquicker.

3.3.1 i iSprites

This isegment iwill igive ithe ifundamental iinsights iconcerning isprites, ihow isprites iare imade, ialtered,
i rendered iand ihow ito imake ilivelinesss iof isprites. iSprites ior igraphical icomponents iin i2D
i interactivity ia isignificant ijob ias ithey igive ithe igame itheir ivisual iappearance. iSprites iare itwo-
dimensional ibitmap ior igraphical iarticles iutilized iin i2D igames. iIn iUnity, isprites iare icharacterized
i by iTexture2D, icritical ipoint iand ia isquare ishape. iEvery isprite ihas ia itexture2d icomponent ifor ivisual
i appearance, ia isignificant ipoint iwhere ithe ipicture ican ibe ipivoted iand iit ihas ilikewise ia isquare ishape
i fringe. iDue ito ithe irectangular iwork, iit iis iadditionally iconceivable ito ijoin ivertex ito ivertex icalled
i vertex isnapping, imaking iadjusting iobjects ia ilot isimpler. I

Sprites iare iadditionally ia ikind iof iadvantage iin iUnity iundertaking iand ithey iare inormally ifound iin
i the iProject iWindow. iSprites iutilized ifor ithe igame iin ithis itheory iwere idownloaded ifrom ithe iweb
i and iwere iimported ito iUnity. iThere iare inumerous i2D isprites iaccessible ion ithe iweb iand iin ithe iUnity
i store, iand ithey iare itotally ifree ifor iindividual iuse. iTo ibring isprite iresources iinto iUnity, igo ito
i Assets> iImport iNew iAssets iwhich iwill iat ithat ipoint iopen ithe iFile iExplorer iwindow iin iWindows
i OS ior ithe iComputer's iFinder iin iMac iOSX. iIn ithe iwake iof ichoosing ia ipicture, iUnity iwill iimport ithe
i record iand iit iwill ibe iappeared ias ian iadvantage iin ithe iProject iWindow. iTo iutilize isuch ipictures ias
i sprites iin i2D, iit iis irequired ito ichange ithe isurface ikind iof ithe ipicture ito iSprite i(2D iand iUI) ifrom ithe
i Inspector iWindow.

Panipat iInstitute iof iEngineering iand iTechnology i Page i11


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

GRAPH i3. iAssets itab iand iGameObject itab

In iUnity iEditor, iit iis iadditionally iconceivable ito imake ispriteGameObjects. iTo imake ione, igo ito
i Assets>Create i>Sprites iand iselect ithe iideal ishape ias ia ipicture, ias iappeared iin iGraph i3. iA isprite
i resource iwill ishow iup ion ithe iProject iWindow, iwhich ican ibe iutilized ibasically iby ihauling iit iinto ithe
i Scene iView ior iHierarchy iWindow, ior ijust iby idouble itapping. iIt iis ilikewise iconceivable ito imake ia
i sprite iby ichoosing iGameObject>2D iObject>Sprite, ias iappeared iin iGraph i3. iAlong ithese ilines
i Unity iwill imake ia iGameObject iwith ia isprite irenderer, ianother isprite, iin ithe iHierarchy iwindow
i with ino isprite iof ithe ipicture. iTo iembed ia ipicture, iselect ithe inew isprite iand ifrom ithe isprite irenderer
i in ithe iInspector iwindow, ialter ithe isprite iby itapping ithe ilittle icircle iand iinformation iany iattractive
i picture ior isprite. i

The iSprite iEditor iis ian ialtering iinstrument ithat ican ibe iutilized ifrom ithe iInspector iWindow, iwhile ia
i specific isprite isurface iin ichose. iRegularly ia isolitary ipicture imay icontain ia ifew idistinctive isprite
i surfaces ithat ican ibe iutilized iin igame iimprovement. iSo ias ito iutilize ithem iexclusively, iit iis iimportant
i to iisolate ithem ifrom iits ientire ipicture isurface. iSolidarity ihas igiven ia isprite imanager iinstrument ito
i acquire isingle icomponents ifrom ia icomposite isurface. iTo iremove isingular isprites ifrom ia isolitary
i picture, ifirst iset ithe iSpriteMode iin ithe iInspector iWindow iwhile ichoosing ithe ipicture isurface, ito
i numerous iand iclick ithe iSprite iEditor.

Panipat iInstitute iof iEngineering iand iTechnology i Page i12


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

GRAPH i4. iSprite iEditor iwindow

In ithe iSprite iEditor iwindow, ialongside ithe isurface ipicture, ithere iare ia ifew icontrols iin ithe itop ibar iof
i the iwindow. iSuch icontrols iincorporate izoom islider, ipixilation islider, iapply, ireturn, itrim iand icut.
i The imost isignificant icontrol iis ithe icut imenu, iwhich igives ithe ichoice ifor ianalyzing ithe ipicture iand
i acquiring isingle icomponents. iDiagram i4 ishows ihow icomponents iare icut iindependently ifrom ia
i composite ipicture ior ispritesheet. i

As ifound iin iGraph i4, idim isquare ishape ioutskirts iin ithe ispritesheet idelineate iunique iand iindividual
i sprite isurfaces. iIt iis iconceivable ito icut ioff irealistic icomponents ijust iby ichoosing iprogrammed itype
i from ithe iSlice imenu iand iclicking icut. iIn ithis iprocedure, iUnity iitself iis irecognizing ievery ione iof ithe
i designs isurfaces iand iflanking ithem iindependently. iWhenever iwanted, iit iis ilikewise iconceivable ito
i cut iphysically iby ibasically iclicking iand ihauling iaround ithe ipicture. i

Sprite iRenderer iis ia irenderer iutilized iby iUnity ifor irendering isprites iin i2D, ithough iin i3D ia iMesh
i Renderer iin iutilized. iThe iSprite iRenderer iis ia isegment iconnected ito ievery ione iof ithe isprites ithat
i are iavailable iin ithe iScene iview ior iHierarchy iwindow. iIn i3D imode, ian iarticle's iappearance irelies
i upon ithe ilighting iand icamera iposition, iyet iin i2D, ipictures iare ishown iby itheir iposition, iscale iand
i revolution iin i2D iorganizes. i

Panipat iInstitute iof iEngineering iand iTechnology i Page i13


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

With iSprite iRenderer iappended, iit iis iconceivable ito iadjust ithe ipicture iproperties iby idiffering
i shading, imaterial, iarranging ilayer, ilayer iarrange ior iin iany ievent, iflipping ithe ipicture iin iX iand iY
i tomahawks. iIn ishading ialternative, iit iis iconceivable ito ichange ithe ishading ior ithe idegree iof
i straightforwardness, iregardless iof iwhether ithe imaterial icollaborates iwith ilightning iand ilayer
i choices iare iutilized ifor isetting ineed ito ia isprite iduring irendering istage.

GRAPH i5. iWalking iAnimation

Graph i5 ishows ieight iseparate ipictures iwhere ia icharacter ihas ivarious iphases iof istrolling. iAt ithe
i point iwhen ithe ipictures iare icircled iin iquick imovement, iit iwill iseem ilike ithe icharacter iis istrolling. i

While ibuilding iup ia igame, iscripting iand igraphical ioriginator iboth iof ia isimilar isignificance. iSo ias ito
i make ia igame ilook iprogressively ipractical iand ilivelier, iliveliness iis iadded ito ithe isprites. iMaking
i livelinesss iwith ithe iUnity iEngine iis ivery iquick iand isimple. iIt iis iconceivable ito imake iliveliness
i utilizing ieither ihand idrawing ior ijust iby idownloading ispritesheets ifrom ithe iweb. iAt ithe ipoint iwhen
i a ilot iof ipictures, ias ishould ibe iobvious iin iGraph i5, iare ichosen iand ihauled iinto ithe iScene iView ior
i Hierarchy iWindow, ia iGameObject iis imade. iSolidarity iat ithat ipoint iprompts ia iwindow icalled
i Create iNew iAnimation, iso ias ito ispare ithe imovement idocument. iAlongside ithe imovement
i document, ia icontroller ipart iis ilikewise imade, iand iwill ibe iappended iwith ithe iGameObject. iIt iis
i likewise iconceivable ito imake iactivitys ifrom ithe iAnimation iWindow. iTo iopen ithe iAnimation
i Window, iessentially iselect iWindow ifrom ithe itab, iat ithat ipoint iAnimation. iTo imake iactivitys iand
i append ithem ito ian iarticle, iselect ithe iGameObject ifrom ithe iHierarchy iWindow, iand idrag ia ipicture
i into ithe itime iscale ion ithe iAnimation iWindow. iIt iis iadditionally iconceivable ito iadjust ithe ispeed iof
i liveliness iby ichanging ithe iqualities iclose ito ithe iexamples iin ithe iAnimation iWindow. i

To ienliven ia icharacter ior isprite, ia icontroller iis irequired ito iget ito iits iAnimator. iTo iopen ithe
i Animator iwindow, iselect iWindow ifrom ithe itab iand iafterward iAnimator, iwhich iwill imake ithe

Panipat iInstitute iof iEngineering iand iTechnology i Page i14


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

i Animator iWindow. iEach iGameObject ican ihave ivarious ilivelinesss iand iit iis iconceivable ito icontrol.

GRAPH i6. iAnimator iWindow

Graph i6 ishows ithe iAnimator iWindow iwhere ithe iorange icolored istate icontains ia irun ianimation iand
i is idefined ias ithe idefault istate. iWhich imeans, ithat iwhenever ithe ianimator iis icalled, iany ianimation
i in ithe irun istate iwill ianimate iimmediately. i

i The iAnimator iwindow ior iState iMachine iwindow ihas ivarious ilayer icontrol, iwhich iwill ibe
i explained ilater iin ithe ithesis, ialongside iwith iits iparameters. iThere iare ifour iparameters ifloat, iinteger,
i Boolean iand itrigger. iWhen ia iGameObject ihas itwo ior imore ianimations, iparameters isets iwhich
i animations ito iplay iand iwhen. iParameters iare iset iby iclicking ithe iwhite iarrow iconnecting ithe irun
i state iand ithe ijump istate, ias iseen iin iGraph i6. iThese ilines iare icalled itransitions. iSuppose ithe
i transition ifrom ithe irun istate ito ithe ijump istate ianimation iis idefined ias ia iBoolean iparameter; iif ithe
i value iis itrue ithen ithe ijump ianimation iis iplayed iand iif ithe ivalue iis ifalse, iit iwill icontinue iwith ithe irun
i animation. iAnimations ilinked ito iany istate iwill irun iimmediately, iwhenever ithe iset iparameter iis itrue
i and iexit istate iforces ithe ianimator ito iquit.

3.3.2 i iPhysics2D

Unity ihas i2D imaterial iscience isettings, iwhich iincorporate idifferent iphysical iscience isegments. iBy
i utilizing ithese iparts, iit iis iconceivable ito iadd imaterial iscience iproperties ito ia iGameObject, ifor
i example, iincluding ipower, igravity ior iimpact. i

Panipat iInstitute iof iEngineering iand iTechnology i Page i15


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

Rigidbody2D iis ia ipart iwhich, iwhen iappended, iputs ithe iSprite iunder ithe iinfluence iof iUnity's
i material iscience imotor. iMoreover, iit iis iconceivable ito ichange ithe iitem's imass, igravity, idrag, ibody
i type, iand ifurthermore iapplying ipowers iutilizing icontents. iRigidbody2D ihas ithree ibody itypes,
i dynamic ibeing ithe imost iwidely irecognized ias iit ienables iarticles ito imove icorrespondingly ito
i development iin ireality. iKinematic ibody itypes iare ijust iready ito islam iinto idynamic ibody itypes iand
i these idon't ihave igravity iin ithem. iDespite ithe ifact ithat iit iis iconceivable ito imove ithem iutilizing
i speed iin icontents, iyet ithey iwon't ibe iinfluenced iby ipower ior igravity. iStatic iRigidbody2D iisn't
i intended ito imove iand iacts ias ia isteady iobject iin iany ievent, iwhile islamming iinto idynamic ibody
i types. i

Colliders2D iparts iare iincluded iso iprotests iwith iRigidbody ican icrash iinto idifferent iarticles iwhile ia
i collider iis ijoined ito ithem. iColliders iare iproximate ishapes ithat idecide ithe isurface ifor iimpact. iBox
i Collider2D iand iCircle iCollider2D iare ithe ifundamental istates iof ithe icollider. iPolygon iCollider2D
i gives ian iexact icollider ishape iby ichanging ithe iline isections iand iedges iopenly. iEdge iCollider2D iis
i equivalent ito iPolygon iCollider2D, iwith ithe iexception iof iit idoesn't ineed ito ibe ian iencased ishape, ifor
i example, ia iline ior ia ibend. i

Physical iscience iMaterial i2D iparts iadd icontact iand ienergy ito ithe iarticles. iChanging icontact
i esteems ichanges ithe icoefficient ibetween ithe iself-collider iand ithe icollaborating icollider, iwhich
i gives ipretty imuch ian ielusive isurface. iEnergy iesteems iset iat i0 igive ino ibob iand iany iworth imore ithan
i 1 iinclude iskip iproperty iwithout ivitality imisfortune. iOn ithe ioff ichance ithat ithe iworth iis isomewhere
i in ithe irange iof i0 iand i1, iat ithat ipoint iit iadds ipotential ivitality iproperty ito ithe iitem, iwhere iit iloses
i vitality ithrough ieach iskip iuntil iit istops. i

Joints2D iparts iare iutilized ito iconnect ione iarticle ito ianother iitem iwith ia iRigidbody2D isegment ior
i only ia ifixed isituation iin iScene isee. iThere iare ia ifew iJoints2D iwith ivarious icollaborations.
i Separation iJoint2D ikeeps itwo iitems iseparated iat ia ispecific iseparation. iFixed iJoint2D ikeeps ithe
i item iin ia ifixed iposition iand idenies iany idevelopment iwhenever islammed iinto idifferent iobjects,
i when iits ibreak ipower iand ibreak itorque iare iset ito ilimitless. iGrating iJoint2D idiminishes ithe isurface
i speeds ibetween itwo iarticles ito izero. iPivot iJoint2D ienables ian iarticle ito iturn iset iup, ifixed iin ia
i situation iin iworld ispace. iIt itends ito ibe iturned ilatently ior iby iapplying iengine ipower ito iit. iRelative
Joint2D ipermits itwo iarticles ito ikeep iup iseparation iposition iand iturn idependent ion ione ianother's
i

Panipat iInstitute iof iEngineering iand iTechnology i Page i16


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

i area. iSlider iJoint2D ienables iitems ito islide ialong ithe iline ifrom itheir iunderlying isituation ito itheir
i pronounced iposition. iSpring iJoint2D ienables iitems ito iact ilike ia ispring. iSpring ipower iwill iapply
i along ithe ipivot iand iwill ikeep iup ito ikeep ia iseparation ibetween iobjects. iTarget iJoint2D iis ia ispring
i type ijoint, iwhich ipermits ian iarticle iacting iunder igravity ito imove ito ia ipredetermined iarea ion ithe
i planet ispace iand ifixes iits iposition. iWheel iJoint2D igoes iabout ias ia imoving iwheel, ion iwhich
i different iarticles ican imove. iIt ihas ia isuspension itype ispring ito ikeep ithe iseparation ibetween itwo
i items. iThe iConstant iForce2D ipart ienables ius ito iadd isteady ipower ito ia iRigidbody. iIt ilets ithe iarticle
i to iquicken iafter isome itime irather ithan isimply ibeginning iat imost iextreme ispeed. iIt iapplies iboth
i direct iand iprecise inonstop ipowers ito ithe iGameObject. i

Effectors2D iparts iare ico-identified iwith ithe iColliders2D ipresent iin ithe iitem. iColliders2D imust ibe
i included iand ithe ialternative i"Utilized iby iEffector" iought ito ibe ichecked iall itogether ifor
i Effectors2D isegments ito iwork. iWith ithe iexception iof iPlatform iEffector2D iand iSurface
i Effector2D, ievery iother ieffector irequire iboth ithe ichoices i"Utilized iby iEffector" iand i"Is iTrigger" ito
i be ichecked. iStage iEffector2D ican ibe iutilized ito ipermit iimpacts ijust ifrom isingle idirection.
i Lightness iEffectors2D iis iutilized ito iget ia iskimming iimpact ion ithe iGameObjects. iTerritory
i Effector2D iapplies igreatness ipower iand iedge ito ithe iitem icrashing iinto iit. iPoint iEffector2D iadds
i fascination iand irepugnance ipower ito ithe iimpacting iobject. iSurface iEffector2D igives iextra ispeed
i when idifferent iobjects islam iinto iit.

Panipat iInstitute iof iEngineering iand iTechnology i Page i17


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 4: THE IMPLEMENTATION i i i i

PROCESS OF THE GAME i i i

The igame ibuilt ifor ithis ithesis ican ibe iused ias ian iexample ion ihow ito imake i2D igames. iFrom ithis
i section ionwards, iI iwill ibe iexplaining ithe ibasics iof ithe imaking iof ia igame iand ihow iit iworks. iHere iI
i will iexplain ithe inecessary iscript ifunctions ithat iare irequired ito icreate ia ibasic i2D igame.

4.1 Creating a New Project i


To imake ianother iproject, iwe ihave ito ichoose iNew ion ithe iupper iright icorner iof ithe iwindow ithat
i opens, iand iafterward iselect ian iarea ito ispare iyour iventure igiving iit ian iundertaking iname. iBeneath
i the iarea isegment, iwe ihave ito icheck i2D ias iwe iwill itake ia ishot iat itwo-dimensional iworld ispace.
i Resources ibundle isees ia ilot iof ithings ithat ican ibe iimported iwhen imaking ianother iundertaking.

4.2 Basic Structure

GRAPH i7. iBasic ilayout iof ithe igame


Chart i7 ishows ithe ifundamental iformat istructure iof ithe igame iwhere ithe iProject iwindow icontains iall
i the iessential iresources iexpected ito ibuild iup ithe igame. iControllers ihave iall ithe iliveliness icontrollers

Panipat iInstitute iof iEngineering iand iTechnology i Page i18


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

i required ito iquicken icertain iitems, isince, ias iclarified iprior, ievery iindividual isprite imust ihave ia
i controller ifor icontrolling imovement icuts.

4.3 Player
In ithis iarea, iI iwill iclarify iabout ithe iqualities iof ithe iplayer. iThe iplayer iis ithe imost isignificant
i character iof ithe igame, ias iit ilets iclients ito iassociate iwith ithe igame iworld. iClients ican icontrol ithe
i player iby idifferent isources iof iinfo icoming iabout ivarious iactivities, ifor iinstance, istrolling, ihopping.

4.3.1 i iPlayer iPhysics i


i Before iproceeding ionward ito ithe idevelopment isegment, iit iis iessential ito iadd iRigidbody2D iand
i Collider2D iparts ito ithe iplayer icharacter. iAs iit iis italked iabout iabove, iit iis iimportant ito iinclude
i Rigidbody2D iwith ithe igoal ithat imaterial iscience ican ibe iapplied ito ithe iplayer isprite iand iCollider2D
i gives isprites ia iphysical iproperty iand ifor icrashing iagainst idifferent icolliders. i

In iRigidbody2D isetting, ithe iestimation iof imass iis idefault ito i1 iand ithe igravity iis iset ito i5.
i Nonetheless, iit iis iconceivable ito ichange ithe iincentive ito iobtain ithe iideal imaterial iscience iconduct.
i In i2D igames, ijust ithe iX iand iY itomahawks iare iutilized. iSo ias ito iconfine iany iturn ithrough ithe iZ
i pivot, iit iis iimportant ito icheck ithe i"Stop iRotation iZ" ibox, iwhich ican ibe ifound iunder ilimitations iin
i the iRigidbody2D isetting. i

While ipicking icolliders ifor ithe isprites iin i2D, ithe icontainer icollider iis iutilized ithe imost, ias ia iresult
i of ithe itwo-dimensional iworld. iIt iis ilikewise iconceivable ito ipick ia ipolygon icollider ifor iincreasingly
i exact iestimation. iIn ithe iwake iof ichoosing ithe iideal icollider, ialter ithe isize iof ithe icollider iso iit
i outskirts iwith ithe isprite isurface. iIn iGraph i8 ithe igreen ibox iaround ithe isprite ishows ithe icollider. i

With ithe iexpansion iof iRigidbody2D, iit iis iconceivable ito imove ithe iplayer ion ia ilevel iplane ior
i vertically iutilizing ispeed. iColliders iwill iempower ithe iplayer ito islam iinto icertain iGameObjects iin
i the igame

Panipat iInstitute iof iEngineering iand iTechnology i Page i19


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

GRAPH i8. iBox-Collider2D iadded ito ithe iplayer isprite


Before iproceeding ionward ito ithe idevelopment isegment, iit iis iessential ito iadd iRigidbody2D iand
i Collider2D iparts ito ithe iplayer icharacter. iAs iit iis italked iabout iabove, iit iis iimportant ito iinclude
i Rigidbody2D iwith ithe igoal ithat imaterial iscience ican ibe iapplied ito ithe iplayer isprite iand iCollider2D
i gives isprites ia iphysical iproperty iand ifor icrashing iagainst idifferent icolliders. i

In iRigidbody2D isetting, ithe iestimation iof imass iis idefault ito i1 iand ithe igravity iis iset ito i5.
i Nonetheless, iit iis iconceivable ito ichange ithe iincentive ito iobtain ithe iideal imaterial iscience iconduct.
i In i2D igames, ijust ithe iX iand iY itomahawks iare iutilized. iSo ias ito iconfine iany iturn ithrough ithe iZ
i pivot, iit iis iimportant ito icheck ithe i"Stop iRotation iZ" ibox, iwhich ican ibe ifound iunder ilimitations iin
i the iRigidbody2D isetting. i

While ipicking icolliders ifor ithe isprites iin i2D, ithe icontainer icollider iis iutilized ithe imost, ias ia iresult
i of ithe itwo-dimensional iworld. iIt iis ilikewise iconceivable ito ipick ia ipolygon icollider ifor iincreasingly
i exact iestimation. iIn ithe iwake iof ichoosing ithe iideal icollider, ialter ithe isize iof ithe icollider iso iit
i outskirts iwith ithe isprite isurface. iIn iGraph i8 ithe igreen ibox iaround ithe isprite ishows ithe icollider. i

With ithe iexpansion iof iRigidbody2D, iit iis iconceivable ito imove ithe iplayer ion ia ilevel iplane ior
i vertically iutilizing ispeed. iColliders iwill iempower ithe iplayer ito islam iinto icertain iGameObjects iin
i the igame.

Panipat iInstitute iof iEngineering iand iTechnology i Page i20


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

4.3.2 i iMovements i
i The iscripting ifor ithe iplayer idevelopments iwere idone iin i"PlayerController" icontent. iIn ithis
i content, i the i principle i class i "PlayerController" i was i gotten i from i base i class
i "CharacterComponents". i"CharacterComponents" ihas itwo iinferred iclasses, ione ibeing
i "PlayerController" iand ithe iother i"EnemyController", iwhich iI iwill iclarify ilater iin ithe iEnemy
i developments isegment. iNote ithat ithe i"CharacterComponents" iclass iis igoing iabout ias ia ibase iclass
i and iits iinferred iclasses iare ijoined ito ithe iGameObjects. i

As ithis iis ia iside-looking iover i2D igame, ithe iplayer iis iconfined idistinctly ito imove ievenly.
iIt iis ilikewise iincluded ifor ithe iplayer ito iincrease ivertical istature ithrough ihopping. iThe
idevelopments iin ithe icontent iare ifinished iby igetting ito ithe ispeed iproperty iin
iRigidbody2D. i

GRAPH i8.1. iFor imoving iin ihorizontal idirection iwith ia iconstant ispeed

Chart i8.1 ishows ia ibasic icode, iwhere ithe iplayer imove ion ia ilevel iplane. iThere iare itwo ifactors iin ithe
i line i"PlayerRigidbody" iand i"moveSpeeed". iPlayerRigidbody iis ia iproperty iof itype iRigidBody2D
i in ithe icontent, iwhich igets iand isets ithe irigidbody2D isegment iappended ito ithe iplayer. iBefore
i RigidBody2D itechniques iand iproperties ican ibe icalled iand iutilized iin ithe icontents, iit iis iimportant
i to iset iit iin iStart() istrategy iby iexpressing i"PlayerRigidBody i= iGetComponent<RigidBody2D>();".
i Another ivariable i"moveSpeed", iwhich iis ia ibuoy, iis icalled ifrom iits ibase iclass
i "CharacterComponent". i"Vector2" iis ia isort iin ithe iUnity iEngine, iwhich icontains icoast iesteems iin iX
i and iY icomponents."GetAxis" iis ia istatic itechnique iin i"Info" iclass, iwhich irestores ia ivirtual ipivot
i named i"Flat", iwhere ithe iworth iis ieither i1 ior i- i1. I

Panipat iInstitute iof iEngineering iand iTechnology i Page i21


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

GRAPH i9. iHorizontal iaxis iin iInput iunder iProject isettings


Chart i9 ishows ithat ithere iis ia ipositive iand ia inegative icatch, iwhich idepicts ithat iwhen ithe ileft ibolt iis
i squeezed ithe iworth i- i1 iwill ibe ienlisted iand i1 iwhen isqueezing ithe icorrect ibolt. iAccordingly, iat
i whatever ipoint ithe iideal ikey iis iinput, iregardless iof iwhether iit iis ithe ileft ibolt ior ithe icorrect ibolt ior
i an iand id, ithe ispeed iin ithe iRigidBody2D iinterprets ithe iX iposition iof ithe iplayer iby i1 ior i- i1 iand
i duplicates iit iby ithe i"moveSpeed" iesteem iwithout ichanging ithe iY iposition. iMoreover, iwhen ithe
i worth iis i1, ithe iplayer iought ito iconfront iright iand ikeeping iin imind ithat ithe iworth iis i- i1, iit iought ito
i confront ileft. I

GRAPH i10. i"ChangingDirection" ifunction ifrom i"CharacterComponents" iscript

Panipat iInstitute iof iEngineering iand iTechnology i Page i22


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

GRAPH i11. i"TurnPlayer" ifunction ifrom i"PlayerController" iscript

In idiagram i10, ithe i"changingDirection()" istrategy iis iwritten iin ithe ibase iclass iwith ithe igoal ithat iboth
i determined iclasses ican iutilize ia isimilar icode. iHere ia ivirtual icatchphrase iis iutilized, iwith ithe igoal
i that ia isimilar icapacity ican ibe isuperseded iin iinferred iclasses, ion ithe ioff ichance ithat iit iis irequired. iIt
i is iessential ithat iall ithe iinferred iclasses iought ito iacquire ievery isingle ibase iclass istrategies. iWithout
i a ivirtual iwatchword, isuperseding iis iimpossible. iIn ithe idiagram, i"facingRight" iis igoing iabout ias ia
i Boolean ivariable, iwhich ijust ireturns ieither iobvious ior ibogus. iIn ithis iway, iin ithe ievent ithat ithe
i player icharacter's iX iposition iis isure, iat ithat ipoint i"facingRight" iis ivalid; ielse, iit iis ibogus i.So iwhen
i the icondition iin ithe iif iexplanation iis ivalid, ichangeDirection() iwill ibe iexecuted iand ithe iplayer iwill
i confront ithe isuitable iheading. iIn idiagram i12 iline i209, iwhen ithe iestimation iof iflat iinformation iis i-
i 1 iand ithe iplayer iis iconfronting iright ior iif ithe iworth iis i1 iand iconfronting ileft, i"changingDirection"
i is icalled. i

Before iincluding ithe ibounce iwork, ithe icharacter iought ito ihave ithe ioption ito iseparate ithe iground
i from idifferent iGameObjects. iTo idecide iif ithe iplayer iis ion ithe iground ior inot, iwe ineed ithree ifactors:
i change iexhibit iof inumerous iground ifocuses, icoast ifor igiving ithose ifocuses ia ispan iand iLayerMask
i to icharacterize iwhich iGameObject iis ithe iground. iFor ithe iTransform iexhibit, imake ithe ifundamental
i measure iof ivoid iGameObjects iand imake ithem ioffspring iof ithe iplayer. iThese ifocuses iought ito ibe
i situated iat iplayer's ifeet iwhere iit ishould icontact ithe iground. iLayer iMask ijust iaccepts ia ilayer ias iits
i chose ichoice. iAt ithe ipoint iwhen ia iGameObject iis ichosen, ion ithe iupper iright icorner iin ithe iInspector
i View, ithere iis ian ialternative inamed ilayer. iIt iis iconceivable ito idecide ia ispecific ilayer ifor ia
i GameObject ior ito iinclude ianother ilayer. iIn ithe igame, iI iutilized i"ground" ias ilayer iname ifor imy
i ground icolliders. i

Since ithe iplayer icomprehends iwhich ilayer iis ithe iground, iit iturns iout ito ibe ia ilot isimpler ito iadd
i bounce icapacity ito iit. iSince iit iwould ibe ifairly iridiculous ito ibounce iwithout iremaining ion ia istrong
i surface. iTo iinclude ibounce iis inearly iequivalent ito imoving. iRather ithan iadding ispeed ito ithe iX ipart,
i we ishould iadd iit ito ithe iY isegment. iObviously, ia ibuoy ivariable iis irequired ito iexpress ithe ibounce
i separation. I

Panipat iInstitute iof iEngineering iand iTechnology i Page i23


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

GRAPH 13. Adding velocity to the player's Y component

GRAPH i14. iFixedUpdate ifunction iin i"BasicEnemyController"

Chart i14 ishows ian iif-proclamation, iat iwhatever ipoint ithe ispacebar ion ithe iconsole iis isqueezed iand
i the iplayer iis ion ithe iground, ithe ispeed iof ithe iplayer icharacter's iY isegment iis ichanged iby ithe
i estimation iof i"jumpHeight". iA isound idocument iis ilikewise iappended iand iis iplayed iany iplace ithe
i player ihops iand ithe ihop iactivity iis iset ito itrigger.

Panipat iInstitute iof iEngineering iand iTechnology i Page i24


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

The iscripting ifor ithe iplayer idevelopments iwere idone iin i"PlayerController" icontent. iIn ithis icontent,
i the iprinciple iclass i"PlayerController" iwas igotten ifrom ibase iclass i"CharacterComponents".
i "CharacterComponents" ihas itwo iinferred iclasses, ione ibeing i"PlayerController" iand ithe iother
i "EnemyController", iwhich iI iwill iclarify ilater iin ithe iEnemy idevelopments isegment. iNote ithat ithe
i "CharacterComponents" iclass iis igoing iabout ias ia ibase iclass iand iits iinferred iclasses iare ijoined ito
i the iGameObjects. i

As ithis iis ia iside-looking iover i2D igame, ithe iplayer iis iconfined idistinctly ito imove ievenly. iIt iis
i likewise iincluded ifor ithe iplayer ito iincrease ivertical istature ithrough ihopping. iThe idevelopments iin
i the icontent iare ifinished iby igetting ito ithe ispeed iproperty iin iRigidbody2D. i

4.4 Enemy
Each icharacter ihas ivarious iactivitys iand idevelopments. iThe i"Green" iis ithe ifundamental ifoe iwith
i straightforward idevelopments istarting iwith ione ipoint ithen ionto ithe inext. iThey ihave icolliders
i appended ito ithem iand ithese iare iset ias itriggers. iAt iwhatever ipoint ithe iplayer icharacter islams iinto iit,
i the iplayer iloses iits iwellbeing. iOther ithan icolliders, iRigidbody2D iand ian iillustrator iare iadditionally
i connected ito iit. iIt iadditionally ihas itwo iGameObjects ias iyoungsters, iwhich icheck iif ithe icharacter iis
i on ithe iground ior iapproach ian iedge. i

The iBoolean ifactors i"wallHit" iand i"atGround" iin iGraph i41, iline i31, icheck iif ithe ihover iin iVector3
i positions iare icovering iwith ithe iLayerMask ivariable, iwhich iis i"whatIsWall". iHere i"whatIsWall" iis
i set ito ithe iground ilayer iin ithe igame. iSo ion ithe ioff ichance ithat iit iis icovering, iat ithat ipoint ithe ifactors
i return igenuine. iIn iline i35, iif ithe iannouncement iexpresses, ithat iif ithe icharacter iis icrashing iinto ithe
i divider ior iisn't icovering iwith ithe iground ilayer, iat ithat ipoint i"moveRight", iwhich iis ia iBoolean
i variable, iisn't i"moveRight". iIt iimplies iif i"moveRight" iwere ivalid, iit iwould ireturn ibogus, iand ithe
i other iway iaround. iIn iline i40 ithe iif-else iexplanation idirects ithe iuprooting iof ithe icharacter. iIn ilines
i 42 iand i48 i"transform.localscale" idecides iif ithe icharacter ishould ilook itowards ithe ileft ior ithe iright,
i and ilines i43 iand i49 icharacterize ithe ispeed iwith iwhich ithe icharacter iwill imove. iHere i"foe" iis ithe
i Rigidbody isegment iand i"moveSpeed" iis ia ibuoy ivariable. iThe icharacter ihas ia isolitary iwalk
i movement iand iit iis iset ito idefault.

Panipat iInstitute iof iEngineering iand iTechnology i Page i25


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

Each icharacter ihas ivarious iactivitys iand idevelopments. iThe i"Green" iis ithe ifundamental ifoe iwith
i straightforward idevelopments istarting iwith ione ipoint ithen ionto ithe inext. iThey ihave icolliders
i appended ito ithem iand ithese iare iset ias itriggers. iAt iwhatever ipoint ithe iplayer icharacter islams iinto iit,
i the iplayer iloses iits iwellbeing. iOther ithan icolliders, iRigidbody2D iand ian iillustrator iare iadditionally
i connected ito iit. iIt iadditionally ihas itwo iGameObjects ias iyoungsters, iwhich icheck iif ithe icharacter iis
i on ithe iground ior iapproach ian iedge. i

The iBoolean ifactors i"wallHit" iand i"atGround" iin iGraph i41, iline i31, icheck iif ithe ihover iin iVector3
i positions iare icovering iwith ithe iLayerMask ivariable, iwhich iis i"whatIsWall". iHere i"whatIsWall" iis
i set ito ithe iground ilayer iin ithe igame. iSo ion ithe ioff ichance ithat iit iis icovering, iat ithat ipoint ithe ifactors
i return igenuine. iIn iline i35, iif ithe iannouncement iexpresses, ithat iif ithe icharacter iis icrashing iinto ithe
i divider ior iisn't icovering iwith ithe iground ilayer, iat ithat ipoint i"moveRight", iwhich iis ia iBoolean
i variable, iisn't i"moveRight". iIt iimplies iif i"moveRight" iwere ivalid, iit iwould ireturn ibogus, iand ithe
i other iway iaround. iIn iline i40 ithe iif-else iexplanation idirects ithe iuprooting iof ithe icharacter. iIn ilines
i 42 iand i48 i"transform.localscale" idecides iif ithe icharacter ishould ilook itowards ithe ileft ior ithe iright,
i and ilines i43 iand i49 icharacterize ithe ispeed iwith iwhich ithe icharacter iwill imove. iHere i"foe" iis ithe
i Rigidbody isegment iand i"moveSpeed" iis ia ibuoy ivariable. iThe icharacter ihas ia isolitary iwalk
i movement iand iit iis iset ito idefault.

4.5 UI iCanvas
The iCanvas iis ia irectangular ispace iin iUnity's iScene iview, iwhere iall ithe iUI ielements iare iplaced. iUI
i elements iinclude iimages, itext, isliders, ibuttons, iinput ifields. iIn ithe iHierarchy iwindow, iCanvas iis ia
i GameObject iand iUI ielements ishould ibe ichildren iof ithe icanvas iin iorder ito iprocess ithem. iWhenever
i a iCanvas iis icreated, ian iEventSystem iis ialso icreated iat ithe isame itime, ias ithe iCanvas iuses iit ifor
i messaging ithe isystem. iBasically, ithe iCanvas imakes ithe igame imore iinteractive, ias iit idisplays
i various itexts, ican ishow ithe iplayer's ihealth, ipoints iand imany imore. iTo icreate ia icanvas, isimply
i right-click ion ithe iHierarchy iwindow ithen iselect iUI i> iCanvas.

4.6 Building the Game


For ithe imotivations ibehind itesting ithe ifull igame ias ia idifferent iapplication, iit iis irequired ito
i construct iit ifirst. iIn iUnity iit iis ivery ieasy ito imanufacture ia igame, ijust iby iclicking iconstruct iand irun
i alternatives iin ithe iFiletab. iAll ithe ivital iscenes iought ito ibe iembedded iin iScenes iin ithe iBuild

Panipat iInstitute iof iEngineering iand iTechnology i Page i26


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

i window ibefore ibuilding ithe igame, ias iappeared iin iGraph i67. iThrough ithis iwindow iit iis iconceivable
i to iassemble ithe igame ifor ivarious istages iand iframeworks, ifor iexample, iPC, iiOS ior iAndroid. iThe
i symbol iand ithe iname iof ithe iapplication ican ilikewise ibe itransformed ifrom ithe iplayer isettings, iin ithe
i base ileft icorner iof ithe iwindow. iAfter ievery ione iof ithe iscenes iare iembedded, ijust iclick iconstruct
i and irun. iIn ithe iwake iof ibuilding ithe iprogram iis idone, ianybody ican iplay ithe igame ithat ihas ibeen
i made.

Panipat iInstitute iof iEngineering iand iTechnology i Page i27


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 5: CODING i i

5.1 iGame Controller


using iPlatformer.Core;
using iPlatformer.Model;
using iUnityEngine;

namespace iPlatformer.Mechanics
{
i i/// i<summary>

i i/// iThis iclass iexposes ithe igame i model iin ithe iinspector, iand iticks ithe

i i/// isimulation.

i i/// i</summary> i

i ipublic iclass iGameController i: iMonoBehaviour

i i{

i ipublic istatic iGameController iInstance i{ iget; iprivate iset; i}

i i //This imodel ifield iis ipublic iand ican ibe itherefore ibe imodified iin ithe i
ii //inspector.
i i i i i i//The ireference iactually icomes ifrom ithe iInstanceRegister, iand iis ishared

i i i i i i i i//through ithe isimulation iand ievents. iUnity i will ideserialize iover ithis

i i i i i i i i//shared ireference iwhen ithe iscene iloads, iallowing ithe imodel ito ibe

i i i i i i i i//conveniently iconfigured iinside ithe iinspector.

i i i i i i i ipublic iPlatformerModel imodel i= iSimulation.GetModel<PlatformerModel>();

iiiiiiii void iOnEnable()


iiiiiiii {
i i i i i i i i i i i iInstance i= ithis;

i i i i i i i i}

iiiiiiii void iOnDisable()


iiiiiiii {
i i i i i i i i i i i iif i(Instance i== ithis) iInstance i= inull;

i i i i i i i i}

iiiiiiii void iUpdate()


iiiiiiii {
i i i i i i i i i i i iif i(Instance i== ithis) iSimulation.Tick();

i i i i i i i i}

i i i i}

5.2 iToken Controller


using iUnityEngine;

namespace iPlatformer.Mechanics
{
i i i i/// i<summary>

i i i i/// iThis iclass ianimates iall itoken iinstances iin ia iscene.

Panipat iInstitute iof iEngineering iand iTechnology i Page i28


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiii /// iThis iallows ia isingle iupdate icall ito ianimate ihundreds iof isprite i
iiii /// ianimations.
i i i i/// iIf ithe itokens iproperty iis iempty, iit i will iautomatically ifind iand iload i

i i i i/// iall itoken iinstances iin ithe iscene iat iruntime.

i i i i/// i</summary>

i i i ipublic iclass iTokenController i: iMonoBehaviour

i i i i{

i i i i i i i i[Tooltip("Frames iper isecond iat iwhich itokens iare ianimated.")]

i i i i i i i ipublic ifloat iframeRate i= i12;

i i i i i i i i[Tooltip("Instances iof itokens i which iare ianimated. iIf iempty, itoken iinstances iare ifound iand iloaded iat

iruntime.")]

i i i i i i i ipublic iTokenInstance[] itokens;

iiiiiiii float inextFrameTime i= i0;

iiiiiiii [ContextMenu("Find iAll iTokens")]


iiiiiiii void iFindAllTokensInScene()
i i i i i i i i{

i i i i i i i i i i i itokens i= iUnityEngine.Object.FindObjectsOfType<TokenInstance>();

i i i i i i i i}

iiiiiiii void iAwake()


iiiiiiii {
i i i i i i i i i i i i//if itokens iare iempty, ifind iall iinstances.

i i i i i i i i i i i i//if itokens iare inot iempty, ithey've ibeen iadded iat ieditor itime.

i i i i i i i i i i i iif i(tokens.Length i== i0)

i i i i i i i i i i i i i i i iFindAllTokensInScene();

i i i i i i i i i i i i//Register iall itokens iso ithey ican i work i with ithis icontroller.

i i i i i i i i i i i ifor i(var ii i= i0; ii i< itokens.Length; ii++)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i itokens[i].tokenIndex i= ii;

i i i i i i i i i i i i i i i itokens[i].controller i= ithis;

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii void iUpdate()


iiiiiiii {
i i i i i i i i i i i i//if iit's itime ifor ithe inext iframe...

i i i i i i i i i i i iif i(Time.time i- inextFrameTime i> i(1f i/ iframeRate))

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i//update iall itokens iwith ithe inext ianimation iframe.

i i i i i i i i i i i i i i i ifor i(var ii i= i0; ii i< itokens.Length; ii++)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i ivar itoken i= itokens[i];

i i i i i i i i i i i i i i i i i i i i//if itoken iis inull, iit ihas ibeen idisabled iand iis ino ilonger ianimated.

i i i i i i i i i i i i i i i i i i i iif i(token i!= inull)

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i itoken._renderer.sprite i= itoken.sprites[token.frame];

i i i i i i i i i i i i i i i i i i i i i i i iif i(token.collected i&& itoken.frame i== itoken.sprites.Length i- i1)

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i itoken.gameObject.SetActive(false);

i i i i i i i i i i i i i i i i i i i i i i i i i i i itokens[i] i= inull;

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i ielse

Panipat iInstitute iof iEngineering iand iTechnology i Page i29


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiiiiiiiiiii {
iiiiiiiiiiiiiiiiiiiiiiiiiiii token.frame i= i(token.frame i+ i1) i% itoken.sprites.Length;
iiiiiiiiiiiiiiiiiiiiiiii }
iiiiiiiiiiiiiiiiiiii }
iiiiiiiiiiiiiiii }
i i i i i i i i i i i i i i i i//calculate ithe itime iof ithe inext iframe.

i i i i i i i i i i i i i i i inextFrameTime i+= i1f i/ iframeRate;

i i i i i i i i i i i i}

i i i i i i i i}

iiii }
}

5.3 iMeta Game Controller


using iUnityEngine;

namespace iPlatformer.Mechanics
{
i i i i/// i<summary>

i i i i/// iThis iclass ianimates iall itoken iinstances iin ia iscene.

i i i i/// iThis iallows ia isingle iupdate icall ito ianimate ihundreds iof isprite i

i i i i/// ianimations.

i i i i/// iIf ithe itokens iproperty iis iempty, iit i will iautomatically ifind iand iload i

i i i i/// iall itoken iinstances iin ithe iscene iat iruntime.

i i i i/// i</summary>

i i i ipublic iclass iTokenController i: iMonoBehaviour

i i i i{

i i i i i i i i[Tooltip("Frames iper isecond iat iwhich itokens iare ianimated.")]

i i i i i i i ipublic ifloat iframeRate i= i12;

i i i i i i i i[Tooltip("Instances iof itokens i which iare ianimated. iIf iempty, itoken iinstances iare ifound iand iloaded iat

iruntime.")]

i i i i i i i ipublic iTokenInstance[] itokens;

iiiiiiii float inextFrameTime i= i0;

iiiiiiii [ContextMenu("Find iAll iTokens")]


iiiiiiii void iFindAllTokensInScene()
i i i i i i i i{

i i i i i i i i i i i itokens i= iUnityEngine.Object.FindObjectsOfType<TokenInstance>();

i i i i i i i i}

iiiiiiii void iAwake()


iiiiiiii {
i i i i i i i i i i i i//if itokens iare iempty, ifind iall iinstances.

i i i i i i i i i i i i//if itokens iare inot iempty, ithey've ibeen iadded iat ieditor itime.

i i i i i i i i i i i iif i(tokens.Length i== i0)

i i i i i i i i i i i i i i i iFindAllTokensInScene();

i i i i i i i i i i i i//Register iall itokens iso ithey ican i work i with ithis icontroller.

i i i i i i i i i i i ifor i(var ii i= i0; ii i< itokens.Length; ii++)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i itokens[i].tokenIndex i= ii;

i i i i i i i i i i i i i i i itokens[i].controller i= ithis;

Panipat iInstitute iof iEngineering iand iTechnology i Page i30


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii }
iiiiiiii }

iiiiiiii void iUpdate()


iiiiiiii {
i i i i i i i i i i i i//if iit's itime ifor ithe inext iframe...

i i i i i i i i i i i iif i(Time.time i- inextFrameTime i> i(1f i/ iframeRate))

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i//update iall itokens iwith ithe inext ianimation iframe.

i i i i i i i i i i i i i i i ifor i(var ii i= i0; ii i< itokens.Length; ii++)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i ivar itoken i= itokens[i];

i i i i i i i i i i i i i i i i i i i i//if itoken iis inull, iit ihas ibeen idisabled iand iis ino ilonger ianimated.

i i i i i i i i i i i i i i i i i i i iif i(token i!= inull)

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i itoken._renderer.sprite i= itoken.sprites[token.frame];

i i i i i i i i i i i i i i i i i i i i i i i iif i(token.collected i&& itoken.frame i== itoken.sprites.Length i- i1)

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i itoken.gameObject.SetActive(false);

i i i i i i i i i i i i i i i i i i i i i i i i i i i itokens[i] i= inull;

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i itoken.frame i= i(token.frame i+ i1) i% itoken.sprites.Length;

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i//calculate ithe itime iof ithe inext iframe.

i i i i i i i i i i i i i i i inextFrameTime i+= i1f i/ iframeRate;

i i i i i i i i i i i i}

i i i i i i i i}

iiii }
}

5.4 iJiggler
using iSystem.Collections;
using iSystem.Collections.Generic;
using iUnityEngine;

public iclass iJiggler i: iMonoBehaviour


{
i i i i[Range(0, i1)]

i i i ipublic ifloat ipower i= i.1f;

iiii [Header("Position iJiggler")]


iiii public ibool ijigPosition i= itrue;
i i i ipublic iVector3 ipositionJigAmount;

i i i i[Range(0, i120)]

i i i ipublic ifloat ipositionFrequency i= i10;

i i i ifloat ipositionTime;

Panipat iInstitute iof iEngineering iand iTechnology i Page i31


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiii [Header("Rotation iJiggler")]


iiii public ibool ijigRotation i= itrue;
i i i ipublic iVector3 irotationJigAmount;

i i i i[Range(0, i120)]

i i i ipublic ifloat irotationFrequency i= i10;

i i i ifloat irotationTime;

iiii [Header("Scale iJiggler")]


iiii public ibool ijigScale i= itrue;
i i i ipublic iVector3 iscaleJigAmount i= inew iVector3(.1f, i-.1f, i.1f);

i i i i[Range(0, i120)]

i i i ipublic ifloat iscaleFrequency i= i10;

i i i ifloat iscaleTime;

iiii Vector3 ibasePosition;


iiii Quaternion ibaseRotation;
i i i iVector3 ibaseScale;

iiii void iStart(){


iiiiiiii basePosition i= ithis.transform.localPosition;
i i i i i i i ibaseRotation i= ithis.transform.localRotation;

i i i i i i i ibaseScale i= ithis.transform.localScale;

i i i i}

iiii // iUpdate iis icalled ionce iper iframe


iiii void iUpdate()
i i i i{

i i i i i i i ivar idt i= iTime.deltaTime;

i i i i i i i ipositionTime i+= idt i* ipositionFrequency;

i i i i i i i irotationTime i+= idt i* irotationFrequency;

i i i i i i i iscaleTime i+= idt i* iscaleFrequency;

iiiiiiii this.transform.localPosition i= ibasePosition i+ ipositionJigAmount i* iMathf.Sin(positionTime) i* ipower;


iiiiiiii this.transform.localRotation i= ibaseRotation i* iQuaternion.Euler(rotationJigAmount i* iMathf.Sin(positionTime)
i* ipower);

i i i i i i i ithis.transform.localScale i= ibaseScale i+ iscaleJigAmount i* iMathf.Sin(scaleTime) i* ipower;

i i i i}

5.5 iMain UIiController


using iSystem.Collections;
using iSystem.Collections.Generic;
using iUnityEngine;

namespace iPlatformer.UI
{
i i i i/// i<summary>

i i i i/// iA isimple icontroller ifor iswitching ibetween iUI ipanels.

i i i i/// i</summary>

i i i ipublic iclass iMainUIController i: iMonoBehaviour

i i i i{

i i i i i i i ipublic iGameObject[] ipanels;

Panipat iInstitute iof iEngineering iand iTechnology i Page i32


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii public ivoid iSetActivePanel(int iindex)


iiiiiiii {
i i i i i i i i i i i ifor i(var ii i= i0; ii i< ipanels.Length; ii++)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i ivar iactive i= ii i== iindex;

i i i i i i i i i i i i i i i ivar ig i= ipanels[i];

i i i i i i i i i i i i i i i iif i(g.activeSelf i!= iactive) ig.SetActive(active);

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii void iOnEnable()


iiiiiiii {
i i i i i i i i i i i iSetActivePanel(0);

i i i i i i i i}

i i i i}

5.6 iCine Machine Brain


using iCinemachine.Utility;
using iSystem;
using iSystem.Collections;
using iSystem.Collections.Generic;
using iUnityEngine;
using iUnityEngine.Events;

namespace iCinemachine
{
i i i i/// i<summary>

i i i i/// iCinemachineBrain iis ithe ilink ibetween ithe iUnity iCamera iand ithe iCinemachine iVirtual

i i i i/// iCameras iin ithe iscene. i iIt imonitors ithe ipriority istack ito ichoose ithe icurrent

i i i i/// iVirtual iCamera, iand iblend i with ianother iif inecessary. i iFinally iand imost iimportantly,

i i i i/// iit iapplies ithe iVirtual iCamera istate ito ithe iattached iUnity iCamera.

i i i i///

i i i i/// iThe iCinemachineBrain iis ialso ithe iplace iwhere irules ifor iblending ibetween ivirtual icameras

i i i i/// iare idefined. i iCamera iblending iis ian iinterpolation iover itime iof ione ivirtual icamera

i i i i/// iposition iand istate ito ianother. iIf iyou ithink iof ivirtual icameras ias icameramen, ithen

i i i i/// iblending iis ia ilittle ilike ione icameraman ismoothly ipassing ithe icamera ito ianother icameraman.

i i i i/// iYou ican ispecify ithe itime iover iwhich ito iblend, ias iwell ias ithe iblend icurve ishape.

i i i i/// iNote ithat ia icamera icut iis ijust ia izero-time iblend.

i i i i/// i</summary>

i i i i[DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]

// i i i i[RequireComponent(typeof(Camera))] i// istrange ibut itrue: iwe ican ilive iwithout iit
i i i i[DisallowMultipleComponent]

#if iUNITY_2018_3_OR_NEWER
i i i i[ExecuteAlways]

#else
i i i i[ExecuteInEditMode]

#endif
i i i i[AddComponentMenu("Cinemachine/CinemachineBrain")]

i i i i[SaveDuringPlay]

i i i ipublic iclass iCinemachineBrain i: iMonoBehaviour

Panipat iInstitute iof iEngineering iand iTechnology i Page i33


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiii {
iiiiiiii /// i<summary>
iiiiiiii /// iWhen ienabled, ithe icurrent icamera iand iblend iwill ibe iindicated iin ithe igame iwindow, ifor idebugging.
i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("When ienabled, ithe icurrent icamera iand iblend iwill ibe iindicated iin ithe igame iwindow, ifor idebugging")]

i i i i i i i ipublic ibool im_ShowDebugText i= ifalse;

iiiiiiii /// i<summary>


iiiiiiii /// iWhen ienabled, ishows ithe icamera's ifrustum iin ithe iscene iview.
i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("When ienabled, ithe icamera's ifrustum i will ibe ishown iat iall itimes iin ithe iscene iview")]

i i i i i i i ipublic ibool im_ShowCameraFrustum i= itrue;

iiiiiiii /// i<summary>


iiiiiiii /// iWhen ienabled, ithe icameras iwill ialways irespond iin ireal-time ito iuser iinput iand idamping,
i i i i i i i i/// ieven iif ithe igame iis irunning iin islow i motion

i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("When ienabled, ithe icameras i will ialways irespond iin ireal-time ito iuser iinput iand idamping, ieven iif ithe

igame iis irunning iin islow i motion")]

i i i i i i i ipublic ibool im_IgnoreTimeScale i= ifalse;

iiiiiiii /// i<summary>


iiiiiiii /// iIf iset, ithis iobject's iY iaxis iwill idefine ithe iworldspace iUp ivector ifor iall ithe
i i i i i i i i/// ivirtual icameras. i iThis iis iuseful iin itop-down igame ienvironments. i iIf inot iset, iUp iis iworldspace iY.

i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("If iset, ithis iobject's iY iaxis iwill idefine ithe i worldspace iUp ivector ifor iall ithe ivirtual icameras. i iThis iis

iuseful ifor iinstance iin itop-down igame ienvironments. i iIf inot iset, iUp iis i worldspace iY. i iSetting ithis iappropriately iis

iimportant, ibecause iVirtual iCameras idon't ilike ilooking istraight iup ior istraight idown.")]

i i i i i i i ipublic iTransform i m_WorldUpOverride;

iiiiiiii /// i<summary>This ienum idefines ithe ioptions iavailable ifor ithe iupdate imethod.</summary>
iiiiiiii [DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]
i i i i i i i ipublic ienum iUpdateMethod

i i i i i i i i{

i i i i i i i i i i i i/// i<summary>Virtual icameras iare iupdated iin isync iwith ithe iPhysics imodule, iin iFixedUpdate</summary>

i i i i i i i i i i i iFixedUpdate,

i i i i i i i i i i i i/// i<summary>Virtual icameras iare iupdated iin iMonoBehaviour iLateUpdate.</summary>

i i i i i i i i i i i iLateUpdate,

i i i i i i i i i i i i/// i<summary>Virtual icameras iare iupdated iaccording ito ihow ithe itarget iis iupdated.</summary>

i i i i i i i i i i i iSmartUpdate

i i i i i i i i};

iiiiiiii /// i<summary>Depending ion ihow ithe itarget iobjects iare ianimated, iadjust ithe iupdate imethod ito
iiiiiiii /// iminimize ithe ipotential ijitter. i iUse iFixedUpdate iif iall iyour itargets iare ianimated iwith ifor iRigidBody
ianimation.

i i i i i i i i/// iSmartUpdate iwill ichoose ithe ibest imethod ifor ieach ivirtual icamera, idepending

i i i i i i i i/// ion ihow ithe itarget iis ianimated.</summary>

i i i i i i i i[Tooltip("Use iFixedUpdate iif iall iyour itargets iare ianimated iduring iFixedUpdate i(e.g. iRigidBodies),

iLateUpdate iif iall iyour itargets iare ianimated iduring ithe inormal iUpdate iloop, iand iSmartUpdate iif iyou i want

iCinemachine ito ido ithe iappropriate ithing ion ia iper-target ibasis. i iSmartUpdate iis ithe irecommended isetting")]

i i i i i i i ipublic iUpdateMethod im_UpdateMethod i= iUpdateMethod.SmartUpdate;

iiiiiiii /// i<summary>


iiiiiiii /// iThe iblend iwhich iis iused iif iyou idon't iexplicitly idefine ia iblend ibetween itwo iVirtual iCameras.

Panipat iInstitute iof iEngineering iand iTechnology i Page i34


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii /// i</summary>


iiiiiiii [CinemachineBlendDefinitionProperty]
i i i i i i i i[Tooltip("The iblend ithat iis iused iin icases iwhere iyou ihaven't iexplicitly idefined ia iblend ibetween itwo iVirtual

iCameras")]

i i i i i i i ipublic iCinemachineBlendDefinition i m_DefaultBlend

i i i i i i i i i i i i= inew iCinemachineBlendDefinition(CinemachineBlendDefinition.Style.EaseInOut, i2f);

iiiiiiii /// i<summary>


iiiiiiii /// iThis iis ithe iasset iwhich icontains icustom isettings ifor ispecific iblends.
i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("This iis ithe iasset ithat icontains icustom isettings ifor iblends ibetween ispecific ivirtual icameras iin iyour

iscene")]

i i i i i i i ipublic iCinemachineBlenderSettings i m_CustomBlends i= inull;

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe iUnity iCamera ithat iis iattached ito ithis iGameObject. i iThis iis ithe icamera
i i i i i i i i/// ithat i will ibe icontrolled iby ithe ibrain.

i i i i i i i i/// i</summary>

i i i i i i i ipublic iCamera iOutputCamera

i i i i i i i i{

i i i i i i i i i i i iget

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(m_OutputCamera i== inull i&& i!Application.isPlaying)

i i i i i i i i i i i i i i i i i i i im_OutputCamera i= iGetComponent<Camera>();

i i i i i i i i i i i i i i i ireturn im_OutputCamera;

i i i i i i i i i i i i}

i i i i i i i i}

i i i i i i i iprivate iCamera im_OutputCamera i= inull; i// inever iuse idirectly i- iuse iaccessor

iiiiiiii /// i<summary>Event iwith ia iCinemachineBrain iparameter</summary>


iiiiiiii [Serializable] ipublic iclass iBrainEvent i: iUnityEvent<CinemachineBrain> i{}

iiiiiiii /// i<summary>Event iwith ia iICinemachineCamera iparameter</summary>


iiiiiiii [Serializable] ipublic iclass iVcamActivatedEvent i: iUnityEvent<ICinemachineCamera, iICinemachineCamera>
i {}

iiiiiiii /// i<summary>This ievent iwill ifire iwhenever ia ivirtual icamera igoes ilive iand ithere iis ino iblend</summary>
iiiiiiii [Tooltip("This ievent iwill ifire iwhenever ia ivirtual icamera igoes ilive iand ithere iis ino iblend")]
i i i i i i i ipublic iBrainEvent i m_CameraCutEvent i= inew iBrainEvent();

iiiiiiii /// i<summary>This ievent iwill ifire iwhenever ia ivirtual icamera igoes ilive. i iIf ia iblend iis iinvolved,
iiiiiiii /// ithen ithe ievent iwill ifire ion ithe ifirst iframe iof ithe iblend</summary>
i i i i i i i i[Tooltip("This ievent i will ifire iwhenever ia ivirtual icamera igoes ilive. i iIf ia iblend iis iinvolved, ithen ithe ievent i will

ifire ion ithe ifirst iframe iof ithe iblend.")]

i i i i i i i ipublic iVcamActivatedEvent i m_CameraActivatedEvent i= inew iVcamActivatedEvent();

iiiiiiii /// i<summary>


iiiiiiii /// iAPI ifor ithe iUnity iEditor.
i i i i i i i i/// iShow ithis icamera ino imatter i what. i iThis iis istatic, iand iso iaffects iall iCinemachine ibrains.

i i i i i i i i/// i</summary>

i i i i i i i ipublic istatic iICinemachineCamera iSoloCamera

i i i i i i i i{

i i i i i i i i i i i iget i{ ireturn i mSoloCamera; i}

i i i i i i i i i i i iset

Panipat iInstitute iof iEngineering iand iTechnology i Page i35


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii {
iiiiiiiiiiiiiiii if i(value i!= inull i&& i!CinemachineCore.Instance.IsLive(value))
iiiiiiiiiiiiiiiiiiii value.OnTransitionFromCamera(null, iVector3.up, iTime.deltaTime);
i i i i i i i i i i i i i i i imSoloCamera i= ivalue;

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii /// i<summary>API ifor ithe iUnity iEditor.</summary>


iiiiiiii /// i<returns>Color iused ito iindicate ithat ia icamera iis iin iSolo imode.</returns>
i i i i i i i ipublic istatic iColor iGetSoloGUIColor() i{ ireturn iColor.Lerp(Color.red, iColor.yellow, i0.8f); i}

iiiiiiii /// i<summary>Get ithe idefault iworld iup ifor ithe ivirtual icameras.</summary>
iiiiiiii public iVector3 iDefaultWorldUp
i i i i i i i i i i i i{ iget i{ ireturn i(m_WorldUpOverride i!= inull) i? im_WorldUpOverride.transform.up i: iVector3.up; i} i}

iiiiiiii private istatic iICinemachineCamera imSoloCamera;


iiiiiiii private iCoroutine imPhysicsCoroutine;

iiiiiiii private ivoid iOnEnable()


iiiiiiii {
i i i i i i i i i i i i// iMake isure ithere iis ia ifirst istack iframe

i i i i i i i i i i i iif i(mFrameStack.Count i== i0)

i i i i i i i i i i i i i i i imFrameStack.Add(new iBrainFrame());

iiiiiiiiiiii m_OutputCamera i= iGetComponent<Camera>();


iiiiiiiiiiii CinemachineCore.Instance.AddActiveBrain(this);
i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers i-= iOnGuiHandler;

i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers i+= iOnGuiHandler;

iiiiiiiiiiii // iWe icheck iin iafter ithe iphysics isystem ihas ihad ia ichance ito imove ithings
iiiiiiiiiiii mPhysicsCoroutine i= iStartCoroutine(AfterPhysics());
iiiiiiii }

iiiiiiii private ivoid iOnDisable()


iiiiiiii {
i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers i-= iOnGuiHandler;

i i i i i i i i i i i iCinemachineCore.Instance.RemoveActiveBrain(this);

i i i i i i i i i i i imFrameStack.Clear();

i i i i i i i i i i i iStopCoroutine(mPhysicsCoroutine);

i i i i i i i i}

iiiiiiii private ivoid iStart()


iiiiiiii {
i i i i i i i i i i i iUpdateVirtualCameras(CinemachineCore.UpdateFilter.Late, i-1f);

i i i i i i i i}

iiiiiiii private ivoid iOnGuiHandler()


iiiiiiii {
i i i i i i i i i i i iif i(!m_ShowDebugText)

i i i i i i i i i i i i i i i iCinemachineDebug.ReleaseScreenPos(this);

i i i i i i i i i i i ielse

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iShow ithe iactive icamera iand iblend

i i i i i i i i i i i i i i i ivar isb i= iCinemachineDebug.SBFromPool();

Panipat iInstitute iof iEngineering iand iTechnology i Page i36


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiii Color icolor i= iGUI.color;


iiiiiiiiiiiiiiii sb.Length i= i0;
i i i i i i i i i i i i i i i isb.Append("CM i");

i i i i i i i i i i i i i i i isb.Append(gameObject.name);

i i i i i i i i i i i i i i i isb.Append(": i");

i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i isb.Append("SOLO i");

i i i i i i i i i i i i i i i i i i i iGUI.color i= iGetSoloGUIColor();

i i i i i i i i i i i i i i i i}

iiiiiiiiiiiiiiii if i(IsBlending)
iiiiiiiiiiiiiiiiiiii sb.Append(ActiveBlend.Description);
i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i iICinemachineCamera ivcam i= iActiveVirtualCamera;

i i i i i i i i i i i i i i i i i i i iif i(vcam i== inull)

i i i i i i i i i i i i i i i i i i i i i i i isb.Append("(none)");

i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i isb.Append("[");

i i i i i i i i i i i i i i i i i i i i i i i isb.Append(vcam.Name);

i i i i i i i i i i i i i i i i i i i i i i i isb.Append("]");

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i istring itext i= isb.ToString();

i i i i i i i i i i i i i i i iRect ir i= iCinemachineDebug.GetScreenPos(this, itext, iGUI.skin.box);

i i i i i i i i i i i i i i i iGUI.Label(r, itext, iGUI.skin.box);

i i i i i i i i i i i i i i i iGUI.color i= icolor;

i i i i i i i i i i i i i i i iCinemachineDebug.ReturnToPool(sb);

i i i i i i i i i i i i}

i i i i i i i i}

#if iUNITY_EDITOR
i i i i i i i iprivate ivoid iOnGUI()

i i i i i i i i{

i i i i i i i i i i i iif i(CinemachineDebug.OnGUIHandlers i!= inull)

i i i i i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers();

i i i i i i i i}

#endif

iiiiiiii WaitForFixedUpdate imWaitForFixedUpdate i= inew iWaitForFixedUpdate();


iiiiiiii private iIEnumerator iAfterPhysics()
i i i i i i i i{

i i i i i i i i i i i iwhile i(true)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iFixedUpdate ican ibe icalled imultiple itimes iper iframe

i i i i i i i i i i i i i i i iyield ireturn imWaitForFixedUpdate;

i i i i i i i i i i i i i i i iif i(m_UpdateMethod i!= iUpdateMethod.LateUpdate)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i iCinemachineCore.UpdateFilter ifilter i= iCinemachineCore.UpdateFilter.Fixed;

i i i i i i i i i i i i i i i i i i i iif i(m_UpdateMethod i== iUpdateMethod.SmartUpdate)

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i// iTrack ithe itargets

Panipat iInstitute iof iEngineering iand iTechnology i Page i37


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiiiiiiiiiii UpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Fixed);
iiiiiiiiiiiiiiiiiiiiiiii filter i= iCinemachineCore.UpdateFilter.SmartFixed;
iiiiiiiiiiiiiiiiiiii }
iiiiiiiiiiiiiiiiiiii UpdateVirtualCameras(filter, iGetEffectiveDeltaTime(true));
iiiiiiiiiiiiiiii }
iiiiiiiiiiii }
iiiiiiii }

iiiiiiii private ivoid iLateUpdate()


iiiiiiii {
i i i i i i i i i i i ifloat ideltaTime i= iGetEffectiveDeltaTime(false);

i i i i i i i i i i i iUpdateFrame0(deltaTime);

i i i i i i i i i i i iUpdateCurrentLiveCameras();

iiiiiiiiiiii if i(m_UpdateMethod i== iUpdateMethod.FixedUpdate)


iiiiiiiiiiii {
i i i i i i i i i i i i i i i i// iSpecial ihandling ifor ifixed iupdate: icameras ithat ihave ibeen ienabled

i i i i i i i i i i i i i i i i// isince ithe ilast iphysics iframe i must ibe iupdated inow

i i i i i i i i i i i i i i i iCinemachineCore.Instance.CurrentUpdateFilter i= iCinemachineCore.UpdateFilter.Fixed;

i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i i i i iSoloCamera.UpdateCameraState(DefaultWorldUp, ideltaTime);

i i i i i i i i i i i i i i i imCurrentLiveCameras.UpdateCameraState(DefaultWorldUp, ideltaTime);

i i i i i i i i i i i i}

i i i i i i i i i i i ielse

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iCinemachineCore.UpdateFilter ifilter i= iCinemachineCore.UpdateFilter.Late;

i i i i i i i i i i i i i i i iif i(m_UpdateMethod i== iUpdateMethod.SmartUpdate)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iTrack ithe itargets

i i i i i i i i i i i i i i i i i i i iUpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Late);

i i i i i i i i i i i i i i i i i i i ifilter i= iCinemachineCore.UpdateFilter.SmartLate;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i iUpdateVirtualCameras(filter, ideltaTime);

i i i i i i i i i i i i}

i i i i i i i i i i i i// iChoose ithe iactive ivcam iand iapply iit ito ithe iUnity icamera

i i i i i i i i i i i iProcessActiveCamera(deltaTime);

i i i i i i i i}

#if iUNITY_EDITOR
i i i i i i i i/// iThis iis ionly ineeded iin ieditor imode ito iforce itimeline ito icall iOnGUI iwhile

i i i i i i i i/// itimeline iis iup iand ithe igame iis inot irunning, iin iorder ito iallow idragging

i i i i i i i i/// ithe icomposer iguide iin ithe igame iview.

i i i i i i i iprivate ivoid iOnPreCull()

i i i i i i i i{

i i i i i i i i i i i iif i(!Application.isPlaying)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iNote: ithis icall iwill icause iany iscreen icanvas iattached ito ithe icamera

i i i i i i i i i i i i i i i i// ito ibe ipainted ione iframe iout iof isync. i iIt iwill ionly ihappen iin ithe ieditor i when inot iplaying.

i i i i i i i i i i i i i i i iProcessActiveCamera(GetEffectiveDeltaTime(false));

i i i i i i i i i i i i}

i i i i i i i i}

#endif

iiiiiiii private ifloat iGetEffectiveDeltaTime(bool ifixedDelta)

Panipat iInstitute iof iEngineering iand iTechnology i Page i38


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii {
iiiiiiiiiiii if i(SoloCamera i!= inull)
iiiiiiiiiiiiiiii return iTime.unscaledDeltaTime;

iiiiiiiiiiii if i(!Application.isPlaying)
iiiiiiiiiiii {
i i i i i i i i i i i i i i i ifor i(int ii i= imFrameStack.Count i- i1; ii i> i0; i--i)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i ivar iframe i= imFrameStack[i];

i i i i i i i i i i i i i i i i i i i iif i(frame.Active)

i i i i i i i i i i i i i i i i i i i i i i i ireturn iframe.TimeOverrideExpired i? i-1 i: iframe.deltaTimeOverride;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i ireturn i-1;

i i i i i i i i i i i i}

i i i i i i i i i i i iif i(m_IgnoreTimeScale)

i i i i i i i i i i i i i i i ireturn ifixedDelta i? iTime.fixedDeltaTime i: iTime.unscaledDeltaTime;

i i i i i i i i i i i ireturn ifixedDelta i? iTime.fixedDeltaTime i: iTime.deltaTime;

i i i i i i i i}

iiiiiiii private ivoid iUpdateVirtualCameras(CinemachineCore.UpdateFilter iupdateFilter, ifloat ideltaTime)


iiiiiiii {
i i i i i i i i i i i i// iWe ialways iupdate iall iactive ivirtual icameras

i i i i i i i i i i i iCinemachineCore.Instance.CurrentUpdateFilter i= iupdateFilter;

i i i i i i i i i i i iCamera icamera i= iOutputCamera;

i i i i i i i i i i i iCinemachineCore.Instance.UpdateAllActiveVirtualCameras(

i i i i i i i i i i i i i i i icamera i== inull i? i-1 i: icamera.cullingMask, iDefaultWorldUp, ideltaTime);

iiiiiiiiiiii // iMake isure iall ilive icameras iget iupdated, iin icase isome iof ithem iare ideactivated
iiiiiiiiiiii if i(SoloCamera i!= inull)
i i i i i i i i i i i i i i i iSoloCamera.UpdateCameraState(DefaultWorldUp, ideltaTime);

i i i i i i i i i i i imCurrentLiveCameras.UpdateCameraState(DefaultWorldUp, ideltaTime);

iiiiiiiiiiii // iRestore ithe ifilter ifor igeneral iuse


iiiiiiiiiiii updateFilter i= iCinemachineCore.UpdateFilter.Late;
i i i i i i i i i i i iif i(Application.isPlaying)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(m_UpdateMethod i== iUpdateMethod.SmartUpdate)

i i i i i i i i i i i i i i i i i i i iupdateFilter i|= iCinemachineCore.UpdateFilter.Smart;

i i i i i i i i i i i i i i i ielse iif i(m_UpdateMethod i== iUpdateMethod.FixedUpdate)

i i i i i i i i i i i i i i i i i i i iupdateFilter i= iCinemachineCore.UpdateFilter.Fixed;

i i i i i i i i i i i i}

i i i i i i i i i i i iCinemachineCore.Instance.CurrentUpdateFilter i= iupdateFilter;

i i i i i i i i}

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe icurrent iactive ivirtual icamera.
i i i i i i i i/// i</summary>

i i i i i i i ipublic iICinemachineCamera iActiveVirtualCamera

i i i i i i i i{

i i i i i i i i i i i iget

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i i i i ireturn iSoloCamera;

i i i i i i i i i i i i i i i ireturn iDeepCamBFromBlend(mCurrentLiveCameras);

Panipat iInstitute iof iEngineering iand iTechnology i Page i39


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii }
iiiiiiii }

iiiiiiii static iICinemachineCamera iDeepCamBFromBlend(CinemachineBlend iblend)


iiiiiiii {
i i i i i i i i i i i iICinemachineCamera ivcam i= iblend.CamB;

i i i i i i i i i i i iwhile i(vcam i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(!vcam.IsValid)

i i i i i i i i i i i i i i i i i i i ireturn inull; i i i i// ideleted!

i i i i i i i i i i i i i i i iBlendSourceVirtualCamera ibs i= ivcam ias iBlendSourceVirtualCamera;

i i i i i i i i i i i i i i i iif i(bs i== inull)

i i i i i i i i i i i i i i i i i i i ibreak;

i i i i i i i i i i i i i i i ivcam i= ibs.Blend.CamB;

i i i i i i i i i i i i}

i i i i i i i i i i i ireturn ivcam;

i i i i i i i i}

iiiiiiii /// i<summary>


iiiiiiii /// iIs ithere ia iblend iin iprogress?
i i i i i i i i/// i</summary>

i i i i i i i ipublic ibool iIsBlending i{ iget i{ ireturn iActiveBlend i!= inull; i} i}

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe icurrent iblend iin iprogress. i iReturns inull iif inone.
i i i i i i i i/// i</summary>

i i i i i i i ipublic iCinemachineBlend iActiveBlend

i i i i i i i i{

i i i i i i i i i i i iget

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i i i i ireturn inull;

i i i i i i i i i i i i i i i iif i(mCurrentLiveCameras.CamA i== inull i || i mCurrentLiveCameras.IsComplete)

i i i i i i i i i i i i i i i i i i i ireturn inull;

i i i i i i i i i i i i i i i ireturn imCurrentLiveCameras;

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii private iclass iBrainFrame


iiiiiiii {
i i i i i i i i i i i ipublic iint iid;

i i i i i i i i i i i ipublic iCinemachineBlend iblend i= inew iCinemachineBlend(null, inull, inull, i0, i0);

i i i i i i i i i i i ipublic ibool iActive i{ iget i{ ireturn iblend.IsValid; i} i}

iiiiiiiiiiii // iWorking idata i- iupdated ievery iframe


iiiiiiiiiiii public iCinemachineBlend iworkingBlend i= inew iCinemachineBlend(null, inull, inull, i0, i0);
i i i i i i i i i i i ipublic iBlendSourceVirtualCamera i workingBlendSource i= inew iBlendSourceVirtualCamera(null);

iiiiiiiiiiii // iUsed iby iTimeline iPreview ifor ioverriding ithe icurrent ivalue iof ideltaTime
iiiiiiiiiiii public ifloat ideltaTimeOverride;
i i i i i i i i i i i ipublic ifloat itimeOfOverride;

i i i i i i i i i i i ipublic ibool iTimeOverrideExpired

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iget i{ ireturn iTime.realtimeSinceStartup i- itimeOfOverride i> iTime.maximumDeltaTime; i}

Panipat iInstitute iof iEngineering iand iTechnology i Page i40


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii }
iiiiiiii }

iiiiiiii // iCurrent igame istate iis ialways iframe i0, ioverrides iare isubsequent iframes
iiiiiiii private iList<BrainFrame> imFrameStack i= inew iList<BrainFrame>();
i i i i i i i iprivate iint imNextFrameId i= i1;

iiiiiiii /// iGet ithe iframe iindex icorresponding ito ithe iID
iiiiiiii private iint iGetBrainFrame(int iwithId)
i i i i i i i i{

i i i i i i i i i i i iint icount i= imFrameStack.Count;

i i i i i i i i i i i ifor i(int ii i= imFrameStack.Count i- i1; ii i> i0; i--i)

i i i i i i i i i i i i i i i iif i(mFrameStack[i].id i== iwithId)

i i i i i i i i i i i i i i i i i i i ireturn ii;

i i i i i i i i i i i i// iNot ifound i- iadd iit

i i i i i i i i i i i imFrameStack.Add(new iBrainFrame() i{ iid i= iwithId i});

i i i i i i i i i i i ireturn imFrameStack.Count i- i1;

i i i i i i i i}

iiiiiiii // iCurrent iBrain iState i- iresult iof iall iframes. i iBlend icamB iis i"current" icamera ialways
iiiiiiii CinemachineBlend imCurrentLiveCameras i= inew iCinemachineBlend(null, inull, inull, i0, i0);

iiiiiiii /// i<summary>


iiiiiiii /// iThis iAPI iis ispecifically ifor iTimeline. i iDo inot iuse iit.
i i i i i i i i/// iOverride ithe icurrent icamera iand icurrent iblend. i iThis isetting i will itrump

i i i i i i i i/// iany iin-game ilogic ithat isets ivirtual icamera ipriorities iand iEnabled istates.

i i i i i i i i/// iThis iis ithe imain iAPI ifor ithe itimeline.

i i i i i i i i/// i</summary>

i i i i i i i i/// i<param iname="overrideId">Id ito irepresent ia ispecific iclient. i iAn iinternal

i i i i i i i i/// istack iis imaintained, i with ithe i most irecent inon-empty ioverride itaking iprecenence.

i i i i i i i i/// iThis iid imust ibe i> i0. i iIf iyou ipass i-1, ia inew iid iwill ibe icreated, iand ireturned.

i i i i i i i i/// iUse ithat iid ifor isubsequent icalls. i iDon't iforget ito

i i i i i i i i/// icall iReleaseCameraOverride iafter iall ioverriding iis ifinished, ito

i i i i i i i i/// ifree ithe iOverideStack iresources.</param>

i i i i i i i i/// i<param iname="camA"> iThe icamera ito iset, icorresponding ito i weight=0</param>

i i i i i i i i/// i<param iname="camB"> iThe icamera ito iset, icorresponding ito i weight=1</param>

i i i i i i i i/// i<param iname="weightB">The iblend i weight. i i0=camA, i1=camB</param>

i i i i i i i i/// i<param iname="deltaTime">override ifor ideltaTime. i iShould ibe iTime.FixedDelta ifor

i i i i i i i i/// itime-based icalculations ito ibe iincluded, i-1 iotherwise</param>

i i i i i i i i/// i<returns>The ioiverride iID. i iDon't iforget ito icall iReleaseCameraOverride

i i i i i i i i/// iafter iall ioverriding iis ifinished, ito ifree ithe iOverideStack iresources.</returns>

i i i i i i i iinternal iint iSetCameraOverride(

i i i i i i i i i i i iint ioverrideId,

i i i i i i i i i i i iICinemachineCamera icamA, iICinemachineCamera icamB,

i i i i i i i i i i i ifloat iweightB, ifloat ideltaTime)

i i i i i i i i{

i i i i i i i i i i i iif i(overrideId i< i0)

i i i i i i i i i i i i i i i ioverrideId i= imNextFrameId++;

iiiiiiiiiiii BrainFrame iframe i= imFrameStack[GetBrainFrame(overrideId)];


iiiiiiiiiiii frame.deltaTimeOverride i= ideltaTime;
i i i i i i i i i i i iframe.timeOfOverride i= iTime.realtimeSinceStartup;

i i i i i i i i i i i iframe.blend.CamA i= icamA;

i i i i i i i i i i i iframe.blend.CamB i= icamB;

Panipat iInstitute iof iEngineering iand iTechnology i Page i41


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii frame.blend.BlendCurve i= iAnimationCurve.Linear(0, i0, i1, i1);


iiiiiiiiiiii frame.blend.Duration i= i1;
i i i i i i i i i i i iframe.blend.TimeInBlend i= i weightB;

iiiiiiiiiiii return ioverrideId;


iiiiiiii }

iiiiiiii /// i<summary>


iiiiiiii /// iThis iAPI iis ispecifically ifor iTimeline. i iDo inot iuse iit.
i i i i i i i i/// iRelease ithe iresources iused ifor ia icamera ioverride iclient.

i i i i i i i i/// iSee iSetCameraOverride.

i i i i i i i i/// i</summary>

i i i i i i i i/// i<param iname="overrideId">The iID ito ireleased. i iThis iis ithe ivalue ithat

i i i i i i i i/// i was ireturned iby iSetCameraOverride</param>

i i i i i i i iinternal ivoid iReleaseCameraOverride(int ioverrideId)

i i i i i i i i{

i i i i i i i i i i i ifor i(int ii i= imFrameStack.Count i- i1; ii i> i0; i--i)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(mFrameStack[i].id i== ioverrideId)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i imFrameStack.RemoveAt(i);

i i i i i i i i i i i i i i i i i i i ireturn;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii ICinemachineCamera imActiveCameraPreviousFrame;


iiiiiiii private ivoid iProcessActiveCamera(float ideltaTime)
i i i i i i i i{

i i i i i i i i i i i ivar iactiveCamera i= iActiveVirtualCamera;

i i i i i i i i i i i iif i(activeCamera i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iHas ithe icurrent icamera ichanged ithis iframe?

i i i i i i i i i i i i i i i iif i(activeCamera i!= imActiveCameraPreviousFrame)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iNotify iincoming icamera iof itransition

i i i i i i i i i i i i i i i i i i i iactiveCamera.OnTransitionFromCamera(

i i i i i i i i i i i i i i i i i i i i i i i imActiveCameraPreviousFrame, iDefaultWorldUp, ideltaTime);

i i i i i i i i i i i i i i i i i i i iif i(m_CameraActivatedEvent i!= inull)

i i i i i i i i i i i i i i i i i i i i i i i im_CameraActivatedEvent.Invoke(activeCamera, imActiveCameraPreviousFrame);

iiiiiiiiiiiiiiiiiiii // iIf iwe're icutting iwithout ia iblend, isend ian ievent


iiiiiiiiiiiiiiiiiiii if i(m_CameraCutEvent i!= inull
i i i i i i i i i i i i i i i i i i i i i i i i i i i i&& i(!IsBlending i || i(mActiveCameraPreviousFrame i!= inull

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i && i!ActiveBlend.Uses(mActiveCameraPreviousFrame))))

i i i i i i i i i i i i i i i i i i i i i i i im_CameraCutEvent.Invoke(this);

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i// iApply ithe ivcam istate ito ithe iUnity icamera

i i i i i i i i i i i i i i i iPushStateToUnityCamera(

i i i i i i i i i i i i i i i i i i i iSoloCamera i!= inull i? iSoloCamera.State i: imCurrentLiveCameras.State);

i i i i i i i i i i i i}

i i i i i i i i i i i imActiveCameraPreviousFrame i= iactiveCamera;

i i i i i i i i}

Panipat iInstitute iof iEngineering iand iTechnology i Page i42


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii private ivoid iUpdateFrame0(float ideltaTime)


iiiiiiii {
i i i i i i i i i i i i// iUpdate ithe iin-game iframe i(frame i0)

i i i i i i i i i i i iBrainFrame iframe i= imFrameStack[0];

iiiiiiiiiiii // iAre iwe itransitioning icameras?


iiiiiiiiiiii var iactiveCamera i= iTopCameraFromPriorityQueue();
i i i i i i i i i i i ivar ioutGoingCamera i= iframe.blend.CamB;

i i i i i i i i i i i iif i(activeCamera i!= ioutGoingCamera)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iDo iwe ineed ito icreate ia igame-play iblend?

i i i i i i i i i i i i i i i iif i((UnityEngine.Object)activeCamera i!= inull

i i i i i i i i i i i i i i i i i i i i&& i(UnityEngine.Object)outGoingCamera i!= inull i&& ideltaTime i>= i0)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iCreate ia iblend i(curve i will ibe inull iif ia icut)

i i i i i i i i i i i i i i i i i i i ivar iblendDef i= iLookupBlend(outGoingCamera, iactiveCamera);

i i i i i i i i i i i i i i i i i i i iif i(blendDef.BlendCurve i!= inull i&& iblendDef.m_Time i> i0)

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i iif i(frame.blend.IsComplete)

i i i i i i i i i i i i i i i i i i i i i i i i i i i iframe.blend.CamA i= ioutGoingCamera; i i// inew iblend

i i i i i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i// iSpecial icase: iif ibacking iout iof ia iblend-in-progress

i i i i i i i i i i i i i i i i i i i i i i i i i i i i// iwith ithe isame iblend iin ireverse, iadjust ithe ibelnd itime

i i i i i i i i i i i i i i i i i i i i i i i i i i i iif i(frame.blend.CamA i== iactiveCamera

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i && iframe.blend.CamB i== ioutGoingCamera

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i&& iframe.blend.Duration i<= iblendDef.m_Time)

i i i i i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i blendDef.m_Time i= iframe.blend.TimeInBlend;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i}

iiiiiiiiiiiiiiiiiiiiiiiiiiii // iChain ito iexisting iblend


iiiiiiiiiiiiiiiiiiiiiiiiiiii frame.blend.CamA i= inew iBlendSourceVirtualCamera(
i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i inew iCinemachineBlend(

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.blend.CamA, iframe.blend.CamB,

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i iframe.blend.BlendCurve, iframe.blend.Duration,

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.blend.TimeInBlend));

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i iframe.blend.BlendCurve i= iblendDef.BlendCurve;

i i i i i i i i i i i i i i i i i i i iframe.blend.Duration i= iblendDef.m_Time;

i i i i i i i i i i i i i i i i i i i iframe.blend.TimeInBlend i= i0;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i// iSet ithe icurrent iactive icamera

i i i i i i i i i i i i i i i iframe.blend.CamB i= iactiveCamera;

i i i i i i i i i i i i}

iiiiiiiiiiii // iAdvance ithe icurrent iblend i(if iany)


iiiiiiiiiiii if i(frame.blend.CamA i!= inull)
i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iframe.blend.TimeInBlend i+= i(deltaTime i>= i0) i? ideltaTime i: iframe.blend.Duration;

i i i i i i i i i i i i i i i iif i(frame.blend.IsComplete)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iNo imore iblend

Panipat iInstitute iof iEngineering iand iTechnology i Page i43


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiiiiiii frame.blend.CamA i= inull;


iiiiiiiiiiiiiiiiiiii frame.blend.BlendCurve i= inull;
i i i i i i i i i i i i i i i i i i i iframe.blend.Duration i= i0;

i i i i i i i i i i i i i i i i i i i iframe.blend.TimeInBlend i= i0;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii private ivoid iUpdateCurrentLiveCameras()


iiiiiiii {
i i i i i i i i i i i i// iResolve ithe icurrent iworking iframe istates iin ithe istack

i i i i i i i i i i i iint ilastActive i= i0;

i i i i i i i i i i i ifor i(int ii i= i0; ii i< imFrameStack.Count; i++i)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iBrainFrame iframe i= imFrameStack[i];

i i i i i i i i i i i i i i i iif i(i i== i0 i|| iframe.Active)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i iframe.workingBlend.CamA i= iframe.blend.CamA;

i i i i i i i i i i i i i i i i i i i iframe.workingBlend.CamB i= iframe.blend.CamB;

i i i i i i i i i i i i i i i i i i i iframe.workingBlend.BlendCurve i= iframe.blend.BlendCurve;

i i i i i i i i i i i i i i i i i i i iframe.workingBlend.Duration i= iframe.blend.Duration;

i i i i i i i i i i i i i i i i i i i iframe.workingBlend.TimeInBlend i= iframe.blend.TimeInBlend;

i i i i i i i i i i i i i i i i i i i iif i(i i> i0 i&& i!frame.blend.IsComplete)

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i iif i(frame.workingBlend.CamA i== inull)

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i iif i(mFrameStack[lastActive].blend.IsComplete)

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i iframe.workingBlend.CamA i= imFrameStack[lastActive].blend.CamB;

i i i i i i i i i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i iframe.workingBlendSource.Blend i= imFrameStack[lastActive].workingBlend;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.workingBlend.CamA i= iframe.workingBlendSource;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i ielse iif i(frame.workingBlend.CamB i== inull)

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i iif i(mFrameStack[lastActive].blend.IsComplete)

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.workingBlend.CamB i= imFrameStack[lastActive].blend.CamB;

i i i i i i i i i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i iframe.workingBlendSource.Blend i= imFrameStack[lastActive].workingBlend;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i iframe.workingBlend.CamB i= iframe.workingBlendSource;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i ilastActive i= ii;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i i i i ivar i workingBlend i= imFrameStack[lastActive].workingBlend;

i i i i i i i i i i i imCurrentLiveCameras.CamA i= i workingBlend.CamA;

i i i i i i i i i i i imCurrentLiveCameras.CamB i= iworkingBlend.CamB;

i i i i i i i i i i i imCurrentLiveCameras.BlendCurve i= iworkingBlend.BlendCurve;

i i i i i i i i i i i imCurrentLiveCameras.Duration i= iworkingBlend.Duration;

i i i i i i i i i i i imCurrentLiveCameras.TimeInBlend i= iworkingBlend.TimeInBlend;

Panipat iInstitute iof iEngineering iand iTechnology i Page i44


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii }

iiiiiiii /// i<summary>


iiiiiiii /// iTrue iif ithe iICinemachineCamera ithe icurrent iactive icamera,
i i i i i i i i/// ior ipart iof ia icurrent iblend, ieither idirectly ior iindirectly ibecause iits iparents iare ilive.

i i i i i i i i/// i</summary>

i i i i i i i i/// i<param iname="vcam">The icamera ito itest iwhether iit iis ilive</param>

i i i i i i i i/// i<param iname="dominantChildOnly">If itruw, i will ionly ireturn itrue iif ithis ivcam iis ithe idominat ilive

ichild</param>

i i i i i i i i/// i<returns>True iif ithe icamera iis ilive i(directly ior iindirectly)

i i i i i i i i/// ior ipart iof ia iblend iin iprogress.</returns>

i i i i i i i ipublic ibool iIsLive(ICinemachineCamera ivcam, ibool idominantChildOnly i= ifalse)

i i i i i i i i{

i i i i i i i i i i i iif i(SoloCamera i== ivcam)

i i i i i i i i i i i i i i i ireturn itrue;

i i i i i i i i i i i iif i(mCurrentLiveCameras.Uses(vcam))

i i i i i i i i i i i i i i i ireturn itrue;

iiiiiiiiiiii ICinemachineCamera iparent i= ivcam.ParentCamera;


iiiiiiiiiiii while i(parent i!= inull i&& iparent.IsLiveChild(vcam, idominantChildOnly))
i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(SoloCamera i== iparent i|| i mCurrentLiveCameras.Uses(parent))

i i i i i i i i i i i i i i i i i i i ireturn itrue;

i i i i i i i i i i i i i i i ivcam i= iparent;

i i i i i i i i i i i i i i i iparent i= ivcam.ParentCamera;

i i i i i i i i i i i i}

i i i i i i i i i i i ireturn ifalse;

i i i i i i i i}

iiiiiiii /// i<summary>


iiiiiiii /// iThe icurrent istate iapplied ito ithe iunity icamera i(may ibe ithe iresult iof ia iblend)
i i i i i i i i/// i</summary>

i i i i i i i ipublic iCameraState iCurrentCameraState i{ iget; iprivate iset; i}

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe ihighest-priority iEnabled iICinemachineCamera
i i i i i i i i/// ithat iis ivisible ito imy icamera. i iCulling iMask iis iused ito itest ivisibility.

i i i i i i i i/// i</summary>

i i i i i i i iprivate iICinemachineCamera iTopCameraFromPriorityQueue()

i i i i i i i i{

i i i i i i i i i i i iCinemachineCore icore i= iCinemachineCore.Instance;

i i i i i i i i i i i iCamera ioutputCamera i= iOutputCamera;

i i i i i i i i i i i iint imask i= ioutputCamera i== inull i? i~0 i: ioutputCamera.cullingMask;

i i i i i i i i i i i iint inumCameras i= icore.VirtualCameraCount;

i i i i i i i i i i i ifor i(int ii i= i0; ii i< inumCameras; i++i)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i ivar icam i= icore.GetVirtualCamera(i);

i i i i i i i i i i i i i i i iGameObject igo i= icam i!= inull i? icam.gameObject i: inull;

i i i i i i i i i i i i i i i iif i(go i!= inull i&& i(mask i& i(1 i<< igo.layer)) i!= i0)

i i i i i i i i i i i i i i i i i i i ireturn icam;

i i i i i i i i i i i i}

i i i i i i i i i i i ireturn inull;

i i i i i i i i}

Panipat iInstitute iof iEngineering iand iTechnology i Page i45


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii /// i<summary>


iiiiiiii /// iCreate ia iblend icurve ifor iblending ifrom ione iICinemachineCamera ito ianother.
i i i i i i i i/// iIf ithere iis ia ispecific iblend idefined ifor ithese icameras iit iwill ibe iused, iotherwise

i i i i i i i i/// ia idefault iblend iwill ibe icreated, i which icould ibe ia icut.

i i i i i i i i/// i</summary>

i i i i i i i iprivate iCinemachineBlendDefinition iLookupBlend(

i i i i i i i i i i i iICinemachineCamera ifromKey, iICinemachineCamera itoKey)

i i i i i i i i{

i i i i i i i i i i i i// iGet ithe iblend icurve ithat's i most iappropriate ifor ithese icameras

i i i i i i i i i i i iCinemachineBlendDefinition iblend i= im_DefaultBlend;

i i i i i i i i i i i iif i(m_CustomBlends i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i istring ifromCameraName i= i(fromKey i!= inull) i? ifromKey.Name i: istring.Empty;

i i i i i i i i i i i i i i i istring itoCameraName i= i(toKey i!= inull) i? itoKey.Name i: istring.Empty;

i i i i i i i i i i i i i i i iblend i= im_CustomBlends.GetBlendForVirtualCameras(

i i i i i i i i i i i i i i i i i i i i i i i ifromCameraName, itoCameraName, iblend);

i i i i i i i i i i i i}

i i i i i i i i i i i iif i(CinemachineCore.GetBlendOverride i!= inull)

i i i i i i i i i i i i i i i iblend i= iCinemachineCore.GetBlendOverride(fromKey, itoKey, iblend, ithis);

i i i i i i i i i i i ireturn iblend;

i i i i i i i i}

iiiiiiii /// i<summary> iApply ia icref="CameraState"/> ito ithe igame iobject</summary>


iiiiiiii private ivoid iPushStateToUnityCamera(CameraState istate)
i i i i i i i i{

i i i i i i i i i i i iCurrentCameraState i= istate;

i i i i i i i i i i i iif i((state.BlendHint i& iCameraState.BlendHintValue.NoPosition) i== i0)

i i i i i i i i i i i i i i i itransform.position i= istate.FinalPosition;

i i i i i i i i i i i iif i((state.BlendHint i& iCameraState.BlendHintValue.NoOrientation) i== i0)

i i i i i i i i i i i i i i i itransform.rotation i= istate.FinalOrientation;

i i i i i i i i i i i iif i((state.BlendHint i& iCameraState.BlendHintValue.NoLens) i== i0)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iCamera icam i= iOutputCamera;

i i i i i i i i i i i i i i i iif i(cam i!= inull)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i icam.nearClipPlane i= istate.Lens.NearClipPlane;

i i i i i i i i i i i i i i i i i i i icam.farClipPlane i= istate.Lens.FarClipPlane;

i i i i i i i i i i i i i i i i i i i icam.fieldOfView i= istate.Lens.FieldOfView;

i i i i i i i i i i i i i i i i i i i iif i(cam.orthographic)

i i i i i i i i i i i i i i i i i i i i i i i icam.orthographicSize i= istate.Lens.OrthographicSize;

#if iUNITY_2018_2_OR_NEWER
i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i icam.usePhysicalProperties i= istate.Lens.IsPhysicalCamera;

i i i i i i i i i i i i i i i i i i i i i i i icam.lensShift i= istate.Lens.LensShift;

i i i i i i i i i i i i i i i i i i i i}

#endif
i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i i i i iif i(CinemachineCore.CameraUpdatedEvent i!= inull)

i i i i i i i i i i i i i i i iCinemachineCore.CameraUpdatedEvent.Invoke(this);

i i i i i i i i}

i i i i}

Panipat iInstitute iof iEngineering iand iTechnology i Page i46


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

5.7 iPlayer Controller


using iCinemachine.Utility;
using iSystem;
using iSystem.Collections;
using iSystem.Collections.Generic;
using iUnityEngine;
using iUnityEngine.Events;

namespace iCinemachine
{
i i i i/// i<summary>

i i i i/// iCinemachineBrain iis ithe ilink ibetween ithe iUnity iCamera iand ithe iCinemachine iVirtual

i i i i/// iCameras iin ithe iscene. i iIt imonitors ithe ipriority istack ito ichoose ithe icurrent

i i i i/// iVirtual iCamera, iand iblend i with ianother iif inecessary. i iFinally iand imost iimportantly,

i i i i/// iit iapplies ithe iVirtual iCamera istate ito ithe iattached iUnity iCamera.

i i i i///

i i i i/// iThe iCinemachineBrain iis ialso ithe iplace iwhere irules ifor iblending ibetween ivirtual icameras

i i i i/// iare idefined. i iCamera iblending iis ian iinterpolation iover itime iof ione ivirtual icamera

i i i i/// iposition iand istate ito ianother. iIf iyou ithink iof ivirtual icameras ias icameramen, ithen

i i i i/// iblending iis ia ilittle ilike ione icameraman ismoothly ipassing ithe icamera ito ianother icameraman.

i i i i/// iYou ican ispecify ithe itime iover iwhich ito iblend, ias iwell ias ithe iblend icurve ishape.

i i i i/// iNote ithat ia icamera icut iis ijust ia izero-time iblend.

i i i i/// i</summary>

i i i i[DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]

// i i i i[RequireComponent(typeof(Camera))] i// istrange ibut itrue: iwe ican ilive iwithout iit
i i i i[DisallowMultipleComponent]

#if iUNITY_2018_3_OR_NEWER
i i i i[ExecuteAlways]

#else
i i i i[ExecuteInEditMode]

#endif
i i i i[AddComponentMenu("Cinemachine/CinemachineBrain")]

i i i i[SaveDuringPlay]

i i i ipublic iclass iCinemachineBrain i: iMonoBehaviour

i i i i{

i i i i i i i i/// i<summary>

i i i i i i i i/// iWhen ienabled, ithe icurrent icamera iand iblend iwill ibe iindicated iin ithe igame i window, ifor idebugging.

i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("When ienabled, ithe icurrent icamera iand iblend iwill ibe iindicated iin ithe igame iwindow, ifor idebugging")]

i i i i i i i ipublic ibool im_ShowDebugText i= ifalse;

iiiiiiii /// i<summary>


iiiiiiii /// iWhen ienabled, ishows ithe icamera's ifrustum iin ithe iscene iview.
i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("When ienabled, ithe icamera's ifrustum i will ibe ishown iat iall itimes iin ithe iscene iview")]

i i i i i i i ipublic ibool im_ShowCameraFrustum i= itrue;

iiiiiiii /// i<summary>


iiiiiiii /// iWhen ienabled, ithe icameras iwill ialways irespond iin ireal-time ito iuser iinput iand idamping,
i i i i i i i i/// ieven iif ithe igame iis irunning iin islow i motion

i i i i i i i i/// i</summary>

Panipat iInstitute iof iEngineering iand iTechnology i Page i47


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii [Tooltip("When ienabled, ithe icameras iwill ialways irespond iin ireal-time ito iuser iinput iand idamping, ieven iif ithe
game iis irunning iin islow imotion")]
i

i i i i i i i ipublic ibool im_IgnoreTimeScale i= ifalse;

iiiiiiii /// i<summary>


iiiiiiii /// iIf iset, ithis iobject's iY iaxis iwill idefine ithe iworldspace iUp ivector ifor iall ithe
i i i i i i i i/// ivirtual icameras. i iThis iis iuseful iin itop-down igame ienvironments. i iIf inot iset, iUp iis iworldspace iY.

i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("If iset, ithis iobject's iY iaxis iwill idefine ithe i worldspace iUp ivector ifor iall ithe ivirtual icameras. i iThis iis

iuseful ifor iinstance iin itop-down igame ienvironments. i iIf inot iset, iUp iis i worldspace iY. i iSetting ithis iappropriately iis

iimportant, ibecause iVirtual iCameras idon't ilike ilooking istraight iup ior istraight idown.")]

i i i i i i i ipublic iTransform i m_WorldUpOverride;

iiiiiiii /// i<summary>This ienum idefines ithe ioptions iavailable ifor ithe iupdate imethod.</summary>
iiiiiiii [DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]
i i i i i i i ipublic ienum iUpdateMethod

i i i i i i i i{

i i i i i i i i i i i i/// i<summary>Virtual icameras iare iupdated iin isync iwith ithe iPhysics imodule, iin iFixedUpdate</summary>

i i i i i i i i i i i iFixedUpdate,

i i i i i i i i i i i i/// i<summary>Virtual icameras iare iupdated iin iMonoBehaviour iLateUpdate.</summary>

i i i i i i i i i i i iLateUpdate,

i i i i i i i i i i i i/// i<summary>Virtual icameras iare iupdated iaccording ito ihow ithe itarget iis iupdated.</summary>

i i i i i i i i i i i iSmartUpdate

i i i i i i i i};

iiiiiiii /// i<summary>Depending ion ihow ithe itarget iobjects iare ianimated, iadjust ithe iupdate imethod ito
iiiiiiii /// iminimize ithe ipotential ijitter. i iUse iFixedUpdate iif iall iyour itargets iare ianimated iwith ifor iRigidBody
ianimation.

i i i i i i i i/// iSmartUpdate iwill ichoose ithe ibest imethod ifor ieach ivirtual icamera, idepending

i i i i i i i i/// ion ihow ithe itarget iis ianimated.</summary>

i i i i i i i i[Tooltip("Use iFixedUpdate iif iall iyour itargets iare ianimated iduring iFixedUpdate i(e.g. iRigidBodies),

iLateUpdate iif iall iyour itargets iare ianimated iduring ithe inormal iUpdate iloop, iand iSmartUpdate iif iyou i want

iCinemachine ito ido ithe iappropriate ithing ion ia iper-target ibasis. i iSmartUpdate iis ithe irecommended isetting")]

i i i i i i i ipublic iUpdateMethod im_UpdateMethod i= iUpdateMethod.SmartUpdate;

iiiiiiii /// i<summary>


iiiiiiii /// iThe iblend iwhich iis iused iif iyou idon't iexplicitly idefine ia iblend ibetween itwo iVirtual iCameras.
i i i i i i i i/// i</summary>

i i i i i i i i[CinemachineBlendDefinitionProperty]

i i i i i i i i[Tooltip("The iblend ithat iis iused iin icases iwhere iyou ihaven't iexplicitly idefined ia iblend ibetween itwo iVirtual

iCameras")]

i i i i i i i ipublic iCinemachineBlendDefinition i m_DefaultBlend

i i i i i i i i i i i i= inew iCinemachineBlendDefinition(CinemachineBlendDefinition.Style.EaseInOut, i2f);

iiiiiiii /// i<summary>


iiiiiiii /// iThis iis ithe iasset iwhich icontains icustom isettings ifor ispecific iblends.
i i i i i i i i/// i</summary>

i i i i i i i i[Tooltip("This iis ithe iasset ithat icontains icustom isettings ifor iblends ibetween ispecific ivirtual icameras iin iyour

iscene")]

i i i i i i i ipublic iCinemachineBlenderSettings i m_CustomBlends i= inull;

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe iUnity iCamera ithat iis iattached ito ithis iGameObject. i iThis iis ithe icamera
i i i i i i i i/// ithat i will ibe icontrolled iby ithe ibrain.

Panipat iInstitute iof iEngineering iand iTechnology i Page i48


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii /// i</summary>


iiiiiiii public iCamera iOutputCamera
i i i i i i i i{

i i i i i i i i i i i iget

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(m_OutputCamera i== inull i&& i!Application.isPlaying)

i i i i i i i i i i i i i i i i i i i im_OutputCamera i= iGetComponent<Camera>();

i i i i i i i i i i i i i i i ireturn im_OutputCamera;

i i i i i i i i i i i i}

i i i i i i i i}

i i i i i i i iprivate iCamera im_OutputCamera i= inull; i// inever iuse idirectly i- iuse iaccessor

iiiiiiii /// i<summary>Event iwith ia iCinemachineBrain iparameter</summary>


iiiiiiii [Serializable] ipublic iclass iBrainEvent i: iUnityEvent<CinemachineBrain> i{}

iiiiiiii /// i<summary>Event iwith ia iICinemachineCamera iparameter</summary>


iiiiiiii [Serializable] ipublic iclass iVcamActivatedEvent i: iUnityEvent<ICinemachineCamera, iICinemachineCamera>
i {}

iiiiiiii /// i<summary>This ievent iwill ifire iwhenever ia ivirtual icamera igoes ilive iand ithere iis ino iblend</summary>
iiiiiiii [Tooltip("This ievent iwill ifire iwhenever ia ivirtual icamera igoes ilive iand ithere iis ino iblend")]
i i i i i i i ipublic iBrainEvent i m_CameraCutEvent i= inew iBrainEvent();

iiiiiiii /// i<summary>This ievent iwill ifire iwhenever ia ivirtual icamera igoes ilive. i iIf ia iblend iis iinvolved,
iiiiiiii /// ithen ithe ievent iwill ifire ion ithe ifirst iframe iof ithe iblend</summary>
i i i i i i i i[Tooltip("This ievent i will ifire iwhenever ia ivirtual icamera igoes ilive. i iIf ia iblend iis iinvolved, ithen ithe ievent i will

ifire ion ithe ifirst iframe iof ithe iblend.")]

i i i i i i i ipublic iVcamActivatedEvent i m_CameraActivatedEvent i= inew iVcamActivatedEvent();

iiiiiiii /// i<summary>


iiiiiiii /// iAPI ifor ithe iUnity iEditor.
i i i i i i i i/// iShow ithis icamera ino imatter i what. i iThis iis istatic, iand iso iaffects iall iCinemachine ibrains.

i i i i i i i i/// i</summary>

i i i i i i i ipublic istatic iICinemachineCamera iSoloCamera

i i i i i i i i{

i i i i i i i i i i i iget i{ ireturn i mSoloCamera; i}

i i i i i i i i i i i iset

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(value i!= inull i&& i!CinemachineCore.Instance.IsLive(value))

i i i i i i i i i i i i i i i i i i i ivalue.OnTransitionFromCamera(null, iVector3.up, iTime.deltaTime);

i i i i i i i i i i i i i i i imSoloCamera i= ivalue;

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii /// i<summary>API ifor ithe iUnity iEditor.</summary>


iiiiiiii /// i<returns>Color iused ito iindicate ithat ia icamera iis iin iSolo imode.</returns>
i i i i i i i ipublic istatic iColor iGetSoloGUIColor() i{ ireturn iColor.Lerp(Color.red, iColor.yellow, i0.8f); i}

iiiiiiii /// i<summary>Get ithe idefault iworld iup ifor ithe ivirtual icameras.</summary>
iiiiiiii public iVector3 iDefaultWorldUp
i i i i i i i i i i i i{ iget i{ ireturn i(m_WorldUpOverride i!= inull) i? im_WorldUpOverride.transform.up i: iVector3.up; i} i}

iiiiiiii private istatic iICinemachineCamera imSoloCamera;


iiiiiiii private iCoroutine imPhysicsCoroutine;

Panipat iInstitute iof iEngineering iand iTechnology i Page i49


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii private ivoid iOnEnable()


iiiiiiii {
i i i i i i i i i i i i// iMake isure ithere iis ia ifirst istack iframe

i i i i i i i i i i i iif i(mFrameStack.Count i== i0)

i i i i i i i i i i i i i i i imFrameStack.Add(new iBrainFrame());

iiiiiiiiiiii m_OutputCamera i= iGetComponent<Camera>();


iiiiiiiiiiii CinemachineCore.Instance.AddActiveBrain(this);
i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers i-= iOnGuiHandler;

i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers i+= iOnGuiHandler;

iiiiiiiiiiii // iWe icheck iin iafter ithe iphysics isystem ihas ihad ia ichance ito imove ithings
iiiiiiiiiiii mPhysicsCoroutine i= iStartCoroutine(AfterPhysics());
iiiiiiii }

iiiiiiii private ivoid iOnDisable()


iiiiiiii {
i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers i-= iOnGuiHandler;

i i i i i i i i i i i iCinemachineCore.Instance.RemoveActiveBrain(this);

i i i i i i i i i i i imFrameStack.Clear();

i i i i i i i i i i i iStopCoroutine(mPhysicsCoroutine);

i i i i i i i i}

iiiiiiii private ivoid iStart()


iiiiiiii {
i i i i i i i i i i i iUpdateVirtualCameras(CinemachineCore.UpdateFilter.Late, i-1f);

i i i i i i i i}

iiiiiiii private ivoid iOnGuiHandler()


iiiiiiii {
i i i i i i i i i i i iif i(!m_ShowDebugText)

i i i i i i i i i i i i i i i iCinemachineDebug.ReleaseScreenPos(this);

i i i i i i i i i i i ielse

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iShow ithe iactive icamera iand iblend

i i i i i i i i i i i i i i i ivar isb i= iCinemachineDebug.SBFromPool();

i i i i i i i i i i i i i i i iColor icolor i= iGUI.color;

i i i i i i i i i i i i i i i isb.Length i= i0;

i i i i i i i i i i i i i i i isb.Append("CM i");

i i i i i i i i i i i i i i i isb.Append(gameObject.name);

i i i i i i i i i i i i i i i isb.Append(": i");

i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i isb.Append("SOLO i");

i i i i i i i i i i i i i i i i i i i iGUI.color i= iGetSoloGUIColor();

i i i i i i i i i i i i i i i i}

iiiiiiiiiiiiiiii if i(IsBlending)
iiiiiiiiiiiiiiiiiiii sb.Append(ActiveBlend.Description);
i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i iICinemachineCamera ivcam i= iActiveVirtualCamera;

i i i i i i i i i i i i i i i i i i i iif i(vcam i== inull)

Panipat iInstitute iof iEngineering iand iTechnology i Page i50


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiiiiiiiiiii sb.Append("(none)");
iiiiiiiiiiiiiiiiiiii else
i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i isb.Append("[");

i i i i i i i i i i i i i i i i i i i i i i i isb.Append(vcam.Name);

i i i i i i i i i i i i i i i i i i i i i i i isb.Append("]");

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i istring itext i= isb.ToString();

i i i i i i i i i i i i i i i iRect ir i= iCinemachineDebug.GetScreenPos(this, itext, iGUI.skin.box);

i i i i i i i i i i i i i i i iGUI.Label(r, itext, iGUI.skin.box);

i i i i i i i i i i i i i i i iGUI.color i= icolor;

i i i i i i i i i i i i i i i iCinemachineDebug.ReturnToPool(sb);

i i i i i i i i i i i i}

i i i i i i i i}

#if iUNITY_EDITOR
i i i i i i i iprivate ivoid iOnGUI()

i i i i i i i i{

i i i i i i i i i i i iif i(CinemachineDebug.OnGUIHandlers i!= inull)

i i i i i i i i i i i i i i i iCinemachineDebug.OnGUIHandlers();

i i i i i i i i}

#endif

iiiiiiii WaitForFixedUpdate imWaitForFixedUpdate i= inew iWaitForFixedUpdate();


iiiiiiii private iIEnumerator iAfterPhysics()
i i i i i i i i{

i i i i i i i i i i i iwhile i(true)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iFixedUpdate ican ibe icalled imultiple itimes iper iframe

i i i i i i i i i i i i i i i iyield ireturn imWaitForFixedUpdate;

i i i i i i i i i i i i i i i iif i(m_UpdateMethod i!= iUpdateMethod.LateUpdate)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i iCinemachineCore.UpdateFilter ifilter i= iCinemachineCore.UpdateFilter.Fixed;

i i i i i i i i i i i i i i i i i i i iif i(m_UpdateMethod i== iUpdateMethod.SmartUpdate)

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i// iTrack ithe itargets

i i i i i i i i i i i i i i i i i i i i i i i iUpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Fixed);

i i i i i i i i i i i i i i i i i i i i i i i ifilter i= iCinemachineCore.UpdateFilter.SmartFixed;

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i iUpdateVirtualCameras(filter, iGetEffectiveDeltaTime(true));

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii private ivoid iLateUpdate()


iiiiiiii {
i i i i i i i i i i i ifloat ideltaTime i= iGetEffectiveDeltaTime(false);

i i i i i i i i i i i iUpdateFrame0(deltaTime);

i i i i i i i i i i i iUpdateCurrentLiveCameras();

iiiiiiiiiiii if i(m_UpdateMethod i== iUpdateMethod.FixedUpdate)


iiiiiiiiiiii {
i i i i i i i i i i i i i i i i// iSpecial ihandling ifor ifixed iupdate: icameras ithat ihave ibeen ienabled

Panipat iInstitute iof iEngineering iand iTechnology i Page i51


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiii // isince ithe ilast iphysics iframe imust ibe iupdated inow
iiiiiiiiiiiiiiii CinemachineCore.Instance.CurrentUpdateFilter i= iCinemachineCore.UpdateFilter.Fixed;
i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i i i i iSoloCamera.UpdateCameraState(DefaultWorldUp, ideltaTime);

i i i i i i i i i i i i i i i imCurrentLiveCameras.UpdateCameraState(DefaultWorldUp, ideltaTime);

i i i i i i i i i i i i}

i i i i i i i i i i i ielse

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iCinemachineCore.UpdateFilter ifilter i= iCinemachineCore.UpdateFilter.Late;

i i i i i i i i i i i i i i i iif i(m_UpdateMethod i== iUpdateMethod.SmartUpdate)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iTrack ithe itargets

i i i i i i i i i i i i i i i i i i i iUpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Late);

i i i i i i i i i i i i i i i i i i i ifilter i= iCinemachineCore.UpdateFilter.SmartLate;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i iUpdateVirtualCameras(filter, ideltaTime);

i i i i i i i i i i i i}

i i i i i i i i i i i i// iChoose ithe iactive ivcam iand iapply iit ito ithe iUnity icamera

i i i i i i i i i i i iProcessActiveCamera(deltaTime);

i i i i i i i i}

#if iUNITY_EDITOR
i i i i i i i i/// iThis iis ionly ineeded iin ieditor imode ito iforce itimeline ito icall iOnGUI iwhile

i i i i i i i i/// itimeline iis iup iand ithe igame iis inot irunning, iin iorder ito iallow idragging

i i i i i i i i/// ithe icomposer iguide iin ithe igame iview.

i i i i i i i iprivate ivoid iOnPreCull()

i i i i i i i i{

i i i i i i i i i i i iif i(!Application.isPlaying)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iNote: ithis icall iwill icause iany iscreen icanvas iattached ito ithe icamera

i i i i i i i i i i i i i i i i// ito ibe ipainted ione iframe iout iof isync. i iIt iwill ionly ihappen iin ithe ieditor i when inot iplaying.

i i i i i i i i i i i i i i i iProcessActiveCamera(GetEffectiveDeltaTime(false));

i i i i i i i i i i i i}

i i i i i i i i}

#endif

iiiiiiii private ifloat iGetEffectiveDeltaTime(bool ifixedDelta)


iiiiiiii {
i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i ireturn iTime.unscaledDeltaTime;

iiiiiiiiiiii if i(!Application.isPlaying)
iiiiiiiiiiii {
i i i i i i i i i i i i i i i ifor i(int ii i= imFrameStack.Count i- i1; ii i> i0; i--i)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i ivar iframe i= imFrameStack[i];

i i i i i i i i i i i i i i i i i i i iif i(frame.Active)

i i i i i i i i i i i i i i i i i i i i i i i ireturn iframe.TimeOverrideExpired i? i-1 i: iframe.deltaTimeOverride;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i ireturn i-1;

i i i i i i i i i i i i}

i i i i i i i i i i i iif i(m_IgnoreTimeScale)

i i i i i i i i i i i i i i i ireturn ifixedDelta i? iTime.fixedDeltaTime i: iTime.unscaledDeltaTime;

i i i i i i i i i i i ireturn ifixedDelta i? iTime.fixedDeltaTime i: iTime.deltaTime;

Panipat iInstitute iof iEngineering iand iTechnology i Page i52


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii }

iiiiiiii private ivoid iUpdateVirtualCameras(CinemachineCore.UpdateFilter iupdateFilter, ifloat ideltaTime)


iiiiiiii {
i i i i i i i i i i i i// iWe ialways iupdate iall iactive ivirtual icameras

i i i i i i i i i i i iCinemachineCore.Instance.CurrentUpdateFilter i= iupdateFilter;

i i i i i i i i i i i iCamera icamera i= iOutputCamera;

i i i i i i i i i i i iCinemachineCore.Instance.UpdateAllActiveVirtualCameras(

i i i i i i i i i i i i i i i icamera i== inull i? i-1 i: icamera.cullingMask, iDefaultWorldUp, ideltaTime);

iiiiiiiiiiii // iMake isure iall ilive icameras iget iupdated, iin icase isome iof ithem iare ideactivated
iiiiiiiiiiii if i(SoloCamera i!= inull)
i i i i i i i i i i i i i i i iSoloCamera.UpdateCameraState(DefaultWorldUp, ideltaTime);

i i i i i i i i i i i imCurrentLiveCameras.UpdateCameraState(DefaultWorldUp, ideltaTime);

iiiiiiiiiiii // iRestore ithe ifilter ifor igeneral iuse


iiiiiiiiiiii updateFilter i= iCinemachineCore.UpdateFilter.Late;
i i i i i i i i i i i iif i(Application.isPlaying)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(m_UpdateMethod i== iUpdateMethod.SmartUpdate)

i i i i i i i i i i i i i i i i i i i iupdateFilter i|= iCinemachineCore.UpdateFilter.Smart;

i i i i i i i i i i i i i i i ielse iif i(m_UpdateMethod i== iUpdateMethod.FixedUpdate)

i i i i i i i i i i i i i i i i i i i iupdateFilter i= iCinemachineCore.UpdateFilter.Fixed;

i i i i i i i i i i i i}

i i i i i i i i i i i iCinemachineCore.Instance.CurrentUpdateFilter i= iupdateFilter;

i i i i i i i i}

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe icurrent iactive ivirtual icamera.
i i i i i i i i/// i</summary>

i i i i i i i ipublic iICinemachineCamera iActiveVirtualCamera

i i i i i i i i{

i i i i i i i i i i i iget

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i i i i ireturn iSoloCamera;

i i i i i i i i i i i i i i i ireturn iDeepCamBFromBlend(mCurrentLiveCameras);

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii static iICinemachineCamera iDeepCamBFromBlend(CinemachineBlend iblend)


iiiiiiii {
i i i i i i i i i i i iICinemachineCamera ivcam i= iblend.CamB;

i i i i i i i i i i i iwhile i(vcam i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(!vcam.IsValid)

i i i i i i i i i i i i i i i i i i i ireturn inull; i i i i// ideleted!

i i i i i i i i i i i i i i i iBlendSourceVirtualCamera ibs i= ivcam ias iBlendSourceVirtualCamera;

i i i i i i i i i i i i i i i iif i(bs i== inull)

i i i i i i i i i i i i i i i i i i i ibreak;

i i i i i i i i i i i i i i i ivcam i= ibs.Blend.CamB;

i i i i i i i i i i i i}

i i i i i i i i i i i ireturn ivcam;

i i i i i i i i}

Panipat iInstitute iof iEngineering iand iTechnology i Page i53


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii /// i<summary>


iiiiiiii /// iIs ithere ia iblend iin iprogress?
i i i i i i i i/// i</summary>

i i i i i i i ipublic ibool iIsBlending i{ iget i{ ireturn iActiveBlend i!= inull; i} i}

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe icurrent iblend iin iprogress. i iReturns inull iif inone.
i i i i i i i i/// i</summary>

i i i i i i i ipublic iCinemachineBlend iActiveBlend

i i i i i i i i{

i i i i i i i i i i i iget

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(SoloCamera i!= inull)

i i i i i i i i i i i i i i i i i i i ireturn inull;

i i i i i i i i i i i i i i i iif i(mCurrentLiveCameras.CamA i== inull i || i mCurrentLiveCameras.IsComplete)

i i i i i i i i i i i i i i i i i i i ireturn inull;

i i i i i i i i i i i i i i i ireturn imCurrentLiveCameras;

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii private iclass iBrainFrame


iiiiiiii {
i i i i i i i i i i i ipublic iint iid;

i i i i i i i i i i i ipublic iCinemachineBlend iblend i= inew iCinemachineBlend(null, inull, inull, i0, i0);

i i i i i i i i i i i ipublic ibool iActive i{ iget i{ ireturn iblend.IsValid; i} i}

iiiiiiiiiiii // iWorking idata i- iupdated ievery iframe


iiiiiiiiiiii public iCinemachineBlend iworkingBlend i= inew iCinemachineBlend(null, inull, inull, i0, i0);
i i i i i i i i i i i ipublic iBlendSourceVirtualCamera i workingBlendSource i= inew iBlendSourceVirtualCamera(null);

iiiiiiiiiiii // iUsed iby iTimeline iPreview ifor ioverriding ithe icurrent ivalue iof ideltaTime
iiiiiiiiiiii public ifloat ideltaTimeOverride;
i i i i i i i i i i i ipublic ifloat itimeOfOverride;

i i i i i i i i i i i ipublic ibool iTimeOverrideExpired

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iget i{ ireturn iTime.realtimeSinceStartup i- itimeOfOverride i> iTime.maximumDeltaTime; i}

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii // iCurrent igame istate iis ialways iframe i0, ioverrides iare isubsequent iframes
iiiiiiii private iList<BrainFrame> imFrameStack i= inew iList<BrainFrame>();
i i i i i i i iprivate iint imNextFrameId i= i1;

iiiiiiii /// iGet ithe iframe iindex icorresponding ito ithe iID
iiiiiiii private iint iGetBrainFrame(int iwithId)
i i i i i i i i{

i i i i i i i i i i i iint icount i= imFrameStack.Count;

i i i i i i i i i i i ifor i(int ii i= imFrameStack.Count i- i1; ii i> i0; i--i)

i i i i i i i i i i i i i i i iif i(mFrameStack[i].id i== iwithId)

i i i i i i i i i i i i i i i i i i i ireturn ii;

i i i i i i i i i i i i// iNot ifound i- iadd iit

i i i i i i i i i i i imFrameStack.Add(new iBrainFrame() i{ iid i= iwithId i});

i i i i i i i i i i i ireturn imFrameStack.Count i- i1;

Panipat iInstitute iof iEngineering iand iTechnology i Page i54


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiii }

iiiiiiii // iCurrent iBrain iState i- iresult iof iall iframes. i iBlend icamB iis i"current" icamera ialways
iiiiiiii CinemachineBlend imCurrentLiveCameras i= inew iCinemachineBlend(null, inull, inull, i0, i0);

iiiiiiii /// i<summary>


iiiiiiii /// iThis iAPI iis ispecifically ifor iTimeline. i iDo inot iuse iit.
i i i i i i i i/// iOverride ithe icurrent icamera iand icurrent iblend. i iThis isetting i will itrump

i i i i i i i i/// iany iin-game ilogic ithat isets ivirtual icamera ipriorities iand iEnabled istates.

i i i i i i i i/// iThis iis ithe imain iAPI ifor ithe itimeline.

i i i i i i i i/// i</summary>

i i i i i i i i/// i<param iname="overrideId">Id ito irepresent ia ispecific iclient. i iAn iinternal

i i i i i i i i/// istack iis imaintained, i with ithe i most irecent inon-empty ioverride itaking iprecenence.

i i i i i i i i/// iThis iid imust ibe i> i0. i iIf iyou ipass i-1, ia inew iid iwill ibe icreated, iand ireturned.

i i i i i i i i/// iUse ithat iid ifor isubsequent icalls. i iDon't iforget ito

i i i i i i i i/// icall iReleaseCameraOverride iafter iall ioverriding iis ifinished, ito

i i i i i i i i/// ifree ithe iOverideStack iresources.</param>

i i i i i i i i/// i<param iname="camA"> iThe icamera ito iset, icorresponding ito i weight=0</param>

i i i i i i i i/// i<param iname="camB"> iThe icamera ito iset, icorresponding ito i weight=1</param>

i i i i i i i i/// i<param iname="weightB">The iblend i weight. i i0=camA, i1=camB</param>

i i i i i i i i/// i<param iname="deltaTime">override ifor ideltaTime. i iShould ibe iTime.FixedDelta ifor

i i i i i i i i/// itime-based icalculations ito ibe iincluded, i-1 iotherwise</param>

i i i i i i i i/// i<returns>The ioiverride iID. i iDon't iforget ito icall iReleaseCameraOverride

i i i i i i i i/// iafter iall ioverriding iis ifinished, ito ifree ithe iOverideStack iresources.</returns>

i i i i i i i iinternal iint iSetCameraOverride(

i i i i i i i i i i i iint ioverrideId,

i i i i i i i i i i i iICinemachineCamera icamA, iICinemachineCamera icamB,

i i i i i i i i i i i ifloat iweightB, ifloat ideltaTime)

i i i i i i i i{

i i i i i i i i i i i iif i(overrideId i< i0)

i i i i i i i i i i i i i i i ioverrideId i= imNextFrameId++;

iiiiiiiiiiii BrainFrame iframe i= imFrameStack[GetBrainFrame(overrideId)];


iiiiiiiiiiii frame.deltaTimeOverride i= ideltaTime;
i i i i i i i i i i i iframe.timeOfOverride i= iTime.realtimeSinceStartup;

i i i i i i i i i i i iframe.blend.CamA i= icamA;

i i i i i i i i i i i iframe.blend.CamB i= icamB;

i i i i i i i i i i i iframe.blend.BlendCurve i= iAnimationCurve.Linear(0, i0, i1, i1);

i i i i i i i i i i i iframe.blend.Duration i= i1;

i i i i i i i i i i i iframe.blend.TimeInBlend i= i weightB;

iiiiiiiiiiii return ioverrideId;


iiiiiiii }

iiiiiiii /// i<summary>


iiiiiiii /// iThis iAPI iis ispecifically ifor iTimeline. i iDo inot iuse iit.
i i i i i i i i/// iRelease ithe iresources iused ifor ia icamera ioverride iclient.

i i i i i i i i/// iSee iSetCameraOverride.

i i i i i i i i/// i</summary>

i i i i i i i i/// i<param iname="overrideId">The iID ito ireleased. i iThis iis ithe ivalue ithat

i i i i i i i i/// i was ireturned iby iSetCameraOverride</param>

i i i i i i i iinternal ivoid iReleaseCameraOverride(int ioverrideId)

i i i i i i i i{

i i i i i i i i i i i ifor i(int ii i= imFrameStack.Count i- i1; ii i> i0; i--i)

Panipat iInstitute iof iEngineering iand iTechnology i Page i55


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii {
iiiiiiiiiiiiiiii if i(mFrameStack[i].id i== ioverrideId)
iiiiiiiiiiiiiiii {
i i i i i i i i i i i i i i i i i i i imFrameStack.RemoveAt(i);

i i i i i i i i i i i i i i i i i i i ireturn;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii ICinemachineCamera imActiveCameraPreviousFrame;


iiiiiiii private ivoid iProcessActiveCamera(float ideltaTime)
i i i i i i i i{

i i i i i i i i i i i ivar iactiveCamera i= iActiveVirtualCamera;

i i i i i i i i i i i iif i(activeCamera i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iHas ithe icurrent icamera ichanged ithis iframe?

i i i i i i i i i i i i i i i iif i(activeCamera i!= imActiveCameraPreviousFrame)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iNotify iincoming icamera iof itransition

i i i i i i i i i i i i i i i i i i i iactiveCamera.OnTransitionFromCamera(

i i i i i i i i i i i i i i i i i i i i i i i imActiveCameraPreviousFrame, iDefaultWorldUp, ideltaTime);

i i i i i i i i i i i i i i i i i i i iif i(m_CameraActivatedEvent i!= inull)

i i i i i i i i i i i i i i i i i i i i i i i im_CameraActivatedEvent.Invoke(activeCamera, imActiveCameraPreviousFrame);

iiiiiiiiiiiiiiiiiiii // iIf iwe're icutting iwithout ia iblend, isend ian ievent


iiiiiiiiiiiiiiiiiiii if i(m_CameraCutEvent i!= inull
i i i i i i i i i i i i i i i i i i i i i i i i i i i i&& i(!IsBlending i || i(mActiveCameraPreviousFrame i!= inull

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i&& i!ActiveBlend.Uses(mActiveCameraPreviousFrame))))

i i i i i i i i i i i i i i i i i i i i i i i im_CameraCutEvent.Invoke(this);

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i// iApply ithe ivcam istate ito ithe iUnity icamera

i i i i i i i i i i i i i i i iPushStateToUnityCamera(

i i i i i i i i i i i i i i i i i i i iSoloCamera i!= inull i? iSoloCamera.State i: imCurrentLiveCameras.State);

i i i i i i i i i i i i}

i i i i i i i i i i i imActiveCameraPreviousFrame i= iactiveCamera;

i i i i i i i i}

iiiiiiii private ivoid iUpdateFrame0(float ideltaTime)


iiiiiiii {
i i i i i i i i i i i i// iUpdate ithe iin-game iframe i(frame i0)

i i i i i i i i i i i iBrainFrame iframe i= imFrameStack[0];

iiiiiiiiiiii // iAre iwe itransitioning icameras?


iiiiiiiiiiii var iactiveCamera i= iTopCameraFromPriorityQueue();
i i i i i i i i i i i ivar ioutGoingCamera i= iframe.blend.CamB;

i i i i i i i i i i i iif i(activeCamera i!= ioutGoingCamera)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i// iDo iwe ineed ito icreate ia igame-play iblend?

i i i i i i i i i i i i i i i iif i((UnityEngine.Object)activeCamera i!= inull

i i i i i i i i i i i i i i i i i i i i&& i(UnityEngine.Object)outGoingCamera i!= inull i&& ideltaTime i>= i0)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iCreate ia iblend i(curve i will ibe inull iif ia icut)

i i i i i i i i i i i i i i i i i i i ivar iblendDef i= iLookupBlend(outGoingCamera, iactiveCamera);

i i i i i i i i i i i i i i i i i i i iif i(blendDef.BlendCurve i!= inull i&& iblendDef.m_Time i> i0)

Panipat iInstitute iof iEngineering iand iTechnology i Page i56


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiiiiiii {
iiiiiiiiiiiiiiiiiiiiiiii if i(frame.blend.IsComplete)
iiiiiiiiiiiiiiiiiiiiiiiiiiii frame.blend.CamA i= ioutGoingCamera; i i// inew iblend
i i i i i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i// iSpecial icase: iif ibacking iout iof ia iblend-in-progress

i i i i i i i i i i i i i i i i i i i i i i i i i i i i// iwith ithe isame iblend iin ireverse, iadjust ithe ibelnd itime

i i i i i i i i i i i i i i i i i i i i i i i i i i i iif i(frame.blend.CamA i== iactiveCamera

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i&& iframe.blend.CamB i== ioutGoingCamera

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i && iframe.blend.Duration i<= iblendDef.m_Time)

i i i i i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i iblendDef.m_Time i= iframe.blend.TimeInBlend;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i}

iiiiiiiiiiiiiiiiiiiiiiiiiiii // iChain ito iexisting iblend


iiiiiiiiiiiiiiiiiiiiiiiiiiii frame.blend.CamA i= inew iBlendSourceVirtualCamera(
i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i inew iCinemachineBlend(

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.blend.CamA, iframe.blend.CamB,

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.blend.BlendCurve, iframe.blend.Duration,

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.blend.TimeInBlend));

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i iframe.blend.BlendCurve i= iblendDef.BlendCurve;

i i i i i i i i i i i i i i i i i i i iframe.blend.Duration i= iblendDef.m_Time;

i i i i i i i i i i i i i i i i i i i iframe.blend.TimeInBlend i= i0;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i// iSet ithe icurrent iactive icamera

i i i i i i i i i i i i i i i iframe.blend.CamB i= iactiveCamera;

i i i i i i i i i i i i}

iiiiiiiiiiii // iAdvance ithe icurrent iblend i(if iany)


iiiiiiiiiiii if i(frame.blend.CamA i!= inull)
i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iframe.blend.TimeInBlend i+= i(deltaTime i>= i0) i? ideltaTime i: iframe.blend.Duration;

i i i i i i i i i i i i i i i iif i(frame.blend.IsComplete)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i// iNo imore iblend

i i i i i i i i i i i i i i i i i i i iframe.blend.CamA i= inull;

i i i i i i i i i i i i i i i i i i i iframe.blend.BlendCurve i= inull;

i i i i i i i i i i i i i i i i i i i iframe.blend.Duration i= i0;

i i i i i i i i i i i i i i i i i i i iframe.blend.TimeInBlend i= i0;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i}

iiiiiiii private ivoid iUpdateCurrentLiveCameras()


iiiiiiii {
i i i i i i i i i i i i// iResolve ithe icurrent iworking iframe istates iin ithe istack

i i i i i i i i i i i iint ilastActive i= i0;

i i i i i i i i i i i ifor i(int ii i= i0; ii i< imFrameStack.Count; i++i)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iBrainFrame iframe i= imFrameStack[i];

i i i i i i i i i i i i i i i iif i(i i== i0 i|| iframe.Active)

i i i i i i i i i i i i i i i i{

Panipat iInstitute iof iEngineering iand iTechnology i Page i57


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiiiiiii frame.workingBlend.CamA i= iframe.blend.CamA;


iiiiiiiiiiiiiiiiiiii frame.workingBlend.CamB i= iframe.blend.CamB;
i i i i i i i i i i i i i i i i i i i iframe.workingBlend.BlendCurve i= iframe.blend.BlendCurve;

i i i i i i i i i i i i i i i i i i i iframe.workingBlend.Duration i= iframe.blend.Duration;

i i i i i i i i i i i i i i i i i i i iframe.workingBlend.TimeInBlend i= iframe.blend.TimeInBlend;

i i i i i i i i i i i i i i i i i i i iif i(i i> i0 i&& i!frame.blend.IsComplete)

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i iif i(frame.workingBlend.CamA i== inull)

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i iif i(mFrameStack[lastActive].blend.IsComplete)

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.workingBlend.CamA i= imFrameStack[lastActive].blend.CamB;

i i i i i i i i i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.workingBlendSource.Blend i= imFrameStack[lastActive].workingBlend;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i iframe.workingBlend.CamA i= iframe.workingBlendSource;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i ielse iif i(frame.workingBlend.CamB i== inull)

i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i iif i(mFrameStack[lastActive].blend.IsComplete)

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.workingBlend.CamB i= imFrameStack[lastActive].blend.CamB;

i i i i i i i i i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.workingBlendSource.Blend i= imFrameStack[lastActive].workingBlend;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i frame.workingBlend.CamB i= iframe.workingBlendSource;

i i i i i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i i i i i i i i ilastActive i= ii;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i i i i ivar i workingBlend i= imFrameStack[lastActive].workingBlend;

i i i i i i i i i i i imCurrentLiveCameras.CamA i= i workingBlend.CamA;

i i i i i i i i i i i imCurrentLiveCameras.CamB i= iworkingBlend.CamB;

i i i i i i i i i i i imCurrentLiveCameras.BlendCurve i= iworkingBlend.BlendCurve;

i i i i i i i i i i i imCurrentLiveCameras.Duration i= iworkingBlend.Duration;

i i i i i i i i i i i imCurrentLiveCameras.TimeInBlend i= iworkingBlend.TimeInBlend;

i i i i i i i i}

iiiiiiii /// i<summary>


iiiiiiii /// iTrue iif ithe iICinemachineCamera ithe icurrent iactive icamera,
i i i i i i i i/// ior ipart iof ia icurrent iblend, ieither idirectly ior iindirectly ibecause iits iparents iare ilive.

i i i i i i i i/// i</summary>

i i i i i i i i/// i<param iname="vcam">The icamera ito itest iwhether iit iis ilive</param>

i i i i i i i i/// i<param iname="dominantChildOnly">If itruw, i will ionly ireturn itrue iif ithis ivcam iis ithe idominat ilive

ichild</param>

i i i i i i i i/// i<returns>True iif ithe icamera iis ilive i(directly ior iindirectly)

i i i i i i i i/// ior ipart iof ia iblend iin iprogress.</returns>

i i i i i i i ipublic ibool iIsLive(ICinemachineCamera ivcam, ibool idominantChildOnly i= ifalse)

i i i i i i i i{

i i i i i i i i i i i iif i(SoloCamera i== ivcam)

i i i i i i i i i i i i i i i ireturn itrue;

i i i i i i i i i i i iif i(mCurrentLiveCameras.Uses(vcam))

i i i i i i i i i i i i i i i ireturn itrue;

Panipat iInstitute iof iEngineering iand iTechnology i Page i58


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii ICinemachineCamera iparent i= ivcam.ParentCamera;


iiiiiiiiiiii while i(parent i!= inull i&& iparent.IsLiveChild(vcam, idominantChildOnly))
i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(SoloCamera i== iparent i|| i mCurrentLiveCameras.Uses(parent))

i i i i i i i i i i i i i i i i i i i ireturn itrue;

i i i i i i i i i i i i i i i ivcam i= iparent;

i i i i i i i i i i i i i i i iparent i= ivcam.ParentCamera;

i i i i i i i i i i i i}

i i i i i i i i i i i ireturn ifalse;

i i i i i i i i}

iiiiiiii /// i<summary>


iiiiiiii /// iThe icurrent istate iapplied ito ithe iunity icamera i(may ibe ithe iresult iof ia iblend)
i i i i i i i i/// i</summary>

i i i i i i i ipublic iCameraState iCurrentCameraState i{ iget; iprivate iset; i}

iiiiiiii /// i<summary>


iiiiiiii /// iGet ithe ihighest-priority iEnabled iICinemachineCamera
i i i i i i i i/// ithat iis ivisible ito imy icamera. i iCulling iMask iis iused ito itest ivisibility.

i i i i i i i i/// i</summary>

i i i i i i i iprivate iICinemachineCamera iTopCameraFromPriorityQueue()

i i i i i i i i{

i i i i i i i i i i i iCinemachineCore icore i= iCinemachineCore.Instance;

i i i i i i i i i i i iCamera ioutputCamera i= iOutputCamera;

i i i i i i i i i i i iint imask i= ioutputCamera i== inull i? i~0 i: ioutputCamera.cullingMask;

i i i i i i i i i i i iint inumCameras i= icore.VirtualCameraCount;

i i i i i i i i i i i ifor i(int ii i= i0; ii i< inumCameras; i++i)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i ivar icam i= icore.GetVirtualCamera(i);

i i i i i i i i i i i i i i i iGameObject igo i= icam i!= inull i? icam.gameObject i: inull;

i i i i i i i i i i i i i i i iif i(go i!= inull i&& i(mask i& i(1 i<< igo.layer)) i!= i0)

i i i i i i i i i i i i i i i i i i i ireturn icam;

i i i i i i i i i i i i}

i i i i i i i i i i i ireturn inull;

i i i i i i i i}

iiiiiiii /// i<summary>


iiiiiiii /// iCreate ia iblend icurve ifor iblending ifrom ione iICinemachineCamera ito ianother.
i i i i i i i i/// iIf ithere iis ia ispecific iblend idefined ifor ithese icameras iit iwill ibe iused, iotherwise

i i i i i i i i/// ia idefault iblend iwill ibe icreated, i which icould ibe ia icut.

i i i i i i i i/// i</summary>

i i i i i i i iprivate iCinemachineBlendDefinition iLookupBlend(

i i i i i i i i i i i iICinemachineCamera ifromKey, iICinemachineCamera itoKey)

i i i i i i i i{

i i i i i i i i i i i i// iGet ithe iblend icurve ithat's i most iappropriate ifor ithese icameras

i i i i i i i i i i i iCinemachineBlendDefinition iblend i= im_DefaultBlend;

i i i i i i i i i i i iif i(m_CustomBlends i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i istring ifromCameraName i= i(fromKey i!= inull) i? ifromKey.Name i: istring.Empty;

i i i i i i i i i i i i i i i istring itoCameraName i= i(toKey i!= inull) i? itoKey.Name i: istring.Empty;

i i i i i i i i i i i i i i i iblend i= im_CustomBlends.GetBlendForVirtualCameras(

i i i i i i i i i i i i i i i i i i i i i i i ifromCameraName, itoCameraName, iblend);

i i i i i i i i i i i i}

Panipat iInstitute iof iEngineering iand iTechnology i Page i59


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii if i(CinemachineCore.GetBlendOverride i!= inull)


iiiiiiiiiiiiiiii blend i= iCinemachineCore.GetBlendOverride(fromKey, itoKey, iblend, ithis);
i i i i i i i i i i i ireturn iblend;

i i i i i i i i}

iiiiiiii /// i<summary> iApply ia icref="CameraState"/> ito ithe igame iobject</summary>


iiiiiiii private ivoid iPushStateToUnityCamera(CameraState istate)
i i i i i i i i{

i i i i i i i i i i i iCurrentCameraState i= istate;

i i i i i i i i i i i iif i((state.BlendHint i& iCameraState.BlendHintValue.NoPosition) i== i0)

i i i i i i i i i i i i i i i itransform.position i= istate.FinalPosition;

i i i i i i i i i i i iif i((state.BlendHint i& iCameraState.BlendHintValue.NoOrientation) i== i0)

i i i i i i i i i i i i i i i itransform.rotation i= istate.FinalOrientation;

i i i i i i i i i i i iif i((state.BlendHint i& iCameraState.BlendHintValue.NoLens) i== i0)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iCamera icam i= iOutputCamera;

i i i i i i i i i i i i i i i iif i(cam i!= inull)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i icam.nearClipPlane i= istate.Lens.NearClipPlane;

i i i i i i i i i i i i i i i i i i i icam.farClipPlane i= istate.Lens.FarClipPlane;

i i i i i i i i i i i i i i i i i i i icam.fieldOfView i= istate.Lens.FieldOfView;

i i i i i i i i i i i i i i i i i i i iif i(cam.orthographic)

i i i i i i i i i i i i i i i i i i i i i i i icam.orthographicSize i= istate.Lens.OrthographicSize;

#if iUNITY_2018_2_OR_NEWER
i i i i i i i i i i i i i i i i i i i ielse

i i i i i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i i i i i icam.usePhysicalProperties i= istate.Lens.IsPhysicalCamera;

i i i i i i i i i i i i i i i i i i i i i i i icam.lensShift i= istate.Lens.LensShift;

i i i i i i i i i i i i i i i i i i i i}

#endif
i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

i i i i i i i i i i i iif i(CinemachineCore.CameraUpdatedEvent i!= inull)

i i i i i i i i i i i i i i i iCinemachineCore.CameraUpdatedEvent.Invoke(this);

i i i i i i i i}

i i i i}

5.10 iAnimation Controller


using iSystem.Collections;
using iSystem.Collections.Generic;
using iPlatformer.Core;
using iPlatformer.Model;
using iUnityEngine;

namespace iPlatformer.Mechanics
{
i i i i/// i<summary>

i i i i/// iAnimationController iintegrates iphysics iand ianimation. iIt iis igenerally iused ifor isimple ienemy ianimation.

i i i i/// i</summary>

i i i i[RequireComponent(typeof(SpriteRenderer), itypeof(Animator))]

i i i ipublic iclass iAnimationController i: iKinematicObject

Panipat iInstitute iof iEngineering iand iTechnology i Page i60


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiii {
iiiiiiii /// i<summary>
iiiiiiii /// iMax ihorizontal ispeed.
i i i i i i i i/// i</summary>

i i i i i i i ipublic ifloat imaxSpeed i= i7;

i i i i i i i i/// i<summary>

i i i i i i i i/// iMax ijump ivelocity

i i i i i i i i/// i</summary>

i i i i i i i ipublic ifloat ijumpTakeOffSpeed i= i7;

iiiiiiii /// i<summary>


iiiiiiii /// iUsed ito iindicated idesired idirection iof itravel.
i i i i i i i i/// i</summary>

i i i i i i i ipublic iVector2 imove;

iiiiiiii /// i<summary>


iiiiiiii /// iSet ito itrue ito iinitiate ia ijump.
i i i i i i i i/// i</summary>

i i i i i i i ipublic ibool ijump;

iiiiiiii /// i<summary>


iiiiiiii /// iSet ito itrue ito iset ithe icurrent ijump ivelocity ito izero.
i i i i i i i i/// i</summary>

i i i i i i i ipublic ibool istopJump;

iiiiiiii SpriteRenderer ispriteRenderer;


iiiiiiii Animator ianimator;
i i i i i i i iPlatformerModel imodel i= iSimulation.GetModel<PlatformerModel>();

iiiiiiii protected ivirtual ivoid iAwake()


iiiiiiii {
i i i i i i i i i i i ispriteRenderer i= iGetComponent<SpriteRenderer>();

i i i i i i i i i i i ianimator i= iGetComponent<Animator>();

i i i i i i i i}

iiiiiiii protected ioverride ivoid iComputeVelocity()


iiiiiiii {
i i i i i i i i i i i iif i(jump i&& iIsGrounded)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i ivelocity.y i= ijumpTakeOffSpeed i* imodel.jumpModifier;

i i i i i i i i i i i i i i i ijump i= ifalse;

i i i i i i i i i i i i}

i i i i i i i i i i i ielse iif i(stopJump)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i istopJump i= ifalse;

i i i i i i i i i i i i i i i iif i(velocity.y i> i0)

i i i i i i i i i i i i i i i i{

i i i i i i i i i i i i i i i i i i i ivelocity.y i= ivelocity.y i * i model.jumpDeceleration;

i i i i i i i i i i i i i i i i}

i i i i i i i i i i i i}

iiiiiiiiiiii if i(move.x i> i0.01f)


iiiiiiiiiiiiiiii spriteRenderer.flipX i= ifalse;
i i i i i i i i i i i ielse iif i(move.x i< i-0.01f)

Panipat iInstitute iof iEngineering iand iTechnology i Page i61


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiiiiiii spriteRenderer.flipX i= itrue;

iiiiiiiiiiii animator.SetBool("grounded", iIsGrounded);


iiiiiiiiiiii animator.SetFloat("velocityX", iMathf.Abs(velocity.x) i/ imaxSpeed);

iiiiiiiiiiii targetVelocity i= imove i* imaxSpeed;


iiiiiiii }
iiii }
}

5.11 iEnemy Controller


using iSystem.Collections;
using iSystem.Collections.Generic;
using iPlatformer.Gameplay;
using iUnityEngine;
using istatic iPlatformer.Core.Simulation;

namespace iPlatformer.Mechanics
{
i i i i/// i<summary>

i i i i/// iA isimple icontroller ifor ienemies. iProvides imovement icontrol iover ia ipatrol ipath.

i i i i/// i</summary>

i i i i[RequireComponent(typeof(AnimationController), itypeof(Collider2D))]

i i i ipublic iclass iEnemyController i: iMonoBehaviour

i i i i{

i i i i i i i ipublic iPatrolPath ipath;

i i i i i i i ipublic iAudioClip iouch;

iiiiiiii internal iPatrolPath.Mover imover;


iiiiiiii internal iAnimationController icontrol;
i i i i i i i iinternal iCollider2D i_collider;

i i i i i i i iinternal iAudioSource i_audio;

i i i i i i i iSpriteRenderer ispriteRenderer;

iiiiiiii public iBounds iBounds i=> i_collider.bounds;

iiiiiiii void iAwake()


iiiiiiii {
i i i i i i i i i i i icontrol i= iGetComponent<AnimationController>();

i i i i i i i i i i i i_collider i= iGetComponent<Collider2D>();

i i i i i i i i i i i i_audio i= iGetComponent<AudioSource>();

i i i i i i i i i i i ispriteRenderer i= iGetComponent<SpriteRenderer>();

i i i i i i i i}

iiiiiiii void iOnCollisionEnter2D(Collision2D icollision)


iiiiiiii {
i i i i i i i i i i i ivar iplayer i= icollision.gameObject.GetComponent<PlayerController>();

i i i i i i i i i i i iif i(player i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i ivar iev i= iSchedule<PlayerEnemyCollision>();

i i i i i i i i i i i i i i i iev.player i= iplayer;

i i i i i i i i i i i i i i i iev.enemy i= ithis;

Panipat iInstitute iof iEngineering iand iTechnology i Page i62


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

iiiiiiiiiiii }
iiiiiiii }

iiiiiiii void iUpdate()


iiiiiiii {
i i i i i i i i i i i iif i(path i!= inull)

i i i i i i i i i i i i{

i i i i i i i i i i i i i i i iif i(mover i== inull) imover i= ipath.CreateMover(control.maxSpeed i* i0.5f);

i i i i i i i i i i i i i i i icontrol.move.x i= iMathf.Clamp(mover.Position.x i- itransform.position.x, i-1, i1);

i i i i i i i i i i i i}

i i i i i i i i}

iiii }
}

Panipat iInstitute iof iEngineering iand iTechnology i Page i63


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 6: OUTPUT i i

Panipat iInstitute iof iEngineering iand iTechnology i Page i64


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

Panipat iInstitute iof iEngineering iand iTechnology i Page i65


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

Panipat iInstitute iof iEngineering iand iTechnology i Page i66


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 7: CONCLUSION i i

In ithis itheory, iI iclarified iabout ithe igame iadvancement iand iprogramming iwith ithe iUnity igame
i motor ialongside ithe idifferent ihighlights ithat imake icreating igames isimpler. iCreating igames iis ia
i very itroublesome iand ilong iprocedure iwithout iappropriate iarranging iand iexecution. iTaking ia ishot
i at ithe ipostulation inot ijust ihelped ime iget iinformation iabout ithe iUnity igame imotor iand igame
i advancement, iyet iadditionally iabout iprogramming. iAs iI ihad ithe ioption ito ipick iup iinside iand iout
i thoughts iregarding ithe igame imaking iand iprogramming iwhich iI iwould inot ihave icome ithrough
i during itypical ieveryday ipractice. iThe igame icreated iwas ifor ilearning ipurposes iand ito ipresent ithe
i most irecent ihighlights iin iUnity2D. iThis iundertaking iwill ibe igrown ifurther iand iimproved ilater ion. i
To ifinish iup, ia igeneral ithought iregarding ia ipresent iday, itwo-dimensional igame ihas ibeen idisplayed
i in ithis ipostulation. iIt iis iimperative ito igain iinformation iin iorder ito icreate iprogressively iconvoluted
i and iawesome igames, ihowever iin ia ibasic iway.

7.1 Limitations iand iErrors iin ithe iDeveloped iSystem:


 The iproject iis istrictly iwindows ibased ibut iit ican ialso ibe ibuilt ifor imobile idevices iwith
i additional iUnity iplug iins.
 The isystem ishould ihave igood iaudio iand igraphics idivers ifor ibest iperformance. i

7.2 Future iEnhancement


 More ilevels ican ibe iadded.
 More ivariations iof ienemies ican ibe iadded.
 The iplayer ican ibe imodified ito iperform imore icomplex iactions.

Panipat iInstitute iof iEngineering iand iTechnology i Page i67


i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i ii 2D iPlatformer iGame i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i

CHAPTER 8: REFERENCES i i

Unity Technologies.2019a. Learning the Interface. Available:


https://docs.unity3d.com/Manual/LearningtheInterface.html. Accessed 14 September 2019.

Unity Technologies.2019b. Project view.Available:


https://docs.unity3d.com/Manual/ProjectView.html. Accessed 14 September 2019.

Unity Technologies.2019c. Scene View.Available:


https://docs.unity3d.com/Manual/UsingTheSceneView.html. Accessed 14 September 2019.

Unity Technologies.2019d. Game View.Available:


https://docs.unity3d.com/Manual/GameView.html. Accessed 14 September 2019.

Unity Technologies.2019e. Hierarchy.Available:


https://docs.unity3d.com/Manual/Hierarchy.html. Accessed 14 September 2019.

Unity Technologies. 2019f. Inspector Window.Available:


https://docs.unity3d.com/Manual/UsingTheInspector.html. Accessed 14 September 2019.

Unity Technologies. 2019g. Toolbar. Available:https://docs.unity3d.com/Manual/Toolbar.html.


Accessed 14 September 2019.

Unity Technologies. 2019h. Sprite Editor.


Available:https://docs.unity3d.com/Manual/SpriteEditor.html. Accessed 10 October 2019.

Unity Technologies. 2019i. Sprite Creator. Available:


https://docs.unity3d.com/Manual/SpriteCreator.html. Accessed 10 October 2019.

Panipat iInstitute iof iEngineering iand iTechnology i Page i68

Вам также может понравиться