Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Designing levels in the editor and Entitas #13

Closed
TheLouisHong opened this issue Jul 30, 2015 · 10 comments
Closed

Designing levels in the editor and Entitas #13

TheLouisHong opened this issue Jul 30, 2015 · 10 comments
Labels

Comments

@TheLouisHong
Copy link

I saw you guy's UNITE talk and I'm so hyped for the framework. But I'm during the Q&A (48:27 into the talk) one person made a very valid point and that is the framework leaves the editor powerless. I saw your example project of cars and in the hierarchy there was game controller a camera and nothing else. One can't even change the position of the goal without changing code.

Since components are just data, isn't it possible to read data from anywhere? My idea is that maybe the code generator can generate placeholder MonoBehaviours. MonoBehaviours can be used by the designer to design. Then when the scene is run, add the placeholder entities to the pool with a start system that reads the data from the placeholder MonoBehaviour?

Thank you for making Entitas open source.

@TheLouisHong TheLouisHong changed the title Is place holder MonoBehaviour generated from CodeGenerator to achieve Is place holder MonoBehaviour generated from CodeGenerator possible? Jul 30, 2015
@TheLouisHong TheLouisHong changed the title Is place holder MonoBehaviour generated from CodeGenerator possible? Is place holder MonoBehaviour generated from CodeGenerator possible? Then we can have designers edit Entities from the editor. Jul 30, 2015
@sschmid
Copy link
Owner

sschmid commented Jul 30, 2015

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

@sschmid
Copy link
Owner

sschmid commented Jul 30, 2015

You might want to scroll up until you see my reply saying "Designing levels"

@sschmid
Copy link
Owner

sschmid commented Jul 30, 2015

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

@sschmid
Copy link
Owner

sschmid commented Jul 30, 2015

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.

@TheLouisHong
Copy link
Author

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.

@SvDvorak
Copy link

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 =)

@sschmid sschmid closed this as completed Jul 31, 2015
@sschmid sschmid changed the title Is place holder MonoBehaviour generated from CodeGenerator possible? Then we can have designers edit Entities from the editor. Designing levels in the editor and Entitas Aug 1, 2015
@sschmid
Copy link
Owner

sschmid commented Aug 1, 2015

@mzaks wrote a blog post addressing this question:
Games, Data and Entitas

@laurentopia
Copy link

laurentopia commented Feb 28, 2017

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)

@goshki
Copy link

goshki commented Feb 28, 2017

I think there's a project that tries to solve this very problem: https://github.com/WoLfulus/Entitas-CSharp-VisualEditor

@WoLfulus
Copy link

@goshki Haven't had time to update it to the last version of entitas though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

6 participants