Game Flow Manual V0.8 Beta EN

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 51

!! 1
User Manual!
v0.8 Beta
Overview
GameFlowisapluginorextensionfortheUnityenginetosimplifyand
acceleratethedevelopmentofvideogamestogreatlyreducethe
barrierformanygamedesignersandartistssupposedscriptingor
programminglogicandspecialeffects.
GameFlowisperfectlyintegratedintheUnityeditoraddingasupport
event-basedvisualprogrammingblocksofsharesthatallowsdesigners
/asgameswithbasicprogrammingskillstobuildperfectlyfunctional
programsinafractionofthetimeitwouldtaketodosothrough
languagesscriptingasC#orJavascript.
GameFlowalsoincludesasetoftoolstofacilitatetheworkofmounting
levelsofplay,suchasavisualeditortrajectoriesaswellasafull
repertoireofprefabs(partsofprefabricatedgame)configuredand
readytouse.
GameFlowisdesignedforreuseandhasanownextensibilityAPIfor
advanceduserswhowanttocreatetheirownblocksofstockorbespoke
events.
Visual programming
Callorvisualprogrammingvisualscripting”tooneinwhichtocreatea
programisnotnecessarytowritelinesofcodeinatexteditor,butonly
manipulatevisualelements.ForGameFlow,thesevisualelementsare
blocksofdifferenttypes(actions,conditions,etc.)thatcanbeassociated
todifferentgameobjects(hereinafterGameObjects)thereatthescene.
Features
Programming
GameFlowletsyoudesignthelogicortheeffectsofagamethrough
programs(sequencesofactions)wecanassociatetheGameObjects,all
withoutleavingtheeditorofUnityitself.
Actions
GameFlowcomesstandardwitharepertoireof150sharestocover
muchofthebasicnecessitiesrequiredindevelopingagame.Acomplete
listisavailableintheActionssection.
Variables
AllactionsandtoolsGameFlowacceptnotonlyspecificvaluesfortheir
propertiesbutalsovariables,whichallowstobuildflexibleandversatile
programs.Thevariables,ofcourse,arealsodefinedfromtheeditor.
Events
GameFlowfacilitatesbasedscheduling(seeanexplanationinChapter
Events)throughavarietyofspecialprograms(Event Programs)thatrun
automaticallywhencertaineventsoccur.
Lists
GameFlowsupportsdynamiclistsofitemsintheeditoritself.Theselists
canbeusedformanypurposesduringthegame,butareespecially
usefultoapplythesameactiontomultipleobjectsinonestep.
Trajectories
GameFlowincorporatesaneditorofbothlinearpathsasbasedon
curvesthatcanbecombinedwithsomeactiontogetthegameobjects
followthemovertimeandalsoforotherpurposessuchasautomated
scenariogenerationwithcurves(oneroad,example).
Forces
GameFlowallowsdefiningforces(vectorswithadirectionanda
magnituderepresentedasarrows)canbeeditedvisuallyintheeditor
andcanbeappliedondemandovertheobjectsyouwant.It’saneasy
waytocommunicatewiththephysicsengineUnitytoaddmotioneffects
toourgame.
Timers
Timers(Timers)arecomponentsthatallowtheimplementationof
programsatregularintervalsorwhenatimeoutexhausted.Canalsobe
usedtoconstructtypemarkerstimecountdowntimerortype.
Pools
Thepoolsarestorehousesofobjectsofthesametypethatimprovethe
performanceofaplayinthosesituationswhereitisnecessaryto
continuouslydisplayamultitudeofobjectsonthescreen.GameFlow
Poolsofferssupportintegratedandeasytouse.
GameFabs
GameFlowincorporatesarepertoireofobjecttemplates(Prefabsinthe
jargonofUnity)wecallGamefabsthataredesignedaspartsreadyto
useandcanconsiderablyacceleratetheinstallationofavideogame.In
thisdirectorywefindfromkeyboarddriversandmouseupgenerators
objectsandreadytousemarkers.
Persistence
Withjustoneclick,GameFlowdealswithdatapersistenceofyourgame
sothatitiseasytoprogramgamesthatrememberthestateofthe
game.
Parameterization
GameFlowallowstheconstructionofparameterizedPrefabsfromthe
editorwithouthavingtowritecode.Thiswayyoucancreatelistsparts
forreuseinotherprojects.
Automation
Perhapsthefeature“hidden”GameFlowmostpowerfulisthatitallows
theexecutionofprogramsnotonlyatruntimebutalsoediting
time.Thatis,youcaneasilybuildprogramsthatgenerateormanipulate
sceneelementsfromtheeditor,thusfacilitatingtheconstructionof
gamelevels.
First Steps
Installation
IfGameFlowwasacquiredintheUnityAssetStoreyourpackage
(.unityPackagefile)alreadyinstalledonyoursystemandreadytousein
ourprojects.Theonlyrequiredstepistoimportthepackagewithinour
projectinoneoftwoways:
1. Ifyoucreateanewproject,checktheappropriatecheckthe
packageGameFlow.unityPackagewindowcreatingnewprojectto
displaydirectlyimported.
2. IfyouwishtoincorporateGameFlowtoanexistingproject,findthe
menuoptionAssets> Import Package> GameFlowandclickthe
Import”buttonintheImportwindowthatappearsbelow.
IfinsteadGameFlowwasnotpurchasedintheUnityAssetStore
installationpackageisalsoverysimple,itjustopenorcreateaproject
wherewewanttoimportGameFlowandthendoubleclickonthe
fileGameFlow.unityPackagetoimmediatelybeginyourImport.
IfyouwantyoucanalsocopythefiletoGameFlow.unityPackage
Standard PackagesfoldershouldappearintheinstallationpathofUnity
forthusitisavailableasapackagepurchasedintheUnityAssetStore.
Afterimportandregardlessofhowwehavedone,weshouldnotethat
intheProjectwindowUnityGameFlowanewfoldercontainingafolder
ofdocuments,some.DLLfilesandaReadmefilecontainsreleasenotes
appear.
Update
Theupdateprocessisexactlyliketheinstallation,ascouldbeconsidered
are-importthepackage.Itshould,however,alwaysreadtherelease
notesforthenewversionpriortoupdatingtoensurethatitdoesnot
includechangesthatmayaffecttheproperfunctioningofourgameor
application.
Help
Documentation
Thedocumentationcontainingtheusermanualandreference
programmingAPIcanbefoundintherelevantsectionofthewebsite
GameFlow.Thissamedocumentationisalsoavailableforconsultation
offlineundertheGameFlow / DocumentationofUnityprojectwherewe
GameFlowimportingthepackagefolder.
ThemanualisinPDFformatwhilethereferencedocumentationisin
HTMLformat,currentlyonlyinEnglishandSpanish.
Contextual Help
AstoaidintheUnityeditor,itisalwaysavailableasalastoptioninthe
contextmenuofeachelement.Thecontextmenuisdisplayedby
clickinganyofthemousebuttonsonthegeariconappearsintheupper
rightcornerofanycomponentorblockGameFlowintheInspector
window.
Quickhelpsummarizedinthewindowsforselectingactionsand
conditions,includinganiconthatgivesusaccesstotheselecteditem
pagemanualisalsodisplayed.
Tutorials
InthesectionoftutorialsontheGameFlowweb,newvideotutorialsthat
explainthroughshortexamplesdevelopingspecifictechniquesstepby
stepthatmaybeusefulwhendevelopingvideogamesareregularly
published.
Forum
Userswhoneedmorehelpcanbefoundontheofficialforum
GameFlow,asiteaimedatsharingexperiences,questionsand
knowledgewiththerestofthecommunity.
Basic Concepts
Basic Components
Containers
PremiumcomponentsaredisplayedintheInspectorwindowand
componentsofUnity,whosebasicfeatureisthattheycontainother
minorcomponentscalledblocks.InGameFlowthefollowingtypesof
containersaredistinguished:
Program:Asequenceofactionstobeinactive(ie,notrunning)until
hisexecutionwasorderedexplicitly.
Programevent(On):Asequenceofactionsthatstart
automaticallywhenaneventsuchasrecognizedbytheprogram
detected.
Variables:Alistshowingallvariablesdefinedwithintheobject.
Keys:Alistshowingallthekeysdefinedwithinthatobject.
Forces:Displaysallforcesdefinedwithintheobject.
Parameters:Showsallparametersdefinedintheobject.The
parametersareaspecialtypeofvariablesasdiscussedinthe
chapter.
Blocks
Theseareelementsthatcannotliveindependentlyoutsideofa
containerandplayingaparticularroleinthefunctionalityofthe
container.InGameFlowfindthefollowingtypes:
Action:Aprogramelementthatmakes(ifenabled)averyspecific
taskbasedonparametersorproperties.Mostactionsareexecuted
instantaneously,butothersonthecontrarywillrunduringthetime
intervalthatyouspecify.
Condition:Anelementoftheprogramthatperformsaspecific
assessmenttoreturna“Trueor“Falseresultthatcanbeusedfor
conditionalactionsasIforWhilecontrollingtheflowofaprogram.
Variable:Adynamicstorageunitthatcanstoreadataofacertain
type.Thegreatpowerofthevariablesistobeusedasthevaluefor
thepropertiesofvirtuallyanyelementofGameFlow:actions,
conditions,toolsorevenforothervariables.
Built-inVariable:Aspecialtypeofvariablethatcannotbeedited
becauseitstypeandvaluearealreadypredefined.Usuallyserveto
consultsysteminformationliketimeanddate,resolution,platform,
etc.
Parameter:Aspecialvariablethoughtthatservesbothtodisplay
theparametersofeventprograms(picturedright)toallowthe
constructionofparameterizedPrefabs.
Key:AkeydefinitionorwaytotellGameFlowwewanttomonitorthe
statusofthatparticularkey.
Force:Adefinitionofaforcethatcanbedisplayedintheeditor.
Tools
Theyarebasicindependentcomponentsthathavetheirownlogicand
itsownformofvisualediting,butareintegratedwithGameFlowto
withstandvariablesandbeingmanipulatedbyaseriesofactionsthat
workspecificallywiththem.Wecanaccessthemthroughthebrowser
andselectingcomponentsGameFlow>Tools.InGameFlowthefollowing
toolsaredistinguished.
List:Acomponentthatstoresasequentialsetofvalueswiththe
samebasetype.Likevariables,GameFlowlistsaredynamicandcan
bemanipulatedtoadd,insert,replace,ordeleteitemsinboth
runtimeandeditingtime.
Timer:Acomponentthatsendstimingeventsatregulartime
intervalswhich,incombinationwithaprogrameventasExpire On
Timerallowsexecutionofactionsfromtimetotimeeitherby
exhaustingatimeout.
Path:Acomponentthatdefinesapathinthespaceofthescene
fromaseriesofpoints,andthatcanbemanipulatedvisuallyandbe
coveredbytheobjectsofourgamebyFollow Pathaction.
Pool:Acomponentthatdefinesacollectionofpre-instantiated
objectsthatcanbeusedatruntime.Theuseofpoolsimproves
performanceinsituationswhereitisnecessarytocontinuously
displaymanyobjectsonscreen,anexamplewouldbeagameships
withmanyscreenshots.
Area:Acomponentthatletsyoudefineacubicareainthesceneand
whileactivatedanddeployedintheInspectorwillbedrawnatall
times.Itisusedtodefineareasofthegamewithouthavingtoresort
tousingBoxColliders.
EventController:Acomponentthatletsyoucontrolwhatevents
aredetectedandwhichareignoredbytheobject.
Note:Asimplecomponentthatallowsyoutoaddatextnotetothe
object,whichcanbeuseful,forexample,torememberwhyweset
certainparametersinaparticularwayatthetime.
Accessories
GameFabs
TheGameFabs(contractionGamePrefabs)areGameObjectsor
hierarchiesconfigurableGameObjectsthatoffercomponentsand/or
logicaluseroftenusedinvideogamesandwhoseincorporationintoa
juevoistrivial,socandramaticallyacceleratemountingprototype
games.GameFabslistisavailableontheGameFabschapter.
Utilities
Theyareintegratedtoolsthatdonotqualifycomponentsandtypically
dealwithconductspecialoperationsthatcangobeyondtheissue.An
exampleofusewouldbeintegratedGameFlowincorporatedintoa
futureversiondebugger.
Templates
ReadymadeTemplatesareincorporatingasystemconfigurationguide
andahigherlevelofGameFabs,asitisresponsiblefordefiningthe
configurationandinterrelationofthese.Thetemplatesupportwillbe
incorporatedinfutureversionsofGameFlow.
Programs
Aprogramisacomponentthatcontainsanorderedlistofactionsthat
theGameFlowenginewillrunsequentiallyallowingbothtogivelifeto
ourplaythingsandcontrollingtheflowofthegame,hencethenameof
thetool.
Aprogrammay,forexample,responsibleforcontrollingthemovement
ofourmaincharacter,whileanotherseriesofprogramscandealwith
managingtheenemies,controllingthegamemarkersandswitchthe
musictoreachcertainpartsofthestage.Basicallyprogramsgivelifeto
agame.
Creating programs
Aseverycomponent,aprogrambeginstoexistwhenaddedanobjectof
particulargame.ThiscanbedoneusingtheAdd Componentbuttonat
thebottomofthelistofcomponentsintheInspectorwindow,looking
belowtheGameFlow> Programsmenuandthenselectingoneofthe
typesofprogramsavailable.
Asdiscussedbelow,consideringthewayaprogramrunsinGameFlow
twobasictypesofprogramsaredistinguished:
IdleProgram:Aprogramthatremainsinactiveuntiltheexecution
isorderedbyeitheranExecute ProgramactionortheExecute
contextmenuoption.
EventProgram:Aprogramthat,ifenabled,startsrunning
automaticallyrecognizedataneventtypeintherangeoflistening
detected.
Programistheonlyprograminactive,withallotherprogramsof
events.Besidesallprogramseventbeginswiththeword“Onsoitis
easytodistinguishthem.
Adding actions
Theactionsarethebuildingblocksfromwhichprogramsarebuilt.They
canbeconsideredsmall,specializedcomponentsthatperformvery
specifictasksbasedonpropertiesthatyouspecifywithintheirownarea
ofeditingintheInspectorwindow.
ToaddactionstoaprogramwehaveaddedwecandoitusingtheAdd
ComponentbuttonInspectorandlookingbelowtheGameFlow>
Actionsmenu,butwe’llhavemorecontrolifweusethe+buttonNew
ActionthatappearsatthebottomoftheprogramareaintheInspector.
Sincethisbuttonappearsatthebottomofeachcontainerofshares,
whethertheprogramitselfthatisanactioncancontainotheractions
asWhile,useallowustodecidewhereexactlytheprogramwewantto
addtheaction,whichwillbemorecomfortabletowalkthenrearranging
theshares.
Also,usethisbuttonwillallowustofindsharesinaneasiermannerasin
thiscaseinsteadofusingthemenuofstandardcomponentsofUnity,a
specialwindowforselectingactionspreparedespeciallyforthistaskwill
open.
Thisnewwindowwillshowusinauniquelistallavailableactions,both
whichbringsthetoolsetasactionscreatedasuserviaAPIGameFlow,
alongwithfastintegratedhelpthatwillallowustogetabetterideathe
purposeofeachaction.
Tochooseanactionjusthavetomovewiththeupanddownarrowsand
pressEnter,ordouble-clickdirectlyontheactionyouwishtoincorporate
intotheprogram.
Thewindowalsohasasearchfilterthatwillallowustoquicklyfilter
actionssothatonlythoseremainingintheirnameenteredtext.Inthe
futurethefilteringmechanismofthiswindowwillbeenhancedtoalso
incorporatesearchbytags,sothattheuserismorelikelytofinda
suitablefortheirpurposesaction.
Order of execution of actions
Asindicatedatthebeginningofthechapter,theactionsinaprogram
areexecutedinsequentialorder,iestartwiththefirstactionprogram
andcontinuesitsexecutionuntil,atwhichpointitbeginswiththe
executionofthesecondactionfromthelist,andsoonuntiltheendof
theprogram.
Asdiscussedinthechapteronflowcontrol,thisisthedefaultorderof
executionforalinearprogram,butbyusingspecialactionssuch
asGrouporIfyoucanvarythisorderofexecutionsothatitisnot
entirelysequentialandbettersuitedtodifferentusecases.
Execution Contexts
Mostprogramsonlyeventwillbeexecutedatruntime(iewhenwehave
giventhePlaybutton)andnotduringeditingtime(iewhileweare
workingontheeditorofUnity)becausetheMosteventsarenot
generateduntilthegameisnotrunning.
However,itisimportanttonotethatGameFlowallows
anyProgram(inactiveprogram)isalsoimplementedintimeediting
usingtheExecuteoptiontothecontextmenu,whichcanbeveryuseful
bothforfastperformancetestswithoutbootingthestaketoautomate
editingtasksprogrammatically.
Actions
Theactionsarethebuildingblocksfromwhichprogramsarebuilt.They
canbeconsideredsmall,specializedcomponentsthatperformvery
specifictasksbasedonpropertiesthatyouspecifywithintheirownarea
ofeditingintheInspectorwindow.
Mostactionsareexecutedinatimelyandinstantlywhentheirturn
comeswithintheirprogram,butotheractions,however,aredesignedto
runduringatimeinterval,reasonwhytypicallytheseactionsincludea
Durationproperty.
Besidesthis,anotherdifferenceofactiononatypicalUnity
script(MonoBehaviour)isthatactionsaredesignedtobeappliedona
targetthatdoesnotnecessarilyhavetomatchtheGameObjectthat
containstheprogramitbelongstotheaction.
GameFlowactionsarerepresentedascollapsibleblockshavingitsown
interfaceasasubcomponent.Ifactioniscollapsed,itonlyshowsitstitle
bar.Iftheactionisexpandedorunfoldedthenitwillalsodisplayallits
properties.Thecoloroftheseblocksisintentionallyslightlydifferentto
thedefaultbackgroundcoloroftheInspectorwindow.
Thereareactionsthatcaninturncontainotheractions,such
asFororRepeatactionsthatallowbuildrepeatloops.Inthesecases,the
actionscontainedaredisplayedwithintheareaofthecontainingaction
withalevelofindentation.
Editing operations
Mostoperationsthatalloweditingtimesharesareavailableinyour
context(geariconontherightsideofthetitleareaofaction)menu.
Collapse / Expand
Anactioncanbeeitherexpandedorcollapsedbyclickingonthearrowin
theupperleftcornerofitstitle,orbyclickinganywhereinthetitlearea
ofaction.
Activation / Deactivation
Toenableordisableanactionsimplycheckoruncheckthecheckbox
thatprecedesitstitle.Enablingordisablingeditingdoesnotaffectthe
propertiesoftheaction,onlyitsimplementation.Offactionwillnotbe
executedbytheprogram,whichwillcontinueexecutionatthenext
triggeredaction.
Rearrangement
Anactioncanbemovedtoanotherplaceintheprogrameitherthrough
theactionsofmovementfromitscontextmenu(Move to Top, Move Up,
Move Down, Move to Bottom)orviaadraganddrop(drag and
drop)initiatedwithaclickonitstitlebar.
Anactionmayalsobetransferredtoanotherprogrambydrag and
droplongasbothprogramsarecontainedwithinthesameGameObject.
Finallyyoucanalsomoveanactionprogramtoprogramactions
usingCutandPaste Action Actioncontextmenu,butagainwiththe
limitationthatbothprograms,boththesourceofactionandtarget
areGameObjectcontainedtherein.
Note:thereiscurrentlynoactionAction Copy,butitsimplementationis
plannedinfuturereleases.
Reset
Anactioncanberestartedtotaketheirdefaultvaluesusing
theResetoptionfromitscontextmenu.
Removal
AnactioncanbeeliminatedbyAction Removeoptionfromitscontext
menu.
Insertion
YoucaninsertanewactionbeforeanotherusingtheInsert New
Actionoptionfromthecontextmenuthataction.
Duplication
YoucanduplicateanactionusingtheDuplicate Actioncontextmenu
option.
New action
Inthoseactionsthathavetheabilitytocontainotheractionssuch
asIfby+ New Actionbuttonappearsatthebottomoftheareaofaction
whenclickedwilldisplaythewindowforselectingactionstoaddactions.
Editing Properties
EditingpropertiesofanactionisperformedasinanyotherpartofUnity,
withsomeslightdifferences:
Somepropertiesmayhaveadditionaloptionsascontextmenus
associatedwithyourtags,whichareindicatedintheinterfacewitha
smallarrowpointingdowntotherightofthetitle.Anexampleis
foundintheDirectionpropertyoftheAddActionForce,whichlets
youspecifythetypeofinputvaluebythislabelincorporatedintothe
contextmenu.
Mostpropertiesareofanytype,incorporatedontherightsidea
smallcirclethroughwhichitispossibletoassociate,asdiscussedin
thenextchapter,avariable.
Someactions(usuallythosewhosenamesbeginwiththe
wordGet)incorporateaspecialfieldtospecifyanoutputvariable,and
thisfieldcanbedrawnasanothervariableforeasewhencomposing
programs.
Help
YoucanconsultthehelpofanactionundertheHelpoptionfromthe
contextmenu.
Implementation of measures
AlthoughthemajorityofthingsonGameFlowaredesignedtorunat
runtime,onlysomeofthesealsoworkineditingtime.Whenanaction
maynotrunontimeeditingGameFlowindicatethisbysendinga
warningmessagetotheconsole.
Moreover,therearealsoactionsthatperformonlyeffectivewhen
executedontimeeditingandwillbeignoredatruntimenotmakesense
inthiscontexttask.
Available Actions
ThefollowingisalistofactionscurrentlyincorporatedinGameFlow
organizedbyfunctionality.
Activation
ActivateGameObject
ActivateGameObjectsInList
DeactivateGameObject
DeactivateGameObjectsInList
DisableBehaviour
DisableBehavioursInList
DisableCollider
DisableProgram
EnableBehaviour
EnableBehavioursInList
EnableCollider
EnableProgram
Variables
DecrementVariableValue
DivideVariableValue
IncrementVariableValue
VariableLimitValue
MultiplyVariableValue
SetVariableValue
ToggleVariableValue
Lists
AddItemToList
ClearList
GetItemFromList
InsertItemInList
RemoveItem
FromList
SetIteminList
Flow Control
Break
For
Group
If
Loop
Repeat
RepeatUntil
RestartProgram
While
Execution
ExecuteProgram
StartProgram
Publisher
ProgressCloseWindow
SetupProgress
ShowProgressWindow
ProgressUpdate
Strings
ConcatenateStrings
GetStringLength
GetSubstring
ReplaceStringIn
Documentation
Comment
Creating Objects
Clone
CreateEmptyGameObject
Instantiate
Destruction of objects
Destroy
State of play
GameOver
StartGame
PauseGame
ResumeGame
TogglePause
Trajectories
FollowPath
GetPathProperty
SetPathProperty
Motion
Follow
Interpolate
LookAt
MoveTo
Rotate
RotateTo
Animation
PlayAnimation
SetAnimatorState
Transform
GetPosition
GetRotation
GetTransform
GetTransformProperty
SetPosition
SetPositionFromScreenPoint
SetRotation
SetTransformProperty
GetWorldPointFromScreenPoint
Audio
GetAudioProperty
SetAudioProperty
PlayMusic
PlaySound
PlaySoundAtSource
StopMusic
StopSoundAtSource
ToggleAudioMute
GUI
GetGUITextProperty
GetGUITextureProperty
SetGUITextProperty
SetGUITextureProperty
Timers
WaitForTimer
RestartTimer
ResumeTimer
StopTimer
Cameras
GetCameraProperty
SetCameraProperty
Pools
GetObjectFromPool
GetPoolCapacity
ResetPool
Random Values
GetRandomColor
GetRandomItemFromList
GetRandomNumber
GetRandomPointInCollider
GetRandomPointInColliderList
GetRandomVector
SetRandomSeed
Restrictions
Confine
SetDistance
GetDistance
Persistence
SaveData
Mouse
HideMouseCursor
ShowMouseCursor
Scenes
LoadScene
GetSceneProperty
Depuration
ClearConsole
LogMessage
PauseEditor
HelloWorld
Navigation
SetNavMeshAgentDestination
Physics
AddForce
GetRigidbodyProperty
GetVelocity
VelocityLimit
Sleep
SleepList
WakeUp
WakeUpList
SetRigidbodyProperty
SetVelocity
Time
SetTimeScale
Wait
GameObjects
GetGameObjectProperty
SetGameObjectProperty
SetParent
Vectors
GetVectorComponent
SetVectorComponent
Visual Effects
SetColor
Application
SetApplicationProperty
ExitGame
Variables
Avariableisacomponentwhichbehavesasadynamicstorageunit.This
meansthatcancontainacertaintypeofdata(text,anumber,acolor,a
referencetoanobject,etc.)andalsobeusedinplaceofsuchavalue
whereGameFlowsupportstheuseofvariables.
SoifforexamplewehaveanactionasSet Color,usedtochangethe
colortoanobject,andrequiresasoneofitspropertiescolorwewantto
changethesubject,wewouldhavetwowaystoindicatewhatshouldbe
saidcolor:
1. Assignthepropertyaparticularcolor,egthered-directlythroughthe
colorpicker,or
2. AssigningaVariablepropertytypeColorindicatingthatwewantto
useasacolorvalueofthevariable(whichwillalsobeacolor,eg
green).
WhathappenswhenyourunthegameisthattheactionSet Colortobe
executedbyaprogramwillevaluateinturnthevalueofeachofthe
variableswhichareassignedtodetermineitspresentvalue.Inother
words,andreturningtoourexample,whatwillhappenisthattheaction
variableask:“Whatcolordoyouhaveatthistime”andthevariablewill
respondwithavalueofgreen”,whichwillbethecolorthataction
eventuallyuseforitspurpose.
Sinceitispossibletochangethevalueofvariablesasmanytimesas
neededthroughoutthelifeoftheprogram,whichoffersintegrated
variablesGameFlowsupportistheabilitytobuildprogramsorusetools
withinputvaluesdynamicthatmayvarydependingonthestateofthe
gameorasotherparameters.
Foritsdynamicnature,inagameweoftenfindtheneedtoworkwith
variables.Someexamplesthatsuggestusewouldbe:createascoring
track,controlthedamagestateofourcharacter,keeptrackofthe
numberofcollectedobjects,etc.
Create variables
Thevariableslivelikeanyanothercomponentwithin
aGameObject,thustocreateitisonlynecessarytoadda
componentVariabletype:
UsingtheAdd ComponentbuttonintheInspectorwindow,or
UsingthemenuComponent> GameFlow> Data> Variable.
IneithercaseifyouarecreatingthefirstvariableintheVariables
GameObjectonecomponent(plural)thatwillactasacontainerforall
blocksofvariablerateweaddtheobjectiscreated.
Fromtherewewillhaveavailableathirdwaytoaddanewvariable
usingthe+ New Variablebuttoninthelowerareaofthecomponentin
theInspectorwindow.
Wewillalsohaveseveraladditionaloptionsinthecontextmenuofthis
componentVariablessuchastheResetoptionoroptionsCollapse
All/Expand Allthatrespectivelyallowustocollapseorexpandall
variablesoftheobjectinonestep.
Definition of variables
Todefineavariablesimplygiveitanappropriateidentifiertothe
purposewewanttogivethevariable,indicatethetypeofdatayouwant
tostoreinitandgiveitaninitialvalue.Optionally,wecanalsoindicate
whetherwewantthevariableispersistentornot.
Type
ThetypessupportedbyGameFlowvariablesare:
String:Text.
Integer:IntegerNumbers.
Float:Decimalnumbers.
Boolean:TrueorFalse.
Vector2:2-dimensionalvector(X,Y).
Vector3:3-dimensionalvector(X,Y,Z).
Rect:Rectangle(X,Y,Width,Height).
Color:Color.
Object:Areferencetoanobject.
Enum:Anenumerationvalue.
Toggle:Markedorunmarked(equivalenttoBoolean).
Tag:GameObjectTag.
Layer:GameObjectLayer.
Type Specification
TheObjectandEnumtypesrequireadditionalspecificationofthe
particularobjecttypeorenumerationcontainingthevariablethatcan
bedonebyaspecialselectionwindowtypesorganizedintotwotabs:
Unity Tab:containsonlythetypesofUnityusableinGameFlow.
OtherTab:containsonlyGameFlowtypesandtypesthattheuser
hasdefinedthroughtheirownscripts.
Conversions type and value
WecallType Castingtotheautomaticmodificationofthetypeofa
variableVariableGameFlowperformedwhenthisismodifiedbysome
actionthatreturnsvaluesthatareofadifferenttypetothevariablehad
atthattime.
ThismeansthatinGameFlowvariablesaredynamictypeand
automaticallyadaptwhenusedtostoreadatatypedifferentfromthat
initiallyhad.Thishasitsadvantages,butalsodisadvantagesshould
thereforebetakenintoaccount.
TheotherconversionoperationisautomaticallyperformedGameFlowto
trytoconvertthecurrentvaluetothenewtype,whenallyoumodifythe
typeofthevariable,whichisnotstrangeperformatauthoringtime.
Thus,ifinavariableoftypeStringhavethealphanumericvalue“3”and
suddenlywedecidedtochangethetypeofthatvariable
toInteger,GameFlowwhathewilldoistrytomakethebestpossible
conversionofuservalues.Inthisexampletheconversionispossibleand
thevalueshallbeupdated,butiftheconversionisnotpossiblethevalue
ofthevariablewouldbecomethedefaultforthenewtypechosen.
Editing operations
Editingoperationsareessentiallythesamefortheactionslistedinthe
previouschapter,exceptthattheCutandPasteoperationsarenot
available.
Assignment by drag & drop
Perhapsthemostimportantoperationthatweshouldknowaboutthe
variableswecanassigntovirtuallyanypropertyofanyoftheactions,
conditionsortoolsincludingGameFlow.
Todothis,simplyclickonthetitleblockvariablewewanttodragupthe
propertyyouwanttoassignthevariableandonceobservethatthefield
ofpropertyisdrawnwithanotherfund,releasethemousebutton.
Assignment with object selector
Theotherwaytoassignavariabletoapropertyistoclickonthesmall
circlethatappearstotherightofthefieldvalueofthepropertytoshow
usawindowGameFlowselectionofspecialobjects,whichresemblesthe
standardUnitybutthatisnotso.
Thefirstdifferenceyouobserveregardingthestandardwindowisthat
theselectorGameFlownotleftasthestandardinthelevel
ofGameObjectsbutisabletoreachthelevelofcomponents,whycan
seeeachandeveryoneofthevariablesthatwecreatedintheproject
andinthescene,eachconvenientlylabeledwiththeidentifierthat
wouldhaveputhim.
TheseconddifferenceisthatGameFlowobserveaddsanextratabthat
willallowustoseeonlythevariablesdefinedwithinthecurrently
selectedGameObjectorifthisbelongstoaprefab,seeonlythevariables
definedwithinthehierarchyoftheprefab.Thisisespeciallyconvenient
whenyourebuildingprefabs,ithelpsustofindthevariablesthatwe
seekandmakesureweneverchooseanexternalvariabletoprefab
faster.
Itshouldalsobenotedthatwhenthepropertywewanttochangeisof
typeobject,theselectorwillallowustochoosebothobjectsofthattype
(whethertheyarecomponentslikeGameObjects)asvariables,sothe
workmodeisidenticaltothatdiscussedandifwewantistodirectly
assignobjectreferencestothetraditionalwayofUnityitcanalsobe
donewithoutanyproblem.
Built-in Variables
Built-inVariablesareaspecialkindofvariableswhosevaluecannotbe
determinedbytheuserbutisalreadypredefined(arevariablesread-
only)andallowustoconsultdynamicsystemsettings,suchasthe
currentdateorresolutionscreen,inasimplemanner.
Allthepredefinedvariablescanbefoundandaddedtotheprojectas
partofprefabBuilt-inoftheGameFlow / Assetsfolderofyourproject,so
youcanfindthematanytimeinAssetstabofthewindowobject
selection.
Thentheintegratedvariablesavailableareasfollows:
Built-in<Day>:Dayofthemonthofthecurrentdate.
Built-in<DeltaTime>:Timeelapsedsincethelastframe.
Built-in<DeviceName>:Nameofdeviceruntime.
Built-in<Hour>:Currenthourin24hformat.
Built-in<Minute>:Currentminute.
Built-in<Month>:Numberofmonthofthecurrentdate.
Built-in<MousePosition>:Currentpositionofthemousepointer.
Built-in<NativeResolution>:Nativeresolutionofthedisplay.
Built-in<ScreenSize>:ScreenResolution/currentwindow.
Built-in<Second>:Currentsecond.
Built-in<Year>:Yearofthecurrentdateinlongformat.
Persistence
Whenwespeakofpersistencetalkabouttheabilityofcertaindatais
notdeletedwhenyouleaveourgamebutremainstoredinthe
nonvolatilememorydeviceonwhichwerunourgamesowecanrestore
themthenexttimeyoubootthegame.
Thisisveryusefulinvideogamesbecauseitallowsustosavevaluable
informationontheprogressoftheplayerorthelaststateinwhichthe
gamewassothatwecanimplementinarelativelysimplewaygames
thatallow“continue”agameinthelastpointbeingmadeorwithout
goingsofarastosimplyrememberwhatwasourbestscore.
GameFlowofferssupporttransparenttotheuserandintegrated
variablepersistence,butfortechnicalreasonscanonlybeusedon
variablesthatareNOToftypeObject.Allwehavetodotogetthevalue
ofavariable“survive”attheendofthegameistocheckthebox
onPersistentinterfaceintheInspectorwindow.
Fromthatmoment,GameFlowwillensurethatthevalueofthatvariable
ispersistent,whichwecanverifyevenwhileweareworkinginthe
Editor,aseachtimeyoupressPlaythevariablewillbethelastvaluethat
hadattheendofthepreviousrun.
Events
Aswesawinearlierchapters,eventprogramsareprogramsthatstart
runningautomaticallyenabledwhenbeingdetectedinitsrangeof
listeninganeventofagiventype.
Inthischapterwewillseeindetailallaspectsofeventprogramsto
understandhowtomakethebestofittosupportevent-driven
programmingGameFlowoffers.
Listening range
Therangelistenerwillfinditatthetopofsomeprogramsofeventssuch
asamenuofoptionsandfunctionsasafilterprogramcanbeusedto
addressonlycertaineventsbasedontheirorigin.
Therangeoflisteningwillusuallythreepossiblevalues:
In This GameObject:whenwejustwanttoattendeventsthathave
beendetectedbycomponentsofthesameGameObjectinwhichis
includedtheprogram.Thisisthedefaultandprovidesbetter
performance.
In This Hierarchy:whenweattendeventsthatcomealsoboththe
parentobjectoftheGameObjectinwhichisincludedtheprogram
andanyofitsGameObjectschildren.
In Any GameObject:whennotwanttodoanyfilteringandwantto
attendtheeventwhateverthesource.
Inmostcases,therangeoflisteningcanbeleftatthedefaultbecauseit
isgoodpracticetolimitthescopeofaprogramtoaminimum.Only
whereweneedtomakeourprogramcapableofactingonelementsof
thewholesceneshouldexpandtherangeoflistening.
Forinstance,ifwemakeaprogramthatchangesthecolorofyour
GameObjectbyclickingwiththemouseonitwillsufficeminimumrange,
butifweseektomakeaprogramtochangethecolorofanyobjectin
thesceneonwhereweclick,weneednecessarilyextendtherangeto
maximum.
Conditions for implementation
Foraneventprogramcanbeginexecutionisautomaticallyrequired:
1. Theprogramitselfisactivatedorenabled.
2. Thattheeventhasoccurredintherangespecifiedintheprogram
listeningevent.
Exceptinsomecases,suchasOnStart,forarunningeventprogramis
notessentialthattheGameObjectinwhichitisincludedisalsoactive,
especiallyifthelisteningrangeissettomaximum.
Event parameters
Mosteventprogramsofferalistofparameterswhosevalueis
completedwithcertainspecificinformationabouttheeventoccurred
justbeforetheprogramstartsrunning.
Theeventparameterssignificantlyexpandthepossibilitiesofaprogram,
sincewecannowmaketheprogramknows,forexample,the
GameObjectthatoriginatedtheeventandgotooneoftheprogram’s
actionsthatparameter.Itwould,inotherwords,asallowingthe
programtoactonanunspecifiedGameObject,atsomepoint,whenthe
eventoccurs,willbeimplementedtobeoneoftheGameObjectsofour
game.
Whentheeventprogramsupportsparameters,itdisplaysasmalllabel
onthebottomrightcornerofyourareaintheInspectorwith
theParameterstextinbold.Clickingonthelabel,justalistof
parametersundertheactionlistwithaformatsimilartovariablesblocks
aredisplayed,becausetheparameterscanbeconsideredread-only
variables.
Likevariables,theeventparameterscanbedraggedtothefieldsof
programactionsthatsupportvariables,butunlikevariables,parameters
canonlybeusedintheprogramofeventitselfanddoesnotallowdrag
themtootherprograms(eventhesametype)norselecttheminthe
ObjectSelector,thenarenotreflectedinit.
Supported Events
Thefollowingisalistofeventtypesrecognizedandsupportedby
GameFlowalongwithabriefdescriptionoftheeventprogramsdealing
managethem.
Initialization events
Theyaretheeventsrelatedtothegameinitializationprocesses.This
typeofeventismanagedbythefollowingprogramsofevent:
OnStart:aprogramofthistyperuntostartagameifthe
GameObjectisactiveorwasnotactive,thefirst(andonlythefirst)
onceactivated.
Activation events
Aretheeventsrelatedtotheactivation/deactivationofa
GameObject.Thistypeofeventismanagedbythefollowingprogramsof
event:
OnActivate:aprogramofthistypewillrunwhenevera
GameObjectpassfrominactivetoactive.NottobeconfusedwithOn
Start,thoughitmaybeequivalenttothecaseofaGameObjectthat
whenstartingthegameisoffandisthenactivatedatsomelater
time.
OnDeactivate:aprogramofthistypewillrunwhenevera
GameObjectpassfromactivetoinactive.
Events Update
Aretheeventsthatarelaunchedregularlycoincidingwithprocesses
themselvesUnityengineupdate.Thistypeofeventismanagedbythe
followingprogramsofevent:
OnUpdate:aprogramofthistypewillrunatthebeginningofeach
frameofplay.Itistheidealtypeofprogramwhenwerunfastand
continuousactions.
OnLateUpdate:aprogramofthistypewillruntheUpdateOn
completionofallprograms.
OnFixedUpdate:programrunningatfixedregularintervalsandis
usedmainlytogiveorderstotheUnityenginePhysics.
Game Events
Aretheeventsthatarereleasedwhenthegeneralstateofthegameis
changed.Thistypeofeventismanagedbythefollowingprogramsof
event:
OnGameStart:aprogramofthistypewillbeexecutedasaresult
ofthechangeofstatethatproducestheStart Gameaction.Indicates
normallythegameitselfhasbegun.
OnGameOver:aprogramofthistypewillbeexecutedasaresult
ofthechangeofstatethatproducestheGame Overaction.Indicates
usuallythegameisover.
OnGamePause:aprogramofthistypeisexecutedwhenthegame
enterspause,usuallyasaresultofanactionorToggle Pause Pause
Game.
OnGameResume:aprogramofthistypewillrunwhenplay
resumesafterbeingpreviouslypaused,usuallyasaresultofan
actionorToggle Pause Resume Game.
Mouse events
Aretheeventsthatarelaunchedwhentheuserperformactionswith
themouseonelementsthatsupportitasGUIorColliderselements.This
typeofeventismanagedbythefollowingprogramsofevent:
OnMouseDown:aprogramofthistypewillrunwhenyouclickany
ofthemousebuttonsonaGUIoranelementCollider.
OnMouseDrag:aprogramofthistypewillrunwhenmouse
movementonaGUIoranColliderelementisdetectedwhileanyof
themousebuttonsiskeptpressed.
OnMouseEnter:aprogramofthistypeisexecutedwhenthe
mouseenterstheareaoccupiedbyaGUIelementoranCollider.
OnMouseExit:aprogramofthistypewillbeexecutedwhenthe
mousepointerleavestheoccupiedbyaGUIelementor
anColliderarea.
OnMouseOver:aprogramofthistypewillrunwhenmousemove
overaGUIelementoranColliderisdetectedwhilenotbeingpressed
anyofthemousebuttons.
OnMouseUp:aprogramofthistypewillruntoreleaseamouse
buttonwasbeingpressedonaGUIoranelementCollider.
Collision events
AretheeventsPhysicsengineUnitylaunchestoreportthattherehave
beencollisionsbetweenobjectsandalsotoindicatethestatusofsuch
collisions.Thistypeofeventismanagedbythefollowingprogramsof
event:
OnCollisionEnter:aprogramofthistypewillbeexecutedassoon
asitdetectsthatithasbegunacollisionbetweentwoobjects.
OnCollisionExit:aprogramofthistypewillrunassoonasit
detectsacollisionbetweentwoobjectsnolongerproduced.
OnCollisionStay:aprogramofthistypewillrunoneveryframeof
thegamewhilecontinuingtoproduceagivencollisionbetweentwo
objects.
OnTriggerEnter:CollisionOnEntersimilarbutapplicablewhenat
leastoneoftheobjectshasamarkedasColliderTrigger Is,thatis,
thatdetectscollisionsbutitistraversablebyotherobjects.
OnTriggerExit:ExitsimilartoOnCollisionbutapplicablewhenat
leastoneoftheobjectshasamarkedColliderIs Trigger.
OnTriggerStay:OnCollisionsimilartoStaybutapplicablewhenat
leastoneoftheobjectshasaColliderIsmarkedasTrigger.
Itisimportanttonotethatasthesefeweventsthatalwaystwoobjects
involved,yournoticeisdoublebecausethecollisionisreportedtoboth
objectsalike.Thismeansyoucanassociateaprogramofthiskindtoany
ofthetwoobjectssusceptibletocollideandinbothcasestheprogram
willrun.Theonlydifference,aswewillbeintheparameterssenttoeach
program.
Time Events
Theyareweather-relatedeventsandcomponentsthatworkbasedon
time,astheTimer(Timer).Thistypeofeventismanagedbythe
followingprogramsofevent:
OnTimerExpire:aprogramofthistypeareexecutedwhen
aTimercomponentnotifiedthatthetimeintervalhaselapsedfor
whichhadbeenscheduled.
Program events
Theseareeventsthatlaunchtheprogramsthemselvestoreport
changesinyourstate.Thistypeofeventismanagedbythefollowing
programsofevent:
OnProgramFinish:aprogramofthistypewillbeexecutedwhena
programintherangeoflisteningfinishedexecuting.
Variables events
TheyarethrowingeventsGameFlowtonotifythatavariable(or
parameter)hasbeenamended.Thistypeofeventismanagedbythe
followingprogramsofevent:
OnVariableChange:aprogramofthistypewillruninboth
runtimeandeditingwhenavariableintherangeoflisteninghas
beenmodified.
OnParameterChange:aprogramofthistypewillruninboth
runtimeandeditingwhenaparameterintherangeoflistening
(whichinthistypeofprogramislimitedtoGameObjectfather)has
beenmodified.
Event Handlers
Eventhandlersarespecialcomponentsthatserveasgeneralevent
filters.WhenaddedtoaGameObjectallowyoutospecifywhichofthe
eventsgeneratedbythisGameObjectthatcorrespondtothetype
managedbythecontrollershouldbenotifiedandwhichwillsimplybe
ignored.
Thiscontrolisespeciallyusefulforoptimizingtheperformanceofa
gameasitreducesthenumberofinternalmessagesthatthesystem
mustprocessmakinglessprocessingtimeperframeneeded.
Controllerstypessupportedeventsare:
ActivationController:Activationeventhandler.
CollisionController:Controllercollisionevents.
MouseController:mouseeventhandler.
TriggerController:ControllerTriggerscollisionevents.
Foratypeofeventisnotifieditscheckboxmustbechecked,whilethose
eventswiththeunlabeledbeignored.
Flow Control
Theprogramflowistheorderinwhichaprogramexecutesitsaction
list.Theprogramflowissequentialbydefault,thatis,itwillfirstrunthe
firstactionenabledtocompletion,thenthenextactionandsoonuntil
theendoftheprogram,butthisorderdoesnotalwaysallowustoget
theresultsweneedinourgame,that’swhyGameFlowgivesusthe
abilitytomodifythisflowinasimplewaybyusingakindofspecialized
actionsinthistask.
Withthesespecializedactions,whichwilldetailthenbepossibleto
implementsophisticatedlogicgameinwhich:
Partsofaprogramareexecutedrepeatedlyanumberoftimes.This
inprogrammingmethodologyiscalled“loop.
Certainpartsofaprogramareexecutedonlywhenmet(ornotmet)
certainconditions.Thisiscalled“fork”orconditionalexecution.
Certainpartsofaprogramnotrunsequentially,ieactionbyaction,
butrunningalltheiractionssimultaneouslyasagroup.
Thewaywecontroltheflowofprogramslargelydefinesthe
programmingqualityofourgame,whichiswhywerecommendyou
clearthebasicideasofprogrammingmethodologybeforeattemptingto
buildprogramswithaflowcontrolverycomplex.
Flow Control Actions
Asmentioned,GameFlowletsyoucontroltheflowofprogramsthrough
theuseofapanelofactionsthatcanbefoundundertheComponent>
GameFlow> Control menu.
Thepurposeofeachoftheseactionsisasfollows:
If:allowsexecutiontobranchbasedontheresultofalistof
conditions.Iftheseconditionsaremet(theoverallresultisTrue)
containedthemainlistofactionswillbeexecuted,whileiftheresult
isFalsealistofsecondaryshares(sharesundertheElsesection)will
run.
For:createaloopexecutionforalistofactionscontained(inother
words,performtheseactionsrepeatedly)anumberoftimeswhichis
givenbythevalueofavariablethatismodifiedateachiterationof
thelooporturnandlimitvalueagainstwhichyouwillcompare.
Repeat:Forasimplifiedversionthatrequiresonlyspecifythe
numberoftimesyouwanttorepeattheactionscontained,without
variablesorlimitvalue.
Loop:asimplifiedversionofRepeatasdefaultexecutionwillloopwill
berepeatedindefinitelywelluntiltheprogramisstoppedoruntilthe
actionscontainedwithinoneBreakaction(seedescriptionbelow)is
executed.
While:implementtheactionscontainedifacertainconditionismet
andwillcontinuetoloopwhilestillmeetsthecondition.
RepeatUntil:implementtheactionscontainedinloopuntilthelist
ofassociatedconditionsaremet.
Group:allowsyoutorunallcontainedactionsinparallel,ie,inthis
typeofblockisnotexpectedthatanactionhasfinishedrunning,but
allactionsareexecutedatatimeandonlywhenallactionsendwhen
youconsiderthattheactionisover.
Break:stopsaloop,makingtheprogramrunninginthenextaction
aftergeneratingtheloopisactivated.
Terms
Theconditionsareatypeofspecialblocksthatusesomeactionsto
determine,initsassessment,howorwhentochangetheprogramflow.
Visuallyconditionsareverysimilartothosesharesbecauselikethese
arerepresentedascollapsibleblockscontainingpropertyfieldsthat
allowustoconfiguretheoperationofthecondition.Onlyvaryincolor,
whichisdifferentfromtheactionsandtheirlocation,astheycanonly
liveinsharesthathavebeendesignedforuseconditions.
Asforeditingoperations,conditionssupportthesameediting
operationsthatactionswithintheirowncontextsandthroughtheir
contextmenus.
Evaluation
Evaluateaconditionistocheckifitistrueornottrue.Inprogramming,a
conditionismetwhenwesaythattheresultisTrue,Falsewhennot
beingmet.Theresultoftheevaluationofaconditioniswhatwecalla
Booleanvalue,asonlysupportstwopossiblevaluesoppositeeachother.
Thisresultanditsinterpretationdependlargelyonhowthecondition
hasbeenconfiguredthroughthepropertiesstatedinitsinterface,which
willnormallyincludeatleastonecomparisonfieldtoindicatewhat
exactlywewanttodowithinthecondition.
GameFlownotonlysupportstheevaluationofaconditionbutthat
createsalistofconditionslinkedbylogicaloperatorsthatalwaysbe
evaluatedusingthelastresultandtheresultoftheconditioncurrently
beingevaluated.Theseoperatorscanbe:
And:thatwillreturnTrueasresultif(andonlyif)thepreviousresult
isTrueandtheconditionunderwhichconnectsalsoevaluatesto
True.Otherwise,itwillreturnFalseasresult.
Or:thatwillreturnresultsforbothTrueifthepreviousresultwas
trueasiftheresultoftheconditionwithwhichconnectsevaluatesto
True.OnlyreturnsFalseifbothresultsarefalse.
Aswehaveseen,thewayinwhichacontrolactioninterpretstheresult
ofevaluatingitslistofconditionsdependsontheinternallogicofeach
action.Toclarifyanydoubtsyoucanalwaysconsultthecontextualhelp
foreachaction.

Navigation menu