Git Product home page Git Product logo

unileo-lite's Introduction

UniLeo - Unity Conversion Workflow for Leopotam ECS Lite

Easy convert GameObjects to Entity

Important! This repository is extension to Leopotam ECS Lite - Engine independent ECS that works with any Game Engine. But Unity Engineers often ask how to integrate Leo with Unity Inspector and deal with Prefabs. This lightweight repository is intended to help with this.

Thanks to SinyavtsevIlya and Leopotam

How to start

First you need to install Leopotam ECS Lite, you can do it with Unity Package Manager

Add new line to Packages/manifest.json

"com.leopotam.ecslite": "https://github.com/Leopotam/ecslite.git",

Second install this repository

"com.voody.unileo.lite": "https://github.com/voody2506/UniLeo-Lite.git",

Don't forget NameSpace

using Voody.UniLeo.Lite;

Create your first component

[Serializable] // <- Important to add Serializable attribute
public struct PlayerComponent {
    public float health;
}

Now you need to control health value within the Unity Inspector, but Unity Engine works only with MonoBehavior classes. Thats mean you need to create MonoBehavior Provider for our component.

Create new script with Mono provider.

public sealed class PlayerComponentProvider : MonoProvider<PlayerComponent> { }

Add PlayerComponentProvider into Inspector

Inspector Preview

Now you can control component values within the Inspector. Congratulations!

At this moment you can not control values from Inspector at Runtime

Choose conversion method

Convert And Inject - Just creates entitie with components based on GameObject

Convert And Destroy - Deletes GameObject after conversion

Convert And Save - Stores associated GameObject entity in ConvertToEntity Script

	// Than just get value from ConvertToEntity MonoBehavior
	if (ConvertToEntity.TryGetEntity().HasValue) {
	  ConvertToEntity.TryGetEntity().Value
	}
Set custom world

You can easily set custom World

Convert your GameObjects to Entity

If you read the Leo's documentation, you know that for successful work with Leo ECS, you should to create Startup ECS Monobehavior. To Automatically convert GameObjects to Entity add ConvertScene() method.

void Start() 
{
    _world = new  EcsWorld ();    
    _systems = new  EcsSystems (_world);
    _systems
        .ConvertScene() // <- Need to add this method
        .Add(new ExampleSystem())
        // Other ECS Systems   
        .Init(); 
 }

ConvertScene - method that automatically scan world, finds GameObjects with MonoProvider, creates entity and adds initial Components to the Entity.

Spawn Prefabs

GameObject.Instantiate(gameObject, position, rotation);
PhotonNetwork.Instantiate <- works in 3rd party Assets

Every Prefab initialize with new entity. Components will be added automatically

Please, add ConvertScene method after UnityEditor extension

#if UNITY_EDITOR
        // add debug systems for custom worlds here, for example:
        // .Add (new Leopotam.EcsLite.UnityEditor.EcsWorldDebugSystem ("events"))
        .Add (new Leopotam.EcsLite.UnityEditor.EcsWorldDebugSystem ())
#endif
        .ConvertScene() // <- Need to add this method

Thanks!

unileo-lite's People

Contributors

naamchan avatar voody2506 avatar yenmoc avatar

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.