SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Unity3D Scripting:
State Machine
Finite-State Machine
Definition:
This is a set of five elements:
(Σ, Q, s ∈ Q, T ⊂ Q, δ : Q x Σ → Q)
where Σ - the alphabet, Q - a set of states,
s - the initial (start) state, T - the set of
accepting states, δ - the transition function.
A graph with a finite number of states (nodes)
and a finite number of CMV transitions
(curves).
Two Questions
How this system would help us in
programming the game logic?
How this approach is better than others?
How To Use
Behavior of the game object may be
divided into a list of different actions:
Starting State
Target Searching
Attack
Death
Structure
Generalization
Any game component, whether a unit, or
a menu based or an abstract game as a
whole, which uses certain rules can be
programmed by using a state machine.
Advantages of State Machine
1. Divided, limited access to the context of state
2. Encapsulated logic for each state
3. Clarity, ability to upgrade code (source code
customization)
4. Reliability
Divided, Limited-Access Context State
Each state controls only its own context
and there is no need to check the set of
variables for other states
Logic Encapsulation for One State
This allows you to quickly respond to
errors that were found during testing, to
localize them and make changes. At the
same time this greatly reduced the
likelihood of introducing errors into
other states, because their context is not
available, and their logic is elsewhere.
Source Code Customization
Behavior of the object becomes more
classification-ruled and understandable.
Behavior modernization takes less time
and complexity associated with
modifications is greatly reduced.
Reliability
Transition from one state to another
occurs only in specific cases, to move
from one state to another if it was not
planned is not possible.
Property of C #: Operator: “Yield"
Operator: “Yield"
● "syntactic sugar"
● implement pattern: enumerator
Is being used for:
● implementing collection
● dividing the methods in several steps
Unity 3D - Specifications
We will use several features Unity3D:
● Operator yield and pattern enumerator.
● Call for one of the standard object methods
inherited from MonoBehaviour:
- Update
- FixedUpdate
- Start, etc.
Unity 3D - Specifications
We need the following entities:
● States
● Manager, which manages the transition
from one state to another
● Model - context of state machine, to
which the state will call to perform a
variety of actions.
State. Implementation Example
State. Description
No need to restrict the user with
inheritance. System is fairly
abstract, to restrict certain
properties of the state through the
interface.
States Manager: Implementation Example
States Manager: Explanation
Key methods:
● Set the initial state
● Infinite state that calls the logic
of the current status
● Cleanup
Infinite cycle. Implementation Example
Infinite Cycle. Clarification
● Possibility of correct completion
● Debug messages output
● Calling IState.Start (), IState.Cleanup (),
IState.DoWork () methods
● Switch state with the help of Field
NextGameState
IState.DoWork (). Implementation Example
Awaiting Something
Check one of the conditions, and if it does not
suffice you pass control higher up and go back
to check conditions at other times when the
manager would transfer control method.
This way you give a chance to any other logic to
be executed in a single game flow (GAME
THREAD), avoiding a whole bunch of problems
related to multithreading.
Methods
For any application, we need a method to invoke
the script cyclically inherited from
MonoBehaviour: Update, FixedUpdate,
LaterUpdate, etc.
Depending on the task you should choose the
right method and call it for update the state
machine.
Before you update the state machine it is
necessary to perform the initial state install. This
can be done easily in the Start or Awake
methods.
Model (context)
Often there is a need preserve some information
between the states was preserved some
information - the context of state machine. This
context could be a script that renews the state
machine. It is possible to store certain flags and
objects necessary for the states in this script.
Also, this context may contain links to game
resources and other game objects. So you pass
a reference from state to state to this script.
This approach will help to avoid a large number
of singletons in the game.

Contenu connexe

En vedette

Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks Sperasoft
 
Unity introduction for programmers
Unity introduction for programmersUnity introduction for programmers
Unity introduction for programmersNoam Gat
 
Game Development with Unity
Game Development with UnityGame Development with Unity
Game Development with Unitydavidluzgouveia
 
게임 프레임워크의 아키텍쳐와 디자인 패턴
게임 프레임워크의 아키텍쳐와 디자인 패턴게임 프레임워크의 아키텍쳐와 디자인 패턴
게임 프레임워크의 아키텍쳐와 디자인 패턴MinGeun Park
 
게임 개발에 자주 사용되는 디자인 패턴
게임 개발에 자주 사용되는 디자인 패턴게임 개발에 자주 사용되는 디자인 패턴
게임 개발에 자주 사용되는 디자인 패턴예림 임
 
Introduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First GameIntroduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First GameSarah Sexton
 

En vedette (12)

Unity 3d Basics
Unity 3d BasicsUnity 3d Basics
Unity 3d Basics
 
Securing PHP Applications
Securing PHP ApplicationsSecuring PHP Applications
Securing PHP Applications
 
Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks
 
NYPF14 Report - CDA
NYPF14 Report - CDANYPF14 Report - CDA
NYPF14 Report - CDA
 
Unity introduction for programmers
Unity introduction for programmersUnity introduction for programmers
Unity introduction for programmers
 
Game Development with Unity
Game Development with UnityGame Development with Unity
Game Development with Unity
 
Unity3D Programming
Unity3D ProgrammingUnity3D Programming
Unity3D Programming
 
Unity is strength presentation slides
Unity is strength presentation slidesUnity is strength presentation slides
Unity is strength presentation slides
 
게임 프레임워크의 아키텍쳐와 디자인 패턴
게임 프레임워크의 아키텍쳐와 디자인 패턴게임 프레임워크의 아키텍쳐와 디자인 패턴
게임 프레임워크의 아키텍쳐와 디자인 패턴
 
Unity presentation
Unity presentationUnity presentation
Unity presentation
 
게임 개발에 자주 사용되는 디자인 패턴
게임 개발에 자주 사용되는 디자인 패턴게임 개발에 자주 사용되는 디자인 패턴
게임 개발에 자주 사용되는 디자인 패턴
 
Introduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First GameIntroduction to Unity3D and Building your First Game
Introduction to Unity3D and Building your First Game
 

Similaire à Unity3D Scripting: State Machine

Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaDicodingEvent
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetupAnton Kropp
 
[Capella Day 2019] Model execution and system simulation in Capella
[Capella Day 2019] Model execution and system simulation in Capella[Capella Day 2019] Model execution and system simulation in Capella
[Capella Day 2019] Model execution and system simulation in CapellaObeo
 
Model Execution and System Simulation
Model Execution and System SimulationModel Execution and System Simulation
Model Execution and System SimulationObeo
 
Microservices Architecture with Vortex — Part II
Microservices Architecture with Vortex — Part IIMicroservices Architecture with Vortex — Part II
Microservices Architecture with Vortex — Part IIAngelo Corsaro
 
Memento Pattern Implementation
Memento Pattern ImplementationMemento Pattern Implementation
Memento Pattern ImplementationSteve Widom
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelinesTimothy Farkas
 
Write better, stronger, faster behat steps with ScenarioStateBehatExtension
Write better, stronger, faster behat steps with ScenarioStateBehatExtensionWrite better, stronger, faster behat steps with ScenarioStateBehatExtension
Write better, stronger, faster behat steps with ScenarioStateBehatExtensionRodrigue Villetard
 
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
 Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ... Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...Big Data Spain
 
Scalability truths and serverless architectures
Scalability truths and serverless architecturesScalability truths and serverless architectures
Scalability truths and serverless architecturesRegunath B
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2NokiaAppForum
 
Introduction to simulation and modeling
Introduction to simulation and modelingIntroduction to simulation and modeling
Introduction to simulation and modelingantim19
 
State Pattern In Flex
State Pattern In FlexState Pattern In Flex
State Pattern In Flextcab22
 
Traffic Simulator
Traffic SimulatorTraffic Simulator
Traffic Simulatorgystell
 
Towards Rapid Implementation of Adaptive Robotic Systems
Towards Rapid Implementation of Adaptive Robotic SystemsTowards Rapid Implementation of Adaptive Robotic Systems
Towards Rapid Implementation of Adaptive Robotic SystemsMeshDynamics
 
Formal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-BFormal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-Bijcsit
 

Similaire à Unity3D Scripting: State Machine (20)

Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetup
 
[Capella Day 2019] Model execution and system simulation in Capella
[Capella Day 2019] Model execution and system simulation in Capella[Capella Day 2019] Model execution and system simulation in Capella
[Capella Day 2019] Model execution and system simulation in Capella
 
Model Execution and System Simulation
Model Execution and System SimulationModel Execution and System Simulation
Model Execution and System Simulation
 
Microservices Architecture with Vortex — Part II
Microservices Architecture with Vortex — Part IIMicroservices Architecture with Vortex — Part II
Microservices Architecture with Vortex — Part II
 
Memento Pattern Implementation
Memento Pattern ImplementationMemento Pattern Implementation
Memento Pattern Implementation
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelines
 
L0537075
L0537075L0537075
L0537075
 
Write better, stronger, faster behat steps with ScenarioStateBehatExtension
Write better, stronger, faster behat steps with ScenarioStateBehatExtensionWrite better, stronger, faster behat steps with ScenarioStateBehatExtension
Write better, stronger, faster behat steps with ScenarioStateBehatExtension
 
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
 Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ... Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
Dataflows: The abstraction that powers Big Data by Raul Castro Fernandez at ...
 
Clone cloud
Clone cloudClone cloud
Clone cloud
 
Scalability truths and serverless architectures
Scalability truths and serverless architecturesScalability truths and serverless architectures
Scalability truths and serverless architectures
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
Introduction to simulation and modeling
Introduction to simulation and modelingIntroduction to simulation and modeling
Introduction to simulation and modeling
 
Trixboxguide
TrixboxguideTrixboxguide
Trixboxguide
 
State Pattern In Flex
State Pattern In FlexState Pattern In Flex
State Pattern In Flex
 
Traffic Simulator
Traffic SimulatorTraffic Simulator
Traffic Simulator
 
Towards Rapid Implementation of Adaptive Robotic Systems
Towards Rapid Implementation of Adaptive Robotic SystemsTowards Rapid Implementation of Adaptive Robotic Systems
Towards Rapid Implementation of Adaptive Robotic Systems
 
Formal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-BFormal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-B
 
Jmh
JmhJmh
Jmh
 

Plus de Sperasoft

особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4Sperasoft
 
концепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted Worldконцепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted WorldSperasoft
 
Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4Sperasoft
 
Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек Sperasoft
 
Gameplay Tags
Gameplay TagsGameplay Tags
Gameplay TagsSperasoft
 
Data Driven Gameplay in UE4
Data Driven Gameplay in UE4Data Driven Gameplay in UE4
Data Driven Gameplay in UE4Sperasoft
 
The theory of relational databases
The theory of relational databasesThe theory of relational databases
The theory of relational databasesSperasoft
 
Automated layout testing using Galen Framework
Automated layout testing using Galen FrameworkAutomated layout testing using Galen Framework
Automated layout testing using Galen FrameworkSperasoft
 
Sperasoft talks: Android Security Threats
Sperasoft talks: Android Security ThreatsSperasoft talks: Android Security Threats
Sperasoft talks: Android Security ThreatsSperasoft
 
Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft
 
Effective Мeetings
Effective МeetingsEffective Мeetings
Effective МeetingsSperasoft
 
Unreal Engine 4 Introduction
Unreal Engine 4 IntroductionUnreal Engine 4 Introduction
Unreal Engine 4 IntroductionSperasoft
 
JIRA Development
JIRA DevelopmentJIRA Development
JIRA DevelopmentSperasoft
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to ElasticsearchSperasoft
 
MOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JSMOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JSSperasoft
 
Quick Intro Into Kanban
Quick Intro Into KanbanQuick Intro Into Kanban
Quick Intro Into KanbanSperasoft
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
Console Development in 15 minutes
Console Development in 15 minutesConsole Development in 15 minutes
Console Development in 15 minutesSperasoft
 
Database Indexes
Database IndexesDatabase Indexes
Database IndexesSperasoft
 

Plus de Sperasoft (20)

особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4
 
концепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted Worldконцепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted World
 
Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4
 
Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек
 
Gameplay Tags
Gameplay TagsGameplay Tags
Gameplay Tags
 
Data Driven Gameplay in UE4
Data Driven Gameplay in UE4Data Driven Gameplay in UE4
Data Driven Gameplay in UE4
 
The theory of relational databases
The theory of relational databasesThe theory of relational databases
The theory of relational databases
 
Automated layout testing using Galen Framework
Automated layout testing using Galen FrameworkAutomated layout testing using Galen Framework
Automated layout testing using Galen Framework
 
Sperasoft talks: Android Security Threats
Sperasoft talks: Android Security ThreatsSperasoft talks: Android Security Threats
Sperasoft talks: Android Security Threats
 
Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on Android
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015
 
Effective Мeetings
Effective МeetingsEffective Мeetings
Effective Мeetings
 
Unreal Engine 4 Introduction
Unreal Engine 4 IntroductionUnreal Engine 4 Introduction
Unreal Engine 4 Introduction
 
JIRA Development
JIRA DevelopmentJIRA Development
JIRA Development
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
MOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JSMOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JS
 
Quick Intro Into Kanban
Quick Intro Into KanbanQuick Intro Into Kanban
Quick Intro Into Kanban
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
Console Development in 15 minutes
Console Development in 15 minutesConsole Development in 15 minutes
Console Development in 15 minutes
 
Database Indexes
Database IndexesDatabase Indexes
Database Indexes
 

Dernier

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Dernier (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Unity3D Scripting: State Machine

  • 2. Finite-State Machine Definition: This is a set of five elements: (Σ, Q, s ∈ Q, T ⊂ Q, δ : Q x Σ → Q) where Σ - the alphabet, Q - a set of states, s - the initial (start) state, T - the set of accepting states, δ - the transition function. A graph with a finite number of states (nodes) and a finite number of CMV transitions (curves).
  • 3. Two Questions How this system would help us in programming the game logic? How this approach is better than others?
  • 4. How To Use Behavior of the game object may be divided into a list of different actions: Starting State Target Searching Attack Death
  • 6. Generalization Any game component, whether a unit, or a menu based or an abstract game as a whole, which uses certain rules can be programmed by using a state machine.
  • 7. Advantages of State Machine 1. Divided, limited access to the context of state 2. Encapsulated logic for each state 3. Clarity, ability to upgrade code (source code customization) 4. Reliability
  • 8. Divided, Limited-Access Context State Each state controls only its own context and there is no need to check the set of variables for other states
  • 9. Logic Encapsulation for One State This allows you to quickly respond to errors that were found during testing, to localize them and make changes. At the same time this greatly reduced the likelihood of introducing errors into other states, because their context is not available, and their logic is elsewhere.
  • 10. Source Code Customization Behavior of the object becomes more classification-ruled and understandable. Behavior modernization takes less time and complexity associated with modifications is greatly reduced.
  • 11. Reliability Transition from one state to another occurs only in specific cases, to move from one state to another if it was not planned is not possible.
  • 12. Property of C #: Operator: “Yield" Operator: “Yield" ● "syntactic sugar" ● implement pattern: enumerator Is being used for: ● implementing collection ● dividing the methods in several steps
  • 13. Unity 3D - Specifications We will use several features Unity3D: ● Operator yield and pattern enumerator. ● Call for one of the standard object methods inherited from MonoBehaviour: - Update - FixedUpdate - Start, etc.
  • 14. Unity 3D - Specifications We need the following entities: ● States ● Manager, which manages the transition from one state to another ● Model - context of state machine, to which the state will call to perform a variety of actions.
  • 16. State. Description No need to restrict the user with inheritance. System is fairly abstract, to restrict certain properties of the state through the interface.
  • 18. States Manager: Explanation Key methods: ● Set the initial state ● Infinite state that calls the logic of the current status ● Cleanup
  • 20. Infinite Cycle. Clarification ● Possibility of correct completion ● Debug messages output ● Calling IState.Start (), IState.Cleanup (), IState.DoWork () methods ● Switch state with the help of Field NextGameState
  • 22. Awaiting Something Check one of the conditions, and if it does not suffice you pass control higher up and go back to check conditions at other times when the manager would transfer control method. This way you give a chance to any other logic to be executed in a single game flow (GAME THREAD), avoiding a whole bunch of problems related to multithreading.
  • 23. Methods For any application, we need a method to invoke the script cyclically inherited from MonoBehaviour: Update, FixedUpdate, LaterUpdate, etc. Depending on the task you should choose the right method and call it for update the state machine. Before you update the state machine it is necessary to perform the initial state install. This can be done easily in the Start or Awake methods.
  • 24. Model (context) Often there is a need preserve some information between the states was preserved some information - the context of state machine. This context could be a script that renews the state machine. It is possible to store certain flags and objects necessary for the states in this script. Also, this context may contain links to game resources and other game objects. So you pass a reference from state to state to this script. This approach will help to avoid a large number of singletons in the game.