Академический Документы
Профессиональный Документы
Культура Документы
CHAPTER 1: INTRODUCTION i i
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.
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.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
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.
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
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
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.
- iProject iWindow i
- iHierarchy iWindow i
- iScene iView i
- iGame iView i
- iInspector iand i
- iToolbar. 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
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.
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.
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.
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.
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
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.
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.
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.
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
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 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
i Animator iWindow. iEach iGameObject ican ihave ivarious ilivelinesss iand iit iis iconceivable ito icontrol.
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
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
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.
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.
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.
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
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.
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
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
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.
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.
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.
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.
CHAPTER 5: CODING i i
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 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}
i i i i i i i i}
i i i i i i i i}
i i i i}
namespace iPlatformer.Mechanics
{
i i i i/// i<summary>
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/// i</summary>
i i i i{
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 i i i i itokens i= iUnityEngine.Object.FindObjectsOfType<TokenInstance>();
i i i i i i i i}
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 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 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}
i i i i i i i i i i i i{
i i i i i i i i i i i i i i i 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 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 i{
i i i 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
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 i i i i i}
iiii }
}
namespace iPlatformer.Mechanics
{
i i i i/// i<summary>
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/// i</summary>
i i i i{
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 i i i i itokens i= iUnityEngine.Object.FindObjectsOfType<TokenInstance>();
i i i i i i i i}
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 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 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;
iiiiiiiiiiii }
iiiiiiii }
i i i i i i i i i i i i{
i i i i i i i i i i i i i i i 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 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 i{
i i i 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 i i i i i i i i i i i i i i i i i}
i i i i i i i i i i i i 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 }
}
5.4 iJiggler
using iSystem.Collections;
using iSystem.Collections.Generic;
using iUnityEngine;
i i i i[Range(0, i120)]
i i i ifloat ipositionTime;
i i i i[Range(0, i120)]
i i i ifloat irotationTime;
i i i i[Range(0, i120)]
i i i ifloat iscaleTime;
i i i i i i i ibaseScale i= ithis.transform.localScale;
i i i i}
i i i i}
namespace iPlatformer.UI
{
i i i i/// i<summary>
i i i i/// i</summary>
i i i i{
i i i 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 ig i= ipanels[i];
i i i i i i i i i i i i}
i i i i i i i i}
i i i i i i i i}
i i i i}
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/// 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]
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 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 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
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.")]
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 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[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")]
iCameras")]
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 i/// i</summary>
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 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>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
i i i i i i i i/// i</summary>
i i i i i i i i{
i i i i i i i i i i i iset
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>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}
i i i i i i i i i i i i i i i imFrameStack.Add(new iBrainFrame());
iiiiiiiiiiii // iWe icheck iin iafter ithe iphysics isystem ihas ihad ia ichance ito imove ithings
iiiiiiiiiiii mPhysicsCoroutine i= iStartCoroutine(AfterPhysics());
iiiiiiii }
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}
i i i i i i i i}
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 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 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 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 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 i i i i iCinemachineDebug.OnGUIHandlers();
i i i i i i i i}
#endif
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{
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 }
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();
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 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 i{
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{
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 {
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 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 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 i i i i iCinemachineCore.Instance.CurrentUpdateFilter i= iupdateFilter;
i i i i i i i i i i i iCinemachineCore.Instance.UpdateAllActiveVirtualCameras(
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);
i i i i i i i i i i i i{
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}
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 i i i i ireturn iSoloCamera;
i i i i i i i i i i i i i i i ireturn iDeepCamBFromBlend(mCurrentLiveCameras);
iiiiiiiiiiii }
iiiiiiii }
i i i 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 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}
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 i i i i ireturn 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 ireturn imCurrentLiveCameras;
i i i i i i i i i i i i}
i i i i i i i i}
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 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 i i i i i i i i ireturn ii;
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);
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/// i</summary>
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/// 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/// iafter iall ioverriding iis ifinished, ito ifree ithe iOverideStack iresources.</returns>
i i i i i i i i i i i iint ioverrideId,
i i i i i i i i{
i i i i i i i i i i i i i i i ioverrideId i= imNextFrameId++;
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</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 i i i i i i i i i i i{
i i i i i i i i i i i 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}
i i i i i i i i i i i i{
i i i i i i i i i i i i i i i i{
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 im_CameraActivatedEvent.Invoke(activeCamera, 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!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 iPushStateToUnityCamera(
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}
i i i i i i i i i i i i{
i i i i i i i i i i i i i i i i{
i i i i i i i i i i i i i i i i i i i 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 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// 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 i{
i i i i i i i i 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}
i i i i i i i i i i i i 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 iframe.blend.CamB 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 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 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}
i i i i i i i i i i i i{
i i i i i i i i i i i 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 i{
i i i i i i i i i i i i i i i i i i i i i i i i{
i i i 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 i{
i i i 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 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;
iiiiiiii }
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{
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;
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}
i i i i i i i i/// i</summary>
i i i i i i i i{
i i i 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(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}
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 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 i{
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 ireturn iblend;
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 i i i i itransform.position i= istate.FinalPosition;
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 i{
i i i i i i i i i i i 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 i i i i iCinemachineCore.CameraUpdatedEvent.Invoke(this);
i i i i i i i i}
i i i i}
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/// 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 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 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 i/// i</summary>
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 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.")]
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 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[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 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 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 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 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>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
i i i i i i i i/// i</summary>
i i i i i i i 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 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>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}
i i i i i i i i i i i i i i i imFrameStack.Add(new iBrainFrame());
iiiiiiiiiiii // iWe icheck iin iafter ithe iphysics isystem ihas ihad ia ichance ito imove ithings
iiiiiiiiiiii mPhysicsCoroutine i= iStartCoroutine(AfterPhysics());
iiiiiiii }
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}
i i i i i i i i}
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 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 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{
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 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 i i i i iCinemachineDebug.OnGUIHandlers();
i i i i i i i i}
#endif
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{
i i i i i i i i i i i i i i i i i i i i{
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}
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();
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 i{
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{
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
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 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 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)
iiiiiiii }
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 iCinemachineCore.Instance.UpdateAllActiveVirtualCameras(
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);
i i i i i i i i i i i i{
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}
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 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}
i i i 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 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}
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 i i i i ireturn 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 ireturn imCurrentLiveCameras;
i i i i i i i i i i i i}
i i i i i i i i}
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 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 i i i i i i i i ireturn ii;
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);
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/// i</summary>
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/// 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/// iafter iall ioverriding iis ifinished, ito ifree ithe iOverideStack iresources.</returns>
i i i i i i i i i i i iint ioverrideId,
i i i i i i i i{
i i i i i i i i i i i i i i i ioverrideId i= imNextFrameId++;
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.Duration i= i1;
i i i i i i i i i i i iframe.blend.TimeInBlend i= i weightB;
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{
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}
i i i i i i i i i i i i{
i i i i i i i i i i i i i i i i{
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 im_CameraActivatedEvent.Invoke(activeCamera, 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!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 iPushStateToUnityCamera(
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}
i i i i 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// 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 i{
i i i i i i i 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}
i i i i i i i i i i i i 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 iframe.blend.CamB 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 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 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}
i i i i i i i i i i i i{
i i i i i i i i i i i 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.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 i{
i i i i i i i i i i i i i i i i i i i i i i i i{
i i i 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 i{
i i i 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 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}
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{
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;
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}
i i i i i i i i/// i</summary>
i i i i i i i i{
i i i 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(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}
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 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 i{
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 i i i i i i i i iCurrentCameraState i= istate;
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 i i i i itransform.rotation i= istate.FinalOrientation;
i i i i i i i i i i i i{
i i i i i i i i i i i 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 i i i i iCinemachineCore.CameraUpdatedEvent.Invoke(this);
i i i i i i i i}
i i i i}
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))]
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 i/// i<summary>
i i i i i i i i/// i</summary>
i i i i i i i i i i i ianimator i= iGetComponent<Animator>();
i i i i i i i i}
i i i i i i i i i i i i{
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 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 i{
i i i i i i i i i i i i i i i i}
i i i i i i i i i i i i}
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 i{
i i i i i i i iSpriteRenderer ispriteRenderer;
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}
i i i i i i i i i i i i{
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;
iiiiiiiiiiii }
iiiiiiii }
i i i i i i i i 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 }
}
CHAPTER 6: OUTPUT 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.
CHAPTER 8: REFERENCES i i