GithubHelp home page GithubHelp logo

virtualmaestro / ecs-unityintegration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ivdstudios/ecs-unityintegration

0.0 1.0 0.0 92 KB

UnityEditor integration for LeoECS Entity Component System framework.

Home Page: https://leopotam.com

License: MIT License

C# 100.00%

ecs-unityintegration's Introduction

gitter license

Unity integration for Entity Component System framework

Unity integration for ECS framework.

Important! It's "structs-based" version, if you search "classes-based" version - check classes-based branch!

C#7.3 or above required for this framework.

Tested on unity 2019.1 (dependent on Unity engine) and contains assembly definition for compiling to separate assembly file for performance reason.

Dependent on ECS framework - ECS framework should be imported to unity project first.

Installation

As unity module

This repository can be installed as unity module directly from git url. In this way new line should be added to Packages/manifest.json:

"com.leopotam.ecs-unityintegration": "https://github.com/Leopotam/ecs-unityintegration.git",

By default last released version will be used. If you need trunk / developing version then develop name of branch should be added after hash:

"com.leopotam.ecs-unityintegration": "https://github.com/Leopotam/ecs-unityintegration.git#develop",

As source

If you can't / don't want to use unity modules, code can be downloaded as sources archive of required release from Releases page.

Editor integration

EcsWorld observer

Integration can be processed with one call of LeopotamGroup.Ecs.UnityIntegration.EcsWorldObserver.Create() metod - this call should be wrapped to #if UNITY_EDITOR preprocessor define:

public class Startup : MonoBehaviour {
    EcsSystems _systems;

    void Start () {
        var world = new EcsWorld ();
        
#if UNITY_EDITOR
        UnityIntegration.EcsWorldObserver.Create (world);
#endif  
        _systems = new EcsSystems(world)
            .Add (new RunSystem1());
            // Additional initialization here...
        _systems.Initialize ();
    }
}

Observer must be created before any entity will be created in ecs-world.

EcsSystems observer

Integration can be processed with one call of LeopotamGroup.Ecs.UnityIntegration.EcsSystemsObserver.Create() metod - this call should be wrapped to #if UNITY_EDITOR preprocessor define:

public class Startup : MonoBehaviour {
    EcsSystems _systems;

    void Start () {
        var world = new EcsWorld ();
        
#if UNITY_EDITOR
        UnityIntegration.EcsWorldObserver.Create (world);
#endif        
        _systems = new EcsSystems(world)
            .Add (new RunSystem1());
            // Additional initialization here...
        _systems.Initialize ();
#if UNITY_EDITOR
        UnityIntegration.EcsSystemsObserver.Create (_systems);
#endif
    }
}

FAQ

I can't edit component fields at any ecs-entity observer.

By design, observer works as readonly copy of ecs world data - you can copy value, but not change it.

I want to create custom inspector view for my component.

Custom component MyComponent1:

public enum MyEnum { True, False }

public class MyComponent1 {
    public MyEnum State;
    public string Name;
}

Inspector for MyComponent1 (should be placed in Editor folder):

class MyComponent1Inspector : IEcsComponentInspector {
    Type IEcsComponentInspector.GetFieldType () {
        return typeof (MyComponent1);
    }

    void IEcsComponentInspector.OnGUI (string label, object value, EcsWorld world, ref EcsEntity entityId) {
        var component = value as MyComponent1;
        EditorGUILayout.LabelField (label, EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        EditorGUILayout.EnumPopup ("State", component.State);
        EditorGUILayout.TextField ("Name", component.Name);
        EditorGUI.indentLevel--;
    }
}

License

The software released under the terms of the MIT license. Enjoy.

Donate

Its free opensource software, but you can buy me a coffee:

Buy Me A Coffee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.