Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dots-guide
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ojm3g19
dots-guide
Commits
c5efbe2c
Commit
c5efbe2c
authored
3 years ago
by
Oliver Mead
Browse files
Options
Downloads
Patches
Plain Diff
write about the entity model
parent
878ae044
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.org
+47
-0
47 additions, 0 deletions
README.org
with
47 additions
and
0 deletions
README.org
+
47
−
0
View file @
c5efbe2c
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
- [[#dots-packages][DOTS Packages]]
- [[#dots-packages][DOTS Packages]]
- [[#platform-packages][Platform Packages]]
- [[#platform-packages][Platform Packages]]
- [[#builds][Builds]]
- [[#builds][Builds]]
- [[#entities][Entities]]
* Preface, "Why?"
* Preface, "Why?"
Unity is in the midst of a transformation that will fundamentally change the way
Unity is in the midst of a transformation that will fundamentally change the way
...
@@ -56,3 +57,49 @@ platform through the asset manager:
...
@@ -56,3 +57,49 @@ platform through the asset manager:
From now on you must build the project by selecting this configuration and using
From now on you must build the project by selecting this configuration and using
the options shown in the inspector.
the options shown in the inspector.
* Entities
In the standard OOP model of game development, functionality is tied to
individual instances of objects. Each Monobehaviour (the class that from which
all standard scripts inherit) has its own ~Start()~, ~Update()~, similar and
accompanying methods. The engine will run all of these sequentially.
In this model, each game object is treated as a collection of data (the entity),
with this data organised into "components". These components are analogous to a
struct in C, they are mutable collections of data, they do not have their own
functionality in the form of methods.
It is the job of a =System= to read and transform the data of the entities. For
example you may have many entities with a ~Character~ component, each with an
~hp~ variable. This will include all players, enemies and NPCs. Characters may
be poisoned during the game, adding a ~Poison~ component to their entity. This
component will contain a value ~float rate~ to determine how much damage to deal
each second, and a ~float duration~ to determine how long the character will be
poisoned for.
You may define a ~StatusSystem~, which manages status effects (in this case
poisoning). It will operate on all of the entities with a ~Character~ /and/ a
~Poison~ component, and update the ~hp~ variable based on the data related to
the poison.
What will this look like? Within the StatusSystem's ~OnUpdate()~ method:
#+begin_src csharp :exports code
float dT = Time.DeltaTime;
Entities
.WithAll<Character, Poison>()
.ForEach(
// define the lambda that transforms the data
(ref Character ch, ref Poison poison, in Entity entity) => {
ch.hp -= poison.rate * dT;
poison.duration -= dT;
if (poison.duration <= 0) // remove the poison component if it has expired
EntityManager.RemoveComponent<Poison>(entity);
})
.ScheduleParallel();
#+end_src
Some keywords are used in the lambda definition that relate to C#'s implementation:
+ ~ref~ creates a mutable reference to the given argument
+ ~in~ creates an immutable reference to the argument (here we are not modifying
~entity~, only passing the reference to the ~EntityManager~ in order to remove
the component)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment