Comments (10)
Quote:
Designing levels
Let me explain, how I see this:
For me levels are just data - some configuration where things are and what their state is. E.g. a building at a certain position in the world that can be attacked and has a certain health.
I don't really care if I get this information from a json or a scene from Unity. In both cases I parse the source and create entities based on the data. In this example I'd create an Entity with BuildingComponent
, PositionComponent
, AttackableComponent
, HealthComponent
The cool thing is, when you're designing your level in Unity, you already have the view, too! So when you parse your scene you already can link the actual building GameObject to the Entity by adding a ViewComponent
public class ViewComponent : IComponent {
public GameObject gameObject;
}
Again: a designer is completely free to create a level. He/she can setup e.g. multiple buildings at different positions, with different health and so on... the important part is: All the Monobehaviours on that GameObject should NOT have any game related logic! Only configuration like transform, health, attackable, etc. They might have some View related logic like animating something on the building. The GameObject should be treated as a dumb view with no behaviour! It's just a View
from entitas.
Here is an example which I think combines the best of both ECS and Unity world.
From the race car example add this to cars you drop into the scene:
using UnityEngine; public class OpponentInScene : MonoBehaviour { public float speed; }
Then change the InitOpponentSystem to this:
`using Entitas;
using UnityEngine;
public sealed class InitOpponentsSystem : IInitializeSystem {
readonly GameContext _context;
public InitOpponentsSystem(Contexts contexts) {
_context = contexts.game;
}
public void Initialize() {
// scan scene and register opponents which already exist
var ops = GameObject.FindObjectsOfType<OpponentInScene>();
foreach (var o in ops) {
var e = _context.CreateEntity();
// e.AddAsset(resourceName);
e.AddView(o.gameObject);
e.AddPosition(o.transform.position.x, o.transform.position.y, o.transform.position.z);
e.AddMove(o.speed, o.speed);
}
//generate
const string resourceName = "Opponent";
for(int i = 1; i < 10; i++) {
var speed = Random.value * 0.02f;
var e = _context.CreateEntity();
e.AddAsset(resourceName);
e.AddPosition(i + i, 0, 0);
e.AddMove(speed, speed);
}
}
}
`
(sorry github ate my formatting, I'll figure it out eventually)
from entitas.
I invite you to visit the Entitas chat, where we just had discussions about this very topic:
https://gitter.im/sschmid/Entitas-CSharp
Alternatively click the "Join the chat" button in the readme
from entitas.
You might want to scroll up until you see my reply saying "Designing levels"
from entitas.
I might create a third example project soon to illustrate what I just wrote, since this is a question that already came up a few times.
from entitas.
That would be amazing 😄 Thanks again! Really enjoyed the talk! Did a fantastic job selling what you guys have to offer to the audience. Instantly fell in love.
from entitas.
I'm one of the persons who had the same question as you. I've made something that works for me currently which essentially scans through the scene at start for any gameobject with a Component container-MonoBehaviour and creates entities using the components specified in the container. The container only has a list of IComponents that I can add and edit using VFW (https://github.com/vexe/VFW). This does not work during runtime though, then I have to go to the entity pool and edit those components, I'm still thinking about how to solve that (or just make it easy to jump to the correct entity during runtime). I'm also curious to see @sschmid solution =)
from entitas.
@mzaks wrote a blog post addressing this question:
Games, Data and Entitas
from entitas.
I think there's a project that tries to solve this very problem: https://github.com/WoLfulus/Entitas-CSharp-VisualEditor
from entitas.
@goshki Haven't had time to update it to the last version of entitas though.
from entitas.
Related Issues (20)
- Unity crashes when clicking on a GameObject with Component of Entitas HOT 8
- Remove DesperateDevs dependencies
- [SOLVED] Unity 2022.3.4f1: Exceptions + broken inspector when looking at any entity HOT 16
- Add/Replace/Remove vs Set/Unset HOT 5
- Boolean in setttings for unique components to actually be unique
- A component with multiple contexts +events, only make event listeners for 1 context
- Could not resolve type with token ... expected class System.Threading.CancellationToken HOT 10
- How to generate codes in a project which has several csproj files? HOT 1
- Update on Entitas 2.0-beta and my situation HOT 3
- [1.14.1]code gen twice and compile error HOT 1
- there is a Error, on click Tools/Jenny/Gennerate, how can I do? HOT 4
- _group.GetEntities().AsParallel().ForAll(Execute);这段语句有GC HOT 2
- Is it feasible to use Entitas in the backend? HOT 7
- Entity Behaviour in Unity inspector not visible HOT 2
- Removal of crucial SearchPaths when executing the wiz command
- How to get all group in some context, without reflection。
- GUI Null ref when trying to view entity in inspector HOT 1
- generator issues HOT 1
- Error running dotnet Jenny/Jenny.Generator.Cli.dll gen -v command - System.IO.FileNotFoundException HOT 1
- Bro i want remove this how i remove
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entitas.